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