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