readconf.c revision 1.18.2.2 1 1.18.2.2 pgoyette /* $NetBSD: readconf.c,v 1.18.2.2 2017/01/07 08:53:42 pgoyette Exp $ */
2 1.18.2.2 pgoyette /* $OpenBSD: readconf.c,v 1.262 2016/10/25 04:08:13 jsg Exp $ */
3 1.18.2.2 pgoyette
4 1.1 christos /*
5 1.1 christos * Author: Tatu Ylonen <ylo (at) cs.hut.fi>
6 1.1 christos * Copyright (c) 1995 Tatu Ylonen <ylo (at) cs.hut.fi>, Espoo, Finland
7 1.1 christos * All rights reserved
8 1.1 christos * Functions for reading the configuration files.
9 1.1 christos *
10 1.1 christos * As far as I am concerned, the code I have written for this software
11 1.1 christos * can be used freely for any purpose. Any derived versions of this
12 1.1 christos * software must be clearly marked as such, and if the derived work is
13 1.1 christos * incompatible with the protocol description in the RFC file, it must be
14 1.1 christos * called by a name other than "ssh" or "Secure Shell".
15 1.1 christos */
16 1.1 christos
17 1.2 christos #include "includes.h"
18 1.18.2.2 pgoyette __RCSID("$NetBSD: readconf.c,v 1.18.2.2 2017/01/07 08:53:42 pgoyette Exp $");
19 1.1 christos #include <sys/types.h>
20 1.1 christos #include <sys/stat.h>
21 1.1 christos #include <sys/socket.h>
22 1.12 christos #include <sys/wait.h>
23 1.12 christos #include <sys/un.h>
24 1.1 christos
25 1.1 christos #include <netinet/in.h>
26 1.5 christos #include <netinet/ip.h>
27 1.1 christos
28 1.1 christos #include <ctype.h>
29 1.1 christos #include <errno.h>
30 1.12 christos #include <fcntl.h>
31 1.18.2.1 pgoyette #include <glob.h>
32 1.1 christos #include <netdb.h>
33 1.12 christos #include <paths.h>
34 1.12 christos #include <pwd.h>
35 1.1 christos #include <signal.h>
36 1.1 christos #include <stdio.h>
37 1.1 christos #include <string.h>
38 1.1 christos #include <unistd.h>
39 1.2 christos #include <limits.h>
40 1.11 christos #include <util.h>
41 1.13 christos #include <vis.h>
42 1.1 christos
43 1.1 christos #include "xmalloc.h"
44 1.1 christos #include "ssh.h"
45 1.1 christos #include "compat.h"
46 1.1 christos #include "cipher.h"
47 1.1 christos #include "pathnames.h"
48 1.1 christos #include "log.h"
49 1.13 christos #include "sshkey.h"
50 1.12 christos #include "misc.h"
51 1.1 christos #include "readconf.h"
52 1.1 christos #include "match.h"
53 1.1 christos #include "kex.h"
54 1.1 christos #include "mac.h"
55 1.11 christos #include "fmt_scaled.h"
56 1.12 christos #include "uidswap.h"
57 1.13 christos #include "myproposal.h"
58 1.13 christos #include "digest.h"
59 1.1 christos
60 1.1 christos /* Format of the configuration file:
61 1.1 christos
62 1.1 christos # Configuration data is parsed as follows:
63 1.1 christos # 1. command line options
64 1.1 christos # 2. user-specific file
65 1.1 christos # 3. system-wide file
66 1.1 christos # Any configuration value is only changed the first time it is set.
67 1.1 christos # Thus, host-specific definitions should be at the beginning of the
68 1.1 christos # configuration file, and defaults at the end.
69 1.1 christos
70 1.1 christos # Host-specific declarations. These may override anything above. A single
71 1.1 christos # host may match multiple declarations; these are processed in the order
72 1.1 christos # that they are given in.
73 1.1 christos
74 1.1 christos Host *.ngs.fi ngs.fi
75 1.1 christos User foo
76 1.1 christos
77 1.1 christos Host fake.com
78 1.1 christos HostName another.host.name.real.org
79 1.1 christos User blaah
80 1.1 christos Port 34289
81 1.1 christos ForwardX11 no
82 1.1 christos ForwardAgent no
83 1.1 christos
84 1.1 christos Host books.com
85 1.1 christos RemoteForward 9999 shadows.cs.hut.fi:9999
86 1.1 christos Cipher 3des
87 1.1 christos
88 1.1 christos Host fascist.blob.com
89 1.1 christos Port 23123
90 1.1 christos User tylonen
91 1.1 christos PasswordAuthentication no
92 1.1 christos
93 1.1 christos Host puukko.hut.fi
94 1.1 christos User t35124p
95 1.1 christos ProxyCommand ssh-proxy %h %p
96 1.1 christos
97 1.1 christos Host *.fr
98 1.1 christos PublicKeyAuthentication no
99 1.1 christos
100 1.1 christos Host *.su
101 1.1 christos Cipher none
102 1.1 christos PasswordAuthentication no
103 1.1 christos
104 1.1 christos Host vpn.fake.com
105 1.1 christos Tunnel yes
106 1.1 christos TunnelDevice 3
107 1.1 christos
108 1.1 christos # Defaults for various options
109 1.1 christos Host *
110 1.1 christos ForwardAgent no
111 1.1 christos ForwardX11 no
112 1.1 christos PasswordAuthentication yes
113 1.1 christos RSAAuthentication yes
114 1.1 christos RhostsRSAAuthentication yes
115 1.1 christos StrictHostKeyChecking yes
116 1.1 christos TcpKeepAlive no
117 1.1 christos IdentityFile ~/.ssh/identity
118 1.1 christos Port 22
119 1.1 christos EscapeChar ~
120 1.1 christos
121 1.1 christos */
122 1.1 christos
123 1.18.2.1 pgoyette static int read_config_file_depth(const char *filename, struct passwd *pw,
124 1.18.2.1 pgoyette const char *host, const char *original_host, Options *options,
125 1.18.2.1 pgoyette int flags, int *activep, int depth);
126 1.18.2.1 pgoyette static int process_config_line_depth(Options *options, struct passwd *pw,
127 1.18.2.1 pgoyette const char *host, const char *original_host, char *line,
128 1.18.2.1 pgoyette const char *filename, int linenum, int *activep, int flags, int depth);
129 1.18.2.1 pgoyette
130 1.1 christos /* Keyword tokens. */
131 1.1 christos
132 1.1 christos typedef enum {
133 1.1 christos oBadOption,
134 1.18.2.1 pgoyette oHost, oMatch, oInclude,
135 1.4 adam oForwardAgent, oForwardX11, oForwardX11Trusted, oForwardX11Timeout,
136 1.4 adam oGatewayPorts, oExitOnForwardFailure,
137 1.1 christos oPasswordAuthentication, oRSAAuthentication,
138 1.1 christos oChallengeResponseAuthentication, oXAuthLocation,
139 1.2 christos #if defined(KRB4) || defined(KRB5)
140 1.2 christos oKerberosAuthentication,
141 1.2 christos #endif
142 1.2 christos #if defined(AFS) || defined(KRB5)
143 1.2 christos oKerberosTgtPassing,
144 1.2 christos #endif
145 1.2 christos #ifdef AFS
146 1.2 christos oAFSTokenPassing,
147 1.2 christos #endif
148 1.1 christos oIdentityFile, oHostName, oPort, oCipher, oRemoteForward, oLocalForward,
149 1.18.2.1 pgoyette oCertificateFile, oAddKeysToAgent, oIdentityAgent,
150 1.12 christos oUser, oEscapeChar, oRhostsRSAAuthentication, oProxyCommand,
151 1.1 christos oGlobalKnownHostsFile, oUserKnownHostsFile, oConnectionAttempts,
152 1.1 christos oBatchMode, oCheckHostIP, oStrictHostKeyChecking, oCompression,
153 1.1 christos oCompressionLevel, oTCPKeepAlive, oNumberOfPasswordPrompts,
154 1.1 christos oUsePrivilegedPort, oLogLevel, oCiphers, oProtocol, oMacs,
155 1.13 christos oPubkeyAuthentication,
156 1.1 christos oKbdInteractiveAuthentication, oKbdInteractiveDevices, oHostKeyAlias,
157 1.1 christos oDynamicForward, oPreferredAuthentications, oHostbasedAuthentication,
158 1.4 adam oHostKeyAlgorithms, oBindAddress, oPKCS11Provider,
159 1.1 christos oClearAllForwardings, oNoHostAuthenticationForLocalhost,
160 1.1 christos oEnableSSHKeysign, oRekeyLimit, oVerifyHostKeyDNS, oConnectTimeout,
161 1.1 christos oAddressFamily, oGssAuthentication, oGssDelegateCreds,
162 1.1 christos oServerAliveInterval, oServerAliveCountMax, oIdentitiesOnly,
163 1.4 adam oSendEnv, oControlPath, oControlMaster, oControlPersist,
164 1.4 adam oHashKnownHosts,
165 1.1 christos oTunnel, oTunnelDevice, oLocalCommand, oPermitLocalCommand,
166 1.17 christos oVisualHostKey,
167 1.12 christos oKexAlgorithms, oIPQoS, oRequestTTY, oIgnoreUnknown, oProxyUseFdpass,
168 1.12 christos oCanonicalDomains, oCanonicalizeHostname, oCanonicalizeMaxDots,
169 1.12 christos oCanonicalizeFallbackLocal, oCanonicalizePermittedCNAMEs,
170 1.13 christos oStreamLocalBindMask, oStreamLocalBindUnlink, oRevokedHostKeys,
171 1.13 christos oFingerprintHash, oUpdateHostkeys, oHostbasedKeyTypes,
172 1.18.2.1 pgoyette oPubkeyAcceptedKeyTypes, oProxyJump,
173 1.2 christos oNoneEnabled, oTcpRcvBufPoll, oTcpRcvBuf, oNoneSwitch, oHPNDisabled,
174 1.2 christos oHPNBufferSize,
175 1.7 tls oSendVersionFirst,
176 1.12 christos oIgnoredUnknownOption, oDeprecated, oUnsupported
177 1.1 christos } OpCodes;
178 1.1 christos
179 1.1 christos /* Textual representations of the tokens. */
180 1.1 christos
181 1.1 christos static struct {
182 1.1 christos const char *name;
183 1.1 christos OpCodes opcode;
184 1.1 christos } keywords[] = {
185 1.1 christos { "forwardagent", oForwardAgent },
186 1.1 christos { "forwardx11", oForwardX11 },
187 1.1 christos { "forwardx11trusted", oForwardX11Trusted },
188 1.4 adam { "forwardx11timeout", oForwardX11Timeout },
189 1.1 christos { "exitonforwardfailure", oExitOnForwardFailure },
190 1.1 christos { "xauthlocation", oXAuthLocation },
191 1.1 christos { "gatewayports", oGatewayPorts },
192 1.1 christos { "useprivilegedport", oUsePrivilegedPort },
193 1.1 christos { "rhostsauthentication", oDeprecated },
194 1.1 christos { "passwordauthentication", oPasswordAuthentication },
195 1.1 christos { "kbdinteractiveauthentication", oKbdInteractiveAuthentication },
196 1.1 christos { "kbdinteractivedevices", oKbdInteractiveDevices },
197 1.1 christos { "rsaauthentication", oRSAAuthentication },
198 1.1 christos { "pubkeyauthentication", oPubkeyAuthentication },
199 1.1 christos { "dsaauthentication", oPubkeyAuthentication }, /* alias */
200 1.1 christos { "rhostsrsaauthentication", oRhostsRSAAuthentication },
201 1.1 christos { "hostbasedauthentication", oHostbasedAuthentication },
202 1.1 christos { "challengeresponseauthentication", oChallengeResponseAuthentication },
203 1.1 christos { "skeyauthentication", oChallengeResponseAuthentication }, /* alias */
204 1.1 christos { "tisauthentication", oChallengeResponseAuthentication }, /* alias */
205 1.2 christos #if defined(KRB4) || defined(KRB5)
206 1.2 christos { "kerberosauthentication", oKerberosAuthentication },
207 1.2 christos #endif
208 1.2 christos #if defined(AFS) || defined(KRB5)
209 1.2 christos { "kerberostgtpassing", oKerberosTgtPassing },
210 1.2 christos { "kerberos5tgtpassing", oKerberosTgtPassing }, /* alias */
211 1.2 christos { "kerberos4tgtpassing", oKerberosTgtPassing }, /* alias */
212 1.2 christos #endif
213 1.2 christos #ifdef AFS
214 1.2 christos { "afstokenpassing", oAFSTokenPassing },
215 1.2 christos #endif
216 1.1 christos #if defined(GSSAPI)
217 1.1 christos { "gssapiauthentication", oGssAuthentication },
218 1.1 christos { "gssapidelegatecredentials", oGssDelegateCreds },
219 1.1 christos #else
220 1.1 christos { "gssapiauthentication", oUnsupported },
221 1.1 christos { "gssapidelegatecredentials", oUnsupported },
222 1.1 christos #endif
223 1.1 christos { "fallbacktorsh", oDeprecated },
224 1.1 christos { "usersh", oDeprecated },
225 1.1 christos { "identityfile", oIdentityFile },
226 1.1 christos { "identityfile2", oIdentityFile }, /* obsolete */
227 1.1 christos { "identitiesonly", oIdentitiesOnly },
228 1.18 christos { "certificatefile", oCertificateFile },
229 1.18 christos { "addkeystoagent", oAddKeysToAgent },
230 1.18.2.1 pgoyette { "identityagent", oIdentityAgent },
231 1.1 christos { "hostname", oHostName },
232 1.1 christos { "hostkeyalias", oHostKeyAlias },
233 1.1 christos { "proxycommand", oProxyCommand },
234 1.1 christos { "port", oPort },
235 1.1 christos { "cipher", oCipher },
236 1.1 christos { "ciphers", oCiphers },
237 1.1 christos { "macs", oMacs },
238 1.1 christos { "protocol", oProtocol },
239 1.1 christos { "remoteforward", oRemoteForward },
240 1.1 christos { "localforward", oLocalForward },
241 1.1 christos { "user", oUser },
242 1.1 christos { "host", oHost },
243 1.12 christos { "match", oMatch },
244 1.1 christos { "escapechar", oEscapeChar },
245 1.1 christos { "globalknownhostsfile", oGlobalKnownHostsFile },
246 1.6 christos { "globalknownhostsfile2", oDeprecated },
247 1.1 christos { "userknownhostsfile", oUserKnownHostsFile },
248 1.13 christos { "userknownhostsfile2", oDeprecated },
249 1.1 christos { "connectionattempts", oConnectionAttempts },
250 1.1 christos { "batchmode", oBatchMode },
251 1.1 christos { "checkhostip", oCheckHostIP },
252 1.1 christos { "stricthostkeychecking", oStrictHostKeyChecking },
253 1.1 christos { "compression", oCompression },
254 1.1 christos { "compressionlevel", oCompressionLevel },
255 1.1 christos { "tcpkeepalive", oTCPKeepAlive },
256 1.1 christos { "keepalive", oTCPKeepAlive }, /* obsolete */
257 1.1 christos { "numberofpasswordprompts", oNumberOfPasswordPrompts },
258 1.1 christos { "loglevel", oLogLevel },
259 1.1 christos { "dynamicforward", oDynamicForward },
260 1.1 christos { "preferredauthentications", oPreferredAuthentications },
261 1.1 christos { "hostkeyalgorithms", oHostKeyAlgorithms },
262 1.1 christos { "bindaddress", oBindAddress },
263 1.4 adam #ifdef ENABLE_PKCS11
264 1.4 adam { "smartcarddevice", oPKCS11Provider },
265 1.4 adam { "pkcs11provider", oPKCS11Provider },
266 1.1 christos #else
267 1.1 christos { "smartcarddevice", oUnsupported },
268 1.4 adam { "pkcs11provider", oUnsupported },
269 1.1 christos #endif
270 1.1 christos { "clearallforwardings", oClearAllForwardings },
271 1.1 christos { "enablesshkeysign", oEnableSSHKeysign },
272 1.1 christos { "verifyhostkeydns", oVerifyHostKeyDNS },
273 1.1 christos { "nohostauthenticationforlocalhost", oNoHostAuthenticationForLocalhost },
274 1.1 christos { "rekeylimit", oRekeyLimit },
275 1.1 christos { "connecttimeout", oConnectTimeout },
276 1.1 christos { "addressfamily", oAddressFamily },
277 1.1 christos { "serveraliveinterval", oServerAliveInterval },
278 1.1 christos { "serveralivecountmax", oServerAliveCountMax },
279 1.1 christos { "sendenv", oSendEnv },
280 1.1 christos { "controlpath", oControlPath },
281 1.1 christos { "controlmaster", oControlMaster },
282 1.4 adam { "controlpersist", oControlPersist },
283 1.1 christos { "hashknownhosts", oHashKnownHosts },
284 1.18.2.1 pgoyette { "include", oInclude },
285 1.1 christos { "tunnel", oTunnel },
286 1.1 christos { "tunneldevice", oTunnelDevice },
287 1.1 christos { "localcommand", oLocalCommand },
288 1.1 christos { "permitlocalcommand", oPermitLocalCommand },
289 1.1 christos { "visualhostkey", oVisualHostKey },
290 1.18 christos { "useroaming", oDeprecated },
291 1.5 christos { "kexalgorithms", oKexAlgorithms },
292 1.5 christos { "ipqos", oIPQoS },
293 1.6 christos { "requesttty", oRequestTTY },
294 1.12 christos { "proxyusefdpass", oProxyUseFdpass },
295 1.12 christos { "canonicaldomains", oCanonicalDomains },
296 1.12 christos { "canonicalizefallbacklocal", oCanonicalizeFallbackLocal },
297 1.12 christos { "canonicalizehostname", oCanonicalizeHostname },
298 1.12 christos { "canonicalizemaxdots", oCanonicalizeMaxDots },
299 1.12 christos { "canonicalizepermittedcnames", oCanonicalizePermittedCNAMEs },
300 1.12 christos { "streamlocalbindmask", oStreamLocalBindMask },
301 1.12 christos { "streamlocalbindunlink", oStreamLocalBindUnlink },
302 1.13 christos { "revokedhostkeys", oRevokedHostKeys },
303 1.13 christos { "fingerprinthash", oFingerprintHash },
304 1.13 christos { "updatehostkeys", oUpdateHostkeys },
305 1.13 christos { "hostbasedkeytypes", oHostbasedKeyTypes },
306 1.16 christos { "pubkeyacceptedkeytypes", oPubkeyAcceptedKeyTypes },
307 1.18.2.1 pgoyette { "proxyjump", oProxyJump },
308 1.2 christos { "noneenabled", oNoneEnabled },
309 1.2 christos { "tcprcvbufpoll", oTcpRcvBufPoll },
310 1.2 christos { "tcprcvbuf", oTcpRcvBuf },
311 1.2 christos { "noneswitch", oNoneSwitch },
312 1.2 christos { "hpndisabled", oHPNDisabled },
313 1.2 christos { "hpnbuffersize", oHPNBufferSize },
314 1.7 tls { "sendversionfirst", oSendVersionFirst },
315 1.12 christos { "ignoreunknown", oIgnoreUnknown },
316 1.18.2.1 pgoyette
317 1.1 christos { NULL, oBadOption }
318 1.1 christos };
319 1.1 christos
320 1.1 christos /*
321 1.1 christos * Adds a local TCP/IP port forward to options. Never returns if there is an
322 1.1 christos * error.
323 1.1 christos */
324 1.1 christos
325 1.1 christos void
326 1.12 christos add_local_forward(Options *options, const struct Forward *newfwd)
327 1.1 christos {
328 1.12 christos struct Forward *fwd;
329 1.1 christos extern uid_t original_real_uid;
330 1.18.2.1 pgoyette int i;
331 1.4 adam
332 1.18.2.2 pgoyette if (!bind_permitted(newfwd->listen_port, original_real_uid) &&
333 1.12 christos newfwd->listen_path == NULL)
334 1.1 christos fatal("Privileged ports can only be forwarded by root.");
335 1.18.2.1 pgoyette /* Don't add duplicates */
336 1.18.2.1 pgoyette for (i = 0; i < options->num_local_forwards; i++) {
337 1.18.2.1 pgoyette if (forward_equals(newfwd, options->local_forwards + i))
338 1.18.2.1 pgoyette return;
339 1.18.2.1 pgoyette }
340 1.14 christos options->local_forwards = xreallocarray(options->local_forwards,
341 1.4 adam options->num_local_forwards + 1,
342 1.4 adam sizeof(*options->local_forwards));
343 1.1 christos fwd = &options->local_forwards[options->num_local_forwards++];
344 1.1 christos
345 1.1 christos fwd->listen_host = newfwd->listen_host;
346 1.1 christos fwd->listen_port = newfwd->listen_port;
347 1.12 christos fwd->listen_path = newfwd->listen_path;
348 1.1 christos fwd->connect_host = newfwd->connect_host;
349 1.1 christos fwd->connect_port = newfwd->connect_port;
350 1.12 christos fwd->connect_path = newfwd->connect_path;
351 1.1 christos }
352 1.1 christos
353 1.1 christos /*
354 1.1 christos * Adds a remote TCP/IP port forward to options. Never returns if there is
355 1.1 christos * an error.
356 1.1 christos */
357 1.1 christos
358 1.1 christos void
359 1.12 christos add_remote_forward(Options *options, const struct Forward *newfwd)
360 1.1 christos {
361 1.12 christos struct Forward *fwd;
362 1.18.2.1 pgoyette int i;
363 1.4 adam
364 1.18.2.1 pgoyette /* Don't add duplicates */
365 1.18.2.1 pgoyette for (i = 0; i < options->num_remote_forwards; i++) {
366 1.18.2.1 pgoyette if (forward_equals(newfwd, options->remote_forwards + i))
367 1.18.2.1 pgoyette return;
368 1.18.2.1 pgoyette }
369 1.14 christos options->remote_forwards = xreallocarray(options->remote_forwards,
370 1.4 adam options->num_remote_forwards + 1,
371 1.4 adam sizeof(*options->remote_forwards));
372 1.1 christos fwd = &options->remote_forwards[options->num_remote_forwards++];
373 1.1 christos
374 1.1 christos fwd->listen_host = newfwd->listen_host;
375 1.1 christos fwd->listen_port = newfwd->listen_port;
376 1.12 christos fwd->listen_path = newfwd->listen_path;
377 1.1 christos fwd->connect_host = newfwd->connect_host;
378 1.1 christos fwd->connect_port = newfwd->connect_port;
379 1.12 christos fwd->connect_path = newfwd->connect_path;
380 1.8 christos fwd->handle = newfwd->handle;
381 1.4 adam fwd->allocated_port = 0;
382 1.1 christos }
383 1.1 christos
384 1.1 christos static void
385 1.1 christos clear_forwardings(Options *options)
386 1.1 christos {
387 1.1 christos int i;
388 1.1 christos
389 1.1 christos for (i = 0; i < options->num_local_forwards; i++) {
390 1.11 christos free(options->local_forwards[i].listen_host);
391 1.12 christos free(options->local_forwards[i].listen_path);
392 1.11 christos free(options->local_forwards[i].connect_host);
393 1.12 christos free(options->local_forwards[i].connect_path);
394 1.1 christos }
395 1.4 adam if (options->num_local_forwards > 0) {
396 1.11 christos free(options->local_forwards);
397 1.4 adam options->local_forwards = NULL;
398 1.4 adam }
399 1.1 christos options->num_local_forwards = 0;
400 1.1 christos for (i = 0; i < options->num_remote_forwards; i++) {
401 1.11 christos free(options->remote_forwards[i].listen_host);
402 1.12 christos free(options->remote_forwards[i].listen_path);
403 1.11 christos free(options->remote_forwards[i].connect_host);
404 1.12 christos free(options->remote_forwards[i].connect_path);
405 1.1 christos }
406 1.4 adam if (options->num_remote_forwards > 0) {
407 1.11 christos free(options->remote_forwards);
408 1.4 adam options->remote_forwards = NULL;
409 1.4 adam }
410 1.1 christos options->num_remote_forwards = 0;
411 1.1 christos options->tun_open = SSH_TUNMODE_NO;
412 1.1 christos }
413 1.1 christos
414 1.9 mlelstv void
415 1.18 christos add_certificate_file(Options *options, const char *path, int userprovided)
416 1.18 christos {
417 1.18 christos int i;
418 1.18 christos
419 1.18 christos if (options->num_certificate_files >= SSH_MAX_CERTIFICATE_FILES)
420 1.18 christos fatal("Too many certificate files specified (max %d)",
421 1.18 christos SSH_MAX_CERTIFICATE_FILES);
422 1.18 christos
423 1.18 christos /* Avoid registering duplicates */
424 1.18 christos for (i = 0; i < options->num_certificate_files; i++) {
425 1.18 christos if (options->certificate_file_userprovided[i] == userprovided &&
426 1.18 christos strcmp(options->certificate_files[i], path) == 0) {
427 1.18 christos debug2("%s: ignoring duplicate key %s", __func__, path);
428 1.18 christos return;
429 1.18 christos }
430 1.18 christos }
431 1.18 christos
432 1.18 christos options->certificate_file_userprovided[options->num_certificate_files] =
433 1.18 christos userprovided;
434 1.18 christos options->certificate_files[options->num_certificate_files++] =
435 1.18 christos xstrdup(path);
436 1.18 christos }
437 1.18 christos
438 1.18 christos void
439 1.9 mlelstv add_identity_file(Options *options, const char *dir, const char *filename,
440 1.9 mlelstv int userprovided)
441 1.9 mlelstv {
442 1.9 mlelstv char *path;
443 1.12 christos int i;
444 1.9 mlelstv
445 1.9 mlelstv if (options->num_identity_files >= SSH_MAX_IDENTITY_FILES)
446 1.9 mlelstv fatal("Too many identity files specified (max %d)",
447 1.9 mlelstv SSH_MAX_IDENTITY_FILES);
448 1.9 mlelstv
449 1.9 mlelstv if (dir == NULL) /* no dir, filename is absolute */
450 1.9 mlelstv path = xstrdup(filename);
451 1.9 mlelstv else
452 1.9 mlelstv (void)xasprintf(&path, "%.100s%.100s", dir, filename);
453 1.9 mlelstv
454 1.12 christos /* Avoid registering duplicates */
455 1.12 christos for (i = 0; i < options->num_identity_files; i++) {
456 1.12 christos if (options->identity_file_userprovided[i] == userprovided &&
457 1.12 christos strcmp(options->identity_files[i], path) == 0) {
458 1.12 christos debug2("%s: ignoring duplicate key %s", __func__, path);
459 1.12 christos free(path);
460 1.12 christos return;
461 1.12 christos }
462 1.12 christos }
463 1.12 christos
464 1.9 mlelstv options->identity_file_userprovided[options->num_identity_files] =
465 1.9 mlelstv userprovided;
466 1.9 mlelstv options->identity_files[options->num_identity_files++] = path;
467 1.9 mlelstv }
468 1.9 mlelstv
469 1.12 christos int
470 1.12 christos default_ssh_port(void)
471 1.12 christos {
472 1.12 christos static int port;
473 1.12 christos struct servent *sp;
474 1.12 christos
475 1.12 christos if (port == 0) {
476 1.12 christos sp = getservbyname(SSH_SERVICE_NAME, "tcp");
477 1.12 christos port = sp ? ntohs(sp->s_port) : SSH_DEFAULT_PORT;
478 1.12 christos }
479 1.12 christos return port;
480 1.12 christos }
481 1.12 christos
482 1.12 christos /*
483 1.12 christos * Execute a command in a shell.
484 1.12 christos * Return its exit status or -1 on abnormal exit.
485 1.12 christos */
486 1.12 christos static int
487 1.12 christos execute_in_shell(const char *cmd)
488 1.12 christos {
489 1.12 christos const char *shell;
490 1.12 christos pid_t pid;
491 1.12 christos int devnull, status;
492 1.12 christos extern uid_t original_real_uid;
493 1.12 christos
494 1.12 christos if ((shell = getenv("SHELL")) == NULL)
495 1.12 christos shell = _PATH_BSHELL;
496 1.12 christos
497 1.12 christos /* Need this to redirect subprocess stdin/out */
498 1.12 christos if ((devnull = open(_PATH_DEVNULL, O_RDWR)) == -1)
499 1.12 christos fatal("open(/dev/null): %s", strerror(errno));
500 1.12 christos
501 1.12 christos debug("Executing command: '%.500s'", cmd);
502 1.12 christos
503 1.12 christos /* Fork and execute the command. */
504 1.12 christos if ((pid = fork()) == 0) {
505 1.12 christos char *argv[4];
506 1.12 christos
507 1.12 christos /* Child. Permanently give up superuser privileges. */
508 1.12 christos permanently_drop_suid(original_real_uid);
509 1.12 christos
510 1.12 christos /* Redirect child stdin and stdout. Leave stderr */
511 1.12 christos if (dup2(devnull, STDIN_FILENO) == -1)
512 1.12 christos fatal("dup2: %s", strerror(errno));
513 1.12 christos if (dup2(devnull, STDOUT_FILENO) == -1)
514 1.12 christos fatal("dup2: %s", strerror(errno));
515 1.12 christos if (devnull > STDERR_FILENO)
516 1.12 christos close(devnull);
517 1.15 christos if (closefrom(STDERR_FILENO + 1) == -1)
518 1.15 christos fatal("closefrom: %s", strerror(errno));
519 1.12 christos
520 1.12 christos argv[0] = __UNCONST(shell);
521 1.12 christos argv[1] = __UNCONST("-c");
522 1.18 christos argv[2] = xstrdup(cmd);
523 1.12 christos argv[3] = NULL;
524 1.12 christos
525 1.12 christos execv(argv[0], argv);
526 1.12 christos error("Unable to execute '%.100s': %s", cmd, strerror(errno));
527 1.12 christos /* Die with signal to make this error apparent to parent. */
528 1.12 christos signal(SIGTERM, SIG_DFL);
529 1.12 christos kill(getpid(), SIGTERM);
530 1.12 christos _exit(1);
531 1.12 christos }
532 1.12 christos /* Parent. */
533 1.12 christos if (pid < 0)
534 1.12 christos fatal("%s: fork: %.100s", __func__, strerror(errno));
535 1.12 christos
536 1.12 christos close(devnull);
537 1.12 christos
538 1.12 christos while (waitpid(pid, &status, 0) == -1) {
539 1.12 christos if (errno != EINTR && errno != EAGAIN)
540 1.12 christos fatal("%s: waitpid: %s", __func__, strerror(errno));
541 1.12 christos }
542 1.12 christos if (!WIFEXITED(status)) {
543 1.12 christos error("command '%.100s' exited abnormally", cmd);
544 1.12 christos return -1;
545 1.13 christos }
546 1.12 christos debug3("command returned status %d", WEXITSTATUS(status));
547 1.12 christos return WEXITSTATUS(status);
548 1.12 christos }
549 1.12 christos
550 1.12 christos /*
551 1.12 christos * Parse and execute a Match directive.
552 1.12 christos */
553 1.12 christos static int
554 1.12 christos match_cfg_line(Options *options, char **condition, struct passwd *pw,
555 1.13 christos const char *host_arg, const char *original_host, int post_canon,
556 1.13 christos const char *filename, int linenum)
557 1.12 christos {
558 1.13 christos char *arg, *oattrib, *attrib, *cmd, *cp = *condition, *host, *criteria;
559 1.12 christos const char *ruser;
560 1.13 christos int r, port, this_result, result = 1, attributes = 0, negate;
561 1.12 christos char thishost[NI_MAXHOST], shorthost[NI_MAXHOST], portstr[NI_MAXSERV];
562 1.12 christos
563 1.12 christos /*
564 1.12 christos * Configuration is likely to be incomplete at this point so we
565 1.12 christos * must be prepared to use default values.
566 1.12 christos */
567 1.12 christos port = options->port <= 0 ? default_ssh_port() : options->port;
568 1.12 christos ruser = options->user == NULL ? pw->pw_name : options->user;
569 1.18 christos if (post_canon) {
570 1.18 christos host = xstrdup(options->hostname);
571 1.18 christos } else if (options->hostname != NULL) {
572 1.12 christos /* NB. Please keep in sync with ssh.c:main() */
573 1.12 christos host = percent_expand(options->hostname,
574 1.12 christos "h", host_arg, (char *)NULL);
575 1.18 christos } else {
576 1.12 christos host = xstrdup(host_arg);
577 1.18 christos }
578 1.12 christos
579 1.13 christos debug2("checking match for '%s' host %s originally %s",
580 1.13 christos cp, host, original_host);
581 1.13 christos while ((oattrib = attrib = strdelim(&cp)) && *attrib != '\0') {
582 1.13 christos criteria = NULL;
583 1.13 christos this_result = 1;
584 1.13 christos if ((negate = attrib[0] == '!'))
585 1.13 christos attrib++;
586 1.13 christos /* criteria "all" and "canonical" have no argument */
587 1.12 christos if (strcasecmp(attrib, "all") == 0) {
588 1.13 christos if (attributes > 1 ||
589 1.12 christos ((arg = strdelim(&cp)) != NULL && *arg != '\0')) {
590 1.13 christos error("%.200s line %d: '%s' cannot be combined "
591 1.13 christos "with other Match attributes",
592 1.13 christos filename, linenum, oattrib);
593 1.12 christos result = -1;
594 1.12 christos goto out;
595 1.12 christos }
596 1.13 christos if (result)
597 1.13 christos result = negate ? 0 : 1;
598 1.12 christos goto out;
599 1.12 christos }
600 1.13 christos attributes++;
601 1.13 christos if (strcasecmp(attrib, "canonical") == 0) {
602 1.13 christos r = !!post_canon; /* force bitmask member to boolean */
603 1.13 christos if (r == (negate ? 1 : 0))
604 1.13 christos this_result = result = 0;
605 1.13 christos debug3("%.200s line %d: %smatched '%s'",
606 1.13 christos filename, linenum,
607 1.13 christos this_result ? "" : "not ", oattrib);
608 1.13 christos continue;
609 1.13 christos }
610 1.13 christos /* All other criteria require an argument */
611 1.12 christos if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
612 1.12 christos error("Missing Match criteria for %s", attrib);
613 1.12 christos result = -1;
614 1.12 christos goto out;
615 1.12 christos }
616 1.12 christos if (strcasecmp(attrib, "host") == 0) {
617 1.13 christos criteria = xstrdup(host);
618 1.14 christos r = match_hostname(host, arg) == 1;
619 1.13 christos if (r == (negate ? 1 : 0))
620 1.13 christos this_result = result = 0;
621 1.12 christos } else if (strcasecmp(attrib, "originalhost") == 0) {
622 1.13 christos criteria = xstrdup(original_host);
623 1.14 christos r = match_hostname(original_host, arg) == 1;
624 1.13 christos if (r == (negate ? 1 : 0))
625 1.13 christos this_result = result = 0;
626 1.12 christos } else if (strcasecmp(attrib, "user") == 0) {
627 1.13 christos criteria = xstrdup(ruser);
628 1.14 christos r = match_pattern_list(ruser, arg, 0) == 1;
629 1.13 christos if (r == (negate ? 1 : 0))
630 1.13 christos this_result = result = 0;
631 1.12 christos } else if (strcasecmp(attrib, "localuser") == 0) {
632 1.13 christos criteria = xstrdup(pw->pw_name);
633 1.14 christos r = match_pattern_list(pw->pw_name, arg, 0) == 1;
634 1.13 christos if (r == (negate ? 1 : 0))
635 1.13 christos this_result = result = 0;
636 1.12 christos } else if (strcasecmp(attrib, "exec") == 0) {
637 1.12 christos if (gethostname(thishost, sizeof(thishost)) == -1)
638 1.12 christos fatal("gethostname: %s", strerror(errno));
639 1.12 christos strlcpy(shorthost, thishost, sizeof(shorthost));
640 1.12 christos shorthost[strcspn(thishost, ".")] = '\0';
641 1.12 christos snprintf(portstr, sizeof(portstr), "%d", port);
642 1.12 christos
643 1.12 christos cmd = percent_expand(arg,
644 1.12 christos "L", shorthost,
645 1.12 christos "d", pw->pw_dir,
646 1.12 christos "h", host,
647 1.12 christos "l", thishost,
648 1.13 christos "n", original_host,
649 1.12 christos "p", portstr,
650 1.12 christos "r", ruser,
651 1.12 christos "u", pw->pw_name,
652 1.12 christos (char *)NULL);
653 1.12 christos if (result != 1) {
654 1.12 christos /* skip execution if prior predicate failed */
655 1.13 christos debug3("%.200s line %d: skipped exec "
656 1.13 christos "\"%.100s\"", filename, linenum, cmd);
657 1.13 christos free(cmd);
658 1.13 christos continue;
659 1.13 christos }
660 1.13 christos r = execute_in_shell(cmd);
661 1.13 christos if (r == -1) {
662 1.13 christos fatal("%.200s line %d: match exec "
663 1.13 christos "'%.100s' error", filename,
664 1.13 christos linenum, cmd);
665 1.12 christos }
666 1.13 christos criteria = xstrdup(cmd);
667 1.12 christos free(cmd);
668 1.13 christos /* Force exit status to boolean */
669 1.13 christos r = r == 0;
670 1.13 christos if (r == (negate ? 1 : 0))
671 1.13 christos this_result = result = 0;
672 1.12 christos } else {
673 1.12 christos error("Unsupported Match attribute %s", attrib);
674 1.12 christos result = -1;
675 1.12 christos goto out;
676 1.12 christos }
677 1.13 christos debug3("%.200s line %d: %smatched '%s \"%.100s\"' ",
678 1.13 christos filename, linenum, this_result ? "": "not ",
679 1.13 christos oattrib, criteria);
680 1.13 christos free(criteria);
681 1.12 christos }
682 1.12 christos if (attributes == 0) {
683 1.12 christos error("One or more attributes required for Match");
684 1.12 christos result = -1;
685 1.12 christos goto out;
686 1.12 christos }
687 1.13 christos out:
688 1.13 christos if (result != -1)
689 1.13 christos debug2("match %sfound", result ? "" : "not ");
690 1.12 christos *condition = cp;
691 1.12 christos free(host);
692 1.12 christos return result;
693 1.12 christos }
694 1.12 christos
695 1.12 christos /* Check and prepare a domain name: removes trailing '.' and lowercases */
696 1.12 christos static void
697 1.12 christos valid_domain(char *name, const char *filename, int linenum)
698 1.12 christos {
699 1.12 christos size_t i, l = strlen(name);
700 1.12 christos u_char c, last = '\0';
701 1.12 christos
702 1.12 christos if (l == 0)
703 1.12 christos fatal("%s line %d: empty hostname suffix", filename, linenum);
704 1.12 christos if (!isalpha((u_char)name[0]) && !isdigit((u_char)name[0]))
705 1.12 christos fatal("%s line %d: hostname suffix \"%.100s\" "
706 1.12 christos "starts with invalid character", filename, linenum, name);
707 1.12 christos for (i = 0; i < l; i++) {
708 1.12 christos c = tolower((u_char)name[i]);
709 1.12 christos name[i] = (char)c;
710 1.12 christos if (last == '.' && c == '.')
711 1.12 christos fatal("%s line %d: hostname suffix \"%.100s\" contains "
712 1.12 christos "consecutive separators", filename, linenum, name);
713 1.12 christos if (c != '.' && c != '-' && !isalnum(c) &&
714 1.12 christos c != '_') /* technically invalid, but common */
715 1.12 christos fatal("%s line %d: hostname suffix \"%.100s\" contains "
716 1.12 christos "invalid characters", filename, linenum, name);
717 1.12 christos last = c;
718 1.12 christos }
719 1.12 christos if (name[l - 1] == '.')
720 1.12 christos name[l - 1] = '\0';
721 1.12 christos }
722 1.12 christos
723 1.1 christos /*
724 1.1 christos * Returns the number of the token pointed to by cp or oBadOption.
725 1.1 christos */
726 1.1 christos static OpCodes
727 1.11 christos parse_token(const char *cp, const char *filename, int linenum,
728 1.11 christos const char *ignored_unknown)
729 1.1 christos {
730 1.11 christos int i;
731 1.1 christos
732 1.1 christos for (i = 0; keywords[i].name; i++)
733 1.11 christos if (strcmp(cp, keywords[i].name) == 0)
734 1.1 christos return keywords[i].opcode;
735 1.14 christos if (ignored_unknown != NULL &&
736 1.14 christos match_pattern_list(cp, ignored_unknown, 1) == 1)
737 1.11 christos return oIgnoredUnknownOption;
738 1.1 christos error("%s: line %d: Bad configuration option: %s",
739 1.1 christos filename, linenum, cp);
740 1.1 christos return oBadOption;
741 1.1 christos }
742 1.1 christos
743 1.12 christos /* Multistate option parsing */
744 1.12 christos struct multistate {
745 1.12 christos const char *key;
746 1.12 christos int value;
747 1.12 christos };
748 1.12 christos static const struct multistate multistate_flag[] = {
749 1.12 christos { "true", 1 },
750 1.12 christos { "false", 0 },
751 1.12 christos { "yes", 1 },
752 1.12 christos { "no", 0 },
753 1.12 christos { NULL, -1 }
754 1.12 christos };
755 1.12 christos static const struct multistate multistate_yesnoask[] = {
756 1.12 christos { "true", 1 },
757 1.12 christos { "false", 0 },
758 1.12 christos { "yes", 1 },
759 1.12 christos { "no", 0 },
760 1.12 christos { "ask", 2 },
761 1.12 christos { NULL, -1 }
762 1.12 christos };
763 1.18 christos static const struct multistate multistate_yesnoaskconfirm[] = {
764 1.18 christos { "true", 1 },
765 1.18 christos { "false", 0 },
766 1.18 christos { "yes", 1 },
767 1.18 christos { "no", 0 },
768 1.18 christos { "ask", 2 },
769 1.18 christos { "confirm", 3 },
770 1.18 christos { NULL, -1 }
771 1.18 christos };
772 1.12 christos static const struct multistate multistate_addressfamily[] = {
773 1.12 christos { "inet", AF_INET },
774 1.12 christos { "inet6", AF_INET6 },
775 1.12 christos { "any", AF_UNSPEC },
776 1.12 christos { NULL, -1 }
777 1.12 christos };
778 1.12 christos static const struct multistate multistate_controlmaster[] = {
779 1.12 christos { "true", SSHCTL_MASTER_YES },
780 1.12 christos { "yes", SSHCTL_MASTER_YES },
781 1.12 christos { "false", SSHCTL_MASTER_NO },
782 1.12 christos { "no", SSHCTL_MASTER_NO },
783 1.12 christos { "auto", SSHCTL_MASTER_AUTO },
784 1.12 christos { "ask", SSHCTL_MASTER_ASK },
785 1.12 christos { "autoask", SSHCTL_MASTER_AUTO_ASK },
786 1.12 christos { NULL, -1 }
787 1.12 christos };
788 1.12 christos static const struct multistate multistate_tunnel[] = {
789 1.12 christos { "ethernet", SSH_TUNMODE_ETHERNET },
790 1.12 christos { "point-to-point", SSH_TUNMODE_POINTOPOINT },
791 1.12 christos { "true", SSH_TUNMODE_DEFAULT },
792 1.12 christos { "yes", SSH_TUNMODE_DEFAULT },
793 1.12 christos { "false", SSH_TUNMODE_NO },
794 1.12 christos { "no", SSH_TUNMODE_NO },
795 1.12 christos { NULL, -1 }
796 1.12 christos };
797 1.12 christos static const struct multistate multistate_requesttty[] = {
798 1.12 christos { "true", REQUEST_TTY_YES },
799 1.12 christos { "yes", REQUEST_TTY_YES },
800 1.12 christos { "false", REQUEST_TTY_NO },
801 1.12 christos { "no", REQUEST_TTY_NO },
802 1.12 christos { "force", REQUEST_TTY_FORCE },
803 1.12 christos { "auto", REQUEST_TTY_AUTO },
804 1.12 christos { NULL, -1 }
805 1.12 christos };
806 1.12 christos static const struct multistate multistate_canonicalizehostname[] = {
807 1.12 christos { "true", SSH_CANONICALISE_YES },
808 1.12 christos { "false", SSH_CANONICALISE_NO },
809 1.12 christos { "yes", SSH_CANONICALISE_YES },
810 1.12 christos { "no", SSH_CANONICALISE_NO },
811 1.12 christos { "always", SSH_CANONICALISE_ALWAYS },
812 1.12 christos { NULL, -1 }
813 1.12 christos };
814 1.12 christos
815 1.1 christos /*
816 1.1 christos * Processes a single option line as used in the configuration files. This
817 1.1 christos * only sets those values that have not already been set.
818 1.1 christos */
819 1.1 christos int
820 1.12 christos process_config_line(Options *options, struct passwd *pw, const char *host,
821 1.13 christos const char *original_host, char *line, const char *filename,
822 1.13 christos int linenum, int *activep, int flags)
823 1.1 christos {
824 1.18.2.1 pgoyette return process_config_line_depth(options, pw, host, original_host,
825 1.18.2.1 pgoyette line, filename, linenum, activep, flags, 0);
826 1.18.2.1 pgoyette }
827 1.18.2.1 pgoyette
828 1.18.2.1 pgoyette #define WHITESPACE " \t\r\n"
829 1.18.2.1 pgoyette static int
830 1.18.2.1 pgoyette process_config_line_depth(Options *options, struct passwd *pw, const char *host,
831 1.18.2.1 pgoyette const char *original_host, char *line, const char *filename,
832 1.18.2.1 pgoyette int linenum, int *activep, int flags, int depth)
833 1.18.2.1 pgoyette {
834 1.6 christos char *s, **charptr, *endofnumber, *keyword, *arg, *arg2;
835 1.6 christos char **cpptr, fwdarg[256];
836 1.11 christos u_int i, *uintptr, max_entries = 0;
837 1.18.2.1 pgoyette int r, oactive, negated, opcode, *intptr, value, value2, cmdline = 0;
838 1.1 christos LogLevel *log_level_ptr;
839 1.11 christos long long val64;
840 1.1 christos size_t len;
841 1.12 christos struct Forward fwd;
842 1.12 christos const struct multistate *multistate_ptr;
843 1.12 christos struct allowed_cname *cname;
844 1.18.2.1 pgoyette glob_t gl;
845 1.12 christos
846 1.12 christos if (activep == NULL) { /* We are processing a command line directive */
847 1.12 christos cmdline = 1;
848 1.12 christos activep = &cmdline;
849 1.12 christos }
850 1.1 christos
851 1.1 christos /* Strip trailing whitespace */
852 1.14 christos if ((len = strlen(line)) == 0)
853 1.14 christos return 0;
854 1.14 christos for (len--; len > 0; len--) {
855 1.1 christos if (strchr(WHITESPACE, line[len]) == NULL)
856 1.1 christos break;
857 1.1 christos line[len] = '\0';
858 1.1 christos }
859 1.1 christos
860 1.1 christos s = line;
861 1.1 christos /* Get the keyword. (Each line is supposed to begin with a keyword). */
862 1.1 christos if ((keyword = strdelim(&s)) == NULL)
863 1.1 christos return 0;
864 1.1 christos /* Ignore leading whitespace. */
865 1.1 christos if (*keyword == '\0')
866 1.1 christos keyword = strdelim(&s);
867 1.1 christos if (keyword == NULL || !*keyword || *keyword == '\n' || *keyword == '#')
868 1.1 christos return 0;
869 1.11 christos /* Match lowercase keyword */
870 1.12 christos lowercase(keyword);
871 1.1 christos
872 1.11 christos opcode = parse_token(keyword, filename, linenum,
873 1.11 christos options->ignored_unknown);
874 1.1 christos
875 1.1 christos switch (opcode) {
876 1.1 christos case oBadOption:
877 1.1 christos /* don't panic, but count bad options */
878 1.1 christos return -1;
879 1.11 christos case oIgnoredUnknownOption:
880 1.11 christos debug("%s line %d: Ignored unknown option \"%s\"",
881 1.11 christos filename, linenum, keyword);
882 1.11 christos return 0;
883 1.1 christos case oConnectTimeout:
884 1.1 christos intptr = &options->connection_timeout;
885 1.1 christos parse_time:
886 1.1 christos arg = strdelim(&s);
887 1.1 christos if (!arg || *arg == '\0')
888 1.1 christos fatal("%s line %d: missing time value.",
889 1.1 christos filename, linenum);
890 1.13 christos if (strcmp(arg, "none") == 0)
891 1.13 christos value = -1;
892 1.13 christos else if ((value = convtime(arg)) == -1)
893 1.1 christos fatal("%s line %d: invalid time value.",
894 1.1 christos filename, linenum);
895 1.1 christos if (*activep && *intptr == -1)
896 1.1 christos *intptr = value;
897 1.1 christos break;
898 1.1 christos
899 1.1 christos case oForwardAgent:
900 1.1 christos intptr = &options->forward_agent;
901 1.12 christos parse_flag:
902 1.12 christos multistate_ptr = multistate_flag;
903 1.12 christos parse_multistate:
904 1.1 christos arg = strdelim(&s);
905 1.1 christos if (!arg || *arg == '\0')
906 1.12 christos fatal("%s line %d: missing argument.",
907 1.12 christos filename, linenum);
908 1.12 christos value = -1;
909 1.12 christos for (i = 0; multistate_ptr[i].key != NULL; i++) {
910 1.12 christos if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
911 1.12 christos value = multistate_ptr[i].value;
912 1.12 christos break;
913 1.12 christos }
914 1.12 christos }
915 1.12 christos if (value == -1)
916 1.12 christos fatal("%s line %d: unsupported option \"%s\".",
917 1.12 christos filename, linenum, arg);
918 1.1 christos if (*activep && *intptr == -1)
919 1.1 christos *intptr = value;
920 1.1 christos break;
921 1.1 christos
922 1.1 christos case oForwardX11:
923 1.1 christos intptr = &options->forward_x11;
924 1.1 christos goto parse_flag;
925 1.1 christos
926 1.1 christos case oForwardX11Trusted:
927 1.1 christos intptr = &options->forward_x11_trusted;
928 1.1 christos goto parse_flag;
929 1.13 christos
930 1.4 adam case oForwardX11Timeout:
931 1.4 adam intptr = &options->forward_x11_timeout;
932 1.4 adam goto parse_time;
933 1.1 christos
934 1.1 christos case oGatewayPorts:
935 1.12 christos intptr = &options->fwd_opts.gateway_ports;
936 1.1 christos goto parse_flag;
937 1.1 christos
938 1.1 christos case oExitOnForwardFailure:
939 1.1 christos intptr = &options->exit_on_forward_failure;
940 1.1 christos goto parse_flag;
941 1.1 christos
942 1.1 christos case oUsePrivilegedPort:
943 1.1 christos intptr = &options->use_privileged_port;
944 1.1 christos goto parse_flag;
945 1.1 christos
946 1.1 christos case oPasswordAuthentication:
947 1.1 christos intptr = &options->password_authentication;
948 1.1 christos goto parse_flag;
949 1.1 christos
950 1.1 christos case oKbdInteractiveAuthentication:
951 1.1 christos intptr = &options->kbd_interactive_authentication;
952 1.1 christos goto parse_flag;
953 1.1 christos
954 1.1 christos case oKbdInteractiveDevices:
955 1.1 christos charptr = &options->kbd_interactive_devices;
956 1.1 christos goto parse_string;
957 1.1 christos
958 1.1 christos case oPubkeyAuthentication:
959 1.1 christos intptr = &options->pubkey_authentication;
960 1.1 christos goto parse_flag;
961 1.1 christos
962 1.1 christos case oRSAAuthentication:
963 1.1 christos intptr = &options->rsa_authentication;
964 1.1 christos goto parse_flag;
965 1.1 christos
966 1.1 christos case oRhostsRSAAuthentication:
967 1.1 christos intptr = &options->rhosts_rsa_authentication;
968 1.1 christos goto parse_flag;
969 1.1 christos
970 1.1 christos case oHostbasedAuthentication:
971 1.1 christos intptr = &options->hostbased_authentication;
972 1.1 christos goto parse_flag;
973 1.1 christos
974 1.1 christos case oChallengeResponseAuthentication:
975 1.1 christos intptr = &options->challenge_response_authentication;
976 1.1 christos goto parse_flag;
977 1.1 christos
978 1.2 christos #if defined(KRB4) || defined(KRB5)
979 1.2 christos case oKerberosAuthentication:
980 1.2 christos intptr = &options->kerberos_authentication;
981 1.2 christos goto parse_flag;
982 1.2 christos #endif
983 1.2 christos #if defined(AFS) || defined(KRB5)
984 1.2 christos case oKerberosTgtPassing:
985 1.2 christos intptr = &options->kerberos_tgt_passing;
986 1.2 christos goto parse_flag;
987 1.2 christos #endif
988 1.2 christos
989 1.1 christos case oGssAuthentication:
990 1.1 christos intptr = &options->gss_authentication;
991 1.1 christos goto parse_flag;
992 1.1 christos
993 1.2 christos #ifdef AFS
994 1.2 christos case oAFSTokenPassing:
995 1.2 christos intptr = &options->afs_token_passing;
996 1.2 christos goto parse_flag;
997 1.2 christos #endif
998 1.2 christos
999 1.1 christos case oGssDelegateCreds:
1000 1.1 christos intptr = &options->gss_deleg_creds;
1001 1.1 christos goto parse_flag;
1002 1.1 christos
1003 1.1 christos case oBatchMode:
1004 1.1 christos intptr = &options->batch_mode;
1005 1.1 christos goto parse_flag;
1006 1.1 christos
1007 1.1 christos case oCheckHostIP:
1008 1.1 christos intptr = &options->check_host_ip;
1009 1.1 christos goto parse_flag;
1010 1.1 christos
1011 1.2 christos case oNoneEnabled:
1012 1.2 christos intptr = &options->none_enabled;
1013 1.2 christos goto parse_flag;
1014 1.2 christos
1015 1.2 christos /* we check to see if the command comes from the */
1016 1.2 christos /* command line or not. If it does then enable it */
1017 1.2 christos /* otherwise fail. NONE should never be a default configuration */
1018 1.2 christos case oNoneSwitch:
1019 1.2 christos if(strcmp(filename,"command-line")==0)
1020 1.2 christos {
1021 1.2 christos intptr = &options->none_switch;
1022 1.2 christos goto parse_flag;
1023 1.2 christos } else {
1024 1.2 christos error("NoneSwitch is found in %.200s.\nYou may only use this configuration option from the command line", filename);
1025 1.2 christos error("Continuing...");
1026 1.2 christos debug("NoneSwitch directive found in %.200s.", filename);
1027 1.2 christos return 0;
1028 1.2 christos }
1029 1.2 christos
1030 1.2 christos case oHPNDisabled:
1031 1.2 christos intptr = &options->hpn_disabled;
1032 1.2 christos goto parse_flag;
1033 1.2 christos
1034 1.2 christos case oHPNBufferSize:
1035 1.2 christos intptr = &options->hpn_buffer_size;
1036 1.2 christos goto parse_int;
1037 1.2 christos
1038 1.2 christos case oTcpRcvBufPoll:
1039 1.2 christos intptr = &options->tcp_rcv_buf_poll;
1040 1.2 christos goto parse_flag;
1041 1.2 christos
1042 1.1 christos case oVerifyHostKeyDNS:
1043 1.1 christos intptr = &options->verify_host_key_dns;
1044 1.12 christos multistate_ptr = multistate_yesnoask;
1045 1.12 christos goto parse_multistate;
1046 1.1 christos
1047 1.1 christos case oStrictHostKeyChecking:
1048 1.1 christos intptr = &options->strict_host_key_checking;
1049 1.12 christos multistate_ptr = multistate_yesnoask;
1050 1.12 christos goto parse_multistate;
1051 1.1 christos
1052 1.1 christos case oCompression:
1053 1.1 christos intptr = &options->compression;
1054 1.1 christos goto parse_flag;
1055 1.1 christos
1056 1.1 christos case oTCPKeepAlive:
1057 1.1 christos intptr = &options->tcp_keep_alive;
1058 1.1 christos goto parse_flag;
1059 1.1 christos
1060 1.1 christos case oNoHostAuthenticationForLocalhost:
1061 1.1 christos intptr = &options->no_host_authentication_for_localhost;
1062 1.1 christos goto parse_flag;
1063 1.1 christos
1064 1.1 christos case oNumberOfPasswordPrompts:
1065 1.1 christos intptr = &options->number_of_password_prompts;
1066 1.1 christos goto parse_int;
1067 1.1 christos
1068 1.1 christos case oCompressionLevel:
1069 1.1 christos intptr = &options->compression_level;
1070 1.1 christos goto parse_int;
1071 1.1 christos
1072 1.1 christos case oRekeyLimit:
1073 1.1 christos arg = strdelim(&s);
1074 1.1 christos if (!arg || *arg == '\0')
1075 1.11 christos fatal("%.200s line %d: Missing argument.", filename,
1076 1.11 christos linenum);
1077 1.11 christos if (strcmp(arg, "default") == 0) {
1078 1.11 christos val64 = 0;
1079 1.11 christos } else {
1080 1.11 christos if (scan_scaled(arg, &val64) == -1)
1081 1.11 christos fatal("%.200s line %d: Bad number '%s': %s",
1082 1.11 christos filename, linenum, arg, strerror(errno));
1083 1.11 christos if (val64 != 0 && val64 < 16)
1084 1.11 christos fatal("%.200s line %d: RekeyLimit too small",
1085 1.11 christos filename, linenum);
1086 1.1 christos }
1087 1.1 christos if (*activep && options->rekey_limit == -1)
1088 1.18 christos options->rekey_limit = val64;
1089 1.11 christos if (s != NULL) { /* optional rekey interval present */
1090 1.11 christos if (strcmp(s, "none") == 0) {
1091 1.11 christos (void)strdelim(&s); /* discard */
1092 1.11 christos break;
1093 1.11 christos }
1094 1.11 christos intptr = &options->rekey_interval;
1095 1.11 christos goto parse_time;
1096 1.11 christos }
1097 1.1 christos break;
1098 1.1 christos
1099 1.1 christos case oIdentityFile:
1100 1.1 christos arg = strdelim(&s);
1101 1.1 christos if (!arg || *arg == '\0')
1102 1.1 christos fatal("%.200s line %d: Missing argument.", filename, linenum);
1103 1.1 christos if (*activep) {
1104 1.1 christos intptr = &options->num_identity_files;
1105 1.1 christos if (*intptr >= SSH_MAX_IDENTITY_FILES)
1106 1.1 christos fatal("%.200s line %d: Too many identity files specified (max %d).",
1107 1.1 christos filename, linenum, SSH_MAX_IDENTITY_FILES);
1108 1.13 christos add_identity_file(options, NULL,
1109 1.13 christos arg, flags & SSHCONF_USERCONF);
1110 1.1 christos }
1111 1.1 christos break;
1112 1.1 christos
1113 1.18 christos case oCertificateFile:
1114 1.18 christos arg = strdelim(&s);
1115 1.18 christos if (!arg || *arg == '\0')
1116 1.18 christos fatal("%.200s line %d: Missing argument.",
1117 1.18 christos filename, linenum);
1118 1.18 christos if (*activep) {
1119 1.18 christos intptr = &options->num_certificate_files;
1120 1.18 christos if (*intptr >= SSH_MAX_CERTIFICATE_FILES) {
1121 1.18 christos fatal("%.200s line %d: Too many certificate "
1122 1.18 christos "files specified (max %d).",
1123 1.18 christos filename, linenum,
1124 1.18 christos SSH_MAX_CERTIFICATE_FILES);
1125 1.18 christos }
1126 1.18 christos add_certificate_file(options, arg,
1127 1.18 christos flags & SSHCONF_USERCONF);
1128 1.18 christos }
1129 1.18 christos break;
1130 1.18 christos
1131 1.1 christos case oXAuthLocation:
1132 1.1 christos charptr=&options->xauth_location;
1133 1.1 christos goto parse_string;
1134 1.1 christos
1135 1.1 christos case oUser:
1136 1.1 christos charptr = &options->user;
1137 1.1 christos parse_string:
1138 1.1 christos arg = strdelim(&s);
1139 1.1 christos if (!arg || *arg == '\0')
1140 1.6 christos fatal("%.200s line %d: Missing argument.",
1141 1.6 christos filename, linenum);
1142 1.1 christos if (*activep && *charptr == NULL)
1143 1.1 christos *charptr = xstrdup(arg);
1144 1.1 christos break;
1145 1.1 christos
1146 1.1 christos case oGlobalKnownHostsFile:
1147 1.6 christos cpptr = (char **)&options->system_hostfiles;
1148 1.6 christos uintptr = &options->num_system_hostfiles;
1149 1.6 christos max_entries = SSH_MAX_HOSTS_FILES;
1150 1.6 christos parse_char_array:
1151 1.6 christos if (*activep && *uintptr == 0) {
1152 1.6 christos while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1153 1.6 christos if ((*uintptr) >= max_entries)
1154 1.6 christos fatal("%s line %d: "
1155 1.6 christos "too many authorized keys files.",
1156 1.6 christos filename, linenum);
1157 1.6 christos cpptr[(*uintptr)++] = xstrdup(arg);
1158 1.6 christos }
1159 1.6 christos }
1160 1.6 christos return 0;
1161 1.1 christos
1162 1.1 christos case oUserKnownHostsFile:
1163 1.6 christos cpptr = (char **)&options->user_hostfiles;
1164 1.6 christos uintptr = &options->num_user_hostfiles;
1165 1.6 christos max_entries = SSH_MAX_HOSTS_FILES;
1166 1.6 christos goto parse_char_array;
1167 1.1 christos
1168 1.1 christos case oHostName:
1169 1.1 christos charptr = &options->hostname;
1170 1.1 christos goto parse_string;
1171 1.1 christos
1172 1.1 christos case oHostKeyAlias:
1173 1.1 christos charptr = &options->host_key_alias;
1174 1.1 christos goto parse_string;
1175 1.1 christos
1176 1.1 christos case oPreferredAuthentications:
1177 1.1 christos charptr = &options->preferred_authentications;
1178 1.1 christos goto parse_string;
1179 1.1 christos
1180 1.1 christos case oBindAddress:
1181 1.1 christos charptr = &options->bind_address;
1182 1.1 christos goto parse_string;
1183 1.1 christos
1184 1.4 adam case oPKCS11Provider:
1185 1.4 adam charptr = &options->pkcs11_provider;
1186 1.1 christos goto parse_string;
1187 1.1 christos
1188 1.1 christos case oProxyCommand:
1189 1.1 christos charptr = &options->proxy_command;
1190 1.18.2.1 pgoyette /* Ignore ProxyCommand if ProxyJump already specified */
1191 1.18.2.1 pgoyette if (options->jump_host != NULL)
1192 1.18.2.1 pgoyette charptr = &options->jump_host; /* Skip below */
1193 1.1 christos parse_command:
1194 1.1 christos if (s == NULL)
1195 1.1 christos fatal("%.200s line %d: Missing argument.", filename, linenum);
1196 1.1 christos len = strspn(s, WHITESPACE "=");
1197 1.1 christos if (*activep && *charptr == NULL)
1198 1.1 christos *charptr = xstrdup(s + len);
1199 1.1 christos return 0;
1200 1.1 christos
1201 1.18.2.1 pgoyette case oProxyJump:
1202 1.18.2.1 pgoyette if (s == NULL) {
1203 1.18.2.1 pgoyette fatal("%.200s line %d: Missing argument.",
1204 1.18.2.1 pgoyette filename, linenum);
1205 1.18.2.1 pgoyette }
1206 1.18.2.1 pgoyette len = strspn(s, WHITESPACE "=");
1207 1.18.2.1 pgoyette if (parse_jump(s + len, options, *activep) == -1) {
1208 1.18.2.1 pgoyette fatal("%.200s line %d: Invalid ProxyJump \"%s\"",
1209 1.18.2.1 pgoyette filename, linenum, s + len);
1210 1.18.2.1 pgoyette }
1211 1.18.2.1 pgoyette return 0;
1212 1.18.2.1 pgoyette
1213 1.1 christos case oPort:
1214 1.1 christos intptr = &options->port;
1215 1.1 christos parse_int:
1216 1.1 christos arg = strdelim(&s);
1217 1.1 christos if (!arg || *arg == '\0')
1218 1.1 christos fatal("%.200s line %d: Missing argument.", filename, linenum);
1219 1.1 christos if (arg[0] < '0' || arg[0] > '9')
1220 1.1 christos fatal("%.200s line %d: Bad number.", filename, linenum);
1221 1.1 christos
1222 1.1 christos /* Octal, decimal, or hex format? */
1223 1.1 christos value = strtol(arg, &endofnumber, 0);
1224 1.1 christos if (arg == endofnumber)
1225 1.1 christos fatal("%.200s line %d: Bad number.", filename, linenum);
1226 1.1 christos if (*activep && *intptr == -1)
1227 1.1 christos *intptr = value;
1228 1.1 christos break;
1229 1.1 christos
1230 1.1 christos case oConnectionAttempts:
1231 1.1 christos intptr = &options->connection_attempts;
1232 1.1 christos goto parse_int;
1233 1.1 christos
1234 1.2 christos case oTcpRcvBuf:
1235 1.2 christos intptr = &options->tcp_rcv_buf;
1236 1.2 christos goto parse_int;
1237 1.2 christos
1238 1.1 christos case oCipher:
1239 1.1 christos intptr = &options->cipher;
1240 1.1 christos arg = strdelim(&s);
1241 1.1 christos if (!arg || *arg == '\0')
1242 1.1 christos fatal("%.200s line %d: Missing argument.", filename, linenum);
1243 1.1 christos value = cipher_number(arg);
1244 1.1 christos if (value == -1)
1245 1.1 christos fatal("%.200s line %d: Bad cipher '%s'.",
1246 1.1 christos filename, linenum, arg ? arg : "<NONE>");
1247 1.1 christos if (*activep && *intptr == -1)
1248 1.1 christos *intptr = value;
1249 1.1 christos break;
1250 1.1 christos
1251 1.1 christos case oCiphers:
1252 1.1 christos arg = strdelim(&s);
1253 1.1 christos if (!arg || *arg == '\0')
1254 1.1 christos fatal("%.200s line %d: Missing argument.", filename, linenum);
1255 1.16 christos if (!ciphers_valid(*arg == '+' ? arg + 1 : arg))
1256 1.1 christos fatal("%.200s line %d: Bad SSH2 cipher spec '%s'.",
1257 1.1 christos filename, linenum, arg ? arg : "<NONE>");
1258 1.1 christos if (*activep && options->ciphers == NULL)
1259 1.1 christos options->ciphers = xstrdup(arg);
1260 1.1 christos break;
1261 1.1 christos
1262 1.1 christos case oMacs:
1263 1.1 christos arg = strdelim(&s);
1264 1.1 christos if (!arg || *arg == '\0')
1265 1.1 christos fatal("%.200s line %d: Missing argument.", filename, linenum);
1266 1.16 christos if (!mac_valid(*arg == '+' ? arg + 1 : arg))
1267 1.1 christos fatal("%.200s line %d: Bad SSH2 Mac spec '%s'.",
1268 1.1 christos filename, linenum, arg ? arg : "<NONE>");
1269 1.1 christos if (*activep && options->macs == NULL)
1270 1.1 christos options->macs = xstrdup(arg);
1271 1.1 christos break;
1272 1.1 christos
1273 1.5 christos case oKexAlgorithms:
1274 1.5 christos arg = strdelim(&s);
1275 1.5 christos if (!arg || *arg == '\0')
1276 1.5 christos fatal("%.200s line %d: Missing argument.",
1277 1.5 christos filename, linenum);
1278 1.16 christos if (!kex_names_valid(*arg == '+' ? arg + 1 : arg))
1279 1.5 christos fatal("%.200s line %d: Bad SSH2 KexAlgorithms '%s'.",
1280 1.5 christos filename, linenum, arg ? arg : "<NONE>");
1281 1.5 christos if (*activep && options->kex_algorithms == NULL)
1282 1.5 christos options->kex_algorithms = xstrdup(arg);
1283 1.5 christos break;
1284 1.5 christos
1285 1.1 christos case oHostKeyAlgorithms:
1286 1.16 christos charptr = &options->hostkeyalgorithms;
1287 1.16 christos parse_keytypes:
1288 1.1 christos arg = strdelim(&s);
1289 1.1 christos if (!arg || *arg == '\0')
1290 1.16 christos fatal("%.200s line %d: Missing argument.",
1291 1.16 christos filename, linenum);
1292 1.16 christos if (!sshkey_names_valid2(*arg == '+' ? arg + 1 : arg, 1))
1293 1.16 christos fatal("%s line %d: Bad key types '%s'.",
1294 1.16 christos filename, linenum, arg ? arg : "<NONE>");
1295 1.16 christos if (*activep && *charptr == NULL)
1296 1.16 christos *charptr = xstrdup(arg);
1297 1.1 christos break;
1298 1.1 christos
1299 1.1 christos case oProtocol:
1300 1.1 christos intptr = &options->protocol;
1301 1.1 christos arg = strdelim(&s);
1302 1.1 christos if (!arg || *arg == '\0')
1303 1.1 christos fatal("%.200s line %d: Missing argument.", filename, linenum);
1304 1.1 christos value = proto_spec(arg);
1305 1.1 christos if (value == SSH_PROTO_UNKNOWN)
1306 1.1 christos fatal("%.200s line %d: Bad protocol spec '%s'.",
1307 1.1 christos filename, linenum, arg ? arg : "<NONE>");
1308 1.1 christos if (*activep && *intptr == SSH_PROTO_UNKNOWN)
1309 1.1 christos *intptr = value;
1310 1.1 christos break;
1311 1.1 christos
1312 1.1 christos case oLogLevel:
1313 1.1 christos log_level_ptr = &options->log_level;
1314 1.1 christos arg = strdelim(&s);
1315 1.1 christos value = log_level_number(arg);
1316 1.1 christos if (value == SYSLOG_LEVEL_NOT_SET)
1317 1.1 christos fatal("%.200s line %d: unsupported log level '%s'",
1318 1.1 christos filename, linenum, arg ? arg : "<NONE>");
1319 1.1 christos if (*activep && *log_level_ptr == SYSLOG_LEVEL_NOT_SET)
1320 1.1 christos *log_level_ptr = (LogLevel) value;
1321 1.1 christos break;
1322 1.1 christos
1323 1.1 christos case oLocalForward:
1324 1.1 christos case oRemoteForward:
1325 1.1 christos case oDynamicForward:
1326 1.1 christos arg = strdelim(&s);
1327 1.1 christos if (arg == NULL || *arg == '\0')
1328 1.1 christos fatal("%.200s line %d: Missing port argument.",
1329 1.1 christos filename, linenum);
1330 1.1 christos
1331 1.1 christos if (opcode == oLocalForward ||
1332 1.1 christos opcode == oRemoteForward) {
1333 1.1 christos arg2 = strdelim(&s);
1334 1.1 christos if (arg2 == NULL || *arg2 == '\0')
1335 1.1 christos fatal("%.200s line %d: Missing target argument.",
1336 1.1 christos filename, linenum);
1337 1.1 christos
1338 1.1 christos /* construct a string for parse_forward */
1339 1.1 christos snprintf(fwdarg, sizeof(fwdarg), "%s:%s", arg, arg2);
1340 1.1 christos } else if (opcode == oDynamicForward) {
1341 1.1 christos strlcpy(fwdarg, arg, sizeof(fwdarg));
1342 1.1 christos }
1343 1.1 christos
1344 1.1 christos if (parse_forward(&fwd, fwdarg,
1345 1.1 christos opcode == oDynamicForward ? 1 : 0,
1346 1.1 christos opcode == oRemoteForward ? 1 : 0) == 0)
1347 1.1 christos fatal("%.200s line %d: Bad forwarding specification.",
1348 1.1 christos filename, linenum);
1349 1.1 christos
1350 1.1 christos if (*activep) {
1351 1.1 christos if (opcode == oLocalForward ||
1352 1.1 christos opcode == oDynamicForward)
1353 1.1 christos add_local_forward(options, &fwd);
1354 1.1 christos else if (opcode == oRemoteForward)
1355 1.1 christos add_remote_forward(options, &fwd);
1356 1.1 christos }
1357 1.1 christos break;
1358 1.1 christos
1359 1.1 christos case oClearAllForwardings:
1360 1.1 christos intptr = &options->clear_forwardings;
1361 1.1 christos goto parse_flag;
1362 1.1 christos
1363 1.1 christos case oHost:
1364 1.12 christos if (cmdline)
1365 1.12 christos fatal("Host directive not supported as a command-line "
1366 1.12 christos "option");
1367 1.1 christos *activep = 0;
1368 1.6 christos arg2 = NULL;
1369 1.6 christos while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1370 1.18.2.1 pgoyette if ((flags & SSHCONF_NEVERMATCH) != 0)
1371 1.18.2.1 pgoyette break;
1372 1.6 christos negated = *arg == '!';
1373 1.6 christos if (negated)
1374 1.6 christos arg++;
1375 1.1 christos if (match_pattern(host, arg)) {
1376 1.6 christos if (negated) {
1377 1.6 christos debug("%.200s line %d: Skipping Host "
1378 1.6 christos "block because of negated match "
1379 1.6 christos "for %.100s", filename, linenum,
1380 1.6 christos arg);
1381 1.6 christos *activep = 0;
1382 1.6 christos break;
1383 1.6 christos }
1384 1.6 christos if (!*activep)
1385 1.6 christos arg2 = arg; /* logged below */
1386 1.1 christos *activep = 1;
1387 1.1 christos }
1388 1.6 christos }
1389 1.6 christos if (*activep)
1390 1.6 christos debug("%.200s line %d: Applying options for %.100s",
1391 1.6 christos filename, linenum, arg2);
1392 1.1 christos /* Avoid garbage check below, as strdelim is done. */
1393 1.1 christos return 0;
1394 1.1 christos
1395 1.12 christos case oMatch:
1396 1.12 christos if (cmdline)
1397 1.12 christos fatal("Host directive not supported as a command-line "
1398 1.12 christos "option");
1399 1.13 christos value = match_cfg_line(options, &s, pw, host, original_host,
1400 1.13 christos flags & SSHCONF_POSTCANON, filename, linenum);
1401 1.12 christos if (value < 0)
1402 1.12 christos fatal("%.200s line %d: Bad Match condition", filename,
1403 1.12 christos linenum);
1404 1.18.2.1 pgoyette *activep = (flags & SSHCONF_NEVERMATCH) ? 0 : value;
1405 1.12 christos break;
1406 1.12 christos
1407 1.1 christos case oEscapeChar:
1408 1.1 christos intptr = &options->escape_char;
1409 1.1 christos arg = strdelim(&s);
1410 1.1 christos if (!arg || *arg == '\0')
1411 1.1 christos fatal("%.200s line %d: Missing argument.", filename, linenum);
1412 1.2 christos value = 0; /* To avoid compiler warning... */
1413 1.14 christos if (strcmp(arg, "none") == 0)
1414 1.14 christos value = SSH_ESCAPECHAR_NONE;
1415 1.14 christos else if (arg[1] == '\0')
1416 1.14 christos value = (u_char) arg[0];
1417 1.14 christos else if (arg[0] == '^' && arg[2] == 0 &&
1418 1.1 christos (u_char) arg[1] >= 64 && (u_char) arg[1] < 128)
1419 1.1 christos value = (u_char) arg[1] & 31;
1420 1.1 christos else {
1421 1.1 christos fatal("%.200s line %d: Bad escape character.",
1422 1.1 christos filename, linenum);
1423 1.1 christos /* NOTREACHED */
1424 1.1 christos value = 0; /* Avoid compiler warning. */
1425 1.1 christos }
1426 1.1 christos if (*activep && *intptr == -1)
1427 1.1 christos *intptr = value;
1428 1.1 christos break;
1429 1.1 christos
1430 1.1 christos case oAddressFamily:
1431 1.1 christos intptr = &options->address_family;
1432 1.12 christos multistate_ptr = multistate_addressfamily;
1433 1.12 christos goto parse_multistate;
1434 1.1 christos
1435 1.1 christos case oEnableSSHKeysign:
1436 1.1 christos intptr = &options->enable_ssh_keysign;
1437 1.1 christos goto parse_flag;
1438 1.1 christos
1439 1.1 christos case oIdentitiesOnly:
1440 1.1 christos intptr = &options->identities_only;
1441 1.1 christos goto parse_flag;
1442 1.1 christos
1443 1.1 christos case oServerAliveInterval:
1444 1.1 christos intptr = &options->server_alive_interval;
1445 1.1 christos goto parse_time;
1446 1.1 christos
1447 1.1 christos case oServerAliveCountMax:
1448 1.1 christos intptr = &options->server_alive_count_max;
1449 1.1 christos goto parse_int;
1450 1.1 christos
1451 1.1 christos case oSendEnv:
1452 1.1 christos while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1453 1.1 christos if (strchr(arg, '=') != NULL)
1454 1.1 christos fatal("%s line %d: Invalid environment name.",
1455 1.1 christos filename, linenum);
1456 1.1 christos if (!*activep)
1457 1.1 christos continue;
1458 1.1 christos if (options->num_send_env >= MAX_SEND_ENV)
1459 1.1 christos fatal("%s line %d: too many send env.",
1460 1.1 christos filename, linenum);
1461 1.1 christos options->send_env[options->num_send_env++] =
1462 1.1 christos xstrdup(arg);
1463 1.1 christos }
1464 1.1 christos break;
1465 1.1 christos
1466 1.1 christos case oControlPath:
1467 1.1 christos charptr = &options->control_path;
1468 1.1 christos goto parse_string;
1469 1.1 christos
1470 1.1 christos case oControlMaster:
1471 1.1 christos intptr = &options->control_master;
1472 1.12 christos multistate_ptr = multistate_controlmaster;
1473 1.12 christos goto parse_multistate;
1474 1.1 christos
1475 1.4 adam case oControlPersist:
1476 1.4 adam /* no/false/yes/true, or a time spec */
1477 1.4 adam intptr = &options->control_persist;
1478 1.4 adam arg = strdelim(&s);
1479 1.4 adam if (!arg || *arg == '\0')
1480 1.4 adam fatal("%.200s line %d: Missing ControlPersist"
1481 1.4 adam " argument.", filename, linenum);
1482 1.4 adam value = 0;
1483 1.4 adam value2 = 0; /* timeout */
1484 1.4 adam if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
1485 1.4 adam value = 0;
1486 1.4 adam else if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
1487 1.4 adam value = 1;
1488 1.4 adam else if ((value2 = convtime(arg)) >= 0)
1489 1.4 adam value = 1;
1490 1.4 adam else
1491 1.4 adam fatal("%.200s line %d: Bad ControlPersist argument.",
1492 1.4 adam filename, linenum);
1493 1.4 adam if (*activep && *intptr == -1) {
1494 1.4 adam *intptr = value;
1495 1.4 adam options->control_persist_timeout = value2;
1496 1.4 adam }
1497 1.4 adam break;
1498 1.4 adam
1499 1.1 christos case oHashKnownHosts:
1500 1.1 christos intptr = &options->hash_known_hosts;
1501 1.1 christos goto parse_flag;
1502 1.1 christos
1503 1.1 christos case oTunnel:
1504 1.1 christos intptr = &options->tun_open;
1505 1.12 christos multistate_ptr = multistate_tunnel;
1506 1.12 christos goto parse_multistate;
1507 1.1 christos
1508 1.1 christos case oTunnelDevice:
1509 1.1 christos arg = strdelim(&s);
1510 1.1 christos if (!arg || *arg == '\0')
1511 1.1 christos fatal("%.200s line %d: Missing argument.", filename, linenum);
1512 1.1 christos value = a2tun(arg, &value2);
1513 1.1 christos if (value == SSH_TUNID_ERR)
1514 1.1 christos fatal("%.200s line %d: Bad tun device.", filename, linenum);
1515 1.1 christos if (*activep) {
1516 1.1 christos options->tun_local = value;
1517 1.1 christos options->tun_remote = value2;
1518 1.1 christos }
1519 1.1 christos break;
1520 1.1 christos
1521 1.1 christos case oLocalCommand:
1522 1.1 christos charptr = &options->local_command;
1523 1.1 christos goto parse_command;
1524 1.1 christos
1525 1.1 christos case oPermitLocalCommand:
1526 1.1 christos intptr = &options->permit_local_command;
1527 1.1 christos goto parse_flag;
1528 1.1 christos
1529 1.1 christos case oVisualHostKey:
1530 1.1 christos intptr = &options->visual_host_key;
1531 1.1 christos goto parse_flag;
1532 1.1 christos
1533 1.18.2.1 pgoyette case oInclude:
1534 1.18.2.1 pgoyette if (cmdline)
1535 1.18.2.1 pgoyette fatal("Include directive not supported as a "
1536 1.18.2.1 pgoyette "command-line option");
1537 1.18.2.1 pgoyette value = 0;
1538 1.18.2.1 pgoyette while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1539 1.18.2.1 pgoyette /*
1540 1.18.2.1 pgoyette * Ensure all paths are anchored. User configuration
1541 1.18.2.1 pgoyette * files may begin with '~/' but system configurations
1542 1.18.2.1 pgoyette * must not. If the path is relative, then treat it
1543 1.18.2.1 pgoyette * as living in ~/.ssh for user configurations or
1544 1.18.2.1 pgoyette * /etc/ssh for system ones.
1545 1.18.2.1 pgoyette */
1546 1.18.2.1 pgoyette if (*arg == '~' && (flags & SSHCONF_USERCONF) == 0)
1547 1.18.2.1 pgoyette fatal("%.200s line %d: bad include path %s.",
1548 1.18.2.1 pgoyette filename, linenum, arg);
1549 1.18.2.1 pgoyette if (*arg != '/' && *arg != '~') {
1550 1.18.2.1 pgoyette xasprintf(&arg2, "%s/%s",
1551 1.18.2.1 pgoyette (flags & SSHCONF_USERCONF) ?
1552 1.18.2.1 pgoyette "~/" _PATH_SSH_USER_DIR : SSHDIR, arg);
1553 1.18.2.1 pgoyette } else
1554 1.18.2.1 pgoyette arg2 = xstrdup(arg);
1555 1.18.2.1 pgoyette memset(&gl, 0, sizeof(gl));
1556 1.18.2.1 pgoyette r = glob(arg2, GLOB_TILDE | GLOB_LIMIT, NULL, &gl);
1557 1.18.2.1 pgoyette if (r == GLOB_NOMATCH) {
1558 1.18.2.1 pgoyette debug("%.200s line %d: include %s matched no "
1559 1.18.2.1 pgoyette "files",filename, linenum, arg2);
1560 1.18.2.1 pgoyette continue;
1561 1.18.2.1 pgoyette } else if (r != 0)
1562 1.18.2.1 pgoyette fatal("%.200s line %d: glob failed for %s.",
1563 1.18.2.1 pgoyette filename, linenum, arg2);
1564 1.18.2.1 pgoyette free(arg2);
1565 1.18.2.1 pgoyette oactive = *activep;
1566 1.18.2.1 pgoyette for (i = 0; i < (u_int)gl.gl_pathc; i++) {
1567 1.18.2.1 pgoyette debug3("%.200s line %d: Including file %s "
1568 1.18.2.1 pgoyette "depth %d%s", filename, linenum,
1569 1.18.2.1 pgoyette gl.gl_pathv[i], depth,
1570 1.18.2.1 pgoyette oactive ? "" : " (parse only)");
1571 1.18.2.1 pgoyette r = read_config_file_depth(gl.gl_pathv[i],
1572 1.18.2.1 pgoyette pw, host, original_host, options,
1573 1.18.2.1 pgoyette flags | SSHCONF_CHECKPERM |
1574 1.18.2.1 pgoyette (oactive ? 0 : SSHCONF_NEVERMATCH),
1575 1.18.2.1 pgoyette activep, depth + 1);
1576 1.18.2.1 pgoyette /*
1577 1.18.2.1 pgoyette * don't let Match in includes clobber the
1578 1.18.2.1 pgoyette * containing file's Match state.
1579 1.18.2.1 pgoyette */
1580 1.18.2.1 pgoyette *activep = oactive;
1581 1.18.2.1 pgoyette if (r != 1)
1582 1.18.2.1 pgoyette value = -1;
1583 1.18.2.1 pgoyette }
1584 1.18.2.1 pgoyette globfree(&gl);
1585 1.18.2.1 pgoyette }
1586 1.18.2.1 pgoyette if (value != 0)
1587 1.18.2.1 pgoyette return value;
1588 1.18.2.1 pgoyette break;
1589 1.18.2.1 pgoyette
1590 1.5 christos case oIPQoS:
1591 1.5 christos arg = strdelim(&s);
1592 1.5 christos if ((value = parse_ipqos(arg)) == -1)
1593 1.5 christos fatal("%s line %d: Bad IPQoS value: %s",
1594 1.5 christos filename, linenum, arg);
1595 1.5 christos arg = strdelim(&s);
1596 1.5 christos if (arg == NULL)
1597 1.5 christos value2 = value;
1598 1.5 christos else if ((value2 = parse_ipqos(arg)) == -1)
1599 1.5 christos fatal("%s line %d: Bad IPQoS value: %s",
1600 1.5 christos filename, linenum, arg);
1601 1.5 christos if (*activep) {
1602 1.5 christos options->ip_qos_interactive = value;
1603 1.5 christos options->ip_qos_bulk = value2;
1604 1.5 christos }
1605 1.5 christos break;
1606 1.5 christos
1607 1.6 christos case oRequestTTY:
1608 1.6 christos intptr = &options->request_tty;
1609 1.12 christos multistate_ptr = multistate_requesttty;
1610 1.12 christos goto parse_multistate;
1611 1.6 christos
1612 1.7 tls case oSendVersionFirst:
1613 1.7 tls intptr = &options->send_version_first;
1614 1.7 tls goto parse_flag;
1615 1.7 tls
1616 1.11 christos case oIgnoreUnknown:
1617 1.11 christos charptr = &options->ignored_unknown;
1618 1.11 christos goto parse_string;
1619 1.11 christos
1620 1.12 christos case oProxyUseFdpass:
1621 1.12 christos intptr = &options->proxy_use_fdpass;
1622 1.12 christos goto parse_flag;
1623 1.12 christos
1624 1.12 christos case oCanonicalDomains:
1625 1.12 christos value = options->num_canonical_domains != 0;
1626 1.12 christos while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1627 1.12 christos valid_domain(arg, filename, linenum);
1628 1.12 christos if (!*activep || value)
1629 1.12 christos continue;
1630 1.12 christos if (options->num_canonical_domains >= MAX_CANON_DOMAINS)
1631 1.12 christos fatal("%s line %d: too many hostname suffixes.",
1632 1.12 christos filename, linenum);
1633 1.12 christos options->canonical_domains[
1634 1.12 christos options->num_canonical_domains++] = xstrdup(arg);
1635 1.12 christos }
1636 1.12 christos break;
1637 1.12 christos
1638 1.12 christos case oCanonicalizePermittedCNAMEs:
1639 1.12 christos value = options->num_permitted_cnames != 0;
1640 1.12 christos while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1641 1.12 christos /* Either '*' for everything or 'list:list' */
1642 1.12 christos if (strcmp(arg, "*") == 0)
1643 1.12 christos arg2 = arg;
1644 1.12 christos else {
1645 1.12 christos lowercase(arg);
1646 1.12 christos if ((arg2 = strchr(arg, ':')) == NULL ||
1647 1.12 christos arg2[1] == '\0') {
1648 1.12 christos fatal("%s line %d: "
1649 1.12 christos "Invalid permitted CNAME \"%s\"",
1650 1.12 christos filename, linenum, arg);
1651 1.12 christos }
1652 1.12 christos *arg2 = '\0';
1653 1.12 christos arg2++;
1654 1.12 christos }
1655 1.12 christos if (!*activep || value)
1656 1.12 christos continue;
1657 1.12 christos if (options->num_permitted_cnames >= MAX_CANON_DOMAINS)
1658 1.12 christos fatal("%s line %d: too many permitted CNAMEs.",
1659 1.12 christos filename, linenum);
1660 1.12 christos cname = options->permitted_cnames +
1661 1.12 christos options->num_permitted_cnames++;
1662 1.12 christos cname->source_list = xstrdup(arg);
1663 1.12 christos cname->target_list = xstrdup(arg2);
1664 1.12 christos }
1665 1.12 christos break;
1666 1.12 christos
1667 1.12 christos case oCanonicalizeHostname:
1668 1.12 christos intptr = &options->canonicalize_hostname;
1669 1.12 christos multistate_ptr = multistate_canonicalizehostname;
1670 1.12 christos goto parse_multistate;
1671 1.12 christos
1672 1.12 christos case oCanonicalizeMaxDots:
1673 1.12 christos intptr = &options->canonicalize_max_dots;
1674 1.12 christos goto parse_int;
1675 1.12 christos
1676 1.12 christos case oCanonicalizeFallbackLocal:
1677 1.12 christos intptr = &options->canonicalize_fallback_local;
1678 1.12 christos goto parse_flag;
1679 1.12 christos
1680 1.12 christos case oStreamLocalBindMask:
1681 1.12 christos arg = strdelim(&s);
1682 1.12 christos if (!arg || *arg == '\0')
1683 1.12 christos fatal("%.200s line %d: Missing StreamLocalBindMask argument.", filename, linenum);
1684 1.12 christos /* Parse mode in octal format */
1685 1.12 christos value = strtol(arg, &endofnumber, 8);
1686 1.12 christos if (arg == endofnumber || value < 0 || value > 0777)
1687 1.12 christos fatal("%.200s line %d: Bad mask.", filename, linenum);
1688 1.12 christos options->fwd_opts.streamlocal_bind_mask = (mode_t)value;
1689 1.12 christos break;
1690 1.12 christos
1691 1.12 christos case oStreamLocalBindUnlink:
1692 1.12 christos intptr = &options->fwd_opts.streamlocal_bind_unlink;
1693 1.12 christos goto parse_flag;
1694 1.12 christos
1695 1.13 christos case oRevokedHostKeys:
1696 1.13 christos charptr = &options->revoked_host_keys;
1697 1.13 christos goto parse_string;
1698 1.13 christos
1699 1.13 christos case oFingerprintHash:
1700 1.13 christos intptr = &options->fingerprint_hash;
1701 1.13 christos arg = strdelim(&s);
1702 1.13 christos if (!arg || *arg == '\0')
1703 1.13 christos fatal("%.200s line %d: Missing argument.",
1704 1.13 christos filename, linenum);
1705 1.13 christos if ((value = ssh_digest_alg_by_name(arg)) == -1)
1706 1.13 christos fatal("%.200s line %d: Invalid hash algorithm \"%s\".",
1707 1.13 christos filename, linenum, arg);
1708 1.13 christos if (*activep && *intptr == -1)
1709 1.13 christos *intptr = value;
1710 1.13 christos break;
1711 1.13 christos
1712 1.13 christos case oUpdateHostkeys:
1713 1.13 christos intptr = &options->update_hostkeys;
1714 1.13 christos multistate_ptr = multistate_yesnoask;
1715 1.13 christos goto parse_multistate;
1716 1.13 christos
1717 1.13 christos case oHostbasedKeyTypes:
1718 1.13 christos charptr = &options->hostbased_key_types;
1719 1.16 christos goto parse_keytypes;
1720 1.16 christos
1721 1.16 christos case oPubkeyAcceptedKeyTypes:
1722 1.16 christos charptr = &options->pubkey_key_types;
1723 1.16 christos goto parse_keytypes;
1724 1.13 christos
1725 1.18 christos case oAddKeysToAgent:
1726 1.18 christos intptr = &options->add_keys_to_agent;
1727 1.18 christos multistate_ptr = multistate_yesnoaskconfirm;
1728 1.18 christos goto parse_multistate;
1729 1.18 christos
1730 1.18.2.1 pgoyette case oIdentityAgent:
1731 1.18.2.1 pgoyette charptr = &options->identity_agent;
1732 1.18.2.1 pgoyette goto parse_string;
1733 1.18.2.1 pgoyette
1734 1.1 christos case oDeprecated:
1735 1.1 christos debug("%s line %d: Deprecated option \"%s\"",
1736 1.1 christos filename, linenum, keyword);
1737 1.1 christos return 0;
1738 1.1 christos
1739 1.1 christos case oUnsupported:
1740 1.1 christos error("%s line %d: Unsupported option \"%s\"",
1741 1.1 christos filename, linenum, keyword);
1742 1.1 christos return 0;
1743 1.1 christos
1744 1.1 christos default:
1745 1.13 christos fatal("%s: Unimplemented opcode %d", __func__, opcode);
1746 1.1 christos }
1747 1.1 christos
1748 1.1 christos /* Check that there is no garbage at end of line. */
1749 1.1 christos if ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1750 1.1 christos fatal("%.200s line %d: garbage at end of line; \"%.200s\".",
1751 1.1 christos filename, linenum, arg);
1752 1.1 christos }
1753 1.1 christos return 0;
1754 1.1 christos }
1755 1.1 christos
1756 1.1 christos /*
1757 1.1 christos * Reads the config file and modifies the options accordingly. Options
1758 1.1 christos * should already be initialized before this call. This never returns if
1759 1.1 christos * there is an error. If the file does not exist, this returns 0.
1760 1.1 christos */
1761 1.1 christos int
1762 1.12 christos read_config_file(const char *filename, struct passwd *pw, const char *host,
1763 1.13 christos const char *original_host, Options *options, int flags)
1764 1.1 christos {
1765 1.18.2.1 pgoyette int active = 1;
1766 1.18.2.1 pgoyette
1767 1.18.2.1 pgoyette return read_config_file_depth(filename, pw, host, original_host,
1768 1.18.2.1 pgoyette options, flags, &active, 0);
1769 1.18.2.1 pgoyette }
1770 1.18.2.1 pgoyette
1771 1.18.2.1 pgoyette #define READCONF_MAX_DEPTH 16
1772 1.18.2.1 pgoyette static int
1773 1.18.2.1 pgoyette read_config_file_depth(const char *filename, struct passwd *pw,
1774 1.18.2.1 pgoyette const char *host, const char *original_host, Options *options,
1775 1.18.2.1 pgoyette int flags, int *activep, int depth)
1776 1.18.2.1 pgoyette {
1777 1.1 christos FILE *f;
1778 1.1 christos char line[1024];
1779 1.18.2.1 pgoyette int linenum;
1780 1.1 christos int bad_options = 0;
1781 1.1 christos
1782 1.18.2.1 pgoyette if (depth < 0 || depth > READCONF_MAX_DEPTH)
1783 1.18.2.1 pgoyette fatal("Too many recursive configuration includes");
1784 1.18.2.1 pgoyette
1785 1.1 christos if ((f = fopen(filename, "r")) == NULL)
1786 1.1 christos return 0;
1787 1.1 christos
1788 1.9 mlelstv if (flags & SSHCONF_CHECKPERM) {
1789 1.1 christos struct stat sb;
1790 1.1 christos
1791 1.1 christos if (fstat(fileno(f), &sb) == -1)
1792 1.1 christos fatal("fstat %s: %s", filename, strerror(errno));
1793 1.1 christos if (((sb.st_uid != 0 && sb.st_uid != getuid()) ||
1794 1.1 christos (sb.st_mode & 022) != 0))
1795 1.1 christos fatal("Bad owner or permissions on %s", filename);
1796 1.1 christos }
1797 1.1 christos
1798 1.1 christos debug("Reading configuration data %.200s", filename);
1799 1.1 christos
1800 1.1 christos /*
1801 1.1 christos * Mark that we are now processing the options. This flag is turned
1802 1.1 christos * on/off by Host specifications.
1803 1.1 christos */
1804 1.1 christos linenum = 0;
1805 1.1 christos while (fgets(line, sizeof(line), f)) {
1806 1.1 christos /* Update line number counter. */
1807 1.1 christos linenum++;
1808 1.18.2.1 pgoyette if (process_config_line_depth(options, pw, host, original_host,
1809 1.18.2.1 pgoyette line, filename, linenum, activep, flags, depth) != 0)
1810 1.1 christos bad_options++;
1811 1.1 christos }
1812 1.1 christos fclose(f);
1813 1.1 christos if (bad_options > 0)
1814 1.1 christos fatal("%s: terminating, %d bad configuration options",
1815 1.1 christos filename, bad_options);
1816 1.1 christos return 1;
1817 1.1 christos }
1818 1.1 christos
1819 1.12 christos /* Returns 1 if a string option is unset or set to "none" or 0 otherwise. */
1820 1.12 christos int
1821 1.12 christos option_clear_or_none(const char *o)
1822 1.12 christos {
1823 1.12 christos return o == NULL || strcasecmp(o, "none") == 0;
1824 1.12 christos }
1825 1.12 christos
1826 1.1 christos /*
1827 1.1 christos * Initializes options to special values that indicate that they have not yet
1828 1.1 christos * been set. Read_config_file will only set options with this value. Options
1829 1.1 christos * are processed in the following order: command line, user config file,
1830 1.1 christos * system config file. Last, fill_default_options is called.
1831 1.1 christos */
1832 1.1 christos
1833 1.1 christos void
1834 1.1 christos initialize_options(Options * options)
1835 1.1 christos {
1836 1.1 christos memset(options, 'X', sizeof(*options));
1837 1.1 christos options->forward_agent = -1;
1838 1.1 christos options->forward_x11 = -1;
1839 1.1 christos options->forward_x11_trusted = -1;
1840 1.4 adam options->forward_x11_timeout = -1;
1841 1.18.2.1 pgoyette options->stdio_forward_host = NULL;
1842 1.18.2.1 pgoyette options->stdio_forward_port = 0;
1843 1.18.2.1 pgoyette options->clear_forwardings = -1;
1844 1.1 christos options->exit_on_forward_failure = -1;
1845 1.1 christos options->xauth_location = NULL;
1846 1.12 christos options->fwd_opts.gateway_ports = -1;
1847 1.12 christos options->fwd_opts.streamlocal_bind_mask = (mode_t)-1;
1848 1.12 christos options->fwd_opts.streamlocal_bind_unlink = -1;
1849 1.1 christos options->use_privileged_port = -1;
1850 1.1 christos options->rsa_authentication = -1;
1851 1.1 christos options->pubkey_authentication = -1;
1852 1.1 christos options->challenge_response_authentication = -1;
1853 1.2 christos #if defined(KRB4) || defined(KRB5)
1854 1.2 christos options->kerberos_authentication = -1;
1855 1.2 christos #endif
1856 1.2 christos #if defined(AFS) || defined(KRB5)
1857 1.2 christos options->kerberos_tgt_passing = -1;
1858 1.2 christos #endif
1859 1.2 christos #ifdef AFS
1860 1.2 christos options->afs_token_passing = -1;
1861 1.2 christos #endif
1862 1.1 christos options->gss_authentication = -1;
1863 1.1 christos options->gss_deleg_creds = -1;
1864 1.1 christos options->password_authentication = -1;
1865 1.1 christos options->kbd_interactive_authentication = -1;
1866 1.1 christos options->kbd_interactive_devices = NULL;
1867 1.1 christos options->rhosts_rsa_authentication = -1;
1868 1.1 christos options->hostbased_authentication = -1;
1869 1.1 christos options->batch_mode = -1;
1870 1.1 christos options->check_host_ip = -1;
1871 1.1 christos options->strict_host_key_checking = -1;
1872 1.1 christos options->compression = -1;
1873 1.1 christos options->tcp_keep_alive = -1;
1874 1.1 christos options->compression_level = -1;
1875 1.1 christos options->port = -1;
1876 1.1 christos options->address_family = -1;
1877 1.1 christos options->connection_attempts = -1;
1878 1.1 christos options->connection_timeout = -1;
1879 1.1 christos options->number_of_password_prompts = -1;
1880 1.1 christos options->cipher = -1;
1881 1.1 christos options->ciphers = NULL;
1882 1.1 christos options->macs = NULL;
1883 1.5 christos options->kex_algorithms = NULL;
1884 1.1 christos options->hostkeyalgorithms = NULL;
1885 1.1 christos options->protocol = SSH_PROTO_UNKNOWN;
1886 1.1 christos options->num_identity_files = 0;
1887 1.18 christos options->num_certificate_files = 0;
1888 1.1 christos options->hostname = NULL;
1889 1.1 christos options->host_key_alias = NULL;
1890 1.1 christos options->proxy_command = NULL;
1891 1.18.2.1 pgoyette options->jump_user = NULL;
1892 1.18.2.1 pgoyette options->jump_host = NULL;
1893 1.18.2.1 pgoyette options->jump_port = -1;
1894 1.18.2.1 pgoyette options->jump_extra = NULL;
1895 1.1 christos options->user = NULL;
1896 1.1 christos options->escape_char = -1;
1897 1.6 christos options->num_system_hostfiles = 0;
1898 1.6 christos options->num_user_hostfiles = 0;
1899 1.4 adam options->local_forwards = NULL;
1900 1.1 christos options->num_local_forwards = 0;
1901 1.4 adam options->remote_forwards = NULL;
1902 1.1 christos options->num_remote_forwards = 0;
1903 1.1 christos options->log_level = SYSLOG_LEVEL_NOT_SET;
1904 1.1 christos options->preferred_authentications = NULL;
1905 1.1 christos options->bind_address = NULL;
1906 1.4 adam options->pkcs11_provider = NULL;
1907 1.1 christos options->enable_ssh_keysign = - 1;
1908 1.1 christos options->no_host_authentication_for_localhost = - 1;
1909 1.1 christos options->identities_only = - 1;
1910 1.1 christos options->rekey_limit = - 1;
1911 1.11 christos options->rekey_interval = -1;
1912 1.1 christos options->verify_host_key_dns = -1;
1913 1.1 christos options->server_alive_interval = -1;
1914 1.1 christos options->server_alive_count_max = -1;
1915 1.1 christos options->num_send_env = 0;
1916 1.1 christos options->control_path = NULL;
1917 1.1 christos options->control_master = -1;
1918 1.4 adam options->control_persist = -1;
1919 1.4 adam options->control_persist_timeout = 0;
1920 1.1 christos options->hash_known_hosts = -1;
1921 1.1 christos options->tun_open = -1;
1922 1.1 christos options->tun_local = -1;
1923 1.1 christos options->tun_remote = -1;
1924 1.1 christos options->local_command = NULL;
1925 1.1 christos options->permit_local_command = -1;
1926 1.18 christos options->add_keys_to_agent = -1;
1927 1.18.2.1 pgoyette options->identity_agent = NULL;
1928 1.1 christos options->visual_host_key = -1;
1929 1.5 christos options->ip_qos_interactive = -1;
1930 1.5 christos options->ip_qos_bulk = -1;
1931 1.6 christos options->request_tty = -1;
1932 1.12 christos options->proxy_use_fdpass = -1;
1933 1.11 christos options->ignored_unknown = NULL;
1934 1.12 christos options->num_canonical_domains = 0;
1935 1.12 christos options->num_permitted_cnames = 0;
1936 1.12 christos options->canonicalize_max_dots = -1;
1937 1.12 christos options->canonicalize_fallback_local = -1;
1938 1.12 christos options->canonicalize_hostname = -1;
1939 1.13 christos options->revoked_host_keys = NULL;
1940 1.13 christos options->fingerprint_hash = -1;
1941 1.13 christos options->update_hostkeys = -1;
1942 1.13 christos options->hostbased_key_types = NULL;
1943 1.16 christos options->pubkey_key_types = NULL;
1944 1.2 christos options->none_switch = -1;
1945 1.2 christos options->none_enabled = -1;
1946 1.2 christos options->hpn_disabled = -1;
1947 1.2 christos options->hpn_buffer_size = -1;
1948 1.2 christos options->tcp_rcv_buf_poll = -1;
1949 1.2 christos options->tcp_rcv_buf = -1;
1950 1.7 tls options->send_version_first = -1;
1951 1.1 christos }
1952 1.1 christos
1953 1.1 christos /*
1954 1.12 christos * A petite version of fill_default_options() that just fills the options
1955 1.12 christos * needed for hostname canonicalization to proceed.
1956 1.12 christos */
1957 1.12 christos void
1958 1.12 christos fill_default_options_for_canonicalization(Options *options)
1959 1.12 christos {
1960 1.12 christos if (options->canonicalize_max_dots == -1)
1961 1.12 christos options->canonicalize_max_dots = 1;
1962 1.12 christos if (options->canonicalize_fallback_local == -1)
1963 1.12 christos options->canonicalize_fallback_local = 1;
1964 1.12 christos if (options->canonicalize_hostname == -1)
1965 1.12 christos options->canonicalize_hostname = SSH_CANONICALISE_NO;
1966 1.12 christos }
1967 1.12 christos
1968 1.12 christos /*
1969 1.1 christos * Called after processing other sources of option data, this fills those
1970 1.1 christos * options for which no value has been specified with their default values.
1971 1.1 christos */
1972 1.1 christos void
1973 1.1 christos fill_default_options(Options * options)
1974 1.1 christos {
1975 1.1 christos if (options->forward_agent == -1)
1976 1.1 christos options->forward_agent = 0;
1977 1.1 christos if (options->forward_x11 == -1)
1978 1.1 christos options->forward_x11 = 0;
1979 1.1 christos if (options->forward_x11_trusted == -1)
1980 1.1 christos options->forward_x11_trusted = 0;
1981 1.4 adam if (options->forward_x11_timeout == -1)
1982 1.4 adam options->forward_x11_timeout = 1200;
1983 1.18.2.1 pgoyette /*
1984 1.18.2.1 pgoyette * stdio forwarding (-W) changes the default for these but we defer
1985 1.18.2.1 pgoyette * setting the values so they can be overridden.
1986 1.18.2.1 pgoyette */
1987 1.1 christos if (options->exit_on_forward_failure == -1)
1988 1.18.2.1 pgoyette options->exit_on_forward_failure =
1989 1.18.2.1 pgoyette options->stdio_forward_host != NULL ? 1 : 0;
1990 1.18.2.1 pgoyette if (options->clear_forwardings == -1)
1991 1.18.2.1 pgoyette options->clear_forwardings =
1992 1.18.2.1 pgoyette options->stdio_forward_host != NULL ? 1 : 0;
1993 1.18.2.1 pgoyette if (options->clear_forwardings == 1)
1994 1.18.2.1 pgoyette clear_forwardings(options);
1995 1.18.2.1 pgoyette
1996 1.1 christos if (options->xauth_location == NULL)
1997 1.5 christos options->xauth_location = __UNCONST(_PATH_XAUTH);
1998 1.12 christos if (options->fwd_opts.gateway_ports == -1)
1999 1.12 christos options->fwd_opts.gateway_ports = 0;
2000 1.12 christos if (options->fwd_opts.streamlocal_bind_mask == (mode_t)-1)
2001 1.12 christos options->fwd_opts.streamlocal_bind_mask = 0177;
2002 1.12 christos if (options->fwd_opts.streamlocal_bind_unlink == -1)
2003 1.12 christos options->fwd_opts.streamlocal_bind_unlink = 0;
2004 1.1 christos if (options->use_privileged_port == -1)
2005 1.1 christos options->use_privileged_port = 0;
2006 1.1 christos if (options->rsa_authentication == -1)
2007 1.1 christos options->rsa_authentication = 1;
2008 1.1 christos if (options->pubkey_authentication == -1)
2009 1.1 christos options->pubkey_authentication = 1;
2010 1.1 christos if (options->challenge_response_authentication == -1)
2011 1.1 christos options->challenge_response_authentication = 1;
2012 1.2 christos #if defined(KRB4) || defined(KRB5)
2013 1.2 christos if (options->kerberos_authentication == -1)
2014 1.2 christos options->kerberos_authentication = 1;
2015 1.2 christos #endif
2016 1.2 christos #if defined(AFS) || defined(KRB5)
2017 1.2 christos if (options->kerberos_tgt_passing == -1)
2018 1.2 christos options->kerberos_tgt_passing = 1;
2019 1.2 christos #endif
2020 1.2 christos #ifdef AFS
2021 1.2 christos if (options->afs_token_passing == -1)
2022 1.2 christos options->afs_token_passing = 1;
2023 1.2 christos #endif
2024 1.1 christos if (options->gss_authentication == -1)
2025 1.1 christos options->gss_authentication = 0;
2026 1.1 christos if (options->gss_deleg_creds == -1)
2027 1.1 christos options->gss_deleg_creds = 0;
2028 1.1 christos if (options->password_authentication == -1)
2029 1.1 christos options->password_authentication = 1;
2030 1.1 christos if (options->kbd_interactive_authentication == -1)
2031 1.1 christos options->kbd_interactive_authentication = 1;
2032 1.1 christos if (options->rhosts_rsa_authentication == -1)
2033 1.1 christos options->rhosts_rsa_authentication = 0;
2034 1.1 christos if (options->hostbased_authentication == -1)
2035 1.1 christos options->hostbased_authentication = 0;
2036 1.1 christos if (options->batch_mode == -1)
2037 1.1 christos options->batch_mode = 0;
2038 1.1 christos if (options->check_host_ip == -1)
2039 1.1 christos options->check_host_ip = 1;
2040 1.1 christos if (options->strict_host_key_checking == -1)
2041 1.1 christos options->strict_host_key_checking = 2; /* 2 is default */
2042 1.1 christos if (options->compression == -1)
2043 1.1 christos options->compression = 0;
2044 1.1 christos if (options->tcp_keep_alive == -1)
2045 1.1 christos options->tcp_keep_alive = 1;
2046 1.1 christos if (options->compression_level == -1)
2047 1.1 christos options->compression_level = 6;
2048 1.1 christos if (options->port == -1)
2049 1.1 christos options->port = 0; /* Filled in ssh_connect. */
2050 1.1 christos if (options->address_family == -1)
2051 1.1 christos options->address_family = AF_UNSPEC;
2052 1.1 christos if (options->connection_attempts == -1)
2053 1.1 christos options->connection_attempts = 1;
2054 1.1 christos if (options->number_of_password_prompts == -1)
2055 1.1 christos options->number_of_password_prompts = 3;
2056 1.1 christos /* Selected in ssh_login(). */
2057 1.1 christos if (options->cipher == -1)
2058 1.1 christos options->cipher = SSH_CIPHER_NOT_SET;
2059 1.1 christos /* options->hostkeyalgorithms, default set in myproposals.h */
2060 1.1 christos if (options->protocol == SSH_PROTO_UNKNOWN)
2061 1.4 adam options->protocol = SSH_PROTO_2;
2062 1.18 christos if (options->add_keys_to_agent == -1)
2063 1.18 christos options->add_keys_to_agent = 0;
2064 1.1 christos if (options->num_identity_files == 0) {
2065 1.1 christos if (options->protocol & SSH_PROTO_1) {
2066 1.10 mlelstv add_identity_file(options, "~/",
2067 1.10 mlelstv _PATH_SSH_CLIENT_IDENTITY, 0);
2068 1.1 christos }
2069 1.1 christos if (options->protocol & SSH_PROTO_2) {
2070 1.10 mlelstv add_identity_file(options, "~/",
2071 1.10 mlelstv _PATH_SSH_CLIENT_ID_RSA, 0);
2072 1.10 mlelstv add_identity_file(options, "~/",
2073 1.10 mlelstv _PATH_SSH_CLIENT_ID_DSA, 0);
2074 1.10 mlelstv add_identity_file(options, "~/",
2075 1.10 mlelstv _PATH_SSH_CLIENT_ID_ECDSA, 0);
2076 1.12 christos add_identity_file(options, "~/",
2077 1.12 christos _PATH_SSH_CLIENT_ID_ED25519, 0);
2078 1.1 christos }
2079 1.1 christos }
2080 1.1 christos if (options->escape_char == -1)
2081 1.1 christos options->escape_char = '~';
2082 1.6 christos if (options->num_system_hostfiles == 0) {
2083 1.6 christos options->system_hostfiles[options->num_system_hostfiles++] =
2084 1.6 christos xstrdup(_PATH_SSH_SYSTEM_HOSTFILE);
2085 1.6 christos options->system_hostfiles[options->num_system_hostfiles++] =
2086 1.6 christos xstrdup(_PATH_SSH_SYSTEM_HOSTFILE2);
2087 1.6 christos }
2088 1.6 christos if (options->num_user_hostfiles == 0) {
2089 1.6 christos options->user_hostfiles[options->num_user_hostfiles++] =
2090 1.6 christos xstrdup(_PATH_SSH_USER_HOSTFILE);
2091 1.6 christos options->user_hostfiles[options->num_user_hostfiles++] =
2092 1.6 christos xstrdup(_PATH_SSH_USER_HOSTFILE2);
2093 1.6 christos }
2094 1.1 christos if (options->log_level == SYSLOG_LEVEL_NOT_SET)
2095 1.1 christos options->log_level = SYSLOG_LEVEL_INFO;
2096 1.1 christos if (options->no_host_authentication_for_localhost == - 1)
2097 1.1 christos options->no_host_authentication_for_localhost = 0;
2098 1.1 christos if (options->identities_only == -1)
2099 1.1 christos options->identities_only = 0;
2100 1.1 christos if (options->enable_ssh_keysign == -1)
2101 1.1 christos options->enable_ssh_keysign = 0;
2102 1.1 christos if (options->rekey_limit == -1)
2103 1.1 christos options->rekey_limit = 0;
2104 1.11 christos if (options->rekey_interval == -1)
2105 1.11 christos options->rekey_interval = 0;
2106 1.1 christos if (options->verify_host_key_dns == -1)
2107 1.1 christos options->verify_host_key_dns = 0;
2108 1.1 christos if (options->server_alive_interval == -1)
2109 1.1 christos options->server_alive_interval = 0;
2110 1.1 christos if (options->server_alive_count_max == -1)
2111 1.1 christos options->server_alive_count_max = 3;
2112 1.2 christos if (options->none_switch == -1)
2113 1.2 christos options->none_switch = 0;
2114 1.2 christos if (options->hpn_disabled == -1)
2115 1.2 christos options->hpn_disabled = 0;
2116 1.2 christos if (options->hpn_buffer_size > -1)
2117 1.2 christos {
2118 1.2 christos /* if a user tries to set the size to 0 set it to 1KB */
2119 1.2 christos if (options->hpn_buffer_size == 0)
2120 1.2 christos options->hpn_buffer_size = 1024;
2121 1.2 christos /*limit the buffer to 64MB*/
2122 1.2 christos if (options->hpn_buffer_size > 65536)
2123 1.2 christos {
2124 1.2 christos options->hpn_buffer_size = 65536*1024;
2125 1.2 christos debug("User requested buffer larger than 64MB. Request reverted to 64MB");
2126 1.2 christos }
2127 1.2 christos debug("hpn_buffer_size set to %d", options->hpn_buffer_size);
2128 1.2 christos }
2129 1.2 christos if (options->tcp_rcv_buf == 0)
2130 1.2 christos options->tcp_rcv_buf = 1;
2131 1.2 christos if (options->tcp_rcv_buf > -1)
2132 1.2 christos options->tcp_rcv_buf *=1024;
2133 1.2 christos if (options->tcp_rcv_buf_poll == -1)
2134 1.2 christos options->tcp_rcv_buf_poll = 1;
2135 1.1 christos if (options->control_master == -1)
2136 1.1 christos options->control_master = 0;
2137 1.4 adam if (options->control_persist == -1) {
2138 1.4 adam options->control_persist = 0;
2139 1.4 adam options->control_persist_timeout = 0;
2140 1.4 adam }
2141 1.1 christos if (options->hash_known_hosts == -1)
2142 1.1 christos options->hash_known_hosts = 0;
2143 1.1 christos if (options->tun_open == -1)
2144 1.1 christos options->tun_open = SSH_TUNMODE_NO;
2145 1.1 christos if (options->tun_local == -1)
2146 1.1 christos options->tun_local = SSH_TUNID_ANY;
2147 1.1 christos if (options->tun_remote == -1)
2148 1.1 christos options->tun_remote = SSH_TUNID_ANY;
2149 1.1 christos if (options->permit_local_command == -1)
2150 1.1 christos options->permit_local_command = 0;
2151 1.1 christos if (options->visual_host_key == -1)
2152 1.1 christos options->visual_host_key = 0;
2153 1.5 christos if (options->ip_qos_interactive == -1)
2154 1.5 christos options->ip_qos_interactive = IPTOS_LOWDELAY;
2155 1.5 christos if (options->ip_qos_bulk == -1)
2156 1.5 christos options->ip_qos_bulk = IPTOS_THROUGHPUT;
2157 1.6 christos if (options->request_tty == -1)
2158 1.6 christos options->request_tty = REQUEST_TTY_AUTO;
2159 1.12 christos if (options->proxy_use_fdpass == -1)
2160 1.12 christos options->proxy_use_fdpass = 0;
2161 1.12 christos if (options->canonicalize_max_dots == -1)
2162 1.12 christos options->canonicalize_max_dots = 1;
2163 1.12 christos if (options->canonicalize_fallback_local == -1)
2164 1.12 christos options->canonicalize_fallback_local = 1;
2165 1.12 christos if (options->canonicalize_hostname == -1)
2166 1.12 christos options->canonicalize_hostname = SSH_CANONICALISE_NO;
2167 1.13 christos if (options->fingerprint_hash == -1)
2168 1.13 christos options->fingerprint_hash = SSH_FP_HASH_DEFAULT;
2169 1.13 christos if (options->update_hostkeys == -1)
2170 1.13 christos options->update_hostkeys = 0;
2171 1.16 christos if (kex_assemble_names(KEX_CLIENT_ENCRYPT, &options->ciphers) != 0 ||
2172 1.16 christos kex_assemble_names(KEX_CLIENT_MAC, &options->macs) != 0 ||
2173 1.16 christos kex_assemble_names(KEX_CLIENT_KEX, &options->kex_algorithms) != 0 ||
2174 1.16 christos kex_assemble_names(KEX_DEFAULT_PK_ALG,
2175 1.16 christos &options->hostbased_key_types) != 0 ||
2176 1.16 christos kex_assemble_names(KEX_DEFAULT_PK_ALG,
2177 1.16 christos &options->pubkey_key_types) != 0)
2178 1.16 christos fatal("%s: kex_assemble_names failed", __func__);
2179 1.13 christos
2180 1.7 tls if (options->send_version_first == -1)
2181 1.7 tls options->send_version_first = 1;
2182 1.12 christos #define CLEAR_ON_NONE(v) \
2183 1.12 christos do { \
2184 1.12 christos if (option_clear_or_none(v)) { \
2185 1.12 christos free(v); \
2186 1.12 christos v = NULL; \
2187 1.12 christos } \
2188 1.12 christos } while(0)
2189 1.12 christos CLEAR_ON_NONE(options->local_command);
2190 1.12 christos CLEAR_ON_NONE(options->proxy_command);
2191 1.12 christos CLEAR_ON_NONE(options->control_path);
2192 1.13 christos CLEAR_ON_NONE(options->revoked_host_keys);
2193 1.18.2.1 pgoyette /* options->identity_agent distinguishes NULL from 'none' */
2194 1.1 christos /* options->user will be set in the main program if appropriate */
2195 1.1 christos /* options->hostname will be set in the main program if appropriate */
2196 1.1 christos /* options->host_key_alias should not be set by default */
2197 1.1 christos /* options->preferred_authentications will be set in ssh */
2198 1.1 christos }
2199 1.1 christos
2200 1.12 christos struct fwdarg {
2201 1.12 christos char *arg;
2202 1.12 christos int ispath;
2203 1.12 christos };
2204 1.12 christos
2205 1.12 christos /*
2206 1.12 christos * parse_fwd_field
2207 1.12 christos * parses the next field in a port forwarding specification.
2208 1.12 christos * sets fwd to the parsed field and advances p past the colon
2209 1.12 christos * or sets it to NULL at end of string.
2210 1.12 christos * returns 0 on success, else non-zero.
2211 1.12 christos */
2212 1.12 christos static int
2213 1.12 christos parse_fwd_field(char **p, struct fwdarg *fwd)
2214 1.12 christos {
2215 1.12 christos char *ep, *cp = *p;
2216 1.12 christos int ispath = 0;
2217 1.12 christos
2218 1.12 christos if (*cp == '\0') {
2219 1.12 christos *p = NULL;
2220 1.12 christos return -1; /* end of string */
2221 1.12 christos }
2222 1.12 christos
2223 1.12 christos /*
2224 1.12 christos * A field escaped with square brackets is used literally.
2225 1.12 christos * XXX - allow ']' to be escaped via backslash?
2226 1.12 christos */
2227 1.12 christos if (*cp == '[') {
2228 1.12 christos /* find matching ']' */
2229 1.12 christos for (ep = cp + 1; *ep != ']' && *ep != '\0'; ep++) {
2230 1.12 christos if (*ep == '/')
2231 1.12 christos ispath = 1;
2232 1.12 christos }
2233 1.12 christos /* no matching ']' or not at end of field. */
2234 1.12 christos if (ep[0] != ']' || (ep[1] != ':' && ep[1] != '\0'))
2235 1.12 christos return -1;
2236 1.12 christos /* NUL terminate the field and advance p past the colon */
2237 1.12 christos *ep++ = '\0';
2238 1.12 christos if (*ep != '\0')
2239 1.12 christos *ep++ = '\0';
2240 1.12 christos fwd->arg = cp + 1;
2241 1.12 christos fwd->ispath = ispath;
2242 1.12 christos *p = ep;
2243 1.12 christos return 0;
2244 1.12 christos }
2245 1.12 christos
2246 1.12 christos for (cp = *p; *cp != '\0'; cp++) {
2247 1.12 christos switch (*cp) {
2248 1.12 christos case '\\':
2249 1.12 christos memmove(cp, cp + 1, strlen(cp + 1) + 1);
2250 1.14 christos if (*cp == '\0')
2251 1.14 christos return -1;
2252 1.12 christos break;
2253 1.12 christos case '/':
2254 1.12 christos ispath = 1;
2255 1.12 christos break;
2256 1.12 christos case ':':
2257 1.12 christos *cp++ = '\0';
2258 1.12 christos goto done;
2259 1.12 christos }
2260 1.12 christos }
2261 1.12 christos done:
2262 1.12 christos fwd->arg = *p;
2263 1.12 christos fwd->ispath = ispath;
2264 1.12 christos *p = cp;
2265 1.12 christos return 0;
2266 1.12 christos }
2267 1.12 christos
2268 1.1 christos /*
2269 1.1 christos * parse_forward
2270 1.1 christos * parses a string containing a port forwarding specification of the form:
2271 1.1 christos * dynamicfwd == 0
2272 1.12 christos * [listenhost:]listenport|listenpath:connecthost:connectport|connectpath
2273 1.12 christos * listenpath:connectpath
2274 1.1 christos * dynamicfwd == 1
2275 1.1 christos * [listenhost:]listenport
2276 1.1 christos * returns number of arguments parsed or zero on error
2277 1.1 christos */
2278 1.1 christos int
2279 1.12 christos parse_forward(struct Forward *fwd, const char *fwdspec, int dynamicfwd, int remotefwd)
2280 1.1 christos {
2281 1.12 christos struct fwdarg fwdargs[4];
2282 1.12 christos char *p, *cp;
2283 1.1 christos int i;
2284 1.1 christos
2285 1.12 christos memset(fwd, 0, sizeof(*fwd));
2286 1.12 christos memset(fwdargs, 0, sizeof(fwdargs));
2287 1.1 christos
2288 1.1 christos cp = p = xstrdup(fwdspec);
2289 1.1 christos
2290 1.1 christos /* skip leading spaces */
2291 1.12 christos while (isspace((u_char)*cp))
2292 1.1 christos cp++;
2293 1.1 christos
2294 1.12 christos for (i = 0; i < 4; ++i) {
2295 1.12 christos if (parse_fwd_field(&cp, &fwdargs[i]) != 0)
2296 1.1 christos break;
2297 1.12 christos }
2298 1.1 christos
2299 1.1 christos /* Check for trailing garbage */
2300 1.12 christos if (cp != NULL && *cp != '\0') {
2301 1.1 christos i = 0; /* failure */
2302 1.12 christos }
2303 1.1 christos
2304 1.1 christos switch (i) {
2305 1.1 christos case 1:
2306 1.12 christos if (fwdargs[0].ispath) {
2307 1.12 christos fwd->listen_path = xstrdup(fwdargs[0].arg);
2308 1.12 christos fwd->listen_port = PORT_STREAMLOCAL;
2309 1.12 christos } else {
2310 1.12 christos fwd->listen_host = NULL;
2311 1.12 christos fwd->listen_port = a2port(fwdargs[0].arg);
2312 1.12 christos }
2313 1.1 christos fwd->connect_host = xstrdup("socks");
2314 1.1 christos break;
2315 1.1 christos
2316 1.1 christos case 2:
2317 1.12 christos if (fwdargs[0].ispath && fwdargs[1].ispath) {
2318 1.12 christos fwd->listen_path = xstrdup(fwdargs[0].arg);
2319 1.12 christos fwd->listen_port = PORT_STREAMLOCAL;
2320 1.12 christos fwd->connect_path = xstrdup(fwdargs[1].arg);
2321 1.12 christos fwd->connect_port = PORT_STREAMLOCAL;
2322 1.12 christos } else if (fwdargs[1].ispath) {
2323 1.12 christos fwd->listen_host = NULL;
2324 1.12 christos fwd->listen_port = a2port(fwdargs[0].arg);
2325 1.12 christos fwd->connect_path = xstrdup(fwdargs[1].arg);
2326 1.12 christos fwd->connect_port = PORT_STREAMLOCAL;
2327 1.12 christos } else {
2328 1.12 christos fwd->listen_host = xstrdup(fwdargs[0].arg);
2329 1.12 christos fwd->listen_port = a2port(fwdargs[1].arg);
2330 1.12 christos fwd->connect_host = xstrdup("socks");
2331 1.12 christos }
2332 1.1 christos break;
2333 1.1 christos
2334 1.1 christos case 3:
2335 1.12 christos if (fwdargs[0].ispath) {
2336 1.12 christos fwd->listen_path = xstrdup(fwdargs[0].arg);
2337 1.12 christos fwd->listen_port = PORT_STREAMLOCAL;
2338 1.12 christos fwd->connect_host = xstrdup(fwdargs[1].arg);
2339 1.12 christos fwd->connect_port = a2port(fwdargs[2].arg);
2340 1.12 christos } else if (fwdargs[2].ispath) {
2341 1.12 christos fwd->listen_host = xstrdup(fwdargs[0].arg);
2342 1.12 christos fwd->listen_port = a2port(fwdargs[1].arg);
2343 1.12 christos fwd->connect_path = xstrdup(fwdargs[2].arg);
2344 1.12 christos fwd->connect_port = PORT_STREAMLOCAL;
2345 1.12 christos } else {
2346 1.12 christos fwd->listen_host = NULL;
2347 1.12 christos fwd->listen_port = a2port(fwdargs[0].arg);
2348 1.12 christos fwd->connect_host = xstrdup(fwdargs[1].arg);
2349 1.12 christos fwd->connect_port = a2port(fwdargs[2].arg);
2350 1.12 christos }
2351 1.1 christos break;
2352 1.1 christos
2353 1.1 christos case 4:
2354 1.12 christos fwd->listen_host = xstrdup(fwdargs[0].arg);
2355 1.12 christos fwd->listen_port = a2port(fwdargs[1].arg);
2356 1.12 christos fwd->connect_host = xstrdup(fwdargs[2].arg);
2357 1.12 christos fwd->connect_port = a2port(fwdargs[3].arg);
2358 1.1 christos break;
2359 1.1 christos default:
2360 1.1 christos i = 0; /* failure */
2361 1.1 christos }
2362 1.1 christos
2363 1.11 christos free(p);
2364 1.1 christos
2365 1.1 christos if (dynamicfwd) {
2366 1.1 christos if (!(i == 1 || i == 2))
2367 1.1 christos goto fail_free;
2368 1.1 christos } else {
2369 1.12 christos if (!(i == 3 || i == 4)) {
2370 1.12 christos if (fwd->connect_path == NULL &&
2371 1.12 christos fwd->listen_path == NULL)
2372 1.12 christos goto fail_free;
2373 1.12 christos }
2374 1.12 christos if (fwd->connect_port <= 0 && fwd->connect_path == NULL)
2375 1.1 christos goto fail_free;
2376 1.1 christos }
2377 1.1 christos
2378 1.12 christos if ((fwd->listen_port < 0 && fwd->listen_path == NULL) ||
2379 1.12 christos (!remotefwd && fwd->listen_port == 0))
2380 1.1 christos goto fail_free;
2381 1.1 christos if (fwd->connect_host != NULL &&
2382 1.1 christos strlen(fwd->connect_host) >= NI_MAXHOST)
2383 1.1 christos goto fail_free;
2384 1.12 christos /* XXX - if connecting to a remote socket, max sun len may not match this host */
2385 1.12 christos if (fwd->connect_path != NULL &&
2386 1.12 christos strlen(fwd->connect_path) >= PATH_MAX_SUN)
2387 1.12 christos goto fail_free;
2388 1.1 christos if (fwd->listen_host != NULL &&
2389 1.1 christos strlen(fwd->listen_host) >= NI_MAXHOST)
2390 1.1 christos goto fail_free;
2391 1.12 christos if (fwd->listen_path != NULL &&
2392 1.12 christos strlen(fwd->listen_path) >= PATH_MAX_SUN)
2393 1.12 christos goto fail_free;
2394 1.1 christos
2395 1.1 christos return (i);
2396 1.1 christos
2397 1.1 christos fail_free:
2398 1.11 christos free(fwd->connect_host);
2399 1.11 christos fwd->connect_host = NULL;
2400 1.12 christos free(fwd->connect_path);
2401 1.12 christos fwd->connect_path = NULL;
2402 1.11 christos free(fwd->listen_host);
2403 1.11 christos fwd->listen_host = NULL;
2404 1.12 christos free(fwd->listen_path);
2405 1.12 christos fwd->listen_path = NULL;
2406 1.1 christos return (0);
2407 1.1 christos }
2408 1.13 christos
2409 1.18.2.1 pgoyette int
2410 1.18.2.1 pgoyette parse_jump(const char *s, Options *o, int active)
2411 1.18.2.1 pgoyette {
2412 1.18.2.1 pgoyette char *orig, *sdup, *cp;
2413 1.18.2.1 pgoyette char *host = NULL, *user = NULL;
2414 1.18.2.1 pgoyette int ret = -1, port = -1, first;
2415 1.18.2.1 pgoyette
2416 1.18.2.1 pgoyette active &= o->proxy_command == NULL && o->jump_host == NULL;
2417 1.18.2.1 pgoyette
2418 1.18.2.1 pgoyette orig = sdup = xstrdup(s);
2419 1.18.2.1 pgoyette first = active;
2420 1.18.2.1 pgoyette do {
2421 1.18.2.1 pgoyette if ((cp = strrchr(sdup, ',')) == NULL)
2422 1.18.2.1 pgoyette cp = sdup; /* last */
2423 1.18.2.1 pgoyette else
2424 1.18.2.1 pgoyette *cp++ = '\0';
2425 1.18.2.1 pgoyette
2426 1.18.2.1 pgoyette if (first) {
2427 1.18.2.1 pgoyette /* First argument and configuration is active */
2428 1.18.2.1 pgoyette if (parse_user_host_port(cp, &user, &host, &port) != 0)
2429 1.18.2.1 pgoyette goto out;
2430 1.18.2.1 pgoyette } else {
2431 1.18.2.1 pgoyette /* Subsequent argument or inactive configuration */
2432 1.18.2.1 pgoyette if (parse_user_host_port(cp, NULL, NULL, NULL) != 0)
2433 1.18.2.1 pgoyette goto out;
2434 1.18.2.1 pgoyette }
2435 1.18.2.1 pgoyette first = 0; /* only check syntax for subsequent hosts */
2436 1.18.2.1 pgoyette } while (cp != sdup);
2437 1.18.2.1 pgoyette /* success */
2438 1.18.2.1 pgoyette if (active) {
2439 1.18.2.1 pgoyette o->jump_user = user;
2440 1.18.2.1 pgoyette o->jump_host = host;
2441 1.18.2.1 pgoyette o->jump_port = port;
2442 1.18.2.1 pgoyette o->proxy_command = xstrdup("none");
2443 1.18.2.1 pgoyette user = host = NULL;
2444 1.18.2.1 pgoyette if ((cp = strrchr(s, ',')) != NULL && cp != s) {
2445 1.18.2.1 pgoyette o->jump_extra = xstrdup(s);
2446 1.18.2.1 pgoyette o->jump_extra[cp - s] = '\0';
2447 1.18.2.1 pgoyette }
2448 1.18.2.1 pgoyette }
2449 1.18.2.1 pgoyette ret = 0;
2450 1.18.2.1 pgoyette out:
2451 1.18.2.1 pgoyette free(orig);
2452 1.18.2.1 pgoyette free(user);
2453 1.18.2.1 pgoyette free(host);
2454 1.18.2.1 pgoyette return ret;
2455 1.18.2.1 pgoyette }
2456 1.18.2.1 pgoyette
2457 1.13 christos /* XXX the following is a near-vebatim copy from servconf.c; refactor */
2458 1.13 christos static const char *
2459 1.13 christos fmt_multistate_int(int val, const struct multistate *m)
2460 1.13 christos {
2461 1.13 christos u_int i;
2462 1.13 christos
2463 1.13 christos for (i = 0; m[i].key != NULL; i++) {
2464 1.13 christos if (m[i].value == val)
2465 1.13 christos return m[i].key;
2466 1.13 christos }
2467 1.13 christos return "UNKNOWN";
2468 1.13 christos }
2469 1.13 christos
2470 1.13 christos static const char *
2471 1.13 christos fmt_intarg(OpCodes code, int val)
2472 1.13 christos {
2473 1.13 christos if (val == -1)
2474 1.13 christos return "unset";
2475 1.13 christos switch (code) {
2476 1.13 christos case oAddressFamily:
2477 1.13 christos return fmt_multistate_int(val, multistate_addressfamily);
2478 1.13 christos case oVerifyHostKeyDNS:
2479 1.13 christos case oStrictHostKeyChecking:
2480 1.13 christos case oUpdateHostkeys:
2481 1.13 christos return fmt_multistate_int(val, multistate_yesnoask);
2482 1.13 christos case oControlMaster:
2483 1.13 christos return fmt_multistate_int(val, multistate_controlmaster);
2484 1.13 christos case oTunnel:
2485 1.13 christos return fmt_multistate_int(val, multistate_tunnel);
2486 1.13 christos case oRequestTTY:
2487 1.13 christos return fmt_multistate_int(val, multistate_requesttty);
2488 1.13 christos case oCanonicalizeHostname:
2489 1.13 christos return fmt_multistate_int(val, multistate_canonicalizehostname);
2490 1.13 christos case oFingerprintHash:
2491 1.13 christos return ssh_digest_alg_name(val);
2492 1.13 christos case oProtocol:
2493 1.13 christos switch (val) {
2494 1.13 christos case SSH_PROTO_1:
2495 1.13 christos return "1";
2496 1.13 christos case SSH_PROTO_2:
2497 1.13 christos return "2";
2498 1.13 christos case (SSH_PROTO_1|SSH_PROTO_2):
2499 1.13 christos return "2,1";
2500 1.13 christos default:
2501 1.13 christos return "UNKNOWN";
2502 1.13 christos }
2503 1.13 christos default:
2504 1.13 christos switch (val) {
2505 1.13 christos case 0:
2506 1.13 christos return "no";
2507 1.13 christos case 1:
2508 1.13 christos return "yes";
2509 1.13 christos default:
2510 1.13 christos return "UNKNOWN";
2511 1.13 christos }
2512 1.13 christos }
2513 1.13 christos }
2514 1.13 christos
2515 1.13 christos static const char *
2516 1.13 christos lookup_opcode_name(OpCodes code)
2517 1.13 christos {
2518 1.13 christos u_int i;
2519 1.13 christos
2520 1.13 christos for (i = 0; keywords[i].name != NULL; i++)
2521 1.13 christos if (keywords[i].opcode == code)
2522 1.13 christos return(keywords[i].name);
2523 1.13 christos return "UNKNOWN";
2524 1.13 christos }
2525 1.13 christos
2526 1.13 christos static void
2527 1.13 christos dump_cfg_int(OpCodes code, int val)
2528 1.13 christos {
2529 1.13 christos printf("%s %d\n", lookup_opcode_name(code), val);
2530 1.13 christos }
2531 1.13 christos
2532 1.13 christos static void
2533 1.13 christos dump_cfg_fmtint(OpCodes code, int val)
2534 1.13 christos {
2535 1.13 christos printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
2536 1.13 christos }
2537 1.13 christos
2538 1.13 christos static void
2539 1.13 christos dump_cfg_string(OpCodes code, const char *val)
2540 1.13 christos {
2541 1.13 christos if (val == NULL)
2542 1.13 christos return;
2543 1.13 christos printf("%s %s\n", lookup_opcode_name(code), val);
2544 1.13 christos }
2545 1.13 christos
2546 1.13 christos static void
2547 1.13 christos dump_cfg_strarray(OpCodes code, u_int count, char **vals)
2548 1.13 christos {
2549 1.13 christos u_int i;
2550 1.13 christos
2551 1.13 christos for (i = 0; i < count; i++)
2552 1.13 christos printf("%s %s\n", lookup_opcode_name(code), vals[i]);
2553 1.13 christos }
2554 1.13 christos
2555 1.13 christos static void
2556 1.13 christos dump_cfg_strarray_oneline(OpCodes code, u_int count, char **vals)
2557 1.13 christos {
2558 1.13 christos u_int i;
2559 1.13 christos
2560 1.13 christos printf("%s", lookup_opcode_name(code));
2561 1.13 christos for (i = 0; i < count; i++)
2562 1.13 christos printf(" %s", vals[i]);
2563 1.13 christos printf("\n");
2564 1.13 christos }
2565 1.13 christos
2566 1.13 christos static void
2567 1.13 christos dump_cfg_forwards(OpCodes code, u_int count, const struct Forward *fwds)
2568 1.13 christos {
2569 1.13 christos const struct Forward *fwd;
2570 1.13 christos u_int i;
2571 1.13 christos
2572 1.13 christos /* oDynamicForward */
2573 1.13 christos for (i = 0; i < count; i++) {
2574 1.13 christos fwd = &fwds[i];
2575 1.13 christos if (code == oDynamicForward &&
2576 1.13 christos strcmp(fwd->connect_host, "socks") != 0)
2577 1.13 christos continue;
2578 1.13 christos if (code == oLocalForward &&
2579 1.13 christos strcmp(fwd->connect_host, "socks") == 0)
2580 1.13 christos continue;
2581 1.13 christos printf("%s", lookup_opcode_name(code));
2582 1.13 christos if (fwd->listen_port == PORT_STREAMLOCAL)
2583 1.13 christos printf(" %s", fwd->listen_path);
2584 1.13 christos else if (fwd->listen_host == NULL)
2585 1.13 christos printf(" %d", fwd->listen_port);
2586 1.13 christos else {
2587 1.13 christos printf(" [%s]:%d",
2588 1.13 christos fwd->listen_host, fwd->listen_port);
2589 1.13 christos }
2590 1.13 christos if (code != oDynamicForward) {
2591 1.13 christos if (fwd->connect_port == PORT_STREAMLOCAL)
2592 1.13 christos printf(" %s", fwd->connect_path);
2593 1.13 christos else if (fwd->connect_host == NULL)
2594 1.13 christos printf(" %d", fwd->connect_port);
2595 1.13 christos else {
2596 1.13 christos printf(" [%s]:%d",
2597 1.13 christos fwd->connect_host, fwd->connect_port);
2598 1.13 christos }
2599 1.13 christos }
2600 1.13 christos printf("\n");
2601 1.13 christos }
2602 1.13 christos }
2603 1.13 christos
2604 1.13 christos void
2605 1.13 christos dump_client_config(Options *o, const char *host)
2606 1.13 christos {
2607 1.13 christos int i;
2608 1.18.2.1 pgoyette char buf[8];
2609 1.13 christos
2610 1.18 christos /* This is normally prepared in ssh_kex2 */
2611 1.18 christos if (kex_assemble_names(KEX_DEFAULT_PK_ALG, &o->hostkeyalgorithms) != 0)
2612 1.18 christos fatal("%s: kex_assemble_names failed", __func__);
2613 1.18 christos
2614 1.13 christos /* Most interesting options first: user, host, port */
2615 1.13 christos dump_cfg_string(oUser, o->user);
2616 1.13 christos dump_cfg_string(oHostName, host);
2617 1.13 christos dump_cfg_int(oPort, o->port);
2618 1.13 christos
2619 1.13 christos /* Flag options */
2620 1.13 christos dump_cfg_fmtint(oAddressFamily, o->address_family);
2621 1.13 christos dump_cfg_fmtint(oBatchMode, o->batch_mode);
2622 1.13 christos dump_cfg_fmtint(oCanonicalizeFallbackLocal, o->canonicalize_fallback_local);
2623 1.13 christos dump_cfg_fmtint(oCanonicalizeHostname, o->canonicalize_hostname);
2624 1.13 christos dump_cfg_fmtint(oChallengeResponseAuthentication, o->challenge_response_authentication);
2625 1.13 christos dump_cfg_fmtint(oCheckHostIP, o->check_host_ip);
2626 1.13 christos dump_cfg_fmtint(oCompression, o->compression);
2627 1.13 christos dump_cfg_fmtint(oControlMaster, o->control_master);
2628 1.13 christos dump_cfg_fmtint(oEnableSSHKeysign, o->enable_ssh_keysign);
2629 1.18.2.1 pgoyette dump_cfg_fmtint(oClearAllForwardings, o->clear_forwardings);
2630 1.13 christos dump_cfg_fmtint(oExitOnForwardFailure, o->exit_on_forward_failure);
2631 1.13 christos dump_cfg_fmtint(oFingerprintHash, o->fingerprint_hash);
2632 1.13 christos dump_cfg_fmtint(oForwardAgent, o->forward_agent);
2633 1.13 christos dump_cfg_fmtint(oForwardX11, o->forward_x11);
2634 1.13 christos dump_cfg_fmtint(oForwardX11Trusted, o->forward_x11_trusted);
2635 1.13 christos dump_cfg_fmtint(oGatewayPorts, o->fwd_opts.gateway_ports);
2636 1.13 christos #ifdef GSSAPI
2637 1.13 christos dump_cfg_fmtint(oGssAuthentication, o->gss_authentication);
2638 1.13 christos dump_cfg_fmtint(oGssDelegateCreds, o->gss_deleg_creds);
2639 1.13 christos #endif /* GSSAPI */
2640 1.13 christos dump_cfg_fmtint(oHashKnownHosts, o->hash_known_hosts);
2641 1.13 christos dump_cfg_fmtint(oHostbasedAuthentication, o->hostbased_authentication);
2642 1.13 christos dump_cfg_fmtint(oIdentitiesOnly, o->identities_only);
2643 1.13 christos dump_cfg_fmtint(oKbdInteractiveAuthentication, o->kbd_interactive_authentication);
2644 1.13 christos dump_cfg_fmtint(oNoHostAuthenticationForLocalhost, o->no_host_authentication_for_localhost);
2645 1.13 christos dump_cfg_fmtint(oPasswordAuthentication, o->password_authentication);
2646 1.13 christos dump_cfg_fmtint(oPermitLocalCommand, o->permit_local_command);
2647 1.13 christos dump_cfg_fmtint(oProtocol, o->protocol);
2648 1.13 christos dump_cfg_fmtint(oProxyUseFdpass, o->proxy_use_fdpass);
2649 1.13 christos dump_cfg_fmtint(oPubkeyAuthentication, o->pubkey_authentication);
2650 1.13 christos dump_cfg_fmtint(oRequestTTY, o->request_tty);
2651 1.13 christos dump_cfg_fmtint(oRhostsRSAAuthentication, o->rhosts_rsa_authentication);
2652 1.13 christos dump_cfg_fmtint(oRSAAuthentication, o->rsa_authentication);
2653 1.13 christos dump_cfg_fmtint(oStreamLocalBindUnlink, o->fwd_opts.streamlocal_bind_unlink);
2654 1.13 christos dump_cfg_fmtint(oStrictHostKeyChecking, o->strict_host_key_checking);
2655 1.13 christos dump_cfg_fmtint(oTCPKeepAlive, o->tcp_keep_alive);
2656 1.13 christos dump_cfg_fmtint(oTunnel, o->tun_open);
2657 1.13 christos dump_cfg_fmtint(oUsePrivilegedPort, o->use_privileged_port);
2658 1.13 christos dump_cfg_fmtint(oVerifyHostKeyDNS, o->verify_host_key_dns);
2659 1.13 christos dump_cfg_fmtint(oVisualHostKey, o->visual_host_key);
2660 1.13 christos dump_cfg_fmtint(oUpdateHostkeys, o->update_hostkeys);
2661 1.13 christos
2662 1.13 christos /* Integer options */
2663 1.13 christos dump_cfg_int(oCanonicalizeMaxDots, o->canonicalize_max_dots);
2664 1.13 christos dump_cfg_int(oCompressionLevel, o->compression_level);
2665 1.13 christos dump_cfg_int(oConnectionAttempts, o->connection_attempts);
2666 1.13 christos dump_cfg_int(oForwardX11Timeout, o->forward_x11_timeout);
2667 1.13 christos dump_cfg_int(oNumberOfPasswordPrompts, o->number_of_password_prompts);
2668 1.13 christos dump_cfg_int(oServerAliveCountMax, o->server_alive_count_max);
2669 1.13 christos dump_cfg_int(oServerAliveInterval, o->server_alive_interval);
2670 1.13 christos
2671 1.13 christos /* String options */
2672 1.13 christos dump_cfg_string(oBindAddress, o->bind_address);
2673 1.13 christos dump_cfg_string(oCiphers, o->ciphers ? o->ciphers : KEX_CLIENT_ENCRYPT);
2674 1.13 christos dump_cfg_string(oControlPath, o->control_path);
2675 1.18 christos dump_cfg_string(oHostKeyAlgorithms, o->hostkeyalgorithms);
2676 1.13 christos dump_cfg_string(oHostKeyAlias, o->host_key_alias);
2677 1.13 christos dump_cfg_string(oHostbasedKeyTypes, o->hostbased_key_types);
2678 1.18.2.1 pgoyette dump_cfg_string(oIdentityAgent, o->identity_agent);
2679 1.13 christos dump_cfg_string(oKbdInteractiveDevices, o->kbd_interactive_devices);
2680 1.13 christos dump_cfg_string(oKexAlgorithms, o->kex_algorithms ? o->kex_algorithms : KEX_CLIENT_KEX);
2681 1.13 christos dump_cfg_string(oLocalCommand, o->local_command);
2682 1.13 christos dump_cfg_string(oLogLevel, log_level_name(o->log_level));
2683 1.13 christos dump_cfg_string(oMacs, o->macs ? o->macs : KEX_CLIENT_MAC);
2684 1.13 christos dump_cfg_string(oPKCS11Provider, o->pkcs11_provider);
2685 1.13 christos dump_cfg_string(oPreferredAuthentications, o->preferred_authentications);
2686 1.18 christos dump_cfg_string(oPubkeyAcceptedKeyTypes, o->pubkey_key_types);
2687 1.13 christos dump_cfg_string(oRevokedHostKeys, o->revoked_host_keys);
2688 1.13 christos dump_cfg_string(oXAuthLocation, o->xauth_location);
2689 1.13 christos
2690 1.13 christos /* Forwards */
2691 1.13 christos dump_cfg_forwards(oDynamicForward, o->num_local_forwards, o->local_forwards);
2692 1.13 christos dump_cfg_forwards(oLocalForward, o->num_local_forwards, o->local_forwards);
2693 1.13 christos dump_cfg_forwards(oRemoteForward, o->num_remote_forwards, o->remote_forwards);
2694 1.13 christos
2695 1.13 christos /* String array options */
2696 1.13 christos dump_cfg_strarray(oIdentityFile, o->num_identity_files, o->identity_files);
2697 1.13 christos dump_cfg_strarray_oneline(oCanonicalDomains, o->num_canonical_domains, o->canonical_domains);
2698 1.13 christos dump_cfg_strarray_oneline(oGlobalKnownHostsFile, o->num_system_hostfiles, o->system_hostfiles);
2699 1.13 christos dump_cfg_strarray_oneline(oUserKnownHostsFile, o->num_user_hostfiles, o->user_hostfiles);
2700 1.13 christos dump_cfg_strarray(oSendEnv, o->num_send_env, o->send_env);
2701 1.13 christos
2702 1.13 christos /* Special cases */
2703 1.13 christos
2704 1.13 christos /* oConnectTimeout */
2705 1.13 christos if (o->connection_timeout == -1)
2706 1.13 christos printf("connecttimeout none\n");
2707 1.13 christos else
2708 1.13 christos dump_cfg_int(oConnectTimeout, o->connection_timeout);
2709 1.13 christos
2710 1.13 christos /* oTunnelDevice */
2711 1.13 christos printf("tunneldevice");
2712 1.13 christos if (o->tun_local == SSH_TUNID_ANY)
2713 1.13 christos printf(" any");
2714 1.13 christos else
2715 1.13 christos printf(" %d", o->tun_local);
2716 1.13 christos if (o->tun_remote == SSH_TUNID_ANY)
2717 1.13 christos printf(":any");
2718 1.13 christos else
2719 1.13 christos printf(":%d", o->tun_remote);
2720 1.13 christos printf("\n");
2721 1.13 christos
2722 1.13 christos /* oCanonicalizePermittedCNAMEs */
2723 1.13 christos if ( o->num_permitted_cnames > 0) {
2724 1.13 christos printf("canonicalizePermittedcnames");
2725 1.13 christos for (i = 0; i < o->num_permitted_cnames; i++) {
2726 1.13 christos printf(" %s:%s", o->permitted_cnames[i].source_list,
2727 1.13 christos o->permitted_cnames[i].target_list);
2728 1.13 christos }
2729 1.13 christos printf("\n");
2730 1.13 christos }
2731 1.13 christos
2732 1.13 christos /* oCipher */
2733 1.13 christos if (o->cipher != SSH_CIPHER_NOT_SET)
2734 1.13 christos printf("Cipher %s\n", cipher_name(o->cipher));
2735 1.13 christos
2736 1.13 christos /* oControlPersist */
2737 1.13 christos if (o->control_persist == 0 || o->control_persist_timeout == 0)
2738 1.13 christos dump_cfg_fmtint(oControlPersist, o->control_persist);
2739 1.13 christos else
2740 1.13 christos dump_cfg_int(oControlPersist, o->control_persist_timeout);
2741 1.13 christos
2742 1.13 christos /* oEscapeChar */
2743 1.13 christos if (o->escape_char == SSH_ESCAPECHAR_NONE)
2744 1.13 christos printf("escapechar none\n");
2745 1.13 christos else {
2746 1.18.2.1 pgoyette vis(buf, o->escape_char, VIS_WHITE, 0);
2747 1.18.2.1 pgoyette printf("escapechar %s\n", buf);
2748 1.13 christos }
2749 1.13 christos
2750 1.13 christos /* oIPQoS */
2751 1.13 christos printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
2752 1.13 christos printf("%s\n", iptos2str(o->ip_qos_bulk));
2753 1.13 christos
2754 1.13 christos /* oRekeyLimit */
2755 1.18 christos printf("rekeylimit %llu %d\n",
2756 1.18 christos (unsigned long long)o->rekey_limit, o->rekey_interval);
2757 1.13 christos
2758 1.13 christos /* oStreamLocalBindMask */
2759 1.13 christos printf("streamlocalbindmask 0%o\n",
2760 1.13 christos o->fwd_opts.streamlocal_bind_mask);
2761 1.18.2.1 pgoyette
2762 1.18.2.1 pgoyette /* oProxyCommand / oProxyJump */
2763 1.18.2.1 pgoyette if (o->jump_host == NULL)
2764 1.18.2.1 pgoyette dump_cfg_string(oProxyCommand, o->proxy_command);
2765 1.18.2.1 pgoyette else {
2766 1.18.2.1 pgoyette /* Check for numeric addresses */
2767 1.18.2.1 pgoyette i = strchr(o->jump_host, ':') != NULL ||
2768 1.18.2.1 pgoyette strspn(o->jump_host, "1234567890.") == strlen(o->jump_host);
2769 1.18.2.1 pgoyette snprintf(buf, sizeof(buf), "%d", o->jump_port);
2770 1.18.2.1 pgoyette printf("proxyjump %s%s%s%s%s%s%s%s%s\n",
2771 1.18.2.1 pgoyette /* optional additional jump spec */
2772 1.18.2.1 pgoyette o->jump_extra == NULL ? "" : o->jump_extra,
2773 1.18.2.1 pgoyette o->jump_extra == NULL ? "" : ",",
2774 1.18.2.1 pgoyette /* optional user */
2775 1.18.2.1 pgoyette o->jump_user == NULL ? "" : o->jump_user,
2776 1.18.2.1 pgoyette o->jump_user == NULL ? "" : "@",
2777 1.18.2.1 pgoyette /* opening [ if hostname is numeric */
2778 1.18.2.1 pgoyette i ? "[" : "",
2779 1.18.2.1 pgoyette /* mandatory hostname */
2780 1.18.2.1 pgoyette o->jump_host,
2781 1.18.2.1 pgoyette /* closing ] if hostname is numeric */
2782 1.18.2.1 pgoyette i ? "]" : "",
2783 1.18.2.1 pgoyette /* optional port number */
2784 1.18.2.1 pgoyette o->jump_port <= 0 ? "" : ":",
2785 1.18.2.1 pgoyette o->jump_port <= 0 ? "" : buf);
2786 1.18.2.1 pgoyette }
2787 1.13 christos }
2788