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