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