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