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