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