Annotation of src/crypto/external/bsd/openssh/dist/readconf.c, Revision 1.37
1.36 kim 1: /* $NetBSD: readconf.c,v 1.35 2021/09/02 11:26:18 christos Exp $ */
1.37 ! christos 2: /* $OpenBSD: readconf.c,v 1.363 2021/09/16 05:36:03 djm Exp $ */
1.32 christos 3:
1.1 christos 4: /*
5: * Author: Tatu Ylonen <ylo@cs.hut.fi>
6: * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
7: * All rights reserved
8: * Functions for reading the configuration files.
9: *
10: * As far as I am concerned, the code I have written for this software
11: * can be used freely for any purpose. Any derived versions of this
12: * software must be clearly marked as such, and if the derived work is
13: * incompatible with the protocol description in the RFC file, it must be
14: * called by a name other than "ssh" or "Secure Shell".
15: */
16:
1.2 christos 17: #include "includes.h"
1.36 kim 18: __RCSID("$NetBSD: readconf.c,v 1.35 2021/09/02 11:26:18 christos Exp $");
1.1 christos 19: #include <sys/types.h>
20: #include <sys/stat.h>
21: #include <sys/socket.h>
1.12 christos 22: #include <sys/wait.h>
23: #include <sys/un.h>
1.1 christos 24:
25: #include <netinet/in.h>
1.5 christos 26: #include <netinet/ip.h>
1.1 christos 27:
28: #include <ctype.h>
29: #include <errno.h>
1.12 christos 30: #include <fcntl.h>
1.19 christos 31: #include <glob.h>
1.1 christos 32: #include <netdb.h>
1.12 christos 33: #include <paths.h>
34: #include <pwd.h>
1.1 christos 35: #include <signal.h>
36: #include <stdio.h>
37: #include <string.h>
1.29 christos 38: #include <stdarg.h>
1.1 christos 39: #include <unistd.h>
1.2 christos 40: #include <limits.h>
1.11 christos 41: #include <util.h>
1.13 christos 42: #include <vis.h>
1.1 christos 43:
44: #include "xmalloc.h"
45: #include "ssh.h"
1.25 christos 46: #include "ssherr.h"
1.1 christos 47: #include "compat.h"
48: #include "cipher.h"
49: #include "pathnames.h"
50: #include "log.h"
1.13 christos 51: #include "sshkey.h"
1.12 christos 52: #include "misc.h"
1.1 christos 53: #include "readconf.h"
54: #include "match.h"
55: #include "kex.h"
56: #include "mac.h"
1.11 christos 57: #include "fmt_scaled.h"
1.12 christos 58: #include "uidswap.h"
1.13 christos 59: #include "myproposal.h"
60: #include "digest.h"
1.1 christos 61:
62: /* Format of the configuration file:
63:
64: # Configuration data is parsed as follows:
65: # 1. command line options
66: # 2. user-specific file
67: # 3. system-wide file
68: # Any configuration value is only changed the first time it is set.
69: # Thus, host-specific definitions should be at the beginning of the
70: # configuration file, and defaults at the end.
71:
72: # Host-specific declarations. These may override anything above. A single
73: # host may match multiple declarations; these are processed in the order
74: # that they are given in.
75:
76: Host *.ngs.fi ngs.fi
77: User foo
78:
79: Host fake.com
1.28 christos 80: Hostname another.host.name.real.org
1.1 christos 81: User blaah
82: Port 34289
83: ForwardX11 no
84: ForwardAgent no
85:
86: Host books.com
87: RemoteForward 9999 shadows.cs.hut.fi:9999
1.21 christos 88: Ciphers 3des-cbc
1.1 christos 89:
90: Host fascist.blob.com
91: Port 23123
92: User tylonen
93: PasswordAuthentication no
94:
95: Host puukko.hut.fi
96: User t35124p
97: ProxyCommand ssh-proxy %h %p
98:
99: Host *.fr
100: PublicKeyAuthentication no
101:
102: Host *.su
1.21 christos 103: Ciphers aes128-ctr
1.1 christos 104: PasswordAuthentication no
105:
106: Host vpn.fake.com
107: Tunnel yes
108: TunnelDevice 3
109:
110: # Defaults for various options
111: Host *
112: ForwardAgent no
113: ForwardX11 no
114: PasswordAuthentication yes
115: StrictHostKeyChecking yes
116: TcpKeepAlive no
117: IdentityFile ~/.ssh/identity
118: Port 22
119: EscapeChar ~
120:
121: */
122:
1.19 christos 123: static int read_config_file_depth(const char *filename, struct passwd *pw,
124: const char *host, const char *original_host, Options *options,
1.27 christos 125: int flags, int *activep, int *want_final_pass, int depth);
1.19 christos 126: static int process_config_line_depth(Options *options, struct passwd *pw,
127: const char *host, const char *original_host, char *line,
1.27 christos 128: const char *filename, int linenum, int *activep, int flags,
129: int *want_final_pass, int depth);
1.19 christos 130:
1.1 christos 131: /* Keyword tokens. */
132:
133: typedef enum {
134: oBadOption,
1.19 christos 135: oHost, oMatch, oInclude,
1.4 adam 136: oForwardAgent, oForwardX11, oForwardX11Trusted, oForwardX11Timeout,
137: oGatewayPorts, oExitOnForwardFailure,
1.29 christos 138: oPasswordAuthentication,
1.35 christos 139: oXAuthLocation,
1.2 christos 140: #if defined(KRB4) || defined(KRB5)
141: oKerberosAuthentication,
142: #endif
143: #if defined(AFS) || defined(KRB5)
144: oKerberosTgtPassing,
145: #endif
146: #ifdef AFS
147: oAFSTokenPassing,
148: #endif
1.29 christos 149: oIdentityFile, oHostname, oPort, oRemoteForward, oLocalForward,
1.33 christos 150: oPermitRemoteOpen,
1.19 christos 151: oCertificateFile, oAddKeysToAgent, oIdentityAgent,
1.29 christos 152: oUser, oEscapeChar, oProxyCommand,
1.1 christos 153: oGlobalKnownHostsFile, oUserKnownHostsFile, oConnectionAttempts,
154: oBatchMode, oCheckHostIP, oStrictHostKeyChecking, oCompression,
1.29 christos 155: oTCPKeepAlive, oNumberOfPasswordPrompts,
1.33 christos 156: oLogFacility, oLogLevel, oLogVerbose, oCiphers, oMacs,
1.13 christos 157: oPubkeyAuthentication,
1.1 christos 158: oKbdInteractiveAuthentication, oKbdInteractiveDevices, oHostKeyAlias,
159: oDynamicForward, oPreferredAuthentications, oHostbasedAuthentication,
1.23 christos 160: oHostKeyAlgorithms, oBindAddress, oBindInterface, oPKCS11Provider,
1.1 christos 161: oClearAllForwardings, oNoHostAuthenticationForLocalhost,
162: oEnableSSHKeysign, oRekeyLimit, oVerifyHostKeyDNS, oConnectTimeout,
163: oAddressFamily, oGssAuthentication, oGssDelegateCreds,
164: oServerAliveInterval, oServerAliveCountMax, oIdentitiesOnly,
1.25 christos 165: oSendEnv, oSetEnv, oControlPath, oControlMaster, oControlPersist,
1.4 adam 166: oHashKnownHosts,
1.22 christos 167: oTunnel, oTunnelDevice,
168: oLocalCommand, oPermitLocalCommand, oRemoteCommand,
1.17 christos 169: oVisualHostKey,
1.35 christos 170: oKexAlgorithms, oIPQoS, oRequestTTY, oSessionType, oStdinNull,
171: oForkAfterAuthentication, oIgnoreUnknown, oProxyUseFdpass,
1.12 christos 172: oCanonicalDomains, oCanonicalizeHostname, oCanonicalizeMaxDots,
173: oCanonicalizeFallbackLocal, oCanonicalizePermittedCNAMEs,
1.13 christos 174: oStreamLocalBindMask, oStreamLocalBindUnlink, oRevokedHostKeys,
1.33 christos 175: oFingerprintHash, oUpdateHostkeys, oHostbasedAcceptedAlgorithms,
176: oPubkeyAcceptedAlgorithms, oCASignatureAlgorithms, oProxyJump,
177: oSecurityKeyProvider, oKnownHostsCommand,
1.2 christos 178: oNoneEnabled, oTcpRcvBufPoll, oTcpRcvBuf, oNoneSwitch, oHPNDisabled,
179: oHPNBufferSize,
1.7 tls 180: oSendVersionFirst,
1.22 christos 181: oIgnore, oIgnoredUnknownOption, oDeprecated, oUnsupported
1.1 christos 182: } OpCodes;
183:
184: /* Textual representations of the tokens. */
185:
186: static struct {
187: const char *name;
188: OpCodes opcode;
189: } keywords[] = {
1.21 christos 190: /* Deprecated options */
1.22 christos 191: { "protocol", oIgnore }, /* NB. silently ignored */
192: { "cipher", oDeprecated },
1.21 christos 193: { "fallbacktorsh", oDeprecated },
194: { "globalknownhostsfile2", oDeprecated },
195: { "rhostsauthentication", oDeprecated },
196: { "userknownhostsfile2", oDeprecated },
197: { "useroaming", oDeprecated },
198: { "usersh", oDeprecated },
1.25 christos 199: { "useprivilegedport", oDeprecated },
1.21 christos 200:
201: /* Unsupported options */
1.30 kim 202: #ifdef AFS
203: { "afstokenpassing", oAFSTokenPassing },
204: #else
1.21 christos 205: { "afstokenpassing", oUnsupported },
1.30 kim 206: #endif
207: #if defined(KRB4) || defined(KRB5)
208: { "kerberosauthentication", oKerberosAuthentication },
209: #else
1.21 christos 210: { "kerberosauthentication", oUnsupported },
1.30 kim 211: #endif
212: #if defined(AFS) || defined(KRB5)
213: { "kerberostgtpassing", oKerberosTgtPassing },
214: { "kerberos5tgtpassing", oKerberosTgtPassing }, /* alias */
215: { "kerberos4tgtpassing", oKerberosTgtPassing }, /* alias */
216: #else
1.21 christos 217: { "kerberostgtpassing", oUnsupported },
1.30 kim 218: { "kerberos5tgtpassing", oUnsupported },
219: { "kerberos4tgtpassing", oUnsupported },
220: #endif
1.29 christos 221: { "rsaauthentication", oUnsupported },
222: { "rhostsrsaauthentication", oUnsupported },
223: { "compressionlevel", oUnsupported },
1.21 christos 224:
225: /* Sometimes-unsupported options */
226: #if defined(GSSAPI)
227: { "gssapiauthentication", oGssAuthentication },
228: { "gssapidelegatecredentials", oGssDelegateCreds },
229: # else
230: { "gssapiauthentication", oUnsupported },
231: { "gssapidelegatecredentials", oUnsupported },
232: #endif
233: #ifdef ENABLE_PKCS11
1.27 christos 234: { "pkcs11provider", oPKCS11Provider },
1.21 christos 235: { "smartcarddevice", oPKCS11Provider },
236: # else
237: { "smartcarddevice", oUnsupported },
238: { "pkcs11provider", oUnsupported },
239: #endif
240:
1.1 christos 241: { "forwardagent", oForwardAgent },
242: { "forwardx11", oForwardX11 },
243: { "forwardx11trusted", oForwardX11Trusted },
1.4 adam 244: { "forwardx11timeout", oForwardX11Timeout },
1.1 christos 245: { "exitonforwardfailure", oExitOnForwardFailure },
246: { "xauthlocation", oXAuthLocation },
247: { "gatewayports", oGatewayPorts },
248: { "passwordauthentication", oPasswordAuthentication },
249: { "kbdinteractiveauthentication", oKbdInteractiveAuthentication },
250: { "kbdinteractivedevices", oKbdInteractiveDevices },
1.36 kim 251: { "challengeresponseauthentication", oKbdInteractiveAuthentication }, /* alias */
252: { "skeyauthentication", oKbdInteractiveAuthentication }, /* alias */
253: { "tisauthentication", oKbdInteractiveAuthentication }, /* alias */
1.1 christos 254: { "pubkeyauthentication", oPubkeyAuthentication },
255: { "dsaauthentication", oPubkeyAuthentication }, /* alias */
256: { "hostbasedauthentication", oHostbasedAuthentication },
257: #if defined(GSSAPI)
258: { "gssapiauthentication", oGssAuthentication },
259: { "gssapidelegatecredentials", oGssDelegateCreds },
260: #else
261: { "gssapiauthentication", oUnsupported },
262: { "gssapidelegatecredentials", oUnsupported },
263: #endif
264: { "identityfile", oIdentityFile },
265: { "identityfile2", oIdentityFile }, /* obsolete */
266: { "identitiesonly", oIdentitiesOnly },
1.18 christos 267: { "certificatefile", oCertificateFile },
268: { "addkeystoagent", oAddKeysToAgent },
1.19 christos 269: { "identityagent", oIdentityAgent },
1.28 christos 270: { "hostname", oHostname },
1.1 christos 271: { "hostkeyalias", oHostKeyAlias },
272: { "proxycommand", oProxyCommand },
273: { "port", oPort },
274: { "ciphers", oCiphers },
275: { "macs", oMacs },
276: { "remoteforward", oRemoteForward },
277: { "localforward", oLocalForward },
1.33 christos 278: { "permitremoteopen", oPermitRemoteOpen },
1.1 christos 279: { "user", oUser },
280: { "host", oHost },
1.12 christos 281: { "match", oMatch },
1.1 christos 282: { "escapechar", oEscapeChar },
283: { "globalknownhostsfile", oGlobalKnownHostsFile },
284: { "userknownhostsfile", oUserKnownHostsFile },
285: { "connectionattempts", oConnectionAttempts },
286: { "batchmode", oBatchMode },
287: { "checkhostip", oCheckHostIP },
288: { "stricthostkeychecking", oStrictHostKeyChecking },
289: { "compression", oCompression },
290: { "tcpkeepalive", oTCPKeepAlive },
291: { "keepalive", oTCPKeepAlive }, /* obsolete */
292: { "numberofpasswordprompts", oNumberOfPasswordPrompts },
1.22 christos 293: { "syslogfacility", oLogFacility },
1.1 christos 294: { "loglevel", oLogLevel },
1.33 christos 295: { "logverbose", oLogVerbose },
1.1 christos 296: { "dynamicforward", oDynamicForward },
297: { "preferredauthentications", oPreferredAuthentications },
298: { "hostkeyalgorithms", oHostKeyAlgorithms },
1.27 christos 299: { "casignaturealgorithms", oCASignatureAlgorithms },
1.1 christos 300: { "bindaddress", oBindAddress },
1.23 christos 301: { "bindinterface", oBindInterface },
1.1 christos 302: { "clearallforwardings", oClearAllForwardings },
303: { "enablesshkeysign", oEnableSSHKeysign },
304: { "verifyhostkeydns", oVerifyHostKeyDNS },
305: { "nohostauthenticationforlocalhost", oNoHostAuthenticationForLocalhost },
306: { "rekeylimit", oRekeyLimit },
307: { "connecttimeout", oConnectTimeout },
308: { "addressfamily", oAddressFamily },
309: { "serveraliveinterval", oServerAliveInterval },
310: { "serveralivecountmax", oServerAliveCountMax },
311: { "sendenv", oSendEnv },
1.25 christos 312: { "setenv", oSetEnv },
1.1 christos 313: { "controlpath", oControlPath },
314: { "controlmaster", oControlMaster },
1.4 adam 315: { "controlpersist", oControlPersist },
1.1 christos 316: { "hashknownhosts", oHashKnownHosts },
1.19 christos 317: { "include", oInclude },
1.1 christos 318: { "tunnel", oTunnel },
319: { "tunneldevice", oTunnelDevice },
320: { "localcommand", oLocalCommand },
321: { "permitlocalcommand", oPermitLocalCommand },
1.22 christos 322: { "remotecommand", oRemoteCommand },
1.1 christos 323: { "visualhostkey", oVisualHostKey },
1.5 christos 324: { "kexalgorithms", oKexAlgorithms },
325: { "ipqos", oIPQoS },
1.6 christos 326: { "requesttty", oRequestTTY },
1.35 christos 327: { "sessiontype", oSessionType },
328: { "stdinnull", oStdinNull },
329: { "forkafterauthentication", oForkAfterAuthentication },
1.12 christos 330: { "proxyusefdpass", oProxyUseFdpass },
331: { "canonicaldomains", oCanonicalDomains },
332: { "canonicalizefallbacklocal", oCanonicalizeFallbackLocal },
333: { "canonicalizehostname", oCanonicalizeHostname },
334: { "canonicalizemaxdots", oCanonicalizeMaxDots },
335: { "canonicalizepermittedcnames", oCanonicalizePermittedCNAMEs },
336: { "streamlocalbindmask", oStreamLocalBindMask },
337: { "streamlocalbindunlink", oStreamLocalBindUnlink },
1.13 christos 338: { "revokedhostkeys", oRevokedHostKeys },
339: { "fingerprinthash", oFingerprintHash },
340: { "updatehostkeys", oUpdateHostkeys },
1.35 christos 341: { "hostbasedacceptedalgorithms", oHostbasedAcceptedAlgorithms },
1.33 christos 342: { "hostbasedkeytypes", oHostbasedAcceptedAlgorithms }, /* obsolete */
343: { "pubkeyacceptedalgorithms", oPubkeyAcceptedAlgorithms },
344: { "pubkeyacceptedkeytypes", oPubkeyAcceptedAlgorithms }, /* obsolete */
1.19 christos 345: { "proxyjump", oProxyJump },
1.2 christos 346: { "noneenabled", oNoneEnabled },
347: { "tcprcvbufpoll", oTcpRcvBufPoll },
348: { "tcprcvbuf", oTcpRcvBuf },
349: { "noneswitch", oNoneSwitch },
350: { "hpndisabled", oHPNDisabled },
351: { "hpnbuffersize", oHPNBufferSize },
1.7 tls 352: { "sendversionfirst", oSendVersionFirst },
1.12 christos 353: { "ignoreunknown", oIgnoreUnknown },
1.29 christos 354: { "proxyjump", oProxyJump },
355: { "securitykeyprovider", oSecurityKeyProvider },
1.33 christos 356: { "knownhostscommand", oKnownHostsCommand },
1.19 christos 357:
1.1 christos 358: { NULL, oBadOption }
359: };
360:
1.33 christos 361: static const char *lookup_opcode_name(OpCodes code);
1.29 christos 362:
363: const char *
364: kex_default_pk_alg(void)
365: {
1.33 christos 366: static char *pkalgs;
367:
368: if (pkalgs == NULL) {
369: char *all_key;
370:
371: all_key = sshkey_alg_list(0, 0, 1, ',');
372: pkalgs = match_filter_allowlist(KEX_DEFAULT_PK_ALG, all_key);
373: free(all_key);
374: }
375: return pkalgs;
1.29 christos 376: }
377:
1.31 christos 378: char *
379: ssh_connection_hash(const char *thishost, const char *host, const char *portstr,
380: const char *user)
381: {
382: struct ssh_digest_ctx *md;
383: u_char conn_hash[SSH_DIGEST_MAX_LENGTH];
384:
385: if ((md = ssh_digest_start(SSH_DIGEST_SHA1)) == NULL ||
386: ssh_digest_update(md, thishost, strlen(thishost)) < 0 ||
387: ssh_digest_update(md, host, strlen(host)) < 0 ||
388: ssh_digest_update(md, portstr, strlen(portstr)) < 0 ||
389: ssh_digest_update(md, user, strlen(user)) < 0 ||
390: ssh_digest_final(md, conn_hash, sizeof(conn_hash)) < 0)
1.33 christos 391: fatal_f("mux digest failed");
1.31 christos 392: ssh_digest_free(md);
393: return tohex(conn_hash, ssh_digest_bytes(SSH_DIGEST_SHA1));
394: }
395:
1.1 christos 396: /*
397: * Adds a local TCP/IP port forward to options. Never returns if there is an
398: * error.
399: */
400:
401: void
1.12 christos 402: add_local_forward(Options *options, const struct Forward *newfwd)
1.1 christos 403: {
1.12 christos 404: struct Forward *fwd;
1.19 christos 405: int i;
1.4 adam 406:
1.19 christos 407: /* Don't add duplicates */
408: for (i = 0; i < options->num_local_forwards; i++) {
409: if (forward_equals(newfwd, options->local_forwards + i))
410: return;
411: }
1.14 christos 412: options->local_forwards = xreallocarray(options->local_forwards,
1.4 adam 413: options->num_local_forwards + 1,
414: sizeof(*options->local_forwards));
1.1 christos 415: fwd = &options->local_forwards[options->num_local_forwards++];
416:
417: fwd->listen_host = newfwd->listen_host;
418: fwd->listen_port = newfwd->listen_port;
1.12 christos 419: fwd->listen_path = newfwd->listen_path;
1.1 christos 420: fwd->connect_host = newfwd->connect_host;
421: fwd->connect_port = newfwd->connect_port;
1.12 christos 422: fwd->connect_path = newfwd->connect_path;
1.1 christos 423: }
424:
425: /*
426: * Adds a remote TCP/IP port forward to options. Never returns if there is
427: * an error.
428: */
429:
430: void
1.12 christos 431: add_remote_forward(Options *options, const struct Forward *newfwd)
1.1 christos 432: {
1.12 christos 433: struct Forward *fwd;
1.19 christos 434: int i;
1.4 adam 435:
1.19 christos 436: /* Don't add duplicates */
437: for (i = 0; i < options->num_remote_forwards; i++) {
438: if (forward_equals(newfwd, options->remote_forwards + i))
439: return;
440: }
1.14 christos 441: options->remote_forwards = xreallocarray(options->remote_forwards,
1.4 adam 442: options->num_remote_forwards + 1,
443: sizeof(*options->remote_forwards));
1.1 christos 444: fwd = &options->remote_forwards[options->num_remote_forwards++];
445:
446: fwd->listen_host = newfwd->listen_host;
447: fwd->listen_port = newfwd->listen_port;
1.12 christos 448: fwd->listen_path = newfwd->listen_path;
1.1 christos 449: fwd->connect_host = newfwd->connect_host;
450: fwd->connect_port = newfwd->connect_port;
1.12 christos 451: fwd->connect_path = newfwd->connect_path;
1.8 christos 452: fwd->handle = newfwd->handle;
1.4 adam 453: fwd->allocated_port = 0;
1.1 christos 454: }
455:
456: static void
457: clear_forwardings(Options *options)
458: {
459: int i;
460:
461: for (i = 0; i < options->num_local_forwards; i++) {
1.11 christos 462: free(options->local_forwards[i].listen_host);
1.12 christos 463: free(options->local_forwards[i].listen_path);
1.11 christos 464: free(options->local_forwards[i].connect_host);
1.12 christos 465: free(options->local_forwards[i].connect_path);
1.1 christos 466: }
1.4 adam 467: if (options->num_local_forwards > 0) {
1.11 christos 468: free(options->local_forwards);
1.4 adam 469: options->local_forwards = NULL;
470: }
1.1 christos 471: options->num_local_forwards = 0;
472: for (i = 0; i < options->num_remote_forwards; i++) {
1.11 christos 473: free(options->remote_forwards[i].listen_host);
1.12 christos 474: free(options->remote_forwards[i].listen_path);
1.11 christos 475: free(options->remote_forwards[i].connect_host);
1.12 christos 476: free(options->remote_forwards[i].connect_path);
1.1 christos 477: }
1.4 adam 478: if (options->num_remote_forwards > 0) {
1.11 christos 479: free(options->remote_forwards);
1.4 adam 480: options->remote_forwards = NULL;
481: }
1.1 christos 482: options->num_remote_forwards = 0;
483: options->tun_open = SSH_TUNMODE_NO;
484: }
485:
1.9 mlelstv 486: void
1.18 christos 487: add_certificate_file(Options *options, const char *path, int userprovided)
488: {
489: int i;
490:
491: if (options->num_certificate_files >= SSH_MAX_CERTIFICATE_FILES)
492: fatal("Too many certificate files specified (max %d)",
493: SSH_MAX_CERTIFICATE_FILES);
494:
495: /* Avoid registering duplicates */
496: for (i = 0; i < options->num_certificate_files; i++) {
497: if (options->certificate_file_userprovided[i] == userprovided &&
498: strcmp(options->certificate_files[i], path) == 0) {
1.33 christos 499: debug2_f("ignoring duplicate key %s", path);
1.18 christos 500: return;
501: }
502: }
503:
504: options->certificate_file_userprovided[options->num_certificate_files] =
505: userprovided;
506: options->certificate_files[options->num_certificate_files++] =
507: xstrdup(path);
508: }
509:
510: void
1.9 mlelstv 511: add_identity_file(Options *options, const char *dir, const char *filename,
512: int userprovided)
513: {
514: char *path;
1.12 christos 515: int i;
1.9 mlelstv 516:
517: if (options->num_identity_files >= SSH_MAX_IDENTITY_FILES)
518: fatal("Too many identity files specified (max %d)",
519: SSH_MAX_IDENTITY_FILES);
520:
521: if (dir == NULL) /* no dir, filename is absolute */
522: path = xstrdup(filename);
1.22 christos 523: else if (xasprintf(&path, "%s%s", dir, filename) >= PATH_MAX)
524: fatal("Identity file path %s too long", path);
1.9 mlelstv 525:
1.12 christos 526: /* Avoid registering duplicates */
527: for (i = 0; i < options->num_identity_files; i++) {
528: if (options->identity_file_userprovided[i] == userprovided &&
529: strcmp(options->identity_files[i], path) == 0) {
1.33 christos 530: debug2_f("ignoring duplicate key %s", path);
1.12 christos 531: free(path);
532: return;
533: }
534: }
535:
1.9 mlelstv 536: options->identity_file_userprovided[options->num_identity_files] =
537: userprovided;
538: options->identity_files[options->num_identity_files++] = path;
539: }
540:
1.12 christos 541: int
542: default_ssh_port(void)
543: {
544: static int port;
545: struct servent *sp;
546:
547: if (port == 0) {
548: sp = getservbyname(SSH_SERVICE_NAME, "tcp");
549: port = sp ? ntohs(sp->s_port) : SSH_DEFAULT_PORT;
550: }
551: return port;
552: }
553:
554: /*
555: * Execute a command in a shell.
556: * Return its exit status or -1 on abnormal exit.
557: */
558: static int
559: execute_in_shell(const char *cmd)
560: {
561: const char *shell;
562: pid_t pid;
1.33 christos 563: int status;
1.12 christos 564:
565: if ((shell = getenv("SHELL")) == NULL)
566: shell = _PATH_BSHELL;
567:
1.28 christos 568: if (access(shell, X_OK) == -1) {
569: fatal("Shell \"%s\" is not executable: %s",
570: shell, strerror(errno));
571: }
572:
1.12 christos 573: debug("Executing command: '%.500s'", cmd);
574:
575: /* Fork and execute the command. */
576: if ((pid = fork()) == 0) {
577: char *argv[4];
578:
1.33 christos 579: if (stdfd_devnull(1, 1, 0) == -1)
580: fatal_f("stdfd_devnull failed");
581: closefrom(STDERR_FILENO + 1);
1.12 christos 582:
583: argv[0] = __UNCONST(shell);
584: argv[1] = __UNCONST("-c");
1.18 christos 585: argv[2] = xstrdup(cmd);
1.12 christos 586: argv[3] = NULL;
587:
588: execv(argv[0], argv);
589: error("Unable to execute '%.100s': %s", cmd, strerror(errno));
590: /* Die with signal to make this error apparent to parent. */
1.29 christos 591: ssh_signal(SIGTERM, SIG_DFL);
1.12 christos 592: kill(getpid(), SIGTERM);
593: _exit(1);
594: }
595: /* Parent. */
1.28 christos 596: if (pid == -1)
1.33 christos 597: fatal_f("fork: %.100s", strerror(errno));
1.12 christos 598:
599: while (waitpid(pid, &status, 0) == -1) {
600: if (errno != EINTR && errno != EAGAIN)
1.33 christos 601: fatal_f("waitpid: %s", strerror(errno));
1.12 christos 602: }
603: if (!WIFEXITED(status)) {
604: error("command '%.100s' exited abnormally", cmd);
605: return -1;
1.13 christos 606: }
1.12 christos 607: debug3("command returned status %d", WEXITSTATUS(status));
608: return WEXITSTATUS(status);
609: }
610:
611: /*
612: * Parse and execute a Match directive.
613: */
614: static int
615: match_cfg_line(Options *options, char **condition, struct passwd *pw,
1.27 christos 616: const char *host_arg, const char *original_host, int final_pass,
617: int *want_final_pass, const char *filename, int linenum)
1.12 christos 618: {
1.13 christos 619: char *arg, *oattrib, *attrib, *cmd, *cp = *condition, *host, *criteria;
1.12 christos 620: const char *ruser;
1.13 christos 621: int r, port, this_result, result = 1, attributes = 0, negate;
1.12 christos 622: char thishost[NI_MAXHOST], shorthost[NI_MAXHOST], portstr[NI_MAXSERV];
1.25 christos 623: char uidstr[32];
1.12 christos 624:
625: /*
626: * Configuration is likely to be incomplete at this point so we
627: * must be prepared to use default values.
628: */
629: port = options->port <= 0 ? default_ssh_port() : options->port;
630: ruser = options->user == NULL ? pw->pw_name : options->user;
1.27 christos 631: if (final_pass) {
1.18 christos 632: host = xstrdup(options->hostname);
633: } else if (options->hostname != NULL) {
1.12 christos 634: /* NB. Please keep in sync with ssh.c:main() */
635: host = percent_expand(options->hostname,
636: "h", host_arg, (char *)NULL);
1.18 christos 637: } else {
1.12 christos 638: host = xstrdup(host_arg);
1.18 christos 639: }
1.12 christos 640:
1.13 christos 641: debug2("checking match for '%s' host %s originally %s",
642: cp, host, original_host);
643: while ((oattrib = attrib = strdelim(&cp)) && *attrib != '\0') {
1.35 christos 644: /* Terminate on comment */
645: if (*attrib == '#') {
646: cp = NULL; /* mark all arguments consumed */
647: break;
648: }
649: arg = criteria = NULL;
1.13 christos 650: this_result = 1;
651: if ((negate = attrib[0] == '!'))
652: attrib++;
1.35 christos 653: /* Criterion "all" has no argument and must appear alone */
1.12 christos 654: if (strcasecmp(attrib, "all") == 0) {
1.35 christos 655: if (attributes > 1 || ((arg = strdelim(&cp)) != NULL &&
656: *arg != '\0' && *arg != '#')) {
1.13 christos 657: error("%.200s line %d: '%s' cannot be combined "
658: "with other Match attributes",
659: filename, linenum, oattrib);
1.12 christos 660: result = -1;
661: goto out;
662: }
1.35 christos 663: if (arg != NULL && *arg == '#')
664: cp = NULL; /* mark all arguments consumed */
1.13 christos 665: if (result)
666: result = negate ? 0 : 1;
1.12 christos 667: goto out;
668: }
1.13 christos 669: attributes++;
1.35 christos 670: /* criteria "final" and "canonical" have no argument */
1.27 christos 671: if (strcasecmp(attrib, "canonical") == 0 ||
672: strcasecmp(attrib, "final") == 0) {
673: /*
674: * If the config requests "Match final" then remember
675: * this so we can perform a second pass later.
676: */
677: if (strcasecmp(attrib, "final") == 0 &&
678: want_final_pass != NULL)
679: *want_final_pass = 1;
680: r = !!final_pass; /* force bitmask member to boolean */
1.13 christos 681: if (r == (negate ? 1 : 0))
682: this_result = result = 0;
683: debug3("%.200s line %d: %smatched '%s'",
684: filename, linenum,
685: this_result ? "" : "not ", oattrib);
686: continue;
687: }
688: /* All other criteria require an argument */
1.35 christos 689: if ((arg = strdelim(&cp)) == NULL ||
690: *arg == '\0' || *arg == '#') {
1.12 christos 691: error("Missing Match criteria for %s", attrib);
692: result = -1;
693: goto out;
694: }
695: if (strcasecmp(attrib, "host") == 0) {
1.13 christos 696: criteria = xstrdup(host);
1.14 christos 697: r = match_hostname(host, arg) == 1;
1.13 christos 698: if (r == (negate ? 1 : 0))
699: this_result = result = 0;
1.12 christos 700: } else if (strcasecmp(attrib, "originalhost") == 0) {
1.13 christos 701: criteria = xstrdup(original_host);
1.14 christos 702: r = match_hostname(original_host, arg) == 1;
1.13 christos 703: if (r == (negate ? 1 : 0))
704: this_result = result = 0;
1.12 christos 705: } else if (strcasecmp(attrib, "user") == 0) {
1.13 christos 706: criteria = xstrdup(ruser);
1.14 christos 707: r = match_pattern_list(ruser, arg, 0) == 1;
1.13 christos 708: if (r == (negate ? 1 : 0))
709: this_result = result = 0;
1.12 christos 710: } else if (strcasecmp(attrib, "localuser") == 0) {
1.13 christos 711: criteria = xstrdup(pw->pw_name);
1.14 christos 712: r = match_pattern_list(pw->pw_name, arg, 0) == 1;
1.13 christos 713: if (r == (negate ? 1 : 0))
714: this_result = result = 0;
1.12 christos 715: } else if (strcasecmp(attrib, "exec") == 0) {
1.32 christos 716: char *conn_hash_hex, *keyalias;
1.31 christos 717:
1.12 christos 718: if (gethostname(thishost, sizeof(thishost)) == -1)
719: fatal("gethostname: %s", strerror(errno));
720: strlcpy(shorthost, thishost, sizeof(shorthost));
721: shorthost[strcspn(thishost, ".")] = '\0';
722: snprintf(portstr, sizeof(portstr), "%d", port);
1.25 christos 723: snprintf(uidstr, sizeof(uidstr), "%llu",
724: (unsigned long long)pw->pw_uid);
1.31 christos 725: conn_hash_hex = ssh_connection_hash(thishost, host,
1.34 christos 726: portstr, ruser);
1.32 christos 727: keyalias = options->host_key_alias ?
728: options->host_key_alias : host;
1.12 christos 729:
730: cmd = percent_expand(arg,
1.31 christos 731: "C", conn_hash_hex,
1.12 christos 732: "L", shorthost,
733: "d", pw->pw_dir,
734: "h", host,
1.32 christos 735: "k", keyalias,
1.12 christos 736: "l", thishost,
1.13 christos 737: "n", original_host,
1.12 christos 738: "p", portstr,
739: "r", ruser,
740: "u", pw->pw_name,
1.25 christos 741: "i", uidstr,
1.12 christos 742: (char *)NULL);
1.31 christos 743: free(conn_hash_hex);
1.12 christos 744: if (result != 1) {
745: /* skip execution if prior predicate failed */
1.13 christos 746: debug3("%.200s line %d: skipped exec "
747: "\"%.100s\"", filename, linenum, cmd);
748: free(cmd);
749: continue;
750: }
751: r = execute_in_shell(cmd);
752: if (r == -1) {
753: fatal("%.200s line %d: match exec "
754: "'%.100s' error", filename,
755: linenum, cmd);
1.12 christos 756: }
1.13 christos 757: criteria = xstrdup(cmd);
1.12 christos 758: free(cmd);
1.13 christos 759: /* Force exit status to boolean */
760: r = r == 0;
761: if (r == (negate ? 1 : 0))
762: this_result = result = 0;
1.12 christos 763: } else {
764: error("Unsupported Match attribute %s", attrib);
765: result = -1;
766: goto out;
767: }
1.13 christos 768: debug3("%.200s line %d: %smatched '%s \"%.100s\"' ",
769: filename, linenum, this_result ? "": "not ",
770: oattrib, criteria);
771: free(criteria);
1.12 christos 772: }
773: if (attributes == 0) {
774: error("One or more attributes required for Match");
775: result = -1;
776: goto out;
777: }
1.13 christos 778: out:
779: if (result != -1)
780: debug2("match %sfound", result ? "" : "not ");
1.12 christos 781: *condition = cp;
782: free(host);
783: return result;
784: }
785:
1.25 christos 786: /* Remove environment variable by pattern */
787: static void
788: rm_env(Options *options, const char *arg, const char *filename, int linenum)
789: {
1.32 christos 790: int i, j, onum_send_env = options->num_send_env;
1.25 christos 791: char *cp;
792:
793: /* Remove an environment variable */
794: for (i = 0; i < options->num_send_env; ) {
795: cp = xstrdup(options->send_env[i]);
796: if (!match_pattern(cp, arg + 1)) {
797: free(cp);
798: i++;
799: continue;
800: }
801: debug3("%s line %d: removing environment %s",
802: filename, linenum, cp);
803: free(cp);
804: free(options->send_env[i]);
805: options->send_env[i] = NULL;
806: for (j = i; j < options->num_send_env - 1; j++) {
807: options->send_env[j] = options->send_env[j + 1];
808: options->send_env[j + 1] = NULL;
809: }
810: options->num_send_env--;
811: /* NB. don't increment i */
812: }
1.32 christos 813: if (onum_send_env != options->num_send_env) {
814: options->send_env = xrecallocarray(options->send_env,
815: onum_send_env, options->num_send_env,
816: sizeof(*options->send_env));
817: }
1.25 christos 818: }
819:
1.1 christos 820: /*
821: * Returns the number of the token pointed to by cp or oBadOption.
822: */
823: static OpCodes
1.11 christos 824: parse_token(const char *cp, const char *filename, int linenum,
825: const char *ignored_unknown)
1.1 christos 826: {
1.11 christos 827: int i;
1.1 christos 828:
829: for (i = 0; keywords[i].name; i++)
1.11 christos 830: if (strcmp(cp, keywords[i].name) == 0)
1.1 christos 831: return keywords[i].opcode;
1.14 christos 832: if (ignored_unknown != NULL &&
833: match_pattern_list(cp, ignored_unknown, 1) == 1)
1.11 christos 834: return oIgnoredUnknownOption;
1.1 christos 835: error("%s: line %d: Bad configuration option: %s",
836: filename, linenum, cp);
837: return oBadOption;
838: }
839:
1.12 christos 840: /* Multistate option parsing */
841: struct multistate {
842: const char *key;
843: int value;
844: };
845: static const struct multistate multistate_flag[] = {
846: { "true", 1 },
847: { "false", 0 },
848: { "yes", 1 },
849: { "no", 0 },
850: { NULL, -1 }
851: };
852: static const struct multistate multistate_yesnoask[] = {
853: { "true", 1 },
854: { "false", 0 },
855: { "yes", 1 },
856: { "no", 0 },
857: { "ask", 2 },
858: { NULL, -1 }
859: };
1.22 christos 860: static const struct multistate multistate_strict_hostkey[] = {
861: { "true", SSH_STRICT_HOSTKEY_YES },
862: { "false", SSH_STRICT_HOSTKEY_OFF },
863: { "yes", SSH_STRICT_HOSTKEY_YES },
864: { "no", SSH_STRICT_HOSTKEY_OFF },
865: { "ask", SSH_STRICT_HOSTKEY_ASK },
866: { "off", SSH_STRICT_HOSTKEY_OFF },
867: { "accept-new", SSH_STRICT_HOSTKEY_NEW },
868: { NULL, -1 }
869: };
1.18 christos 870: static const struct multistate multistate_yesnoaskconfirm[] = {
871: { "true", 1 },
872: { "false", 0 },
873: { "yes", 1 },
874: { "no", 0 },
875: { "ask", 2 },
876: { "confirm", 3 },
877: { NULL, -1 }
878: };
1.12 christos 879: static const struct multistate multistate_addressfamily[] = {
880: { "inet", AF_INET },
881: { "inet6", AF_INET6 },
882: { "any", AF_UNSPEC },
883: { NULL, -1 }
884: };
885: static const struct multistate multistate_controlmaster[] = {
886: { "true", SSHCTL_MASTER_YES },
887: { "yes", SSHCTL_MASTER_YES },
888: { "false", SSHCTL_MASTER_NO },
889: { "no", SSHCTL_MASTER_NO },
890: { "auto", SSHCTL_MASTER_AUTO },
891: { "ask", SSHCTL_MASTER_ASK },
892: { "autoask", SSHCTL_MASTER_AUTO_ASK },
893: { NULL, -1 }
894: };
895: static const struct multistate multistate_tunnel[] = {
896: { "ethernet", SSH_TUNMODE_ETHERNET },
897: { "point-to-point", SSH_TUNMODE_POINTOPOINT },
898: { "true", SSH_TUNMODE_DEFAULT },
899: { "yes", SSH_TUNMODE_DEFAULT },
900: { "false", SSH_TUNMODE_NO },
901: { "no", SSH_TUNMODE_NO },
902: { NULL, -1 }
903: };
904: static const struct multistate multistate_requesttty[] = {
905: { "true", REQUEST_TTY_YES },
906: { "yes", REQUEST_TTY_YES },
907: { "false", REQUEST_TTY_NO },
908: { "no", REQUEST_TTY_NO },
909: { "force", REQUEST_TTY_FORCE },
910: { "auto", REQUEST_TTY_AUTO },
911: { NULL, -1 }
912: };
1.35 christos 913: static const struct multistate multistate_sessiontype[] = {
914: { "none", SESSION_TYPE_NONE },
915: { "subsystem", SESSION_TYPE_SUBSYSTEM },
916: { "default", SESSION_TYPE_DEFAULT },
917: { NULL, -1 }
918: };
1.12 christos 919: static const struct multistate multistate_canonicalizehostname[] = {
920: { "true", SSH_CANONICALISE_YES },
921: { "false", SSH_CANONICALISE_NO },
922: { "yes", SSH_CANONICALISE_YES },
923: { "no", SSH_CANONICALISE_NO },
924: { "always", SSH_CANONICALISE_ALWAYS },
925: { NULL, -1 }
926: };
1.29 christos 927: static const struct multistate multistate_compression[] = {
928: #ifdef WITH_ZLIB
929: { "yes", COMP_ZLIB },
930: #endif
931: { "no", COMP_NONE },
932: { NULL, -1 }
933: };
1.12 christos 934:
1.32 christos 935: static int
936: parse_multistate_value(const char *arg, const char *filename, int linenum,
937: const struct multistate *multistate_ptr)
938: {
939: int i;
940:
1.33 christos 941: if (!arg || *arg == '\0') {
942: error("%s line %d: missing argument.", filename, linenum);
943: return -1;
944: }
1.32 christos 945: for (i = 0; multistate_ptr[i].key != NULL; i++) {
946: if (strcasecmp(arg, multistate_ptr[i].key) == 0)
947: return multistate_ptr[i].value;
948: }
949: return -1;
950: }
951:
1.1 christos 952: /*
953: * Processes a single option line as used in the configuration files. This
954: * only sets those values that have not already been set.
955: */
956: int
1.12 christos 957: process_config_line(Options *options, struct passwd *pw, const char *host,
1.13 christos 958: const char *original_host, char *line, const char *filename,
959: int linenum, int *activep, int flags)
1.1 christos 960: {
1.19 christos 961: return process_config_line_depth(options, pw, host, original_host,
1.27 christos 962: line, filename, linenum, activep, flags, NULL, 0);
1.19 christos 963: }
964:
965: #define WHITESPACE " \t\r\n"
966: static int
967: process_config_line_depth(Options *options, struct passwd *pw, const char *host,
968: const char *original_host, char *line, const char *filename,
1.27 christos 969: int linenum, int *activep, int flags, int *want_final_pass, int depth)
1.19 christos 970: {
1.35 christos 971: char *str, **charptr, *endofnumber, *keyword, *arg, *arg2, *p, ch;
1.33 christos 972: char **cpptr, ***cppptr, fwdarg[256];
973: u_int i, *uintptr, uvalue, max_entries = 0;
1.19 christos 974: int r, oactive, negated, opcode, *intptr, value, value2, cmdline = 0;
1.22 christos 975: int remotefwd, dynamicfwd;
1.1 christos 976: LogLevel *log_level_ptr;
1.22 christos 977: SyslogFacility *log_facility_ptr;
1.11 christos 978: long long val64;
1.1 christos 979: size_t len;
1.12 christos 980: struct Forward fwd;
981: const struct multistate *multistate_ptr;
982: struct allowed_cname *cname;
1.19 christos 983: glob_t gl;
1.23 christos 984: const char *errstr;
1.35 christos 985: char **oav = NULL, **av;
986: int oac = 0, ac;
987: int ret = -1;
1.12 christos 988:
989: if (activep == NULL) { /* We are processing a command line directive */
990: cmdline = 1;
991: activep = &cmdline;
992: }
1.1 christos 993:
1.21 christos 994: /* Strip trailing whitespace. Allow \f (form feed) at EOL only */
1.14 christos 995: if ((len = strlen(line)) == 0)
996: return 0;
997: for (len--; len > 0; len--) {
1.21 christos 998: if (strchr(WHITESPACE "\f", line[len]) == NULL)
1.1 christos 999: break;
1000: line[len] = '\0';
1001: }
1002:
1.35 christos 1003: str = line;
1.1 christos 1004: /* Get the keyword. (Each line is supposed to begin with a keyword). */
1.35 christos 1005: if ((keyword = strdelim(&str)) == NULL)
1.1 christos 1006: return 0;
1007: /* Ignore leading whitespace. */
1008: if (*keyword == '\0')
1.35 christos 1009: keyword = strdelim(&str);
1.1 christos 1010: if (keyword == NULL || !*keyword || *keyword == '\n' || *keyword == '#')
1011: return 0;
1.11 christos 1012: /* Match lowercase keyword */
1.12 christos 1013: lowercase(keyword);
1.1 christos 1014:
1.35 christos 1015: /* Prepare to parse remainder of line */
1016: if (str != NULL)
1017: str += strspn(str, WHITESPACE);
1018: if (str == NULL || *str == '\0') {
1019: error("%s line %d: no argument after keyword \"%s\"",
1020: filename, linenum, keyword);
1021: return -1;
1022: }
1.11 christos 1023: opcode = parse_token(keyword, filename, linenum,
1024: options->ignored_unknown);
1.35 christos 1025: if (argv_split(str, &oac, &oav, 1) != 0) {
1026: error("%s line %d: invalid quotes", filename, linenum);
1027: return -1;
1028: }
1029: ac = oac;
1030: av = oav;
1.1 christos 1031:
1032: switch (opcode) {
1033: case oBadOption:
1034: /* don't panic, but count bad options */
1.35 christos 1035: goto out;
1.22 christos 1036: case oIgnore:
1.35 christos 1037: argv_consume(&ac);
1038: break;
1.11 christos 1039: case oIgnoredUnknownOption:
1040: debug("%s line %d: Ignored unknown option \"%s\"",
1041: filename, linenum, keyword);
1.35 christos 1042: argv_consume(&ac);
1043: break;
1.1 christos 1044: case oConnectTimeout:
1045: intptr = &options->connection_timeout;
1046: parse_time:
1.35 christos 1047: arg = argv_next(&ac, &av);
1.33 christos 1048: if (!arg || *arg == '\0') {
1049: error("%s line %d: missing time value.",
1.1 christos 1050: filename, linenum);
1.35 christos 1051: goto out;
1.33 christos 1052: }
1.13 christos 1053: if (strcmp(arg, "none") == 0)
1054: value = -1;
1.33 christos 1055: else if ((value = convtime(arg)) == -1) {
1056: error("%s line %d: invalid time value.",
1.1 christos 1057: filename, linenum);
1.35 christos 1058: goto out;
1.33 christos 1059: }
1.1 christos 1060: if (*activep && *intptr == -1)
1061: *intptr = value;
1062: break;
1063:
1064: case oForwardAgent:
1065: intptr = &options->forward_agent;
1.29 christos 1066:
1.35 christos 1067: arg = argv_next(&ac, &av);
1.33 christos 1068: if (!arg || *arg == '\0') {
1069: error("%s line %d: missing argument.",
1.29 christos 1070: filename, linenum);
1.35 christos 1071: goto out;
1.33 christos 1072: }
1.29 christos 1073:
1074: value = -1;
1075: multistate_ptr = multistate_flag;
1076: for (i = 0; multistate_ptr[i].key != NULL; i++) {
1077: if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
1078: value = multistate_ptr[i].value;
1079: break;
1080: }
1081: }
1082: if (value != -1) {
1083: if (*activep && *intptr == -1)
1084: *intptr = value;
1085: break;
1086: }
1087: /* ForwardAgent wasn't 'yes' or 'no', assume a path */
1088: if (*activep && *intptr == -1)
1089: *intptr = 1;
1090:
1091: charptr = &options->forward_agent_sock_path;
1092: goto parse_agent_path;
1093:
1094: case oForwardX11:
1095: intptr = &options->forward_x11;
1.12 christos 1096: parse_flag:
1097: multistate_ptr = multistate_flag;
1098: parse_multistate:
1.35 christos 1099: arg = argv_next(&ac, &av);
1.32 christos 1100: if ((value = parse_multistate_value(arg, filename, linenum,
1.34 christos 1101: multistate_ptr)) == -1) {
1.33 christos 1102: error("%s line %d: unsupported option \"%s\".",
1.12 christos 1103: filename, linenum, arg);
1.35 christos 1104: goto out;
1.32 christos 1105: }
1.1 christos 1106: if (*activep && *intptr == -1)
1107: *intptr = value;
1108: break;
1109:
1110: case oForwardX11Trusted:
1111: intptr = &options->forward_x11_trusted;
1112: goto parse_flag;
1.13 christos 1113:
1.4 adam 1114: case oForwardX11Timeout:
1115: intptr = &options->forward_x11_timeout;
1116: goto parse_time;
1.1 christos 1117:
1118: case oGatewayPorts:
1.12 christos 1119: intptr = &options->fwd_opts.gateway_ports;
1.1 christos 1120: goto parse_flag;
1121:
1122: case oExitOnForwardFailure:
1123: intptr = &options->exit_on_forward_failure;
1124: goto parse_flag;
1125:
1126: case oPasswordAuthentication:
1127: intptr = &options->password_authentication;
1128: goto parse_flag;
1129:
1130: case oKbdInteractiveAuthentication:
1131: intptr = &options->kbd_interactive_authentication;
1132: goto parse_flag;
1133:
1134: case oKbdInteractiveDevices:
1135: charptr = &options->kbd_interactive_devices;
1136: goto parse_string;
1137:
1138: case oPubkeyAuthentication:
1139: intptr = &options->pubkey_authentication;
1140: goto parse_flag;
1141:
1142: case oHostbasedAuthentication:
1143: intptr = &options->hostbased_authentication;
1144: goto parse_flag;
1145:
1.2 christos 1146: #if defined(KRB4) || defined(KRB5)
1147: case oKerberosAuthentication:
1148: intptr = &options->kerberos_authentication;
1149: goto parse_flag;
1150: #endif
1151: #if defined(AFS) || defined(KRB5)
1152: case oKerberosTgtPassing:
1153: intptr = &options->kerberos_tgt_passing;
1154: goto parse_flag;
1155: #endif
1156:
1.1 christos 1157: case oGssAuthentication:
1158: intptr = &options->gss_authentication;
1159: goto parse_flag;
1160:
1.2 christos 1161: #ifdef AFS
1162: case oAFSTokenPassing:
1163: intptr = &options->afs_token_passing;
1164: goto parse_flag;
1165: #endif
1166:
1.1 christos 1167: case oGssDelegateCreds:
1168: intptr = &options->gss_deleg_creds;
1169: goto parse_flag;
1170:
1171: case oBatchMode:
1172: intptr = &options->batch_mode;
1173: goto parse_flag;
1174:
1175: case oCheckHostIP:
1176: intptr = &options->check_host_ip;
1177: goto parse_flag;
1178:
1.2 christos 1179: case oNoneEnabled:
1180: intptr = &options->none_enabled;
1181: goto parse_flag;
1182:
1183: /* we check to see if the command comes from the */
1184: /* command line or not. If it does then enable it */
1185: /* otherwise fail. NONE should never be a default configuration */
1186: case oNoneSwitch:
1187: if(strcmp(filename,"command-line")==0)
1188: {
1189: intptr = &options->none_switch;
1190: goto parse_flag;
1191: } else {
1192: error("NoneSwitch is found in %.200s.\nYou may only use this configuration option from the command line", filename);
1193: error("Continuing...");
1194: debug("NoneSwitch directive found in %.200s.", filename);
1195: return 0;
1196: }
1197:
1198: case oHPNDisabled:
1199: intptr = &options->hpn_disabled;
1200: goto parse_flag;
1201:
1202: case oHPNBufferSize:
1203: intptr = &options->hpn_buffer_size;
1204: goto parse_int;
1205:
1206: case oTcpRcvBufPoll:
1207: intptr = &options->tcp_rcv_buf_poll;
1208: goto parse_flag;
1209:
1.1 christos 1210: case oVerifyHostKeyDNS:
1211: intptr = &options->verify_host_key_dns;
1.12 christos 1212: multistate_ptr = multistate_yesnoask;
1213: goto parse_multistate;
1.1 christos 1214:
1215: case oStrictHostKeyChecking:
1216: intptr = &options->strict_host_key_checking;
1.22 christos 1217: multistate_ptr = multistate_strict_hostkey;
1.12 christos 1218: goto parse_multistate;
1.1 christos 1219:
1220: case oCompression:
1221: intptr = &options->compression;
1.29 christos 1222: multistate_ptr = multistate_compression;
1223: goto parse_multistate;
1.1 christos 1224:
1225: case oTCPKeepAlive:
1226: intptr = &options->tcp_keep_alive;
1227: goto parse_flag;
1228:
1229: case oNoHostAuthenticationForLocalhost:
1230: intptr = &options->no_host_authentication_for_localhost;
1231: goto parse_flag;
1232:
1233: case oNumberOfPasswordPrompts:
1234: intptr = &options->number_of_password_prompts;
1235: goto parse_int;
1236:
1237: case oRekeyLimit:
1.35 christos 1238: arg = argv_next(&ac, &av);
1.33 christos 1239: if (!arg || *arg == '\0') {
1240: error("%.200s line %d: Missing argument.", filename,
1.11 christos 1241: linenum);
1.35 christos 1242: goto out;
1.33 christos 1243: }
1.11 christos 1244: if (strcmp(arg, "default") == 0) {
1245: val64 = 0;
1246: } else {
1.33 christos 1247: if (scan_scaled(arg, &val64) == -1) {
1248: error("%.200s line %d: Bad number '%s': %s",
1.11 christos 1249: filename, linenum, arg, strerror(errno));
1.35 christos 1250: goto out;
1.33 christos 1251: }
1252: if (val64 != 0 && val64 < 16) {
1253: error("%.200s line %d: RekeyLimit too small",
1.11 christos 1254: filename, linenum);
1.35 christos 1255: goto out;
1.33 christos 1256: }
1.1 christos 1257: }
1258: if (*activep && options->rekey_limit == -1)
1.18 christos 1259: options->rekey_limit = val64;
1.35 christos 1260: if (ac != 0) { /* optional rekey interval present */
1261: if (strcmp(av[0], "none") == 0) {
1262: (void)argv_next(&ac, &av); /* discard */
1.11 christos 1263: break;
1264: }
1265: intptr = &options->rekey_interval;
1266: goto parse_time;
1267: }
1.1 christos 1268: break;
1269:
1270: case oIdentityFile:
1.35 christos 1271: arg = argv_next(&ac, &av);
1.33 christos 1272: if (!arg || *arg == '\0') {
1273: error("%.200s line %d: Missing argument.",
1274: filename, linenum);
1.35 christos 1275: goto out;
1.33 christos 1276: }
1.1 christos 1277: if (*activep) {
1278: intptr = &options->num_identity_files;
1.33 christos 1279: if (*intptr >= SSH_MAX_IDENTITY_FILES) {
1280: error("%.200s line %d: Too many identity files "
1281: "specified (max %d).", filename, linenum,
1282: SSH_MAX_IDENTITY_FILES);
1.35 christos 1283: goto out;
1.33 christos 1284: }
1.13 christos 1285: add_identity_file(options, NULL,
1286: arg, flags & SSHCONF_USERCONF);
1.1 christos 1287: }
1288: break;
1289:
1.18 christos 1290: case oCertificateFile:
1.35 christos 1291: arg = argv_next(&ac, &av);
1.33 christos 1292: if (!arg || *arg == '\0') {
1293: error("%.200s line %d: Missing argument.",
1.18 christos 1294: filename, linenum);
1.35 christos 1295: goto out;
1.33 christos 1296: }
1.18 christos 1297: if (*activep) {
1298: intptr = &options->num_certificate_files;
1299: if (*intptr >= SSH_MAX_CERTIFICATE_FILES) {
1.33 christos 1300: error("%.200s line %d: Too many certificate "
1.18 christos 1301: "files specified (max %d).",
1302: filename, linenum,
1303: SSH_MAX_CERTIFICATE_FILES);
1.35 christos 1304: goto out;
1.18 christos 1305: }
1306: add_certificate_file(options, arg,
1307: flags & SSHCONF_USERCONF);
1308: }
1309: break;
1310:
1.1 christos 1311: case oXAuthLocation:
1312: charptr=&options->xauth_location;
1313: goto parse_string;
1314:
1315: case oUser:
1316: charptr = &options->user;
1317: parse_string:
1.35 christos 1318: arg = argv_next(&ac, &av);
1.33 christos 1319: if (!arg || *arg == '\0') {
1320: error("%.200s line %d: Missing argument.",
1.6 christos 1321: filename, linenum);
1.35 christos 1322: goto out;
1.33 christos 1323: }
1.1 christos 1324: if (*activep && *charptr == NULL)
1325: *charptr = xstrdup(arg);
1326: break;
1327:
1328: case oGlobalKnownHostsFile:
1.6 christos 1329: cpptr = (char **)&options->system_hostfiles;
1330: uintptr = &options->num_system_hostfiles;
1331: max_entries = SSH_MAX_HOSTS_FILES;
1332: parse_char_array:
1.35 christos 1333: i = 0;
1334: value = *uintptr == 0; /* was array empty when we started? */
1335: while ((arg = argv_next(&ac, &av)) != NULL) {
1336: if (*arg == '\0') {
1337: error("%s line %d: keyword %s empty argument",
1338: filename, linenum, keyword);
1339: goto out;
1340: }
1341: /* Allow "none" only in first position */
1342: if (strcasecmp(arg, "none") == 0) {
1343: if (i > 0 || ac > 0) {
1344: error("%s line %d: keyword %s \"none\" "
1345: "argument must appear alone.",
1346: filename, linenum, keyword);
1347: goto out;
1348: }
1349: }
1350: i++;
1351: if (*activep && value) {
1.33 christos 1352: if ((*uintptr) >= max_entries) {
1.35 christos 1353: error("%s line %d: too many %s "
1354: "entries.", filename, linenum,
1355: keyword);
1356: goto out;
1.33 christos 1357: }
1.6 christos 1358: cpptr[(*uintptr)++] = xstrdup(arg);
1359: }
1360: }
1.35 christos 1361: break;
1.1 christos 1362:
1363: case oUserKnownHostsFile:
1.6 christos 1364: cpptr = (char **)&options->user_hostfiles;
1365: uintptr = &options->num_user_hostfiles;
1366: max_entries = SSH_MAX_HOSTS_FILES;
1367: goto parse_char_array;
1.1 christos 1368:
1.28 christos 1369: case oHostname:
1.1 christos 1370: charptr = &options->hostname;
1371: goto parse_string;
1372:
1373: case oHostKeyAlias:
1374: charptr = &options->host_key_alias;
1375: goto parse_string;
1376:
1377: case oPreferredAuthentications:
1378: charptr = &options->preferred_authentications;
1379: goto parse_string;
1380:
1381: case oBindAddress:
1382: charptr = &options->bind_address;
1383: goto parse_string;
1384:
1.23 christos 1385: case oBindInterface:
1386: charptr = &options->bind_interface;
1387: goto parse_string;
1388:
1.4 adam 1389: case oPKCS11Provider:
1390: charptr = &options->pkcs11_provider;
1.1 christos 1391: goto parse_string;
1392:
1.29 christos 1393: case oSecurityKeyProvider:
1394: charptr = &options->sk_provider;
1395: goto parse_string;
1396:
1.33 christos 1397: case oKnownHostsCommand:
1398: charptr = &options->known_hosts_command;
1399: goto parse_command;
1400:
1.1 christos 1401: case oProxyCommand:
1402: charptr = &options->proxy_command;
1.19 christos 1403: /* Ignore ProxyCommand if ProxyJump already specified */
1404: if (options->jump_host != NULL)
1405: charptr = &options->jump_host; /* Skip below */
1.1 christos 1406: parse_command:
1.35 christos 1407: if (str == NULL) {
1.33 christos 1408: error("%.200s line %d: Missing argument.",
1409: filename, linenum);
1.35 christos 1410: goto out;
1.33 christos 1411: }
1.35 christos 1412: len = strspn(str, WHITESPACE "=");
1.1 christos 1413: if (*activep && *charptr == NULL)
1.35 christos 1414: *charptr = xstrdup(str + len);
1415: argv_consume(&ac);
1416: break;
1.1 christos 1417:
1.19 christos 1418: case oProxyJump:
1.35 christos 1419: if (str == NULL) {
1.33 christos 1420: error("%.200s line %d: Missing argument.",
1.19 christos 1421: filename, linenum);
1.35 christos 1422: goto out;
1.19 christos 1423: }
1.35 christos 1424: len = strspn(str, WHITESPACE "=");
1425: /* XXX use argv? */
1426: if (parse_jump(str + len, options, *activep) == -1) {
1.33 christos 1427: error("%.200s line %d: Invalid ProxyJump \"%s\"",
1.35 christos 1428: filename, linenum, str + len);
1429: goto out;
1.19 christos 1430: }
1.35 christos 1431: argv_consume(&ac);
1432: break;
1.19 christos 1433:
1.1 christos 1434: case oPort:
1.35 christos 1435: arg = argv_next(&ac, &av);
1.33 christos 1436: if (!arg || *arg == '\0') {
1437: error("%.200s line %d: Missing argument.",
1.27 christos 1438: filename, linenum);
1.35 christos 1439: goto out;
1.33 christos 1440: }
1.27 christos 1441: value = a2port(arg);
1.33 christos 1442: if (value <= 0) {
1443: error("%.200s line %d: Bad port '%s'.",
1.27 christos 1444: filename, linenum, arg);
1.35 christos 1445: goto out;
1.33 christos 1446: }
1.27 christos 1447: if (*activep && options->port == -1)
1448: options->port = value;
1449: break;
1450:
1451: case oConnectionAttempts:
1452: intptr = &options->connection_attempts;
1.1 christos 1453: parse_int:
1.35 christos 1454: arg = argv_next(&ac, &av);
1.33 christos 1455: if ((errstr = atoi_err(arg, &value)) != NULL) {
1456: error("%s line %d: integer value %s.",
1.23 christos 1457: filename, linenum, errstr);
1.35 christos 1458: goto out;
1.33 christos 1459: }
1.1 christos 1460: if (*activep && *intptr == -1)
1461: *intptr = value;
1462: break;
1463:
1.2 christos 1464: case oTcpRcvBuf:
1465: intptr = &options->tcp_rcv_buf;
1466: goto parse_int;
1467:
1.1 christos 1468: case oCiphers:
1.35 christos 1469: arg = argv_next(&ac, &av);
1.33 christos 1470: if (!arg || *arg == '\0') {
1471: error("%.200s line %d: Missing argument.",
1472: filename, linenum);
1.35 christos 1473: goto out;
1.33 christos 1474: }
1.28 christos 1475: if (*arg != '-' &&
1.33 christos 1476: !ciphers_valid(*arg == '+' || *arg == '^' ? arg + 1 : arg)){
1477: error("%.200s line %d: Bad SSH2 cipher spec '%s'.",
1.1 christos 1478: filename, linenum, arg ? arg : "<NONE>");
1.35 christos 1479: goto out;
1.33 christos 1480: }
1.1 christos 1481: if (*activep && options->ciphers == NULL)
1482: options->ciphers = xstrdup(arg);
1483: break;
1484:
1485: case oMacs:
1.35 christos 1486: arg = argv_next(&ac, &av);
1.33 christos 1487: if (!arg || *arg == '\0') {
1488: error("%.200s line %d: Missing argument.",
1489: filename, linenum);
1.35 christos 1490: goto out;
1.33 christos 1491: }
1.28 christos 1492: if (*arg != '-' &&
1.33 christos 1493: !mac_valid(*arg == '+' || *arg == '^' ? arg + 1 : arg)) {
1494: error("%.200s line %d: Bad SSH2 MAC spec '%s'.",
1.1 christos 1495: filename, linenum, arg ? arg : "<NONE>");
1.35 christos 1496: goto out;
1.33 christos 1497: }
1.1 christos 1498: if (*activep && options->macs == NULL)
1499: options->macs = xstrdup(arg);
1500: break;
1501:
1.5 christos 1502: case oKexAlgorithms:
1.35 christos 1503: arg = argv_next(&ac, &av);
1.33 christos 1504: if (!arg || *arg == '\0') {
1505: error("%.200s line %d: Missing argument.",
1.5 christos 1506: filename, linenum);
1.35 christos 1507: goto out;
1.33 christos 1508: }
1.21 christos 1509: if (*arg != '-' &&
1.28 christos 1510: !kex_names_valid(*arg == '+' || *arg == '^' ?
1.33 christos 1511: arg + 1 : arg)) {
1512: error("%.200s line %d: Bad SSH2 KexAlgorithms '%s'.",
1.5 christos 1513: filename, linenum, arg ? arg : "<NONE>");
1.35 christos 1514: goto out;
1.33 christos 1515: }
1.5 christos 1516: if (*activep && options->kex_algorithms == NULL)
1517: options->kex_algorithms = xstrdup(arg);
1518: break;
1519:
1.1 christos 1520: case oHostKeyAlgorithms:
1.16 christos 1521: charptr = &options->hostkeyalgorithms;
1.33 christos 1522: parse_pubkey_algos:
1.35 christos 1523: arg = argv_next(&ac, &av);
1.33 christos 1524: if (!arg || *arg == '\0') {
1525: error("%.200s line %d: Missing argument.",
1.16 christos 1526: filename, linenum);
1.35 christos 1527: goto out;
1.33 christos 1528: }
1.21 christos 1529: if (*arg != '-' &&
1.28 christos 1530: !sshkey_names_valid2(*arg == '+' || *arg == '^' ?
1.33 christos 1531: arg + 1 : arg, 1)) {
1532: error("%s line %d: Bad key types '%s'.",
1533: filename, linenum, arg ? arg : "<NONE>");
1.35 christos 1534: goto out;
1.33 christos 1535: }
1.16 christos 1536: if (*activep && *charptr == NULL)
1537: *charptr = xstrdup(arg);
1.1 christos 1538: break;
1539:
1.27 christos 1540: case oCASignatureAlgorithms:
1541: charptr = &options->ca_sign_algorithms;
1.33 christos 1542: goto parse_pubkey_algos;
1.27 christos 1543:
1.1 christos 1544: case oLogLevel:
1545: log_level_ptr = &options->log_level;
1.35 christos 1546: arg = argv_next(&ac, &av);
1.1 christos 1547: value = log_level_number(arg);
1.33 christos 1548: if (value == SYSLOG_LEVEL_NOT_SET) {
1549: error("%.200s line %d: unsupported log level '%s'",
1.1 christos 1550: filename, linenum, arg ? arg : "<NONE>");
1.35 christos 1551: goto out;
1.33 christos 1552: }
1.1 christos 1553: if (*activep && *log_level_ptr == SYSLOG_LEVEL_NOT_SET)
1554: *log_level_ptr = (LogLevel) value;
1555: break;
1556:
1.22 christos 1557: case oLogFacility:
1558: log_facility_ptr = &options->log_facility;
1.35 christos 1559: arg = argv_next(&ac, &av);
1.22 christos 1560: value = log_facility_number(arg);
1.33 christos 1561: if (value == SYSLOG_FACILITY_NOT_SET) {
1562: error("%.200s line %d: unsupported log facility '%s'",
1.22 christos 1563: filename, linenum, arg ? arg : "<NONE>");
1.35 christos 1564: goto out;
1.33 christos 1565: }
1.22 christos 1566: if (*log_facility_ptr == -1)
1567: *log_facility_ptr = (SyslogFacility) value;
1568: break;
1569:
1.33 christos 1570: case oLogVerbose:
1571: cppptr = &options->log_verbose;
1572: uintptr = &options->num_log_verbose;
1.35 christos 1573: i = 0;
1574: while ((arg = argv_next(&ac, &av)) != NULL) {
1575: if (*arg == '\0') {
1576: error("%s line %d: keyword %s empty argument",
1577: filename, linenum, keyword);
1578: goto out;
1579: }
1580: /* Allow "none" only in first position */
1581: if (strcasecmp(arg, "none") == 0) {
1582: if (i > 0 || ac > 0) {
1583: error("%s line %d: keyword %s \"none\" "
1584: "argument must appear alone.",
1585: filename, linenum, keyword);
1586: goto out;
1587: }
1588: }
1589: i++;
1590: if (*activep && *uintptr == 0) {
1.33 christos 1591: *cppptr = xrecallocarray(*cppptr, *uintptr,
1592: *uintptr + 1, sizeof(**cppptr));
1593: (*cppptr)[(*uintptr)++] = xstrdup(arg);
1594: }
1595: }
1.35 christos 1596: break;
1.33 christos 1597:
1.1 christos 1598: case oLocalForward:
1599: case oRemoteForward:
1600: case oDynamicForward:
1.35 christos 1601: arg = argv_next(&ac, &av);
1.33 christos 1602: if (!arg || *arg == '\0') {
1603: error("%.200s line %d: Missing argument.",
1.1 christos 1604: filename, linenum);
1.35 christos 1605: goto out;
1.33 christos 1606: }
1.1 christos 1607:
1.22 christos 1608: remotefwd = (opcode == oRemoteForward);
1609: dynamicfwd = (opcode == oDynamicForward);
1610:
1611: if (!dynamicfwd) {
1.35 christos 1612: arg2 = argv_next(&ac, &av);
1.22 christos 1613: if (arg2 == NULL || *arg2 == '\0') {
1614: if (remotefwd)
1615: dynamicfwd = 1;
1.33 christos 1616: else {
1617: error("%.200s line %d: Missing target "
1.22 christos 1618: "argument.", filename, linenum);
1.35 christos 1619: goto out;
1.33 christos 1620: }
1.22 christos 1621: } else {
1622: /* construct a string for parse_forward */
1623: snprintf(fwdarg, sizeof(fwdarg), "%s:%s", arg,
1624: arg2);
1625: }
1626: }
1627: if (dynamicfwd)
1.1 christos 1628: strlcpy(fwdarg, arg, sizeof(fwdarg));
1629:
1.33 christos 1630: if (parse_forward(&fwd, fwdarg, dynamicfwd, remotefwd) == 0) {
1631: error("%.200s line %d: Bad forwarding specification.",
1.1 christos 1632: filename, linenum);
1.35 christos 1633: goto out;
1.33 christos 1634: }
1.1 christos 1635:
1636: if (*activep) {
1.22 christos 1637: if (remotefwd) {
1638: add_remote_forward(options, &fwd);
1639: } else {
1.1 christos 1640: add_local_forward(options, &fwd);
1.22 christos 1641: }
1.1 christos 1642: }
1643: break;
1644:
1.33 christos 1645: case oPermitRemoteOpen:
1646: uintptr = &options->num_permitted_remote_opens;
1647: cppptr = &options->permitted_remote_opens;
1.35 christos 1648: arg = argv_next(&ac, &av);
1.33 christos 1649: if (!arg || *arg == '\0')
1650: fatal("%s line %d: missing %s specification",
1651: filename, linenum, lookup_opcode_name(opcode));
1652: uvalue = *uintptr; /* modified later */
1653: if (strcmp(arg, "any") == 0 || strcmp(arg, "none") == 0) {
1654: if (*activep && uvalue == 0) {
1655: *uintptr = 1;
1656: *cppptr = xcalloc(1, sizeof(**cppptr));
1657: (*cppptr)[0] = xstrdup(arg);
1658: }
1659: break;
1660: }
1.35 christos 1661: while ((arg = argv_next(&ac, &av)) != NULL) {
1.33 christos 1662: arg2 = xstrdup(arg);
1663: ch = '\0';
1664: p = hpdelim2(&arg, &ch);
1665: if (p == NULL || ch == '/') {
1666: fatal("%s line %d: missing host in %s",
1667: filename, linenum,
1668: lookup_opcode_name(opcode));
1669: }
1670: p = cleanhostname(p);
1671: /*
1672: * don't want to use permitopen_port to avoid
1673: * dependency on channels.[ch] here.
1674: */
1675: if (arg == NULL ||
1676: (strcmp(arg, "*") != 0 && a2port(arg) <= 0)) {
1677: fatal("%s line %d: bad port number in %s",
1678: filename, linenum,
1679: lookup_opcode_name(opcode));
1680: }
1681: if (*activep && uvalue == 0) {
1682: opt_array_append(filename, linenum,
1683: lookup_opcode_name(opcode),
1684: cppptr, uintptr, arg2);
1685: }
1686: free(arg2);
1687: }
1688: break;
1689:
1.1 christos 1690: case oClearAllForwardings:
1691: intptr = &options->clear_forwardings;
1692: goto parse_flag;
1693:
1694: case oHost:
1.33 christos 1695: if (cmdline) {
1696: error("Host directive not supported as a command-line "
1.12 christos 1697: "option");
1.35 christos 1698: goto out;
1.33 christos 1699: }
1.1 christos 1700: *activep = 0;
1.6 christos 1701: arg2 = NULL;
1.35 christos 1702: while ((arg = argv_next(&ac, &av)) != NULL) {
1703: if (*arg == '\0') {
1704: error("%s line %d: keyword %s empty argument",
1705: filename, linenum, keyword);
1706: goto out;
1707: }
1708: if ((flags & SSHCONF_NEVERMATCH) != 0) {
1709: argv_consume(&ac);
1.19 christos 1710: break;
1.35 christos 1711: }
1.6 christos 1712: negated = *arg == '!';
1713: if (negated)
1714: arg++;
1.1 christos 1715: if (match_pattern(host, arg)) {
1.6 christos 1716: if (negated) {
1717: debug("%.200s line %d: Skipping Host "
1718: "block because of negated match "
1719: "for %.100s", filename, linenum,
1720: arg);
1721: *activep = 0;
1.35 christos 1722: argv_consume(&ac);
1.6 christos 1723: break;
1724: }
1725: if (!*activep)
1726: arg2 = arg; /* logged below */
1.1 christos 1727: *activep = 1;
1728: }
1.6 christos 1729: }
1730: if (*activep)
1731: debug("%.200s line %d: Applying options for %.100s",
1732: filename, linenum, arg2);
1.35 christos 1733: break;
1.1 christos 1734:
1.12 christos 1735: case oMatch:
1.33 christos 1736: if (cmdline) {
1737: error("Host directive not supported as a command-line "
1.12 christos 1738: "option");
1.35 christos 1739: goto out;
1.33 christos 1740: }
1.35 christos 1741: value = match_cfg_line(options, &str, pw, host, original_host,
1.27 christos 1742: flags & SSHCONF_FINAL, want_final_pass,
1743: filename, linenum);
1.33 christos 1744: if (value < 0) {
1745: error("%.200s line %d: Bad Match condition", filename,
1.12 christos 1746: linenum);
1.35 christos 1747: goto out;
1.33 christos 1748: }
1.19 christos 1749: *activep = (flags & SSHCONF_NEVERMATCH) ? 0 : value;
1.35 christos 1750: /*
1751: * If match_cfg_line() didn't consume all its arguments then
1752: * arrange for the extra arguments check below to fail.
1753: */
1754:
1755: if (str == NULL || *str == '\0')
1756: argv_consume(&ac);
1.12 christos 1757: break;
1758:
1.1 christos 1759: case oEscapeChar:
1760: intptr = &options->escape_char;
1.35 christos 1761: arg = argv_next(&ac, &av);
1.33 christos 1762: if (!arg || *arg == '\0') {
1763: error("%.200s line %d: Missing argument.",
1764: filename, linenum);
1.35 christos 1765: goto out;
1.33 christos 1766: }
1.14 christos 1767: if (strcmp(arg, "none") == 0)
1768: value = SSH_ESCAPECHAR_NONE;
1769: else if (arg[1] == '\0')
1770: value = (u_char) arg[0];
1771: else if (arg[0] == '^' && arg[2] == 0 &&
1.1 christos 1772: (u_char) arg[1] >= 64 && (u_char) arg[1] < 128)
1773: value = (u_char) arg[1] & 31;
1774: else {
1.33 christos 1775: error("%.200s line %d: Bad escape character.",
1.1 christos 1776: filename, linenum);
1.35 christos 1777: goto out;
1.1 christos 1778: }
1779: if (*activep && *intptr == -1)
1780: *intptr = value;
1781: break;
1782:
1783: case oAddressFamily:
1784: intptr = &options->address_family;
1.12 christos 1785: multistate_ptr = multistate_addressfamily;
1786: goto parse_multistate;
1.1 christos 1787:
1788: case oEnableSSHKeysign:
1789: intptr = &options->enable_ssh_keysign;
1790: goto parse_flag;
1791:
1792: case oIdentitiesOnly:
1793: intptr = &options->identities_only;
1794: goto parse_flag;
1795:
1796: case oServerAliveInterval:
1797: intptr = &options->server_alive_interval;
1798: goto parse_time;
1799:
1800: case oServerAliveCountMax:
1801: intptr = &options->server_alive_count_max;
1802: goto parse_int;
1803:
1804: case oSendEnv:
1.35 christos 1805: while ((arg = argv_next(&ac, &av)) != NULL) {
1806: if (*arg == '\0' || strchr(arg, '=') != NULL) {
1.33 christos 1807: error("%s line %d: Invalid environment name.",
1.1 christos 1808: filename, linenum);
1.35 christos 1809: goto out;
1.33 christos 1810: }
1.1 christos 1811: if (!*activep)
1812: continue;
1.25 christos 1813: if (*arg == '-') {
1814: /* Removing an env var */
1815: rm_env(options, arg, filename, linenum);
1816: continue;
1817: } else {
1818: /* Adding an env var */
1.33 christos 1819: if (options->num_send_env >= INT_MAX) {
1820: error("%s line %d: too many send env.",
1.25 christos 1821: filename, linenum);
1.35 christos 1822: goto out;
1.33 christos 1823: }
1.25 christos 1824: options->send_env = xrecallocarray(
1825: options->send_env, options->num_send_env,
1826: options->num_send_env + 1,
1827: sizeof(*options->send_env));
1828: options->send_env[options->num_send_env++] =
1829: xstrdup(arg);
1830: }
1831: }
1832: break;
1833:
1834: case oSetEnv:
1835: value = options->num_setenv;
1.35 christos 1836: while ((arg = argv_next(&ac, &av)) != NULL) {
1.33 christos 1837: if (strchr(arg, '=') == NULL) {
1838: error("%s line %d: Invalid SetEnv.",
1.25 christos 1839: filename, linenum);
1.35 christos 1840: goto out;
1.33 christos 1841: }
1.25 christos 1842: if (!*activep || value != 0)
1843: continue;
1844: /* Adding a setenv var */
1.33 christos 1845: if (options->num_setenv >= INT_MAX) {
1846: error("%s line %d: too many SetEnv.",
1.1 christos 1847: filename, linenum);
1.35 christos 1848: goto out;
1.33 christos 1849: }
1.25 christos 1850: options->setenv = xrecallocarray(
1851: options->setenv, options->num_setenv,
1852: options->num_setenv + 1, sizeof(*options->setenv));
1853: options->setenv[options->num_setenv++] = xstrdup(arg);
1.1 christos 1854: }
1855: break;
1856:
1857: case oControlPath:
1858: charptr = &options->control_path;
1859: goto parse_string;
1860:
1861: case oControlMaster:
1862: intptr = &options->control_master;
1.12 christos 1863: multistate_ptr = multistate_controlmaster;
1864: goto parse_multistate;
1.1 christos 1865:
1.4 adam 1866: case oControlPersist:
1867: /* no/false/yes/true, or a time spec */
1868: intptr = &options->control_persist;
1.35 christos 1869: arg = argv_next(&ac, &av);
1.33 christos 1870: if (!arg || *arg == '\0') {
1871: error("%.200s line %d: Missing ControlPersist"
1.4 adam 1872: " argument.", filename, linenum);
1.35 christos 1873: goto out;
1.33 christos 1874: }
1.4 adam 1875: value = 0;
1876: value2 = 0; /* timeout */
1877: if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
1878: value = 0;
1879: else if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
1880: value = 1;
1881: else if ((value2 = convtime(arg)) >= 0)
1882: value = 1;
1.33 christos 1883: else {
1884: error("%.200s line %d: Bad ControlPersist argument.",
1.4 adam 1885: filename, linenum);
1.35 christos 1886: goto out;
1.33 christos 1887: }
1.4 adam 1888: if (*activep && *intptr == -1) {
1889: *intptr = value;
1890: options->control_persist_timeout = value2;
1891: }
1892: break;
1893:
1.1 christos 1894: case oHashKnownHosts:
1895: intptr = &options->hash_known_hosts;
1896: goto parse_flag;
1897:
1898: case oTunnel:
1899: intptr = &options->tun_open;
1.12 christos 1900: multistate_ptr = multistate_tunnel;
1901: goto parse_multistate;
1.1 christos 1902:
1903: case oTunnelDevice:
1.35 christos 1904: arg = argv_next(&ac, &av);
1.33 christos 1905: if (!arg || *arg == '\0') {
1906: error("%.200s line %d: Missing argument.",
1907: filename, linenum);
1.35 christos 1908: goto out;
1.33 christos 1909: }
1.1 christos 1910: value = a2tun(arg, &value2);
1.33 christos 1911: if (value == SSH_TUNID_ERR) {
1912: error("%.200s line %d: Bad tun device.",
1913: filename, linenum);
1.35 christos 1914: goto out;
1.33 christos 1915: }
1.35 christos 1916: if (*activep && options->tun_local == -1) {
1.1 christos 1917: options->tun_local = value;
1918: options->tun_remote = value2;
1919: }
1920: break;
1921:
1922: case oLocalCommand:
1923: charptr = &options->local_command;
1924: goto parse_command;
1925:
1926: case oPermitLocalCommand:
1927: intptr = &options->permit_local_command;
1928: goto parse_flag;
1929:
1.22 christos 1930: case oRemoteCommand:
1931: charptr = &options->remote_command;
1932: goto parse_command;
1933:
1.1 christos 1934: case oVisualHostKey:
1935: intptr = &options->visual_host_key;
1936: goto parse_flag;
1937:
1.19 christos 1938: case oInclude:
1.33 christos 1939: if (cmdline) {
1940: error("Include directive not supported as a "
1.19 christos 1941: "command-line option");
1.35 christos 1942: goto out;
1.33 christos 1943: }
1.19 christos 1944: value = 0;
1.35 christos 1945: while ((arg = argv_next(&ac, &av)) != NULL) {
1946: if (*arg == '\0') {
1947: error("%s line %d: keyword %s empty argument",
1948: filename, linenum, keyword);
1949: goto out;
1950: }
1.19 christos 1951: /*
1952: * Ensure all paths are anchored. User configuration
1953: * files may begin with '~/' but system configurations
1954: * must not. If the path is relative, then treat it
1955: * as living in ~/.ssh for user configurations or
1956: * /etc/ssh for system ones.
1957: */
1.33 christos 1958: if (*arg == '~' && (flags & SSHCONF_USERCONF) == 0) {
1959: error("%.200s line %d: bad include path %s.",
1.19 christos 1960: filename, linenum, arg);
1.35 christos 1961: goto out;
1.33 christos 1962: }
1.27 christos 1963: if (!path_absolute(arg) && *arg != '~') {
1.19 christos 1964: xasprintf(&arg2, "%s/%s",
1965: (flags & SSHCONF_USERCONF) ?
1966: "~/" _PATH_SSH_USER_DIR : SSHDIR, arg);
1967: } else
1968: arg2 = xstrdup(arg);
1969: memset(&gl, 0, sizeof(gl));
1970: r = glob(arg2, GLOB_TILDE | GLOB_LIMIT, NULL, &gl);
1971: if (r == GLOB_NOMATCH) {
1972: debug("%.200s line %d: include %s matched no "
1973: "files",filename, linenum, arg2);
1.21 christos 1974: free(arg2);
1.19 christos 1975: continue;
1.33 christos 1976: } else if (r != 0) {
1977: error("%.200s line %d: glob failed for %s.",
1.19 christos 1978: filename, linenum, arg2);
1.35 christos 1979: goto out;
1.33 christos 1980: }
1.19 christos 1981: free(arg2);
1982: oactive = *activep;
1.29 christos 1983: for (i = 0; i < gl.gl_pathc; i++) {
1.19 christos 1984: debug3("%.200s line %d: Including file %s "
1985: "depth %d%s", filename, linenum,
1986: gl.gl_pathv[i], depth,
1987: oactive ? "" : " (parse only)");
1988: r = read_config_file_depth(gl.gl_pathv[i],
1989: pw, host, original_host, options,
1990: flags | SSHCONF_CHECKPERM |
1991: (oactive ? 0 : SSHCONF_NEVERMATCH),
1.27 christos 1992: activep, want_final_pass, depth + 1);
1.21 christos 1993: if (r != 1 && errno != ENOENT) {
1.33 christos 1994: error("Can't open user config file "
1.21 christos 1995: "%.100s: %.100s", gl.gl_pathv[i],
1996: strerror(errno));
1.33 christos 1997: globfree(&gl);
1.35 christos 1998: goto out;
1.21 christos 1999: }
1.19 christos 2000: /*
2001: * don't let Match in includes clobber the
2002: * containing file's Match state.
2003: */
2004: *activep = oactive;
2005: if (r != 1)
2006: value = -1;
2007: }
2008: globfree(&gl);
2009: }
2010: if (value != 0)
1.35 christos 2011: ret = value;
1.19 christos 2012: break;
2013:
1.5 christos 2014: case oIPQoS:
1.35 christos 2015: arg = argv_next(&ac, &av);
1.33 christos 2016: if ((value = parse_ipqos(arg)) == -1) {
2017: error("%s line %d: Bad IPQoS value: %s",
1.5 christos 2018: filename, linenum, arg);
1.35 christos 2019: goto out;
1.33 christos 2020: }
1.35 christos 2021: arg = argv_next(&ac, &av);
1.5 christos 2022: if (arg == NULL)
2023: value2 = value;
1.33 christos 2024: else if ((value2 = parse_ipqos(arg)) == -1) {
2025: error("%s line %d: Bad IPQoS value: %s",
1.5 christos 2026: filename, linenum, arg);
1.35 christos 2027: goto out;
1.33 christos 2028: }
1.35 christos 2029: if (*activep && options->ip_qos_interactive == -1) {
1.5 christos 2030: options->ip_qos_interactive = value;
2031: options->ip_qos_bulk = value2;
2032: }
2033: break;
2034:
1.6 christos 2035: case oRequestTTY:
2036: intptr = &options->request_tty;
1.12 christos 2037: multistate_ptr = multistate_requesttty;
2038: goto parse_multistate;
1.6 christos 2039:
1.7 tls 2040: case oSendVersionFirst:
2041: intptr = &options->send_version_first;
2042: goto parse_flag;
2043:
1.35 christos 2044: case oSessionType:
2045: intptr = &options->session_type;
2046: multistate_ptr = multistate_sessiontype;
2047: goto parse_multistate;
2048:
2049: case oStdinNull:
2050: intptr = &options->stdin_null;
2051: goto parse_flag;
2052:
2053: case oForkAfterAuthentication:
2054: intptr = &options->fork_after_authentication;
2055: goto parse_flag;
2056:
1.11 christos 2057: case oIgnoreUnknown:
2058: charptr = &options->ignored_unknown;
2059: goto parse_string;
2060:
1.12 christos 2061: case oProxyUseFdpass:
2062: intptr = &options->proxy_use_fdpass;
2063: goto parse_flag;
2064:
2065: case oCanonicalDomains:
2066: value = options->num_canonical_domains != 0;
1.35 christos 2067: i = 0;
2068: while ((arg = argv_next(&ac, &av)) != NULL) {
2069: if (*arg == '\0') {
2070: error("%s line %d: keyword %s empty argument",
2071: filename, linenum, keyword);
2072: goto out;
2073: }
2074: /* Allow "none" only in first position */
2075: if (strcasecmp(arg, "none") == 0) {
2076: if (i > 0 || ac > 0) {
2077: error("%s line %d: keyword %s \"none\" "
2078: "argument must appear alone.",
2079: filename, linenum, keyword);
2080: goto out;
2081: }
2082: }
2083: i++;
1.23 christos 2084: if (!valid_domain(arg, 1, &errstr)) {
1.33 christos 2085: error("%s line %d: %s", filename, linenum,
1.23 christos 2086: errstr);
1.35 christos 2087: goto out;
1.23 christos 2088: }
1.12 christos 2089: if (!*activep || value)
2090: continue;
1.33 christos 2091: if (options->num_canonical_domains >=
2092: MAX_CANON_DOMAINS) {
2093: error("%s line %d: too many hostname suffixes.",
1.12 christos 2094: filename, linenum);
1.35 christos 2095: goto out;
1.33 christos 2096: }
1.12 christos 2097: options->canonical_domains[
2098: options->num_canonical_domains++] = xstrdup(arg);
2099: }
2100: break;
2101:
2102: case oCanonicalizePermittedCNAMEs:
2103: value = options->num_permitted_cnames != 0;
1.37 ! christos 2104: i = 0;
1.35 christos 2105: while ((arg = argv_next(&ac, &av)) != NULL) {
1.37 ! christos 2106: char empty[] = "";
! 2107: /*
! 2108: * Either 'none' (only in first position), '*' for
! 2109: * everything or 'list:list'
! 2110: */
! 2111: if (strcasecmp(arg, "none") == 0) {
! 2112: if (i > 0 || ac > 0) {
! 2113: error("%s line %d: keyword %s \"none\" "
! 2114: "argument must appear alone.",
! 2115: filename, linenum, keyword);
! 2116: goto out;
! 2117: }
! 2118: arg2 = empty;
! 2119: } else if (strcmp(arg, "*") == 0) {
1.12 christos 2120: arg2 = arg;
1.37 ! christos 2121: } else {
1.12 christos 2122: lowercase(arg);
2123: if ((arg2 = strchr(arg, ':')) == NULL ||
2124: arg2[1] == '\0') {
1.33 christos 2125: error("%s line %d: "
1.12 christos 2126: "Invalid permitted CNAME \"%s\"",
2127: filename, linenum, arg);
1.35 christos 2128: goto out;
1.12 christos 2129: }
2130: *arg2 = '\0';
2131: arg2++;
2132: }
1.37 ! christos 2133: i++;
1.12 christos 2134: if (!*activep || value)
2135: continue;
1.33 christos 2136: if (options->num_permitted_cnames >=
2137: MAX_CANON_DOMAINS) {
2138: error("%s line %d: too many permitted CNAMEs.",
1.12 christos 2139: filename, linenum);
1.35 christos 2140: goto out;
1.33 christos 2141: }
1.12 christos 2142: cname = options->permitted_cnames +
2143: options->num_permitted_cnames++;
2144: cname->source_list = xstrdup(arg);
2145: cname->target_list = xstrdup(arg2);
2146: }
2147: break;
2148:
2149: case oCanonicalizeHostname:
2150: intptr = &options->canonicalize_hostname;
2151: multistate_ptr = multistate_canonicalizehostname;
2152: goto parse_multistate;
2153:
2154: case oCanonicalizeMaxDots:
2155: intptr = &options->canonicalize_max_dots;
2156: goto parse_int;
2157:
2158: case oCanonicalizeFallbackLocal:
2159: intptr = &options->canonicalize_fallback_local;
2160: goto parse_flag;
2161:
2162: case oStreamLocalBindMask:
1.35 christos 2163: arg = argv_next(&ac, &av);
1.33 christos 2164: if (!arg || *arg == '\0') {
2165: error("%.200s line %d: Missing StreamLocalBindMask "
2166: "argument.", filename, linenum);
1.35 christos 2167: goto out;
1.33 christos 2168: }
1.12 christos 2169: /* Parse mode in octal format */
2170: value = strtol(arg, &endofnumber, 8);
1.33 christos 2171: if (arg == endofnumber || value < 0 || value > 0777) {
2172: error("%.200s line %d: Bad mask.", filename, linenum);
1.35 christos 2173: goto out;
1.33 christos 2174: }
1.12 christos 2175: options->fwd_opts.streamlocal_bind_mask = (mode_t)value;
2176: break;
2177:
2178: case oStreamLocalBindUnlink:
2179: intptr = &options->fwd_opts.streamlocal_bind_unlink;
2180: goto parse_flag;
2181:
1.13 christos 2182: case oRevokedHostKeys:
2183: charptr = &options->revoked_host_keys;
2184: goto parse_string;
2185:
2186: case oFingerprintHash:
2187: intptr = &options->fingerprint_hash;
1.35 christos 2188: arg = argv_next(&ac, &av);
1.33 christos 2189: if (!arg || *arg == '\0') {
2190: error("%.200s line %d: Missing argument.",
1.13 christos 2191: filename, linenum);
1.35 christos 2192: goto out;
1.33 christos 2193: }
2194: if ((value = ssh_digest_alg_by_name(arg)) == -1) {
2195: error("%.200s line %d: Invalid hash algorithm \"%s\".",
1.13 christos 2196: filename, linenum, arg);
1.35 christos 2197: goto out;
1.33 christos 2198: }
1.13 christos 2199: if (*activep && *intptr == -1)
2200: *intptr = value;
2201: break;
2202:
2203: case oUpdateHostkeys:
2204: intptr = &options->update_hostkeys;
2205: multistate_ptr = multistate_yesnoask;
2206: goto parse_multistate;
2207:
1.33 christos 2208: case oHostbasedAcceptedAlgorithms:
2209: charptr = &options->hostbased_accepted_algos;
2210: goto parse_pubkey_algos;
2211:
2212: case oPubkeyAcceptedAlgorithms:
2213: charptr = &options->pubkey_accepted_algos;
2214: goto parse_pubkey_algos;
1.13 christos 2215:
1.18 christos 2216: case oAddKeysToAgent:
1.35 christos 2217: arg = argv_next(&ac, &av);
2218: arg2 = argv_next(&ac, &av);
1.32 christos 2219: value = parse_multistate_value(arg, filename, linenum,
1.34 christos 2220: multistate_yesnoaskconfirm);
1.32 christos 2221: value2 = 0; /* unlimited lifespan by default */
2222: if (value == 3 && arg2 != NULL) {
2223: /* allow "AddKeysToAgent confirm 5m" */
1.33 christos 2224: if ((value2 = convtime(arg2)) == -1 ||
2225: value2 > INT_MAX) {
2226: error("%s line %d: invalid time value.",
1.32 christos 2227: filename, linenum);
1.35 christos 2228: goto out;
1.33 christos 2229: }
1.32 christos 2230: } else if (value == -1 && arg2 == NULL) {
1.33 christos 2231: if ((value2 = convtime(arg)) == -1 ||
2232: value2 > INT_MAX) {
2233: error("%s line %d: unsupported option",
1.32 christos 2234: filename, linenum);
1.35 christos 2235: goto out;
1.33 christos 2236: }
1.32 christos 2237: value = 1; /* yes */
2238: } else if (value == -1 || arg2 != NULL) {
1.33 christos 2239: error("%s line %d: unsupported option",
1.32 christos 2240: filename, linenum);
1.35 christos 2241: goto out;
1.32 christos 2242: }
2243: if (*activep && options->add_keys_to_agent == -1) {
2244: options->add_keys_to_agent = value;
2245: options->add_keys_to_agent_lifespan = value2;
2246: }
2247: break;
1.18 christos 2248:
1.19 christos 2249: case oIdentityAgent:
2250: charptr = &options->identity_agent;
1.35 christos 2251: arg = argv_next(&ac, &av);
1.33 christos 2252: if (!arg || *arg == '\0') {
2253: error("%.200s line %d: Missing argument.",
1.27 christos 2254: filename, linenum);
1.35 christos 2255: goto out;
1.33 christos 2256: }
1.29 christos 2257: parse_agent_path:
1.27 christos 2258: /* Extra validation if the string represents an env var. */
1.33 christos 2259: if ((arg2 = dollar_expand(&r, arg)) == NULL || r) {
2260: error("%.200s line %d: Invalid environment expansion "
1.32 christos 2261: "%s.", filename, linenum, arg);
1.35 christos 2262: goto out;
1.33 christos 2263: }
1.32 christos 2264: free(arg2);
2265: /* check for legacy environment format */
1.33 christos 2266: if (arg[0] == '$' && arg[1] != '{' &&
2267: !valid_env_name(arg + 1)) {
2268: error("%.200s line %d: Invalid environment name %s.",
1.27 christos 2269: filename, linenum, arg);
1.35 christos 2270: goto out;
1.27 christos 2271: }
2272: if (*activep && *charptr == NULL)
2273: *charptr = xstrdup(arg);
2274: break;
1.19 christos 2275:
1.1 christos 2276: case oDeprecated:
2277: debug("%s line %d: Deprecated option \"%s\"",
2278: filename, linenum, keyword);
1.35 christos 2279: argv_consume(&ac);
2280: break;
1.1 christos 2281:
2282: case oUnsupported:
2283: error("%s line %d: Unsupported option \"%s\"",
2284: filename, linenum, keyword);
1.35 christos 2285: argv_consume(&ac);
2286: break;
1.1 christos 2287:
2288: default:
1.33 christos 2289: error("%s line %d: Unimplemented opcode %d",
2290: filename, linenum, opcode);
1.35 christos 2291: goto out;
1.1 christos 2292: }
2293:
2294: /* Check that there is no garbage at end of line. */
1.35 christos 2295: if (ac > 0) {
2296: error("%.200s line %d: keyword %s extra arguments "
2297: "at end of line", filename, linenum, keyword);
2298: goto out;
1.1 christos 2299: }
1.35 christos 2300:
2301: /* success */
2302: ret = 0;
2303: out:
2304: argv_free(oav, oac);
2305: return ret;
1.1 christos 2306: }
2307:
2308: /*
2309: * Reads the config file and modifies the options accordingly. Options
2310: * should already be initialized before this call. This never returns if
2311: * there is an error. If the file does not exist, this returns 0.
2312: */
2313: int
1.12 christos 2314: read_config_file(const char *filename, struct passwd *pw, const char *host,
1.27 christos 2315: const char *original_host, Options *options, int flags,
2316: int *want_final_pass)
1.1 christos 2317: {
1.19 christos 2318: int active = 1;
2319:
2320: return read_config_file_depth(filename, pw, host, original_host,
1.27 christos 2321: options, flags, &active, want_final_pass, 0);
1.19 christos 2322: }
2323:
2324: #define READCONF_MAX_DEPTH 16
2325: static int
2326: read_config_file_depth(const char *filename, struct passwd *pw,
2327: const char *host, const char *original_host, Options *options,
1.27 christos 2328: int flags, int *activep, int *want_final_pass, int depth)
1.19 christos 2329: {
1.1 christos 2330: FILE *f;
1.35 christos 2331: char *line = NULL;
1.25 christos 2332: size_t linesize = 0;
1.19 christos 2333: int linenum;
1.1 christos 2334: int bad_options = 0;
2335:
1.19 christos 2336: if (depth < 0 || depth > READCONF_MAX_DEPTH)
2337: fatal("Too many recursive configuration includes");
2338:
1.1 christos 2339: if ((f = fopen(filename, "r")) == NULL)
2340: return 0;
2341:
1.9 mlelstv 2342: if (flags & SSHCONF_CHECKPERM) {
1.1 christos 2343: struct stat sb;
2344:
2345: if (fstat(fileno(f), &sb) == -1)
2346: fatal("fstat %s: %s", filename, strerror(errno));
2347: if (((sb.st_uid != 0 && sb.st_uid != getuid()) ||
2348: (sb.st_mode & 022) != 0))
2349: fatal("Bad owner or permissions on %s", filename);
2350: }
2351:
2352: debug("Reading configuration data %.200s", filename);
2353:
2354: /*
2355: * Mark that we are now processing the options. This flag is turned
2356: * on/off by Host specifications.
2357: */
2358: linenum = 0;
1.25 christos 2359: while (getline(&line, &linesize, f) != -1) {
1.1 christos 2360: /* Update line number counter. */
2361: linenum++;
1.33 christos 2362: /*
2363: * Trim out comments and strip whitespace.
2364: * NB - preserve newlines, they are needed to reproduce
2365: * line numbers later for error messages.
2366: */
1.19 christos 2367: if (process_config_line_depth(options, pw, host, original_host,
1.27 christos 2368: line, filename, linenum, activep, flags, want_final_pass,
2369: depth) != 0)
1.1 christos 2370: bad_options++;
2371: }
1.25 christos 2372: free(line);
1.1 christos 2373: fclose(f);
2374: if (bad_options > 0)
2375: fatal("%s: terminating, %d bad configuration options",
2376: filename, bad_options);
2377: return 1;
2378: }
2379:
1.12 christos 2380: /* Returns 1 if a string option is unset or set to "none" or 0 otherwise. */
2381: int
2382: option_clear_or_none(const char *o)
2383: {
2384: return o == NULL || strcasecmp(o, "none") == 0;
2385: }
2386:
1.1 christos 2387: /*
1.37 ! christos 2388: * Returns 1 if CanonicalizePermittedCNAMEs have been specified, 0 otherwise.
! 2389: * Allowed to be called on non-final configuration.
! 2390: */
! 2391: int
! 2392: config_has_permitted_cnames(Options *options)
! 2393: {
! 2394: if (options->num_permitted_cnames == 1 &&
! 2395: strcasecmp(options->permitted_cnames[0].source_list, "none") == 0 &&
! 2396: strcmp(options->permitted_cnames[0].target_list, "") == 0)
! 2397: return 0;
! 2398: return options->num_permitted_cnames > 0;
! 2399: }
! 2400:
! 2401: /*
1.1 christos 2402: * Initializes options to special values that indicate that they have not yet
2403: * been set. Read_config_file will only set options with this value. Options
2404: * are processed in the following order: command line, user config file,
2405: * system config file. Last, fill_default_options is called.
2406: */
2407:
2408: void
2409: initialize_options(Options * options)
2410: {
2411: memset(options, 'X', sizeof(*options));
2412: options->forward_agent = -1;
1.29 christos 2413: options->forward_agent_sock_path = NULL;
1.1 christos 2414: options->forward_x11 = -1;
2415: options->forward_x11_trusted = -1;
1.4 adam 2416: options->forward_x11_timeout = -1;
1.19 christos 2417: options->stdio_forward_host = NULL;
2418: options->stdio_forward_port = 0;
2419: options->clear_forwardings = -1;
1.1 christos 2420: options->exit_on_forward_failure = -1;
2421: options->xauth_location = NULL;
1.12 christos 2422: options->fwd_opts.gateway_ports = -1;
2423: options->fwd_opts.streamlocal_bind_mask = (mode_t)-1;
2424: options->fwd_opts.streamlocal_bind_unlink = -1;
1.1 christos 2425: options->pubkey_authentication = -1;
1.2 christos 2426: #if defined(KRB4) || defined(KRB5)
2427: options->kerberos_authentication = -1;
2428: #endif
2429: #if defined(AFS) || defined(KRB5)
2430: options->kerberos_tgt_passing = -1;
2431: #endif
2432: #ifdef AFS
2433: options->afs_token_passing = -1;
2434: #endif
1.1 christos 2435: options->gss_authentication = -1;
2436: options->gss_deleg_creds = -1;
2437: options->password_authentication = -1;
2438: options->kbd_interactive_authentication = -1;
2439: options->kbd_interactive_devices = NULL;
2440: options->hostbased_authentication = -1;
2441: options->batch_mode = -1;
2442: options->check_host_ip = -1;
2443: options->strict_host_key_checking = -1;
2444: options->compression = -1;
2445: options->tcp_keep_alive = -1;
2446: options->port = -1;
2447: options->address_family = -1;
2448: options->connection_attempts = -1;
2449: options->connection_timeout = -1;
2450: options->number_of_password_prompts = -1;
2451: options->ciphers = NULL;
2452: options->macs = NULL;
1.5 christos 2453: options->kex_algorithms = NULL;
1.1 christos 2454: options->hostkeyalgorithms = NULL;
1.27 christos 2455: options->ca_sign_algorithms = NULL;
1.1 christos 2456: options->num_identity_files = 0;
1.33 christos 2457: memset(options->identity_keys, 0, sizeof(options->identity_keys));
1.18 christos 2458: options->num_certificate_files = 0;
1.33 christos 2459: memset(options->certificates, 0, sizeof(options->certificates));
1.1 christos 2460: options->hostname = NULL;
2461: options->host_key_alias = NULL;
2462: options->proxy_command = NULL;
1.19 christos 2463: options->jump_user = NULL;
2464: options->jump_host = NULL;
2465: options->jump_port = -1;
2466: options->jump_extra = NULL;
1.1 christos 2467: options->user = NULL;
2468: options->escape_char = -1;
1.6 christos 2469: options->num_system_hostfiles = 0;
2470: options->num_user_hostfiles = 0;
1.4 adam 2471: options->local_forwards = NULL;
1.1 christos 2472: options->num_local_forwards = 0;
1.4 adam 2473: options->remote_forwards = NULL;
1.1 christos 2474: options->num_remote_forwards = 0;
1.33 christos 2475: options->permitted_remote_opens = NULL;
2476: options->num_permitted_remote_opens = 0;
1.22 christos 2477: options->log_facility = SYSLOG_FACILITY_NOT_SET;
1.1 christos 2478: options->log_level = SYSLOG_LEVEL_NOT_SET;
1.33 christos 2479: options->num_log_verbose = 0;
2480: options->log_verbose = NULL;
1.1 christos 2481: options->preferred_authentications = NULL;
2482: options->bind_address = NULL;
1.23 christos 2483: options->bind_interface = NULL;
1.4 adam 2484: options->pkcs11_provider = NULL;
1.29 christos 2485: options->sk_provider = NULL;
1.1 christos 2486: options->enable_ssh_keysign = - 1;
2487: options->no_host_authentication_for_localhost = - 1;
2488: options->identities_only = - 1;
2489: options->rekey_limit = - 1;
1.11 christos 2490: options->rekey_interval = -1;
1.1 christos 2491: options->verify_host_key_dns = -1;
2492: options->server_alive_interval = -1;
2493: options->server_alive_count_max = -1;
1.25 christos 2494: options->send_env = NULL;
1.1 christos 2495: options->num_send_env = 0;
1.25 christos 2496: options->setenv = NULL;
2497: options->num_setenv = 0;
1.1 christos 2498: options->control_path = NULL;
2499: options->control_master = -1;
1.4 adam 2500: options->control_persist = -1;
2501: options->control_persist_timeout = 0;
1.1 christos 2502: options->hash_known_hosts = -1;
2503: options->tun_open = -1;
2504: options->tun_local = -1;
2505: options->tun_remote = -1;
2506: options->local_command = NULL;
2507: options->permit_local_command = -1;
1.22 christos 2508: options->remote_command = NULL;
1.18 christos 2509: options->add_keys_to_agent = -1;
1.32 christos 2510: options->add_keys_to_agent_lifespan = -1;
1.19 christos 2511: options->identity_agent = NULL;
1.1 christos 2512: options->visual_host_key = -1;
1.5 christos 2513: options->ip_qos_interactive = -1;
2514: options->ip_qos_bulk = -1;
1.6 christos 2515: options->request_tty = -1;
1.35 christos 2516: options->session_type = -1;
2517: options->stdin_null = -1;
2518: options->fork_after_authentication = -1;
1.12 christos 2519: options->proxy_use_fdpass = -1;
1.11 christos 2520: options->ignored_unknown = NULL;
1.12 christos 2521: options->num_canonical_domains = 0;
2522: options->num_permitted_cnames = 0;
2523: options->canonicalize_max_dots = -1;
2524: options->canonicalize_fallback_local = -1;
2525: options->canonicalize_hostname = -1;
1.13 christos 2526: options->revoked_host_keys = NULL;
2527: options->fingerprint_hash = -1;
2528: options->update_hostkeys = -1;
1.33 christos 2529: options->hostbased_accepted_algos = NULL;
2530: options->pubkey_accepted_algos = NULL;
2531: options->known_hosts_command = NULL;
1.2 christos 2532: options->none_switch = -1;
2533: options->none_enabled = -1;
2534: options->hpn_disabled = -1;
2535: options->hpn_buffer_size = -1;
2536: options->tcp_rcv_buf_poll = -1;
2537: options->tcp_rcv_buf = -1;
1.7 tls 2538: options->send_version_first = -1;
1.1 christos 2539: }
2540:
2541: /*
1.12 christos 2542: * A petite version of fill_default_options() that just fills the options
2543: * needed for hostname canonicalization to proceed.
2544: */
2545: void
2546: fill_default_options_for_canonicalization(Options *options)
2547: {
2548: if (options->canonicalize_max_dots == -1)
2549: options->canonicalize_max_dots = 1;
2550: if (options->canonicalize_fallback_local == -1)
2551: options->canonicalize_fallback_local = 1;
2552: if (options->canonicalize_hostname == -1)
2553: options->canonicalize_hostname = SSH_CANONICALISE_NO;
2554: }
2555:
2556: /*
1.1 christos 2557: * Called after processing other sources of option data, this fills those
2558: * options for which no value has been specified with their default values.
2559: */
1.33 christos 2560: int
1.1 christos 2561: fill_default_options(Options * options)
2562: {
1.27 christos 2563: char *all_cipher, *all_mac, *all_kex, *all_key, *all_sig;
1.29 christos 2564: char *def_cipher, *def_mac, *def_kex, *def_key, *def_sig;
1.33 christos 2565: int ret = 0, r;
1.25 christos 2566:
1.1 christos 2567: if (options->forward_agent == -1)
2568: options->forward_agent = 0;
2569: if (options->forward_x11 == -1)
2570: options->forward_x11 = 0;
2571: if (options->forward_x11_trusted == -1)
2572: options->forward_x11_trusted = 0;
1.4 adam 2573: if (options->forward_x11_timeout == -1)
2574: options->forward_x11_timeout = 1200;
1.19 christos 2575: /*
2576: * stdio forwarding (-W) changes the default for these but we defer
2577: * setting the values so they can be overridden.
2578: */
1.1 christos 2579: if (options->exit_on_forward_failure == -1)
1.19 christos 2580: options->exit_on_forward_failure =
2581: options->stdio_forward_host != NULL ? 1 : 0;
2582: if (options->clear_forwardings == -1)
2583: options->clear_forwardings =
2584: options->stdio_forward_host != NULL ? 1 : 0;
2585: if (options->clear_forwardings == 1)
2586: clear_forwardings(options);
2587:
1.1 christos 2588: if (options->xauth_location == NULL)
1.33 christos 2589: options->xauth_location = xstrdup(_PATH_XAUTH);
1.12 christos 2590: if (options->fwd_opts.gateway_ports == -1)
2591: options->fwd_opts.gateway_ports = 0;
2592: if (options->fwd_opts.streamlocal_bind_mask == (mode_t)-1)
2593: options->fwd_opts.streamlocal_bind_mask = 0177;
2594: if (options->fwd_opts.streamlocal_bind_unlink == -1)
2595: options->fwd_opts.streamlocal_bind_unlink = 0;
1.1 christos 2596: if (options->pubkey_authentication == -1)
2597: options->pubkey_authentication = 1;
1.2 christos 2598: #if defined(KRB4) || defined(KRB5)
2599: if (options->kerberos_authentication == -1)
2600: options->kerberos_authentication = 1;
2601: #endif
2602: #if defined(AFS) || defined(KRB5)
2603: if (options->kerberos_tgt_passing == -1)
2604: options->kerberos_tgt_passing = 1;
2605: #endif
2606: #ifdef AFS
2607: if (options->afs_token_passing == -1)
2608: options->afs_token_passing = 1;
2609: #endif
1.1 christos 2610: if (options->gss_authentication == -1)
2611: options->gss_authentication = 0;
2612: if (options->gss_deleg_creds == -1)
2613: options->gss_deleg_creds = 0;
2614: if (options->password_authentication == -1)
2615: options->password_authentication = 1;
2616: if (options->kbd_interactive_authentication == -1)
2617: options->kbd_interactive_authentication = 1;
2618: if (options->hostbased_authentication == -1)
2619: options->hostbased_authentication = 0;
2620: if (options->batch_mode == -1)
2621: options->batch_mode = 0;
2622: if (options->check_host_ip == -1)
1.33 christos 2623: options->check_host_ip = 0;
1.1 christos 2624: if (options->strict_host_key_checking == -1)
1.22 christos 2625: options->strict_host_key_checking = SSH_STRICT_HOSTKEY_ASK;
1.1 christos 2626: if (options->compression == -1)
2627: options->compression = 0;
2628: if (options->tcp_keep_alive == -1)
2629: options->tcp_keep_alive = 1;
2630: if (options->port == -1)
2631: options->port = 0; /* Filled in ssh_connect. */
2632: if (options->address_family == -1)
2633: options->address_family = AF_UNSPEC;
2634: if (options->connection_attempts == -1)
2635: options->connection_attempts = 1;
2636: if (options->number_of_password_prompts == -1)
2637: options->number_of_password_prompts = 3;
2638: /* options->hostkeyalgorithms, default set in myproposals.h */
1.32 christos 2639: if (options->add_keys_to_agent == -1) {
1.18 christos 2640: options->add_keys_to_agent = 0;
1.32 christos 2641: options->add_keys_to_agent_lifespan = 0;
2642: }
1.1 christos 2643: if (options->num_identity_files == 0) {
1.22 christos 2644: add_identity_file(options, "~/", _PATH_SSH_CLIENT_ID_RSA, 0);
2645: add_identity_file(options, "~/", _PATH_SSH_CLIENT_ID_DSA, 0);
2646: add_identity_file(options, "~/", _PATH_SSH_CLIENT_ID_ECDSA, 0);
2647: add_identity_file(options, "~/",
1.29 christos 2648: _PATH_SSH_CLIENT_ID_ECDSA_SK, 0);
2649: add_identity_file(options, "~/",
1.22 christos 2650: _PATH_SSH_CLIENT_ID_ED25519, 0);
1.29 christos 2651: add_identity_file(options, "~/",
2652: _PATH_SSH_CLIENT_ID_ED25519_SK, 0);
1.23 christos 2653: add_identity_file(options, "~/", _PATH_SSH_CLIENT_ID_XMSS, 0);
1.1 christos 2654: }
2655: if (options->escape_char == -1)
2656: options->escape_char = '~';
1.6 christos 2657: if (options->num_system_hostfiles == 0) {
2658: options->system_hostfiles[options->num_system_hostfiles++] =
2659: xstrdup(_PATH_SSH_SYSTEM_HOSTFILE);
2660: options->system_hostfiles[options->num_system_hostfiles++] =
2661: xstrdup(_PATH_SSH_SYSTEM_HOSTFILE2);
2662: }
1.33 christos 2663: if (options->update_hostkeys == -1) {
2664: if (options->verify_host_key_dns <= 0 &&
2665: (options->num_user_hostfiles == 0 ||
2666: (options->num_user_hostfiles == 1 && strcmp(options->
2667: user_hostfiles[0], _PATH_SSH_USER_HOSTFILE) == 0)))
2668: options->update_hostkeys = SSH_UPDATE_HOSTKEYS_YES;
2669: else
1.29 christos 2670: options->update_hostkeys = SSH_UPDATE_HOSTKEYS_NO;
1.33 christos 2671: }
1.6 christos 2672: if (options->num_user_hostfiles == 0) {
2673: options->user_hostfiles[options->num_user_hostfiles++] =
2674: xstrdup(_PATH_SSH_USER_HOSTFILE);
2675: options->user_hostfiles[options->num_user_hostfiles++] =
2676: xstrdup(_PATH_SSH_USER_HOSTFILE2);
2677: }
1.1 christos 2678: if (options->log_level == SYSLOG_LEVEL_NOT_SET)
2679: options->log_level = SYSLOG_LEVEL_INFO;
1.22 christos 2680: if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
2681: options->log_facility = SYSLOG_FACILITY_USER;
1.1 christos 2682: if (options->no_host_authentication_for_localhost == - 1)
2683: options->no_host_authentication_for_localhost = 0;
2684: if (options->identities_only == -1)
2685: options->identities_only = 0;
2686: if (options->enable_ssh_keysign == -1)
2687: options->enable_ssh_keysign = 0;
2688: if (options->rekey_limit == -1)
2689: options->rekey_limit = 0;
1.11 christos 2690: if (options->rekey_interval == -1)
2691: options->rekey_interval = 0;
1.1 christos 2692: if (options->verify_host_key_dns == -1)
2693: options->verify_host_key_dns = 0;
2694: if (options->server_alive_interval == -1)
2695: options->server_alive_interval = 0;
2696: if (options->server_alive_count_max == -1)
2697: options->server_alive_count_max = 3;
1.2 christos 2698: if (options->none_switch == -1)
2699: options->none_switch = 0;
2700: if (options->hpn_disabled == -1)
2701: options->hpn_disabled = 0;
2702: if (options->hpn_buffer_size > -1)
2703: {
2704: /* if a user tries to set the size to 0 set it to 1KB */
2705: if (options->hpn_buffer_size == 0)
2706: options->hpn_buffer_size = 1024;
2707: /*limit the buffer to 64MB*/
2708: if (options->hpn_buffer_size > 65536)
2709: {
2710: options->hpn_buffer_size = 65536*1024;
2711: debug("User requested buffer larger than 64MB. Request reverted to 64MB");
2712: }
2713: debug("hpn_buffer_size set to %d", options->hpn_buffer_size);
2714: }
2715: if (options->tcp_rcv_buf == 0)
2716: options->tcp_rcv_buf = 1;
2717: if (options->tcp_rcv_buf > -1)
2718: options->tcp_rcv_buf *=1024;
2719: if (options->tcp_rcv_buf_poll == -1)
2720: options->tcp_rcv_buf_poll = 1;
1.1 christos 2721: if (options->control_master == -1)
2722: options->control_master = 0;
1.4 adam 2723: if (options->control_persist == -1) {
2724: options->control_persist = 0;
2725: options->control_persist_timeout = 0;
2726: }
1.1 christos 2727: if (options->hash_known_hosts == -1)
2728: options->hash_known_hosts = 0;
2729: if (options->tun_open == -1)
2730: options->tun_open = SSH_TUNMODE_NO;
2731: if (options->tun_local == -1)
2732: options->tun_local = SSH_TUNID_ANY;
2733: if (options->tun_remote == -1)
2734: options->tun_remote = SSH_TUNID_ANY;
2735: if (options->permit_local_command == -1)
2736: options->permit_local_command = 0;
2737: if (options->visual_host_key == -1)
2738: options->visual_host_key = 0;
1.5 christos 2739: if (options->ip_qos_interactive == -1)
1.25 christos 2740: options->ip_qos_interactive = IPTOS_DSCP_AF21;
1.5 christos 2741: if (options->ip_qos_bulk == -1)
1.25 christos 2742: options->ip_qos_bulk = IPTOS_DSCP_CS1;
1.6 christos 2743: if (options->request_tty == -1)
2744: options->request_tty = REQUEST_TTY_AUTO;
1.35 christos 2745: if (options->session_type == -1)
2746: options->session_type = SESSION_TYPE_DEFAULT;
2747: if (options->stdin_null == -1)
2748: options->stdin_null = 0;
2749: if (options->fork_after_authentication == -1)
2750: options->fork_after_authentication = 0;
1.12 christos 2751: if (options->proxy_use_fdpass == -1)
2752: options->proxy_use_fdpass = 0;
2753: if (options->canonicalize_max_dots == -1)
2754: options->canonicalize_max_dots = 1;
2755: if (options->canonicalize_fallback_local == -1)
2756: options->canonicalize_fallback_local = 1;
2757: if (options->canonicalize_hostname == -1)
2758: options->canonicalize_hostname = SSH_CANONICALISE_NO;
1.13 christos 2759: if (options->fingerprint_hash == -1)
2760: options->fingerprint_hash = SSH_FP_HASH_DEFAULT;
1.29 christos 2761: if (options->sk_provider == NULL)
2762: options->sk_provider = xstrdup("internal");
1.25 christos 2763:
2764: /* Expand KEX name lists */
2765: all_cipher = cipher_alg_list(',', 0);
2766: all_mac = mac_alg_list(',');
2767: all_kex = kex_alg_list(',');
2768: all_key = sshkey_alg_list(0, 0, 1, ',');
1.27 christos 2769: all_sig = sshkey_alg_list(0, 1, 1, ',');
1.29 christos 2770: /* remove unsupported algos from default lists */
1.32 christos 2771: def_cipher = match_filter_allowlist(KEX_CLIENT_ENCRYPT, all_cipher);
2772: def_mac = match_filter_allowlist(KEX_CLIENT_MAC, all_mac);
2773: def_kex = match_filter_allowlist(KEX_CLIENT_KEX, all_kex);
2774: def_key = match_filter_allowlist(KEX_DEFAULT_PK_ALG, all_key);
2775: def_sig = match_filter_allowlist(SSH_ALLOWED_CA_SIGALGS, all_sig);
1.25 christos 2776: #define ASSEMBLE(what, defaults, all) \
2777: do { \
2778: if ((r = kex_assemble_names(&options->what, \
1.33 christos 2779: defaults, all)) != 0) { \
2780: error_fr(r, "%s", #what); \
2781: goto fail; \
2782: } \
1.25 christos 2783: } while (0)
1.29 christos 2784: ASSEMBLE(ciphers, def_cipher, all_cipher);
2785: ASSEMBLE(macs, def_mac, all_mac);
2786: ASSEMBLE(kex_algorithms, def_kex, all_kex);
1.33 christos 2787: ASSEMBLE(hostbased_accepted_algos, def_key, all_key);
2788: ASSEMBLE(pubkey_accepted_algos, def_key, all_key);
1.29 christos 2789: ASSEMBLE(ca_sign_algorithms, def_sig, all_sig);
1.25 christos 2790: #undef ASSEMBLE
1.13 christos 2791:
1.7 tls 2792: if (options->send_version_first == -1)
2793: options->send_version_first = 1;
1.12 christos 2794: #define CLEAR_ON_NONE(v) \
2795: do { \
2796: if (option_clear_or_none(v)) { \
2797: free(v); \
2798: v = NULL; \
2799: } \
2800: } while(0)
2801: CLEAR_ON_NONE(options->local_command);
1.22 christos 2802: CLEAR_ON_NONE(options->remote_command);
1.12 christos 2803: CLEAR_ON_NONE(options->proxy_command);
2804: CLEAR_ON_NONE(options->control_path);
1.13 christos 2805: CLEAR_ON_NONE(options->revoked_host_keys);
1.27 christos 2806: CLEAR_ON_NONE(options->pkcs11_provider);
1.29 christos 2807: CLEAR_ON_NONE(options->sk_provider);
1.33 christos 2808: CLEAR_ON_NONE(options->known_hosts_command);
1.25 christos 2809: if (options->jump_host != NULL &&
2810: strcmp(options->jump_host, "none") == 0 &&
2811: options->jump_port == 0 && options->jump_user == NULL) {
2812: free(options->jump_host);
2813: options->jump_host = NULL;
2814: }
1.37 ! christos 2815: if (options->num_permitted_cnames == 1 &&
! 2816: !config_has_permitted_cnames(options)) {
! 2817: /* clean up CanonicalizePermittedCNAMEs=none */
! 2818: free(options->permitted_cnames[0].source_list);
! 2819: free(options->permitted_cnames[0].target_list);
! 2820: memset(options->permitted_cnames, '\0',
! 2821: sizeof(*options->permitted_cnames));
! 2822: options->num_permitted_cnames = 0;
! 2823: }
1.19 christos 2824: /* options->identity_agent distinguishes NULL from 'none' */
1.1 christos 2825: /* options->user will be set in the main program if appropriate */
2826: /* options->hostname will be set in the main program if appropriate */
2827: /* options->host_key_alias should not be set by default */
2828: /* options->preferred_authentications will be set in ssh */
1.33 christos 2829:
2830: /* success */
2831: ret = 0;
2832: fail:
2833: free(all_cipher);
2834: free(all_mac);
2835: free(all_kex);
2836: free(all_key);
2837: free(all_sig);
2838: free(def_cipher);
2839: free(def_mac);
2840: free(def_kex);
2841: free(def_key);
2842: free(def_sig);
2843: return ret;
2844: }
2845:
2846: void
2847: free_options(Options *o)
2848: {
2849: int i;
2850:
2851: if (o == NULL)
2852: return;
2853:
2854: #define FREE_ARRAY(type, n, a) \
2855: do { \
2856: type _i; \
2857: for (_i = 0; _i < (n); _i++) \
2858: free((a)[_i]); \
2859: } while (0)
2860:
2861: free(o->forward_agent_sock_path);
2862: free(o->xauth_location);
2863: FREE_ARRAY(u_int, o->num_log_verbose, o->log_verbose);
2864: free(o->log_verbose);
2865: free(o->ciphers);
2866: free(o->macs);
2867: free(o->hostkeyalgorithms);
2868: free(o->kex_algorithms);
2869: free(o->ca_sign_algorithms);
2870: free(o->hostname);
2871: free(o->host_key_alias);
2872: free(o->proxy_command);
2873: free(o->user);
2874: FREE_ARRAY(u_int, o->num_system_hostfiles, o->system_hostfiles);
2875: FREE_ARRAY(u_int, o->num_user_hostfiles, o->user_hostfiles);
2876: free(o->preferred_authentications);
2877: free(o->bind_address);
2878: free(o->bind_interface);
2879: free(o->pkcs11_provider);
2880: free(o->sk_provider);
2881: for (i = 0; i < o->num_identity_files; i++) {
2882: free(o->identity_files[i]);
2883: sshkey_free(o->identity_keys[i]);
2884: }
2885: for (i = 0; i < o->num_certificate_files; i++) {
2886: free(o->certificate_files[i]);
2887: sshkey_free(o->certificates[i]);
2888: }
2889: free(o->identity_agent);
2890: for (i = 0; i < o->num_local_forwards; i++) {
2891: free(o->local_forwards[i].listen_host);
2892: free(o->local_forwards[i].listen_path);
2893: free(o->local_forwards[i].connect_host);
2894: free(o->local_forwards[i].connect_path);
2895: }
2896: free(o->local_forwards);
2897: for (i = 0; i < o->num_remote_forwards; i++) {
2898: free(o->remote_forwards[i].listen_host);
2899: free(o->remote_forwards[i].listen_path);
2900: free(o->remote_forwards[i].connect_host);
2901: free(o->remote_forwards[i].connect_path);
2902: }
2903: free(o->remote_forwards);
2904: free(o->stdio_forward_host);
2905: FREE_ARRAY(int, o->num_send_env, o->send_env);
2906: free(o->send_env);
2907: FREE_ARRAY(int, o->num_setenv, o->setenv);
2908: free(o->setenv);
2909: free(o->control_path);
2910: free(o->local_command);
2911: free(o->remote_command);
2912: FREE_ARRAY(int, o->num_canonical_domains, o->canonical_domains);
2913: for (i = 0; i < o->num_permitted_cnames; i++) {
2914: free(o->permitted_cnames[i].source_list);
2915: free(o->permitted_cnames[i].target_list);
2916: }
2917: free(o->revoked_host_keys);
2918: free(o->hostbased_accepted_algos);
2919: free(o->pubkey_accepted_algos);
2920: free(o->jump_user);
2921: free(o->jump_host);
2922: free(o->jump_extra);
2923: free(o->ignored_unknown);
2924: explicit_bzero(o, sizeof(*o));
2925: #undef FREE_ARRAY
1.1 christos 2926: }
2927:
1.12 christos 2928: struct fwdarg {
2929: char *arg;
2930: int ispath;
2931: };
2932:
2933: /*
2934: * parse_fwd_field
2935: * parses the next field in a port forwarding specification.
2936: * sets fwd to the parsed field and advances p past the colon
2937: * or sets it to NULL at end of string.
2938: * returns 0 on success, else non-zero.
2939: */
2940: static int
2941: parse_fwd_field(char **p, struct fwdarg *fwd)
2942: {
2943: char *ep, *cp = *p;
2944: int ispath = 0;
2945:
2946: if (*cp == '\0') {
2947: *p = NULL;
2948: return -1; /* end of string */
2949: }
2950:
2951: /*
2952: * A field escaped with square brackets is used literally.
2953: * XXX - allow ']' to be escaped via backslash?
2954: */
2955: if (*cp == '[') {
2956: /* find matching ']' */
2957: for (ep = cp + 1; *ep != ']' && *ep != '\0'; ep++) {
2958: if (*ep == '/')
2959: ispath = 1;
2960: }
2961: /* no matching ']' or not at end of field. */
2962: if (ep[0] != ']' || (ep[1] != ':' && ep[1] != '\0'))
2963: return -1;
2964: /* NUL terminate the field and advance p past the colon */
2965: *ep++ = '\0';
2966: if (*ep != '\0')
2967: *ep++ = '\0';
2968: fwd->arg = cp + 1;
2969: fwd->ispath = ispath;
2970: *p = ep;
2971: return 0;
2972: }
2973:
2974: for (cp = *p; *cp != '\0'; cp++) {
2975: switch (*cp) {
2976: case '\\':
2977: memmove(cp, cp + 1, strlen(cp + 1) + 1);
1.14 christos 2978: if (*cp == '\0')
2979: return -1;
1.12 christos 2980: break;
2981: case '/':
2982: ispath = 1;
2983: break;
2984: case ':':
2985: *cp++ = '\0';
2986: goto done;
2987: }
2988: }
2989: done:
2990: fwd->arg = *p;
2991: fwd->ispath = ispath;
2992: *p = cp;
2993: return 0;
2994: }
2995:
1.1 christos 2996: /*
2997: * parse_forward
2998: * parses a string containing a port forwarding specification of the form:
2999: * dynamicfwd == 0
1.12 christos 3000: * [listenhost:]listenport|listenpath:connecthost:connectport|connectpath
3001: * listenpath:connectpath
1.1 christos 3002: * dynamicfwd == 1
3003: * [listenhost:]listenport
3004: * returns number of arguments parsed or zero on error
3005: */
3006: int
1.12 christos 3007: parse_forward(struct Forward *fwd, const char *fwdspec, int dynamicfwd, int remotefwd)
1.1 christos 3008: {
1.12 christos 3009: struct fwdarg fwdargs[4];
3010: char *p, *cp;
1.32 christos 3011: int i, err;
1.1 christos 3012:
1.12 christos 3013: memset(fwd, 0, sizeof(*fwd));
3014: memset(fwdargs, 0, sizeof(fwdargs));
1.1 christos 3015:
1.32 christos 3016: /*
3017: * We expand environment variables before checking if we think they're
3018: * paths so that if ${VAR} expands to a fully qualified path it is
3019: * treated as a path.
3020: */
3021: cp = p = dollar_expand(&err, fwdspec);
3022: if (p == NULL || err)
3023: return 0;
1.1 christos 3024:
3025: /* skip leading spaces */
1.12 christos 3026: while (isspace((u_char)*cp))
1.1 christos 3027: cp++;
3028:
1.12 christos 3029: for (i = 0; i < 4; ++i) {
3030: if (parse_fwd_field(&cp, &fwdargs[i]) != 0)
1.1 christos 3031: break;
1.12 christos 3032: }
1.1 christos 3033:
3034: /* Check for trailing garbage */
1.12 christos 3035: if (cp != NULL && *cp != '\0') {
1.1 christos 3036: i = 0; /* failure */
1.12 christos 3037: }
1.1 christos 3038:
3039: switch (i) {
3040: case 1:
1.12 christos 3041: if (fwdargs[0].ispath) {
3042: fwd->listen_path = xstrdup(fwdargs[0].arg);
3043: fwd->listen_port = PORT_STREAMLOCAL;
3044: } else {
3045: fwd->listen_host = NULL;
3046: fwd->listen_port = a2port(fwdargs[0].arg);
3047: }
1.1 christos 3048: fwd->connect_host = xstrdup("socks");
3049: break;
3050:
3051: case 2:
1.12 christos 3052: if (fwdargs[0].ispath && fwdargs[1].ispath) {
3053: fwd->listen_path = xstrdup(fwdargs[0].arg);
3054: fwd->listen_port = PORT_STREAMLOCAL;
3055: fwd->connect_path = xstrdup(fwdargs[1].arg);
3056: fwd->connect_port = PORT_STREAMLOCAL;
3057: } else if (fwdargs[1].ispath) {
3058: fwd->listen_host = NULL;
3059: fwd->listen_port = a2port(fwdargs[0].arg);
3060: fwd->connect_path = xstrdup(fwdargs[1].arg);
3061: fwd->connect_port = PORT_STREAMLOCAL;
3062: } else {
3063: fwd->listen_host = xstrdup(fwdargs[0].arg);
3064: fwd->listen_port = a2port(fwdargs[1].arg);
3065: fwd->connect_host = xstrdup("socks");
3066: }
1.1 christos 3067: break;
3068:
3069: case 3:
1.12 christos 3070: if (fwdargs[0].ispath) {
3071: fwd->listen_path = xstrdup(fwdargs[0].arg);
3072: fwd->listen_port = PORT_STREAMLOCAL;
3073: fwd->connect_host = xstrdup(fwdargs[1].arg);
3074: fwd->connect_port = a2port(fwdargs[2].arg);
3075: } else if (fwdargs[2].ispath) {
3076: fwd->listen_host = xstrdup(fwdargs[0].arg);
3077: fwd->listen_port = a2port(fwdargs[1].arg);
3078: fwd->connect_path = xstrdup(fwdargs[2].arg);
3079: fwd->connect_port = PORT_STREAMLOCAL;
3080: } else {
3081: fwd->listen_host = NULL;
3082: fwd->listen_port = a2port(fwdargs[0].arg);
3083: fwd->connect_host = xstrdup(fwdargs[1].arg);
3084: fwd->connect_port = a2port(fwdargs[2].arg);
3085: }
1.1 christos 3086: break;
3087:
3088: case 4:
1.12 christos 3089: fwd->listen_host = xstrdup(fwdargs[0].arg);
3090: fwd->listen_port = a2port(fwdargs[1].arg);
3091: fwd->connect_host = xstrdup(fwdargs[2].arg);
3092: fwd->connect_port = a2port(fwdargs[3].arg);
1.1 christos 3093: break;
3094: default:
3095: i = 0; /* failure */
3096: }
3097:
1.11 christos 3098: free(p);
1.1 christos 3099:
3100: if (dynamicfwd) {
3101: if (!(i == 1 || i == 2))
3102: goto fail_free;
3103: } else {
1.12 christos 3104: if (!(i == 3 || i == 4)) {
3105: if (fwd->connect_path == NULL &&
3106: fwd->listen_path == NULL)
3107: goto fail_free;
3108: }
3109: if (fwd->connect_port <= 0 && fwd->connect_path == NULL)
1.1 christos 3110: goto fail_free;
3111: }
3112:
1.12 christos 3113: if ((fwd->listen_port < 0 && fwd->listen_path == NULL) ||
3114: (!remotefwd && fwd->listen_port == 0))
1.1 christos 3115: goto fail_free;
3116: if (fwd->connect_host != NULL &&
3117: strlen(fwd->connect_host) >= NI_MAXHOST)
3118: goto fail_free;
1.35 christos 3119: /*
3120: * XXX - if connecting to a remote socket, max sun len may not
3121: * match this host
3122: */
1.12 christos 3123: if (fwd->connect_path != NULL &&
3124: strlen(fwd->connect_path) >= PATH_MAX_SUN)
3125: goto fail_free;
1.1 christos 3126: if (fwd->listen_host != NULL &&
3127: strlen(fwd->listen_host) >= NI_MAXHOST)
3128: goto fail_free;
1.12 christos 3129: if (fwd->listen_path != NULL &&
3130: strlen(fwd->listen_path) >= PATH_MAX_SUN)
3131: goto fail_free;
1.1 christos 3132:
3133: return (i);
3134:
3135: fail_free:
1.11 christos 3136: free(fwd->connect_host);
3137: fwd->connect_host = NULL;
1.12 christos 3138: free(fwd->connect_path);
3139: fwd->connect_path = NULL;
1.11 christos 3140: free(fwd->listen_host);
3141: fwd->listen_host = NULL;
1.12 christos 3142: free(fwd->listen_path);
3143: fwd->listen_path = NULL;
1.1 christos 3144: return (0);
3145: }
1.13 christos 3146:
1.19 christos 3147: int
3148: parse_jump(const char *s, Options *o, int active)
3149: {
3150: char *orig, *sdup, *cp;
3151: char *host = NULL, *user = NULL;
1.33 christos 3152: int r, ret = -1, port = -1, first;
1.19 christos 3153:
3154: active &= o->proxy_command == NULL && o->jump_host == NULL;
3155:
3156: orig = sdup = xstrdup(s);
1.35 christos 3157:
3158: /* Remove comment and trailing whitespace */
3159: if ((cp = strchr(orig, '#')) != NULL)
3160: *cp = '\0';
3161: rtrim(orig);
3162:
1.19 christos 3163: first = active;
3164: do {
1.25 christos 3165: if (strcasecmp(s, "none") == 0)
3166: break;
1.19 christos 3167: if ((cp = strrchr(sdup, ',')) == NULL)
3168: cp = sdup; /* last */
3169: else
3170: *cp++ = '\0';
3171:
3172: if (first) {
3173: /* First argument and configuration is active */
1.33 christos 3174: r = parse_ssh_uri(cp, &user, &host, &port);
3175: if (r == -1 || (r == 1 &&
3176: parse_user_host_port(cp, &user, &host, &port) != 0))
1.19 christos 3177: goto out;
3178: } else {
3179: /* Subsequent argument or inactive configuration */
1.33 christos 3180: r = parse_ssh_uri(cp, NULL, NULL, NULL);
3181: if (r == -1 || (r == 1 &&
3182: parse_user_host_port(cp, NULL, NULL, NULL) != 0))
1.19 christos 3183: goto out;
3184: }
3185: first = 0; /* only check syntax for subsequent hosts */
3186: } while (cp != sdup);
3187: /* success */
3188: if (active) {
1.25 christos 3189: if (strcasecmp(s, "none") == 0) {
3190: o->jump_host = xstrdup("none");
3191: o->jump_port = 0;
3192: } else {
3193: o->jump_user = user;
3194: o->jump_host = host;
3195: o->jump_port = port;
3196: o->proxy_command = xstrdup("none");
3197: user = host = NULL;
3198: if ((cp = strrchr(s, ',')) != NULL && cp != s) {
3199: o->jump_extra = xstrdup(s);
3200: o->jump_extra[cp - s] = '\0';
3201: }
1.19 christos 3202: }
3203: }
3204: ret = 0;
3205: out:
3206: free(orig);
3207: free(user);
3208: free(host);
3209: return ret;
3210: }
3211:
1.23 christos 3212: int
3213: parse_ssh_uri(const char *uri, char **userp, char **hostp, int *portp)
3214: {
1.33 christos 3215: char *user = NULL, *host = NULL, *path = NULL;
3216: int r, port;
1.23 christos 3217:
1.33 christos 3218: r = parse_uri("ssh", uri, &user, &host, &port, &path);
1.23 christos 3219: if (r == 0 && path != NULL)
3220: r = -1; /* path not allowed */
1.33 christos 3221: if (r == 0) {
3222: if (userp != NULL) {
3223: *userp = user;
3224: user = NULL;
3225: }
3226: if (hostp != NULL) {
3227: *hostp = host;
3228: host = NULL;
3229: }
3230: if (portp != NULL)
3231: *portp = port;
3232: }
3233: free(user);
3234: free(host);
3235: free(path);
1.23 christos 3236: return r;
3237: }
3238:
1.13 christos 3239: /* XXX the following is a near-vebatim copy from servconf.c; refactor */
3240: static const char *
3241: fmt_multistate_int(int val, const struct multistate *m)
3242: {
3243: u_int i;
3244:
3245: for (i = 0; m[i].key != NULL; i++) {
3246: if (m[i].value == val)
3247: return m[i].key;
3248: }
3249: return "UNKNOWN";
3250: }
3251:
3252: static const char *
3253: fmt_intarg(OpCodes code, int val)
3254: {
3255: if (val == -1)
3256: return "unset";
3257: switch (code) {
3258: case oAddressFamily:
3259: return fmt_multistate_int(val, multistate_addressfamily);
3260: case oVerifyHostKeyDNS:
3261: case oUpdateHostkeys:
3262: return fmt_multistate_int(val, multistate_yesnoask);
1.22 christos 3263: case oStrictHostKeyChecking:
3264: return fmt_multistate_int(val, multistate_strict_hostkey);
1.13 christos 3265: case oControlMaster:
3266: return fmt_multistate_int(val, multistate_controlmaster);
3267: case oTunnel:
3268: return fmt_multistate_int(val, multistate_tunnel);
3269: case oRequestTTY:
3270: return fmt_multistate_int(val, multistate_requesttty);
1.35 christos 3271: case oSessionType:
3272: return fmt_multistate_int(val, multistate_sessiontype);
1.13 christos 3273: case oCanonicalizeHostname:
3274: return fmt_multistate_int(val, multistate_canonicalizehostname);
1.25 christos 3275: case oAddKeysToAgent:
3276: return fmt_multistate_int(val, multistate_yesnoaskconfirm);
1.13 christos 3277: case oFingerprintHash:
3278: return ssh_digest_alg_name(val);
3279: default:
3280: switch (val) {
3281: case 0:
3282: return "no";
3283: case 1:
3284: return "yes";
3285: default:
3286: return "UNKNOWN";
3287: }
3288: }
3289: }
3290:
3291: static const char *
3292: lookup_opcode_name(OpCodes code)
3293: {
3294: u_int i;
3295:
3296: for (i = 0; keywords[i].name != NULL; i++)
3297: if (keywords[i].opcode == code)
3298: return(keywords[i].name);
3299: return "UNKNOWN";
3300: }
3301:
3302: static void
3303: dump_cfg_int(OpCodes code, int val)
3304: {
3305: printf("%s %d\n", lookup_opcode_name(code), val);
3306: }
3307:
3308: static void
3309: dump_cfg_fmtint(OpCodes code, int val)
3310: {
3311: printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
3312: }
3313:
3314: static void
3315: dump_cfg_string(OpCodes code, const char *val)
3316: {
3317: if (val == NULL)
3318: return;
3319: printf("%s %s\n", lookup_opcode_name(code), val);
3320: }
3321:
3322: static void
3323: dump_cfg_strarray(OpCodes code, u_int count, char **vals)
3324: {
3325: u_int i;
3326:
3327: for (i = 0; i < count; i++)
3328: printf("%s %s\n", lookup_opcode_name(code), vals[i]);
3329: }
3330:
3331: static void
3332: dump_cfg_strarray_oneline(OpCodes code, u_int count, char **vals)
3333: {
3334: u_int i;
3335:
3336: printf("%s", lookup_opcode_name(code));
1.35 christos 3337: if (count == 0)
3338: printf(" none");
1.13 christos 3339: for (i = 0; i < count; i++)
3340: printf(" %s", vals[i]);
3341: printf("\n");
3342: }
3343:
3344: static void
3345: dump_cfg_forwards(OpCodes code, u_int count, const struct Forward *fwds)
3346: {
3347: const struct Forward *fwd;
3348: u_int i;
3349:
3350: /* oDynamicForward */
3351: for (i = 0; i < count; i++) {
3352: fwd = &fwds[i];
1.21 christos 3353: if (code == oDynamicForward && fwd->connect_host != NULL &&
1.13 christos 3354: strcmp(fwd->connect_host, "socks") != 0)
3355: continue;
1.21 christos 3356: if (code == oLocalForward && fwd->connect_host != NULL &&
1.13 christos 3357: strcmp(fwd->connect_host, "socks") == 0)
3358: continue;
3359: printf("%s", lookup_opcode_name(code));
3360: if (fwd->listen_port == PORT_STREAMLOCAL)
3361: printf(" %s", fwd->listen_path);
3362: else if (fwd->listen_host == NULL)
3363: printf(" %d", fwd->listen_port);
3364: else {
3365: printf(" [%s]:%d",
3366: fwd->listen_host, fwd->listen_port);
3367: }
3368: if (code != oDynamicForward) {
3369: if (fwd->connect_port == PORT_STREAMLOCAL)
3370: printf(" %s", fwd->connect_path);
3371: else if (fwd->connect_host == NULL)
3372: printf(" %d", fwd->connect_port);
3373: else {
3374: printf(" [%s]:%d",
3375: fwd->connect_host, fwd->connect_port);
3376: }
3377: }
3378: printf("\n");
3379: }
3380: }
3381:
3382: void
3383: dump_client_config(Options *o, const char *host)
3384: {
1.29 christos 3385: int i, r;
1.25 christos 3386: char buf[8], *all_key;
1.13 christos 3387:
1.29 christos 3388: /*
3389: * Expand HostKeyAlgorithms name lists. This isn't handled in
3390: * fill_default_options() like the other algorithm lists because
3391: * the host key algorithms are by default dynamically chosen based
3392: * on the host's keys found in known_hosts.
3393: */
1.25 christos 3394: all_key = sshkey_alg_list(0, 0, 1, ',');
1.29 christos 3395: if ((r = kex_assemble_names(&o->hostkeyalgorithms, kex_default_pk_alg(),
3396: all_key)) != 0)
1.33 christos 3397: fatal_fr(r, "expand HostKeyAlgorithms");
1.25 christos 3398: free(all_key);
1.18 christos 3399:
1.13 christos 3400: /* Most interesting options first: user, host, port */
3401: dump_cfg_string(oUser, o->user);
1.28 christos 3402: dump_cfg_string(oHostname, host);
1.13 christos 3403: dump_cfg_int(oPort, o->port);
3404:
3405: /* Flag options */
3406: dump_cfg_fmtint(oAddressFamily, o->address_family);
3407: dump_cfg_fmtint(oBatchMode, o->batch_mode);
3408: dump_cfg_fmtint(oCanonicalizeFallbackLocal, o->canonicalize_fallback_local);
3409: dump_cfg_fmtint(oCanonicalizeHostname, o->canonicalize_hostname);
3410: dump_cfg_fmtint(oCheckHostIP, o->check_host_ip);
3411: dump_cfg_fmtint(oCompression, o->compression);
3412: dump_cfg_fmtint(oControlMaster, o->control_master);
3413: dump_cfg_fmtint(oEnableSSHKeysign, o->enable_ssh_keysign);
1.19 christos 3414: dump_cfg_fmtint(oClearAllForwardings, o->clear_forwardings);
1.13 christos 3415: dump_cfg_fmtint(oExitOnForwardFailure, o->exit_on_forward_failure);
3416: dump_cfg_fmtint(oFingerprintHash, o->fingerprint_hash);
3417: dump_cfg_fmtint(oForwardX11, o->forward_x11);
3418: dump_cfg_fmtint(oForwardX11Trusted, o->forward_x11_trusted);
3419: dump_cfg_fmtint(oGatewayPorts, o->fwd_opts.gateway_ports);
3420: #ifdef GSSAPI
3421: dump_cfg_fmtint(oGssAuthentication, o->gss_authentication);
3422: dump_cfg_fmtint(oGssDelegateCreds, o->gss_deleg_creds);
3423: #endif /* GSSAPI */
3424: dump_cfg_fmtint(oHashKnownHosts, o->hash_known_hosts);
3425: dump_cfg_fmtint(oHostbasedAuthentication, o->hostbased_authentication);
3426: dump_cfg_fmtint(oIdentitiesOnly, o->identities_only);
3427: dump_cfg_fmtint(oKbdInteractiveAuthentication, o->kbd_interactive_authentication);
3428: dump_cfg_fmtint(oNoHostAuthenticationForLocalhost, o->no_host_authentication_for_localhost);
3429: dump_cfg_fmtint(oPasswordAuthentication, o->password_authentication);
3430: dump_cfg_fmtint(oPermitLocalCommand, o->permit_local_command);
3431: dump_cfg_fmtint(oProxyUseFdpass, o->proxy_use_fdpass);
3432: dump_cfg_fmtint(oPubkeyAuthentication, o->pubkey_authentication);
3433: dump_cfg_fmtint(oRequestTTY, o->request_tty);
1.35 christos 3434: dump_cfg_fmtint(oSessionType, o->session_type);
3435: dump_cfg_fmtint(oStdinNull, o->stdin_null);
3436: dump_cfg_fmtint(oForkAfterAuthentication, o->fork_after_authentication);
1.13 christos 3437: dump_cfg_fmtint(oStreamLocalBindUnlink, o->fwd_opts.streamlocal_bind_unlink);
3438: dump_cfg_fmtint(oStrictHostKeyChecking, o->strict_host_key_checking);
3439: dump_cfg_fmtint(oTCPKeepAlive, o->tcp_keep_alive);
3440: dump_cfg_fmtint(oTunnel, o->tun_open);
3441: dump_cfg_fmtint(oVerifyHostKeyDNS, o->verify_host_key_dns);
3442: dump_cfg_fmtint(oVisualHostKey, o->visual_host_key);
3443: dump_cfg_fmtint(oUpdateHostkeys, o->update_hostkeys);
3444:
3445: /* Integer options */
3446: dump_cfg_int(oCanonicalizeMaxDots, o->canonicalize_max_dots);
3447: dump_cfg_int(oConnectionAttempts, o->connection_attempts);
3448: dump_cfg_int(oForwardX11Timeout, o->forward_x11_timeout);
3449: dump_cfg_int(oNumberOfPasswordPrompts, o->number_of_password_prompts);
3450: dump_cfg_int(oServerAliveCountMax, o->server_alive_count_max);
3451: dump_cfg_int(oServerAliveInterval, o->server_alive_interval);
3452:
3453: /* String options */
3454: dump_cfg_string(oBindAddress, o->bind_address);
1.23 christos 3455: dump_cfg_string(oBindInterface, o->bind_interface);
1.29 christos 3456: dump_cfg_string(oCiphers, o->ciphers);
1.13 christos 3457: dump_cfg_string(oControlPath, o->control_path);
1.18 christos 3458: dump_cfg_string(oHostKeyAlgorithms, o->hostkeyalgorithms);
1.13 christos 3459: dump_cfg_string(oHostKeyAlias, o->host_key_alias);
1.33 christos 3460: dump_cfg_string(oHostbasedAcceptedAlgorithms, o->hostbased_accepted_algos);
1.19 christos 3461: dump_cfg_string(oIdentityAgent, o->identity_agent);
1.25 christos 3462: dump_cfg_string(oIgnoreUnknown, o->ignored_unknown);
1.13 christos 3463: dump_cfg_string(oKbdInteractiveDevices, o->kbd_interactive_devices);
1.29 christos 3464: dump_cfg_string(oKexAlgorithms, o->kex_algorithms);
3465: dump_cfg_string(oCASignatureAlgorithms, o->ca_sign_algorithms);
1.13 christos 3466: dump_cfg_string(oLocalCommand, o->local_command);
1.22 christos 3467: dump_cfg_string(oRemoteCommand, o->remote_command);
1.13 christos 3468: dump_cfg_string(oLogLevel, log_level_name(o->log_level));
1.29 christos 3469: dump_cfg_string(oMacs, o->macs);
1.21 christos 3470: #ifdef ENABLE_PKCS11
1.13 christos 3471: dump_cfg_string(oPKCS11Provider, o->pkcs11_provider);
1.21 christos 3472: #endif
1.29 christos 3473: dump_cfg_string(oSecurityKeyProvider, o->sk_provider);
1.13 christos 3474: dump_cfg_string(oPreferredAuthentications, o->preferred_authentications);
1.33 christos 3475: dump_cfg_string(oPubkeyAcceptedAlgorithms, o->pubkey_accepted_algos);
1.13 christos 3476: dump_cfg_string(oRevokedHostKeys, o->revoked_host_keys);
3477: dump_cfg_string(oXAuthLocation, o->xauth_location);
1.33 christos 3478: dump_cfg_string(oKnownHostsCommand, o->known_hosts_command);
1.13 christos 3479:
3480: /* Forwards */
3481: dump_cfg_forwards(oDynamicForward, o->num_local_forwards, o->local_forwards);
3482: dump_cfg_forwards(oLocalForward, o->num_local_forwards, o->local_forwards);
3483: dump_cfg_forwards(oRemoteForward, o->num_remote_forwards, o->remote_forwards);
3484:
3485: /* String array options */
3486: dump_cfg_strarray(oIdentityFile, o->num_identity_files, o->identity_files);
3487: dump_cfg_strarray_oneline(oCanonicalDomains, o->num_canonical_domains, o->canonical_domains);
1.25 christos 3488: dump_cfg_strarray(oCertificateFile, o->num_certificate_files, o->certificate_files);
1.13 christos 3489: dump_cfg_strarray_oneline(oGlobalKnownHostsFile, o->num_system_hostfiles, o->system_hostfiles);
3490: dump_cfg_strarray_oneline(oUserKnownHostsFile, o->num_user_hostfiles, o->user_hostfiles);
3491: dump_cfg_strarray(oSendEnv, o->num_send_env, o->send_env);
1.25 christos 3492: dump_cfg_strarray(oSetEnv, o->num_setenv, o->setenv);
1.33 christos 3493: dump_cfg_strarray_oneline(oLogVerbose,
3494: o->num_log_verbose, o->log_verbose);
1.13 christos 3495:
3496: /* Special cases */
3497:
1.33 christos 3498: /* PermitRemoteOpen */
3499: if (o->num_permitted_remote_opens == 0)
3500: printf("%s any\n", lookup_opcode_name(oPermitRemoteOpen));
3501: else
3502: dump_cfg_strarray_oneline(oPermitRemoteOpen,
3503: o->num_permitted_remote_opens, o->permitted_remote_opens);
3504:
1.32 christos 3505: /* AddKeysToAgent */
3506: if (o->add_keys_to_agent_lifespan <= 0)
3507: dump_cfg_fmtint(oAddKeysToAgent, o->add_keys_to_agent);
3508: else {
3509: printf("addkeystoagent%s %d\n",
3510: o->add_keys_to_agent == 3 ? " confirm" : "",
3511: o->add_keys_to_agent_lifespan);
3512: }
3513:
1.29 christos 3514: /* oForwardAgent */
3515: if (o->forward_agent_sock_path == NULL)
3516: dump_cfg_fmtint(oForwardAgent, o->forward_agent);
3517: else
3518: dump_cfg_string(oForwardAgent, o->forward_agent_sock_path);
3519:
1.13 christos 3520: /* oConnectTimeout */
3521: if (o->connection_timeout == -1)
3522: printf("connecttimeout none\n");
3523: else
3524: dump_cfg_int(oConnectTimeout, o->connection_timeout);
3525:
3526: /* oTunnelDevice */
3527: printf("tunneldevice");
3528: if (o->tun_local == SSH_TUNID_ANY)
3529: printf(" any");
3530: else
3531: printf(" %d", o->tun_local);
3532: if (o->tun_remote == SSH_TUNID_ANY)
3533: printf(":any");
3534: else
3535: printf(":%d", o->tun_remote);
3536: printf("\n");
3537:
3538: /* oCanonicalizePermittedCNAMEs */
1.37 ! christos 3539: printf("canonicalizePermittedcnames");
! 3540: if (o->num_permitted_cnames == 0)
! 3541: printf(" none");
! 3542: for (i = 0; i < o->num_permitted_cnames; i++) {
! 3543: printf(" %s:%s", o->permitted_cnames[i].source_list,
! 3544: o->permitted_cnames[i].target_list);
1.13 christos 3545: }
1.37 ! christos 3546: printf("\n");
1.13 christos 3547:
3548: /* oControlPersist */
3549: if (o->control_persist == 0 || o->control_persist_timeout == 0)
3550: dump_cfg_fmtint(oControlPersist, o->control_persist);
3551: else
3552: dump_cfg_int(oControlPersist, o->control_persist_timeout);
3553:
3554: /* oEscapeChar */
3555: if (o->escape_char == SSH_ESCAPECHAR_NONE)
3556: printf("escapechar none\n");
3557: else {
1.19 christos 3558: vis(buf, o->escape_char, VIS_WHITE, 0);
3559: printf("escapechar %s\n", buf);
1.13 christos 3560: }
3561:
3562: /* oIPQoS */
3563: printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
3564: printf("%s\n", iptos2str(o->ip_qos_bulk));
3565:
3566: /* oRekeyLimit */
1.18 christos 3567: printf("rekeylimit %llu %d\n",
3568: (unsigned long long)o->rekey_limit, o->rekey_interval);
1.13 christos 3569:
3570: /* oStreamLocalBindMask */
3571: printf("streamlocalbindmask 0%o\n",
3572: o->fwd_opts.streamlocal_bind_mask);
1.19 christos 3573:
1.25 christos 3574: /* oLogFacility */
3575: printf("syslogfacility %s\n", log_facility_name(o->log_facility));
3576:
1.19 christos 3577: /* oProxyCommand / oProxyJump */
3578: if (o->jump_host == NULL)
3579: dump_cfg_string(oProxyCommand, o->proxy_command);
3580: else {
3581: /* Check for numeric addresses */
3582: i = strchr(o->jump_host, ':') != NULL ||
3583: strspn(o->jump_host, "1234567890.") == strlen(o->jump_host);
3584: snprintf(buf, sizeof(buf), "%d", o->jump_port);
3585: printf("proxyjump %s%s%s%s%s%s%s%s%s\n",
3586: /* optional additional jump spec */
3587: o->jump_extra == NULL ? "" : o->jump_extra,
3588: o->jump_extra == NULL ? "" : ",",
3589: /* optional user */
3590: o->jump_user == NULL ? "" : o->jump_user,
3591: o->jump_user == NULL ? "" : "@",
3592: /* opening [ if hostname is numeric */
3593: i ? "[" : "",
3594: /* mandatory hostname */
3595: o->jump_host,
3596: /* closing ] if hostname is numeric */
3597: i ? "]" : "",
3598: /* optional port number */
3599: o->jump_port <= 0 ? "" : ":",
3600: o->jump_port <= 0 ? "" : buf);
3601: }
1.13 christos 3602: }
CVSweb <webmaster@jp.NetBSD.org>