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