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