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