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