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