Annotation of src/usr.bin/ssh/readconf.c, Revision 1.298
1.298 ! djm 1: /* $OpenBSD: readconf.c,v 1.297 2018/08/12 20:19:13 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.297 djm 41: #include "ssherr.h"
1.25 markus 42: #include "compat.h"
1.58 markus 43: #include "cipher.h"
1.55 markus 44: #include "pathnames.h"
1.58 markus 45: #include "log.h"
1.227 djm 46: #include "sshkey.h"
1.220 millert 47: #include "misc.h"
1.58 markus 48: #include "readconf.h"
49: #include "match.h"
1.62 markus 50: #include "kex.h"
51: #include "mac.h"
1.206 djm 52: #include "uidswap.h"
1.221 djm 53: #include "myproposal.h"
1.224 djm 54: #include "digest.h"
1.1 deraadt 55:
56: /* Format of the configuration file:
57:
58: # Configuration data is parsed as follows:
59: # 1. command line options
60: # 2. user-specific file
61: # 3. system-wide file
62: # Any configuration value is only changed the first time it is set.
63: # Thus, host-specific definitions should be at the beginning of the
64: # configuration file, and defaults at the end.
65:
66: # Host-specific declarations. These may override anything above. A single
67: # host may match multiple declarations; these are processed in the order
68: # that they are given in.
69:
70: Host *.ngs.fi ngs.fi
1.96 markus 71: User foo
1.1 deraadt 72:
73: Host fake.com
74: HostName another.host.name.real.org
75: User blaah
76: Port 34289
77: ForwardX11 no
78: ForwardAgent no
79:
80: Host books.com
81: RemoteForward 9999 shadows.cs.hut.fi:9999
1.266 djm 82: Ciphers 3des-cbc
1.1 deraadt 83:
84: Host fascist.blob.com
85: Port 23123
86: User tylonen
87: PasswordAuthentication no
88:
89: Host puukko.hut.fi
90: User t35124p
91: ProxyCommand ssh-proxy %h %p
92:
93: Host *.fr
1.96 markus 94: PublicKeyAuthentication no
1.1 deraadt 95:
96: Host *.su
1.266 djm 97: Ciphers aes128-ctr
1.1 deraadt 98: PasswordAuthentication no
99:
1.144 reyk 100: Host vpn.fake.com
101: Tunnel yes
102: TunnelDevice 3
103:
1.1 deraadt 104: # Defaults for various options
105: Host *
106: ForwardAgent no
1.50 markus 107: ForwardX11 no
1.1 deraadt 108: PasswordAuthentication yes
109: RSAAuthentication yes
110: RhostsRSAAuthentication yes
111: StrictHostKeyChecking yes
1.126 markus 112: TcpKeepAlive no
1.1 deraadt 113: IdentityFile ~/.ssh/identity
114: Port 22
115: EscapeChar ~
116:
117: */
118:
1.252 djm 119: static int read_config_file_depth(const char *filename, struct passwd *pw,
120: const char *host, const char *original_host, Options *options,
121: int flags, int *activep, int depth);
122: static int process_config_line_depth(Options *options, struct passwd *pw,
123: const char *host, const char *original_host, char *line,
124: const char *filename, int linenum, int *activep, int flags, int depth);
125:
1.1 deraadt 126: /* Keyword tokens. */
127:
1.17 markus 128: typedef enum {
129: oBadOption,
1.252 djm 130: oHost, oMatch, oInclude,
1.186 djm 131: oForwardAgent, oForwardX11, oForwardX11Trusted, oForwardX11Timeout,
132: oGatewayPorts, oExitOnForwardFailure,
1.100 deraadt 133: oPasswordAuthentication, oRSAAuthentication,
1.59 markus 134: oChallengeResponseAuthentication, oXAuthLocation,
1.17 markus 135: oIdentityFile, oHostName, oPort, oCipher, oRemoteForward, oLocalForward,
1.253 markus 136: oCertificateFile, oAddKeysToAgent, oIdentityAgent,
1.206 djm 137: oUser, oEscapeChar, oRhostsRSAAuthentication, oProxyCommand,
1.17 markus 138: oGlobalKnownHostsFile, oUserKnownHostsFile, oConnectionAttempts,
139: oBatchMode, oCheckHostIP, oStrictHostKeyChecking, oCompression,
1.126 markus 140: oCompressionLevel, oTCPKeepAlive, oNumberOfPasswordPrompts,
1.273 djm 141: oUsePrivilegedPort, oLogFacility, oLogLevel, oCiphers, oMacs,
1.221 djm 142: oPubkeyAuthentication,
1.67 markus 143: oKbdInteractiveAuthentication, oKbdInteractiveDevices, oHostKeyAlias,
1.76 markus 144: oDynamicForward, oPreferredAuthentications, oHostbasedAuthentication,
1.282 djm 145: oHostKeyAlgorithms, oBindAddress, oBindInterface, oPKCS11Provider,
1.96 markus 146: oClearAllForwardings, oNoHostAuthenticationForLocalhost,
1.111 djm 147: oEnableSSHKeysign, oRekeyLimit, oVerifyHostKeyDNS, oConnectTimeout,
1.118 markus 148: oAddressFamily, oGssAuthentication, oGssDelegateCreds,
1.128 markus 149: oServerAliveInterval, oServerAliveCountMax, oIdentitiesOnly,
1.290 djm 150: oSendEnv, oSetEnv, oControlPath, oControlMaster, oControlPersist,
1.187 djm 151: oHashKnownHosts,
1.277 bluhm 152: oTunnel, oTunnelDevice,
153: oLocalCommand, oPermitLocalCommand, oRemoteCommand,
1.248 markus 154: oVisualHostKey,
1.205 djm 155: oKexAlgorithms, oIPQoS, oRequestTTY, oIgnoreUnknown, oProxyUseFdpass,
1.209 djm 156: oCanonicalDomains, oCanonicalizeHostname, oCanonicalizeMaxDots,
157: oCanonicalizeFallbackLocal, oCanonicalizePermittedCNAMEs,
1.223 djm 158: oStreamLocalBindMask, oStreamLocalBindUnlink, oRevokedHostKeys,
1.230 djm 159: oFingerprintHash, oUpdateHostkeys, oHostbasedKeyTypes,
1.298 ! djm 160: oPubkeyAcceptedKeyTypes, oCASignatureAlgorithms, oProxyJump,
1.273 djm 161: oIgnore, oIgnoredUnknownOption, oDeprecated, oUnsupported
1.1 deraadt 162: } OpCodes;
163:
164: /* Textual representations of the tokens. */
165:
1.17 markus 166: static struct {
167: const char *name;
168: OpCodes opcode;
169: } keywords[] = {
1.266 djm 170: /* Deprecated options */
1.273 djm 171: { "protocol", oIgnore }, /* NB. silently ignored */
1.274 djm 172: { "cipher", oDeprecated },
1.266 djm 173: { "fallbacktorsh", oDeprecated },
174: { "globalknownhostsfile2", oDeprecated },
175: { "rhostsauthentication", oDeprecated },
176: { "userknownhostsfile2", oDeprecated },
177: { "useroaming", oDeprecated },
178: { "usersh", oDeprecated },
1.294 dtucker 179: { "useprivilegedport", oDeprecated },
1.266 djm 180:
181: /* Unsupported options */
182: { "afstokenpassing", oUnsupported },
183: { "kerberosauthentication", oUnsupported },
184: { "kerberostgtpassing", oUnsupported },
185:
186: /* Sometimes-unsupported options */
187: #if defined(GSSAPI)
188: { "gssapiauthentication", oGssAuthentication },
189: { "gssapidelegatecredentials", oGssDelegateCreds },
190: # else
191: { "gssapiauthentication", oUnsupported },
192: { "gssapidelegatecredentials", oUnsupported },
193: #endif
194: #ifdef ENABLE_PKCS11
195: { "smartcarddevice", oPKCS11Provider },
196: { "pkcs11provider", oPKCS11Provider },
197: # else
198: { "smartcarddevice", oUnsupported },
199: { "pkcs11provider", oUnsupported },
200: #endif
201: { "rsaauthentication", oUnsupported },
202: { "rhostsrsaauthentication", oUnsupported },
203: { "compressionlevel", oUnsupported },
204:
1.17 markus 205: { "forwardagent", oForwardAgent },
206: { "forwardx11", oForwardX11 },
1.123 markus 207: { "forwardx11trusted", oForwardX11Trusted },
1.186 djm 208: { "forwardx11timeout", oForwardX11Timeout },
1.153 markus 209: { "exitonforwardfailure", oExitOnForwardFailure },
1.34 markus 210: { "xauthlocation", oXAuthLocation },
1.17 markus 211: { "gatewayports", oGatewayPorts },
212: { "passwordauthentication", oPasswordAuthentication },
1.48 markus 213: { "kbdinteractiveauthentication", oKbdInteractiveAuthentication },
214: { "kbdinteractivedevices", oKbdInteractiveDevices },
1.50 markus 215: { "pubkeyauthentication", oPubkeyAuthentication },
1.59 markus 216: { "dsaauthentication", oPubkeyAuthentication }, /* alias */
1.73 markus 217: { "hostbasedauthentication", oHostbasedAuthentication },
1.59 markus 218: { "challengeresponseauthentication", oChallengeResponseAuthentication },
219: { "skeyauthentication", oChallengeResponseAuthentication }, /* alias */
220: { "tisauthentication", oChallengeResponseAuthentication }, /* alias */
1.17 markus 221: { "identityfile", oIdentityFile },
1.174 stevesk 222: { "identityfile2", oIdentityFile }, /* obsolete */
1.128 markus 223: { "identitiesonly", oIdentitiesOnly },
1.241 djm 224: { "certificatefile", oCertificateFile },
1.246 jcs 225: { "addkeystoagent", oAddKeysToAgent },
1.253 markus 226: { "identityagent", oIdentityAgent },
1.17 markus 227: { "hostname", oHostName },
1.52 markus 228: { "hostkeyalias", oHostKeyAlias },
1.17 markus 229: { "proxycommand", oProxyCommand },
230: { "port", oPort },
1.25 markus 231: { "ciphers", oCiphers },
1.62 markus 232: { "macs", oMacs },
1.17 markus 233: { "remoteforward", oRemoteForward },
234: { "localforward", oLocalForward },
235: { "user", oUser },
236: { "host", oHost },
1.206 djm 237: { "match", oMatch },
1.17 markus 238: { "escapechar", oEscapeChar },
239: { "globalknownhostsfile", oGlobalKnownHostsFile },
1.174 stevesk 240: { "userknownhostsfile", oUserKnownHostsFile },
1.17 markus 241: { "connectionattempts", oConnectionAttempts },
242: { "batchmode", oBatchMode },
243: { "checkhostip", oCheckHostIP },
244: { "stricthostkeychecking", oStrictHostKeyChecking },
245: { "compression", oCompression },
1.126 markus 246: { "tcpkeepalive", oTCPKeepAlive },
247: { "keepalive", oTCPKeepAlive }, /* obsolete */
1.17 markus 248: { "numberofpasswordprompts", oNumberOfPasswordPrompts },
1.271 dtucker 249: { "syslogfacility", oLogFacility },
1.17 markus 250: { "loglevel", oLogLevel },
1.71 markus 251: { "dynamicforward", oDynamicForward },
1.67 markus 252: { "preferredauthentications", oPreferredAuthentications },
1.76 markus 253: { "hostkeyalgorithms", oHostKeyAlgorithms },
1.298 ! djm 254: { "casignaturealgorithms", oCASignatureAlgorithms },
1.77 markus 255: { "bindaddress", oBindAddress },
1.282 djm 256: { "bindinterface", oBindInterface },
1.93 deraadt 257: { "clearallforwardings", oClearAllForwardings },
1.101 markus 258: { "enablesshkeysign", oEnableSSHKeysign },
1.107 jakob 259: { "verifyhostkeydns", oVerifyHostKeyDNS },
1.93 deraadt 260: { "nohostauthenticationforlocalhost", oNoHostAuthenticationForLocalhost },
1.105 markus 261: { "rekeylimit", oRekeyLimit },
1.111 djm 262: { "connecttimeout", oConnectTimeout },
1.112 djm 263: { "addressfamily", oAddressFamily },
1.127 markus 264: { "serveraliveinterval", oServerAliveInterval },
265: { "serveralivecountmax", oServerAliveCountMax },
1.130 djm 266: { "sendenv", oSendEnv },
1.290 djm 267: { "setenv", oSetEnv },
1.132 djm 268: { "controlpath", oControlPath },
269: { "controlmaster", oControlMaster },
1.187 djm 270: { "controlpersist", oControlPersist },
1.136 djm 271: { "hashknownhosts", oHashKnownHosts },
1.252 djm 272: { "include", oInclude },
1.144 reyk 273: { "tunnel", oTunnel },
274: { "tunneldevice", oTunnelDevice },
275: { "localcommand", oLocalCommand },
276: { "permitlocalcommand", oPermitLocalCommand },
1.277 bluhm 277: { "remotecommand", oRemoteCommand },
1.167 grunk 278: { "visualhostkey", oVisualHostKey },
1.189 djm 279: { "kexalgorithms", oKexAlgorithms },
1.190 djm 280: { "ipqos", oIPQoS },
1.192 djm 281: { "requesttty", oRequestTTY },
1.205 djm 282: { "proxyusefdpass", oProxyUseFdpass },
1.208 djm 283: { "canonicaldomains", oCanonicalDomains },
1.209 djm 284: { "canonicalizefallbacklocal", oCanonicalizeFallbackLocal },
285: { "canonicalizehostname", oCanonicalizeHostname },
286: { "canonicalizemaxdots", oCanonicalizeMaxDots },
287: { "canonicalizepermittedcnames", oCanonicalizePermittedCNAMEs },
1.220 millert 288: { "streamlocalbindmask", oStreamLocalBindMask },
289: { "streamlocalbindunlink", oStreamLocalBindUnlink },
1.223 djm 290: { "revokedhostkeys", oRevokedHostKeys },
1.224 djm 291: { "fingerprinthash", oFingerprintHash },
1.229 djm 292: { "updatehostkeys", oUpdateHostkeys },
1.230 djm 293: { "hostbasedkeytypes", oHostbasedKeyTypes },
1.238 markus 294: { "pubkeyacceptedkeytypes", oPubkeyAcceptedKeyTypes },
1.199 djm 295: { "ignoreunknown", oIgnoreUnknown },
1.257 djm 296: { "proxyjump", oProxyJump },
1.171 djm 297:
1.92 stevesk 298: { NULL, oBadOption }
1.13 markus 299: };
300:
1.19 markus 301: /*
302: * Adds a local TCP/IP port forward to options. Never returns if there is an
303: * error.
304: */
1.1 deraadt 305:
1.26 markus 306: void
1.220 millert 307: add_local_forward(Options *options, const struct Forward *newfwd)
1.1 deraadt 308: {
1.220 millert 309: struct Forward *fwd;
1.251 djm 310: int i;
1.185 djm 311:
1.251 djm 312: /* Don't add duplicates */
313: for (i = 0; i < options->num_local_forwards; i++) {
314: if (forward_equals(newfwd, options->local_forwards + i))
315: return;
316: }
1.234 deraadt 317: options->local_forwards = xreallocarray(options->local_forwards,
1.185 djm 318: options->num_local_forwards + 1,
319: sizeof(*options->local_forwards));
1.17 markus 320: fwd = &options->local_forwards[options->num_local_forwards++];
1.135 djm 321:
1.172 stevesk 322: fwd->listen_host = newfwd->listen_host;
1.135 djm 323: fwd->listen_port = newfwd->listen_port;
1.220 millert 324: fwd->listen_path = newfwd->listen_path;
1.172 stevesk 325: fwd->connect_host = newfwd->connect_host;
1.135 djm 326: fwd->connect_port = newfwd->connect_port;
1.220 millert 327: fwd->connect_path = newfwd->connect_path;
1.1 deraadt 328: }
329:
1.19 markus 330: /*
331: * Adds a remote TCP/IP port forward to options. Never returns if there is
332: * an error.
333: */
1.1 deraadt 334:
1.26 markus 335: void
1.220 millert 336: add_remote_forward(Options *options, const struct Forward *newfwd)
1.1 deraadt 337: {
1.220 millert 338: struct Forward *fwd;
1.251 djm 339: int i;
1.185 djm 340:
1.251 djm 341: /* Don't add duplicates */
342: for (i = 0; i < options->num_remote_forwards; i++) {
343: if (forward_equals(newfwd, options->remote_forwards + i))
344: return;
345: }
1.234 deraadt 346: options->remote_forwards = xreallocarray(options->remote_forwards,
1.185 djm 347: options->num_remote_forwards + 1,
348: sizeof(*options->remote_forwards));
1.17 markus 349: fwd = &options->remote_forwards[options->num_remote_forwards++];
1.135 djm 350:
1.172 stevesk 351: fwd->listen_host = newfwd->listen_host;
1.135 djm 352: fwd->listen_port = newfwd->listen_port;
1.220 millert 353: fwd->listen_path = newfwd->listen_path;
1.172 stevesk 354: fwd->connect_host = newfwd->connect_host;
1.135 djm 355: fwd->connect_port = newfwd->connect_port;
1.220 millert 356: fwd->connect_path = newfwd->connect_path;
1.194 markus 357: fwd->handle = newfwd->handle;
1.184 markus 358: fwd->allocated_port = 0;
1.1 deraadt 359: }
360:
1.90 stevesk 361: static void
362: clear_forwardings(Options *options)
363: {
364: int i;
365:
1.135 djm 366: for (i = 0; i < options->num_local_forwards; i++) {
1.202 djm 367: free(options->local_forwards[i].listen_host);
1.220 millert 368: free(options->local_forwards[i].listen_path);
1.202 djm 369: free(options->local_forwards[i].connect_host);
1.220 millert 370: free(options->local_forwards[i].connect_path);
1.135 djm 371: }
1.185 djm 372: if (options->num_local_forwards > 0) {
1.202 djm 373: free(options->local_forwards);
1.185 djm 374: options->local_forwards = NULL;
375: }
1.90 stevesk 376: options->num_local_forwards = 0;
1.135 djm 377: for (i = 0; i < options->num_remote_forwards; i++) {
1.202 djm 378: free(options->remote_forwards[i].listen_host);
1.220 millert 379: free(options->remote_forwards[i].listen_path);
1.202 djm 380: free(options->remote_forwards[i].connect_host);
1.220 millert 381: free(options->remote_forwards[i].connect_path);
1.135 djm 382: }
1.185 djm 383: if (options->num_remote_forwards > 0) {
1.202 djm 384: free(options->remote_forwards);
1.185 djm 385: options->remote_forwards = NULL;
386: }
1.90 stevesk 387: options->num_remote_forwards = 0;
1.145 reyk 388: options->tun_open = SSH_TUNMODE_NO;
1.90 stevesk 389: }
390:
1.195 dtucker 391: void
1.241 djm 392: add_certificate_file(Options *options, const char *path, int userprovided)
393: {
394: int i;
395:
396: if (options->num_certificate_files >= SSH_MAX_CERTIFICATE_FILES)
397: fatal("Too many certificate files specified (max %d)",
398: SSH_MAX_CERTIFICATE_FILES);
399:
400: /* Avoid registering duplicates */
401: for (i = 0; i < options->num_certificate_files; i++) {
402: if (options->certificate_file_userprovided[i] == userprovided &&
403: strcmp(options->certificate_files[i], path) == 0) {
404: debug2("%s: ignoring duplicate key %s", __func__, path);
405: return;
406: }
407: }
408:
409: options->certificate_file_userprovided[options->num_certificate_files] =
410: userprovided;
411: options->certificate_files[options->num_certificate_files++] =
412: xstrdup(path);
413: }
414:
415: void
1.195 dtucker 416: add_identity_file(Options *options, const char *dir, const char *filename,
417: int userprovided)
418: {
419: char *path;
1.219 djm 420: int i;
1.195 dtucker 421:
422: if (options->num_identity_files >= SSH_MAX_IDENTITY_FILES)
423: fatal("Too many identity files specified (max %d)",
424: SSH_MAX_IDENTITY_FILES);
425:
426: if (dir == NULL) /* no dir, filename is absolute */
427: path = xstrdup(filename);
1.276 djm 428: else if (xasprintf(&path, "%s%s", dir, filename) >= PATH_MAX)
429: fatal("Identity file path %s too long", path);
1.219 djm 430:
431: /* Avoid registering duplicates */
432: for (i = 0; i < options->num_identity_files; i++) {
433: if (options->identity_file_userprovided[i] == userprovided &&
434: strcmp(options->identity_files[i], path) == 0) {
435: debug2("%s: ignoring duplicate key %s", __func__, path);
436: free(path);
437: return;
438: }
439: }
1.195 dtucker 440:
441: options->identity_file_userprovided[options->num_identity_files] =
442: userprovided;
443: options->identity_files[options->num_identity_files++] = path;
444: }
445:
1.206 djm 446: int
447: default_ssh_port(void)
448: {
449: static int port;
450: struct servent *sp;
451:
452: if (port == 0) {
453: sp = getservbyname(SSH_SERVICE_NAME, "tcp");
454: port = sp ? ntohs(sp->s_port) : SSH_DEFAULT_PORT;
455: }
456: return port;
457: }
458:
459: /*
460: * Execute a command in a shell.
461: * Return its exit status or -1 on abnormal exit.
462: */
463: static int
464: execute_in_shell(const char *cmd)
465: {
1.243 dtucker 466: char *shell;
1.206 djm 467: pid_t pid;
468: int devnull, status;
469:
470: if ((shell = getenv("SHELL")) == NULL)
471: shell = _PATH_BSHELL;
472:
473: /* Need this to redirect subprocess stdin/out */
474: if ((devnull = open(_PATH_DEVNULL, O_RDWR)) == -1)
475: fatal("open(/dev/null): %s", strerror(errno));
476:
477: debug("Executing command: '%.500s'", cmd);
478:
479: /* Fork and execute the command. */
480: if ((pid = fork()) == 0) {
1.245 djm 481: char *argv[4];
1.206 djm 482:
483: /* Redirect child stdin and stdout. Leave stderr */
484: if (dup2(devnull, STDIN_FILENO) == -1)
485: fatal("dup2: %s", strerror(errno));
486: if (dup2(devnull, STDOUT_FILENO) == -1)
487: fatal("dup2: %s", strerror(errno));
488: if (devnull > STDERR_FILENO)
489: close(devnull);
490: closefrom(STDERR_FILENO + 1);
1.245 djm 491:
492: argv[0] = shell;
493: argv[1] = "-c";
494: argv[2] = xstrdup(cmd);
495: argv[3] = NULL;
1.206 djm 496:
497: execv(argv[0], argv);
498: error("Unable to execute '%.100s': %s", cmd, strerror(errno));
499: /* Die with signal to make this error apparent to parent. */
500: signal(SIGTERM, SIG_DFL);
501: kill(getpid(), SIGTERM);
502: _exit(1);
503: }
504: /* Parent. */
505: if (pid < 0)
506: fatal("%s: fork: %.100s", __func__, strerror(errno));
507:
508: close(devnull);
509:
510: while (waitpid(pid, &status, 0) == -1) {
511: if (errno != EINTR && errno != EAGAIN)
512: fatal("%s: waitpid: %s", __func__, strerror(errno));
513: }
514: if (!WIFEXITED(status)) {
515: error("command '%.100s' exited abnormally", cmd);
516: return -1;
1.221 djm 517: }
1.206 djm 518: debug3("command returned status %d", WEXITSTATUS(status));
519: return WEXITSTATUS(status);
520: }
521:
522: /*
523: * Parse and execute a Match directive.
524: */
525: static int
526: match_cfg_line(Options *options, char **condition, struct passwd *pw,
1.221 djm 527: const char *host_arg, const char *original_host, int post_canon,
528: const char *filename, int linenum)
1.206 djm 529: {
1.221 djm 530: char *arg, *oattrib, *attrib, *cmd, *cp = *condition, *host, *criteria;
1.211 djm 531: const char *ruser;
1.221 djm 532: int r, port, this_result, result = 1, attributes = 0, negate;
1.206 djm 533: char thishost[NI_MAXHOST], shorthost[NI_MAXHOST], portstr[NI_MAXSERV];
1.288 djm 534: char uidstr[32];
1.206 djm 535:
536: /*
537: * Configuration is likely to be incomplete at this point so we
538: * must be prepared to use default values.
539: */
540: port = options->port <= 0 ? default_ssh_port() : options->port;
541: ruser = options->user == NULL ? pw->pw_name : options->user;
1.250 djm 542: if (post_canon) {
543: host = xstrdup(options->hostname);
544: } else if (options->hostname != NULL) {
1.212 djm 545: /* NB. Please keep in sync with ssh.c:main() */
1.211 djm 546: host = percent_expand(options->hostname,
547: "h", host_arg, (char *)NULL);
1.250 djm 548: } else {
1.211 djm 549: host = xstrdup(host_arg);
1.250 djm 550: }
1.206 djm 551:
1.221 djm 552: debug2("checking match for '%s' host %s originally %s",
553: cp, host, original_host);
554: while ((oattrib = attrib = strdelim(&cp)) && *attrib != '\0') {
555: criteria = NULL;
556: this_result = 1;
557: if ((negate = attrib[0] == '!'))
558: attrib++;
559: /* criteria "all" and "canonical" have no argument */
1.213 dtucker 560: if (strcasecmp(attrib, "all") == 0) {
1.221 djm 561: if (attributes > 1 ||
1.213 dtucker 562: ((arg = strdelim(&cp)) != NULL && *arg != '\0')) {
1.221 djm 563: error("%.200s line %d: '%s' cannot be combined "
564: "with other Match attributes",
565: filename, linenum, oattrib);
1.213 dtucker 566: result = -1;
567: goto out;
568: }
1.221 djm 569: if (result)
570: result = negate ? 0 : 1;
1.213 dtucker 571: goto out;
572: }
1.221 djm 573: attributes++;
574: if (strcasecmp(attrib, "canonical") == 0) {
575: r = !!post_canon; /* force bitmask member to boolean */
576: if (r == (negate ? 1 : 0))
577: this_result = result = 0;
578: debug3("%.200s line %d: %smatched '%s'",
579: filename, linenum,
580: this_result ? "" : "not ", oattrib);
581: continue;
582: }
583: /* All other criteria require an argument */
1.206 djm 584: if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
585: error("Missing Match criteria for %s", attrib);
1.211 djm 586: result = -1;
587: goto out;
1.206 djm 588: }
589: if (strcasecmp(attrib, "host") == 0) {
1.221 djm 590: criteria = xstrdup(host);
1.235 djm 591: r = match_hostname(host, arg) == 1;
1.221 djm 592: if (r == (negate ? 1 : 0))
593: this_result = result = 0;
1.206 djm 594: } else if (strcasecmp(attrib, "originalhost") == 0) {
1.221 djm 595: criteria = xstrdup(original_host);
1.235 djm 596: r = match_hostname(original_host, arg) == 1;
1.221 djm 597: if (r == (negate ? 1 : 0))
598: this_result = result = 0;
1.206 djm 599: } else if (strcasecmp(attrib, "user") == 0) {
1.221 djm 600: criteria = xstrdup(ruser);
1.235 djm 601: r = match_pattern_list(ruser, arg, 0) == 1;
1.221 djm 602: if (r == (negate ? 1 : 0))
603: this_result = result = 0;
1.206 djm 604: } else if (strcasecmp(attrib, "localuser") == 0) {
1.221 djm 605: criteria = xstrdup(pw->pw_name);
1.235 djm 606: r = match_pattern_list(pw->pw_name, arg, 0) == 1;
1.221 djm 607: if (r == (negate ? 1 : 0))
608: this_result = result = 0;
1.210 djm 609: } else if (strcasecmp(attrib, "exec") == 0) {
1.206 djm 610: if (gethostname(thishost, sizeof(thishost)) == -1)
611: fatal("gethostname: %s", strerror(errno));
612: strlcpy(shorthost, thishost, sizeof(shorthost));
613: shorthost[strcspn(thishost, ".")] = '\0';
614: snprintf(portstr, sizeof(portstr), "%d", port);
1.288 djm 615: snprintf(uidstr, sizeof(uidstr), "%llu",
616: (unsigned long long)pw->pw_uid);
1.206 djm 617:
618: cmd = percent_expand(arg,
619: "L", shorthost,
620: "d", pw->pw_dir,
621: "h", host,
622: "l", thishost,
1.221 djm 623: "n", original_host,
1.206 djm 624: "p", portstr,
625: "r", ruser,
626: "u", pw->pw_name,
1.288 djm 627: "i", uidstr,
1.206 djm 628: (char *)NULL);
1.217 djm 629: if (result != 1) {
630: /* skip execution if prior predicate failed */
1.221 djm 631: debug3("%.200s line %d: skipped exec "
632: "\"%.100s\"", filename, linenum, cmd);
633: free(cmd);
634: continue;
635: }
636: r = execute_in_shell(cmd);
637: if (r == -1) {
638: fatal("%.200s line %d: match exec "
639: "'%.100s' error", filename,
640: linenum, cmd);
1.217 djm 641: }
1.221 djm 642: criteria = xstrdup(cmd);
1.206 djm 643: free(cmd);
1.221 djm 644: /* Force exit status to boolean */
645: r = r == 0;
646: if (r == (negate ? 1 : 0))
647: this_result = result = 0;
1.206 djm 648: } else {
649: error("Unsupported Match attribute %s", attrib);
1.211 djm 650: result = -1;
651: goto out;
1.206 djm 652: }
1.221 djm 653: debug3("%.200s line %d: %smatched '%s \"%.100s\"' ",
654: filename, linenum, this_result ? "": "not ",
655: oattrib, criteria);
656: free(criteria);
1.213 dtucker 657: }
658: if (attributes == 0) {
659: error("One or more attributes required for Match");
660: result = -1;
661: goto out;
1.206 djm 662: }
1.221 djm 663: out:
664: if (result != -1)
665: debug2("match %sfound", result ? "" : "not ");
1.206 djm 666: *condition = cp;
1.211 djm 667: free(host);
1.206 djm 668: return result;
669: }
670:
1.286 djm 671: /* Remove environment variable by pattern */
672: static void
673: rm_env(Options *options, const char *arg, const char *filename, int linenum)
674: {
675: int i, j;
676: char *cp;
677:
678: /* Remove an environment variable */
679: for (i = 0; i < options->num_send_env; ) {
680: cp = xstrdup(options->send_env[i]);
681: if (!match_pattern(cp, arg + 1)) {
682: free(cp);
683: i++;
684: continue;
685: }
686: debug3("%s line %d: removing environment %s",
687: filename, linenum, cp);
688: free(cp);
689: free(options->send_env[i]);
690: options->send_env[i] = NULL;
691: for (j = i; j < options->num_send_env - 1; j++) {
692: options->send_env[j] = options->send_env[j + 1];
693: options->send_env[j + 1] = NULL;
694: }
695: options->num_send_env--;
696: /* NB. don't increment i */
697: }
698: }
699:
1.19 markus 700: /*
1.70 stevesk 701: * Returns the number of the token pointed to by cp or oBadOption.
1.19 markus 702: */
1.26 markus 703: static OpCodes
1.199 djm 704: parse_token(const char *cp, const char *filename, int linenum,
705: const char *ignored_unknown)
1.1 deraadt 706: {
1.199 djm 707: int i;
1.1 deraadt 708:
1.17 markus 709: for (i = 0; keywords[i].name; i++)
1.199 djm 710: if (strcmp(cp, keywords[i].name) == 0)
1.17 markus 711: return keywords[i].opcode;
1.235 djm 712: if (ignored_unknown != NULL &&
713: match_pattern_list(cp, ignored_unknown, 1) == 1)
1.199 djm 714: return oIgnoredUnknownOption;
1.75 stevesk 715: error("%s: line %d: Bad configuration option: %s",
716: filename, linenum, cp);
1.17 markus 717: return oBadOption;
1.1 deraadt 718: }
719:
1.207 djm 720: /* Multistate option parsing */
721: struct multistate {
722: char *key;
723: int value;
724: };
725: static const struct multistate multistate_flag[] = {
726: { "true", 1 },
727: { "false", 0 },
728: { "yes", 1 },
729: { "no", 0 },
730: { NULL, -1 }
731: };
732: static const struct multistate multistate_yesnoask[] = {
733: { "true", 1 },
734: { "false", 0 },
735: { "yes", 1 },
736: { "no", 0 },
737: { "ask", 2 },
738: { NULL, -1 }
739: };
1.278 djm 740: static const struct multistate multistate_strict_hostkey[] = {
741: { "true", SSH_STRICT_HOSTKEY_YES },
742: { "false", SSH_STRICT_HOSTKEY_OFF },
743: { "yes", SSH_STRICT_HOSTKEY_YES },
744: { "no", SSH_STRICT_HOSTKEY_OFF },
745: { "ask", SSH_STRICT_HOSTKEY_ASK },
746: { "off", SSH_STRICT_HOSTKEY_OFF },
747: { "accept-new", SSH_STRICT_HOSTKEY_NEW },
748: { NULL, -1 }
749: };
1.246 jcs 750: static const struct multistate multistate_yesnoaskconfirm[] = {
751: { "true", 1 },
752: { "false", 0 },
753: { "yes", 1 },
754: { "no", 0 },
755: { "ask", 2 },
756: { "confirm", 3 },
757: { NULL, -1 }
758: };
1.207 djm 759: static const struct multistate multistate_addressfamily[] = {
760: { "inet", AF_INET },
761: { "inet6", AF_INET6 },
762: { "any", AF_UNSPEC },
763: { NULL, -1 }
764: };
765: static const struct multistate multistate_controlmaster[] = {
766: { "true", SSHCTL_MASTER_YES },
767: { "yes", SSHCTL_MASTER_YES },
768: { "false", SSHCTL_MASTER_NO },
769: { "no", SSHCTL_MASTER_NO },
770: { "auto", SSHCTL_MASTER_AUTO },
771: { "ask", SSHCTL_MASTER_ASK },
772: { "autoask", SSHCTL_MASTER_AUTO_ASK },
773: { NULL, -1 }
774: };
775: static const struct multistate multistate_tunnel[] = {
776: { "ethernet", SSH_TUNMODE_ETHERNET },
777: { "point-to-point", SSH_TUNMODE_POINTOPOINT },
778: { "true", SSH_TUNMODE_DEFAULT },
779: { "yes", SSH_TUNMODE_DEFAULT },
780: { "false", SSH_TUNMODE_NO },
781: { "no", SSH_TUNMODE_NO },
782: { NULL, -1 }
783: };
784: static const struct multistate multistate_requesttty[] = {
785: { "true", REQUEST_TTY_YES },
786: { "yes", REQUEST_TTY_YES },
787: { "false", REQUEST_TTY_NO },
788: { "no", REQUEST_TTY_NO },
789: { "force", REQUEST_TTY_FORCE },
790: { "auto", REQUEST_TTY_AUTO },
791: { NULL, -1 }
792: };
1.209 djm 793: static const struct multistate multistate_canonicalizehostname[] = {
1.208 djm 794: { "true", SSH_CANONICALISE_YES },
795: { "false", SSH_CANONICALISE_NO },
796: { "yes", SSH_CANONICALISE_YES },
797: { "no", SSH_CANONICALISE_NO },
798: { "always", SSH_CANONICALISE_ALWAYS },
799: { NULL, -1 }
800: };
1.207 djm 801:
1.19 markus 802: /*
803: * Processes a single option line as used in the configuration files. This
804: * only sets those values that have not already been set.
805: */
1.14 markus 806: int
1.206 djm 807: process_config_line(Options *options, struct passwd *pw, const char *host,
1.221 djm 808: const char *original_host, char *line, const char *filename,
809: int linenum, int *activep, int flags)
1.1 deraadt 810: {
1.252 djm 811: return process_config_line_depth(options, pw, host, original_host,
812: line, filename, linenum, activep, flags, 0);
813: }
814:
815: #define WHITESPACE " \t\r\n"
816: static int
817: process_config_line_depth(Options *options, struct passwd *pw, const char *host,
818: const char *original_host, char *line, const char *filename,
819: int linenum, int *activep, int flags, int depth)
820: {
1.193 djm 821: char *s, **charptr, *endofnumber, *keyword, *arg, *arg2;
822: char **cpptr, fwdarg[256];
1.199 djm 823: u_int i, *uintptr, max_entries = 0;
1.252 djm 824: int r, oactive, negated, opcode, *intptr, value, value2, cmdline = 0;
1.279 markus 825: int remotefwd, dynamicfwd;
1.164 dtucker 826: LogLevel *log_level_ptr;
1.271 dtucker 827: SyslogFacility *log_facility_ptr;
1.201 dtucker 828: long long val64;
1.102 markus 829: size_t len;
1.220 millert 830: struct Forward fwd;
1.207 djm 831: const struct multistate *multistate_ptr;
1.208 djm 832: struct allowed_cname *cname;
1.252 djm 833: glob_t gl;
1.281 dtucker 834: const char *errstr;
1.106 djm 835:
1.206 djm 836: if (activep == NULL) { /* We are processing a command line directive */
837: cmdline = 1;
838: activep = &cmdline;
839: }
840:
1.267 djm 841: /* Strip trailing whitespace. Allow \f (form feed) at EOL only */
1.233 djm 842: if ((len = strlen(line)) == 0)
843: return 0;
844: for (len--; len > 0; len--) {
1.267 djm 845: if (strchr(WHITESPACE "\f", line[len]) == NULL)
1.106 djm 846: break;
847: line[len] = '\0';
848: }
1.1 deraadt 849:
1.42 provos 850: s = line;
851: /* Get the keyword. (Each line is supposed to begin with a keyword). */
1.149 djm 852: if ((keyword = strdelim(&s)) == NULL)
853: return 0;
1.42 provos 854: /* Ignore leading whitespace. */
855: if (*keyword == '\0')
1.43 markus 856: keyword = strdelim(&s);
1.56 deraadt 857: if (keyword == NULL || !*keyword || *keyword == '\n' || *keyword == '#')
1.17 markus 858: return 0;
1.199 djm 859: /* Match lowercase keyword */
1.207 djm 860: lowercase(keyword);
1.17 markus 861:
1.199 djm 862: opcode = parse_token(keyword, filename, linenum,
863: options->ignored_unknown);
1.17 markus 864:
865: switch (opcode) {
866: case oBadOption:
1.19 markus 867: /* don't panic, but count bad options */
868: return -1;
1.273 djm 869: case oIgnore:
870: return 0;
1.199 djm 871: case oIgnoredUnknownOption:
872: debug("%s line %d: Ignored unknown option \"%s\"",
873: filename, linenum, keyword);
874: return 0;
1.111 djm 875: case oConnectTimeout:
876: intptr = &options->connection_timeout;
1.127 markus 877: parse_time:
1.111 djm 878: arg = strdelim(&s);
879: if (!arg || *arg == '\0')
880: fatal("%s line %d: missing time value.",
881: filename, linenum);
1.221 djm 882: if (strcmp(arg, "none") == 0)
883: value = -1;
884: else if ((value = convtime(arg)) == -1)
1.111 djm 885: fatal("%s line %d: invalid time value.",
886: filename, linenum);
1.160 dtucker 887: if (*activep && *intptr == -1)
1.111 djm 888: *intptr = value;
889: break;
890:
1.17 markus 891: case oForwardAgent:
892: intptr = &options->forward_agent;
1.207 djm 893: parse_flag:
894: multistate_ptr = multistate_flag;
895: parse_multistate:
1.42 provos 896: arg = strdelim(&s);
1.40 ho 897: if (!arg || *arg == '\0')
1.207 djm 898: fatal("%s line %d: missing argument.",
899: filename, linenum);
900: value = -1;
901: for (i = 0; multistate_ptr[i].key != NULL; i++) {
902: if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
903: value = multistate_ptr[i].value;
904: break;
905: }
906: }
907: if (value == -1)
908: fatal("%s line %d: unsupported option \"%s\".",
909: filename, linenum, arg);
1.17 markus 910: if (*activep && *intptr == -1)
911: *intptr = value;
912: break;
913:
914: case oForwardX11:
915: intptr = &options->forward_x11;
916: goto parse_flag;
917:
1.123 markus 918: case oForwardX11Trusted:
919: intptr = &options->forward_x11_trusted;
920: goto parse_flag;
1.221 djm 921:
1.186 djm 922: case oForwardX11Timeout:
923: intptr = &options->forward_x11_timeout;
924: goto parse_time;
1.123 markus 925:
1.17 markus 926: case oGatewayPorts:
1.220 millert 927: intptr = &options->fwd_opts.gateway_ports;
1.17 markus 928: goto parse_flag;
929:
1.153 markus 930: case oExitOnForwardFailure:
931: intptr = &options->exit_on_forward_failure;
932: goto parse_flag;
933:
1.17 markus 934: case oPasswordAuthentication:
935: intptr = &options->password_authentication;
936: goto parse_flag;
937:
1.48 markus 938: case oKbdInteractiveAuthentication:
939: intptr = &options->kbd_interactive_authentication;
940: goto parse_flag;
941:
942: case oKbdInteractiveDevices:
943: charptr = &options->kbd_interactive_devices;
944: goto parse_string;
945:
1.50 markus 946: case oPubkeyAuthentication:
947: intptr = &options->pubkey_authentication;
1.30 markus 948: goto parse_flag;
949:
1.72 markus 950: case oHostbasedAuthentication:
951: intptr = &options->hostbased_authentication;
952: goto parse_flag;
953:
1.59 markus 954: case oChallengeResponseAuthentication:
1.78 markus 955: intptr = &options->challenge_response_authentication;
1.17 markus 956: goto parse_flag;
1.108 jakob 957:
1.118 markus 958: case oGssAuthentication:
959: intptr = &options->gss_authentication;
960: goto parse_flag;
961:
962: case oGssDelegateCreds:
963: intptr = &options->gss_deleg_creds;
964: goto parse_flag;
965:
1.17 markus 966: case oBatchMode:
967: intptr = &options->batch_mode;
968: goto parse_flag;
969:
970: case oCheckHostIP:
971: intptr = &options->check_host_ip;
1.167 grunk 972: goto parse_flag;
1.17 markus 973:
1.107 jakob 974: case oVerifyHostKeyDNS:
975: intptr = &options->verify_host_key_dns;
1.207 djm 976: multistate_ptr = multistate_yesnoask;
977: goto parse_multistate;
1.107 jakob 978:
1.17 markus 979: case oStrictHostKeyChecking:
980: intptr = &options->strict_host_key_checking;
1.278 djm 981: multistate_ptr = multistate_strict_hostkey;
1.207 djm 982: goto parse_multistate;
1.17 markus 983:
984: case oCompression:
985: intptr = &options->compression;
986: goto parse_flag;
987:
1.126 markus 988: case oTCPKeepAlive:
989: intptr = &options->tcp_keep_alive;
1.17 markus 990: goto parse_flag;
991:
1.91 markus 992: case oNoHostAuthenticationForLocalhost:
993: intptr = &options->no_host_authentication_for_localhost;
994: goto parse_flag;
995:
1.17 markus 996: case oNumberOfPasswordPrompts:
997: intptr = &options->number_of_password_prompts;
998: goto parse_int;
999:
1.105 markus 1000: case oRekeyLimit:
1001: arg = strdelim(&s);
1002: if (!arg || *arg == '\0')
1.198 dtucker 1003: fatal("%.200s line %d: Missing argument.", filename,
1004: linenum);
1005: if (strcmp(arg, "default") == 0) {
1006: val64 = 0;
1007: } else {
1.200 dtucker 1008: if (scan_scaled(arg, &val64) == -1)
1009: fatal("%.200s line %d: Bad number '%s': %s",
1010: filename, linenum, arg, strerror(errno));
1.198 dtucker 1011: if (val64 != 0 && val64 < 16)
1012: fatal("%.200s line %d: RekeyLimit too small",
1013: filename, linenum);
1.105 markus 1014: }
1.165 djm 1015: if (*activep && options->rekey_limit == -1)
1.249 dtucker 1016: options->rekey_limit = val64;
1.198 dtucker 1017: if (s != NULL) { /* optional rekey interval present */
1018: if (strcmp(s, "none") == 0) {
1019: (void)strdelim(&s); /* discard */
1020: break;
1021: }
1022: intptr = &options->rekey_interval;
1023: goto parse_time;
1024: }
1.105 markus 1025: break;
1026:
1.17 markus 1027: case oIdentityFile:
1.42 provos 1028: arg = strdelim(&s);
1.40 ho 1029: if (!arg || *arg == '\0')
1.17 markus 1030: fatal("%.200s line %d: Missing argument.", filename, linenum);
1031: if (*activep) {
1.50 markus 1032: intptr = &options->num_identity_files;
1.27 markus 1033: if (*intptr >= SSH_MAX_IDENTITY_FILES)
1.17 markus 1034: fatal("%.200s line %d: Too many identity files specified (max %d).",
1.93 deraadt 1035: filename, linenum, SSH_MAX_IDENTITY_FILES);
1.221 djm 1036: add_identity_file(options, NULL,
1037: arg, flags & SSHCONF_USERCONF);
1.17 markus 1038: }
1039: break;
1040:
1.241 djm 1041: case oCertificateFile:
1042: arg = strdelim(&s);
1043: if (!arg || *arg == '\0')
1044: fatal("%.200s line %d: Missing argument.",
1045: filename, linenum);
1046: if (*activep) {
1047: intptr = &options->num_certificate_files;
1048: if (*intptr >= SSH_MAX_CERTIFICATE_FILES) {
1049: fatal("%.200s line %d: Too many certificate "
1050: "files specified (max %d).",
1051: filename, linenum,
1052: SSH_MAX_CERTIFICATE_FILES);
1053: }
1054: add_certificate_file(options, arg,
1055: flags & SSHCONF_USERCONF);
1056: }
1057: break;
1058:
1.34 markus 1059: case oXAuthLocation:
1060: charptr=&options->xauth_location;
1061: goto parse_string;
1062:
1.17 markus 1063: case oUser:
1064: charptr = &options->user;
1065: parse_string:
1.42 provos 1066: arg = strdelim(&s);
1.40 ho 1067: if (!arg || *arg == '\0')
1.193 djm 1068: fatal("%.200s line %d: Missing argument.",
1069: filename, linenum);
1.17 markus 1070: if (*activep && *charptr == NULL)
1.38 provos 1071: *charptr = xstrdup(arg);
1.17 markus 1072: break;
1073:
1074: case oGlobalKnownHostsFile:
1.193 djm 1075: cpptr = (char **)&options->system_hostfiles;
1076: uintptr = &options->num_system_hostfiles;
1077: max_entries = SSH_MAX_HOSTS_FILES;
1078: parse_char_array:
1079: if (*activep && *uintptr == 0) {
1080: while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1081: if ((*uintptr) >= max_entries)
1082: fatal("%s line %d: "
1083: "too many authorized keys files.",
1084: filename, linenum);
1085: cpptr[(*uintptr)++] = xstrdup(arg);
1086: }
1087: }
1088: return 0;
1.17 markus 1089:
1090: case oUserKnownHostsFile:
1.193 djm 1091: cpptr = (char **)&options->user_hostfiles;
1092: uintptr = &options->num_user_hostfiles;
1093: max_entries = SSH_MAX_HOSTS_FILES;
1094: goto parse_char_array;
1.27 markus 1095:
1.17 markus 1096: case oHostName:
1097: charptr = &options->hostname;
1098: goto parse_string;
1099:
1.52 markus 1100: case oHostKeyAlias:
1101: charptr = &options->host_key_alias;
1102: goto parse_string;
1103:
1.67 markus 1104: case oPreferredAuthentications:
1105: charptr = &options->preferred_authentications;
1106: goto parse_string;
1107:
1.77 markus 1108: case oBindAddress:
1109: charptr = &options->bind_address;
1110: goto parse_string;
1111:
1.282 djm 1112: case oBindInterface:
1113: charptr = &options->bind_interface;
1114: goto parse_string;
1115:
1.183 markus 1116: case oPKCS11Provider:
1117: charptr = &options->pkcs11_provider;
1.86 markus 1118: goto parse_string;
1.85 jakob 1119:
1.17 markus 1120: case oProxyCommand:
1.144 reyk 1121: charptr = &options->proxy_command;
1.257 djm 1122: /* Ignore ProxyCommand if ProxyJump already specified */
1123: if (options->jump_host != NULL)
1124: charptr = &options->jump_host; /* Skip below */
1.144 reyk 1125: parse_command:
1.113 markus 1126: if (s == NULL)
1127: fatal("%.200s line %d: Missing argument.", filename, linenum);
1.102 markus 1128: len = strspn(s, WHITESPACE "=");
1.17 markus 1129: if (*activep && *charptr == NULL)
1.102 markus 1130: *charptr = xstrdup(s + len);
1.17 markus 1131: return 0;
1132:
1.257 djm 1133: case oProxyJump:
1134: if (s == NULL) {
1135: fatal("%.200s line %d: Missing argument.",
1136: filename, linenum);
1137: }
1138: len = strspn(s, WHITESPACE "=");
1139: if (parse_jump(s + len, options, *activep) == -1) {
1140: fatal("%.200s line %d: Invalid ProxyJump \"%s\"",
1141: filename, linenum, s + len);
1142: }
1143: return 0;
1144:
1.17 markus 1145: case oPort:
1146: intptr = &options->port;
1147: parse_int:
1.42 provos 1148: arg = strdelim(&s);
1.281 dtucker 1149: if ((errstr = atoi_err(arg, &value)) != NULL)
1150: fatal("%s line %d: integer value %s.",
1151: filename, linenum, errstr);
1.17 markus 1152: if (*activep && *intptr == -1)
1153: *intptr = value;
1154: break;
1155:
1156: case oConnectionAttempts:
1157: intptr = &options->connection_attempts;
1158: goto parse_int;
1159:
1.25 markus 1160: case oCiphers:
1.42 provos 1161: arg = strdelim(&s);
1.40 ho 1162: if (!arg || *arg == '\0')
1.32 markus 1163: fatal("%.200s line %d: Missing argument.", filename, linenum);
1.268 djm 1164: if (*arg != '-' && !ciphers_valid(*arg == '+' ? arg + 1 : arg))
1.31 markus 1165: fatal("%.200s line %d: Bad SSH2 cipher spec '%s'.",
1.93 deraadt 1166: filename, linenum, arg ? arg : "<NONE>");
1.25 markus 1167: if (*activep && options->ciphers == NULL)
1.38 provos 1168: options->ciphers = xstrdup(arg);
1.25 markus 1169: break;
1170:
1.62 markus 1171: case oMacs:
1172: arg = strdelim(&s);
1173: if (!arg || *arg == '\0')
1174: fatal("%.200s line %d: Missing argument.", filename, linenum);
1.268 djm 1175: if (*arg != '-' && !mac_valid(*arg == '+' ? arg + 1 : arg))
1.62 markus 1176: fatal("%.200s line %d: Bad SSH2 Mac spec '%s'.",
1.93 deraadt 1177: filename, linenum, arg ? arg : "<NONE>");
1.62 markus 1178: if (*activep && options->macs == NULL)
1179: options->macs = xstrdup(arg);
1180: break;
1181:
1.189 djm 1182: case oKexAlgorithms:
1183: arg = strdelim(&s);
1184: if (!arg || *arg == '\0')
1185: fatal("%.200s line %d: Missing argument.",
1186: filename, linenum);
1.268 djm 1187: if (*arg != '-' &&
1188: !kex_names_valid(*arg == '+' ? arg + 1 : arg))
1.189 djm 1189: fatal("%.200s line %d: Bad SSH2 KexAlgorithms '%s'.",
1190: filename, linenum, arg ? arg : "<NONE>");
1191: if (*activep && options->kex_algorithms == NULL)
1192: options->kex_algorithms = xstrdup(arg);
1193: break;
1194:
1.76 markus 1195: case oHostKeyAlgorithms:
1.238 markus 1196: charptr = &options->hostkeyalgorithms;
1197: parse_keytypes:
1.76 markus 1198: arg = strdelim(&s);
1199: if (!arg || *arg == '\0')
1.238 markus 1200: fatal("%.200s line %d: Missing argument.",
1201: filename, linenum);
1.268 djm 1202: if (*arg != '-' &&
1203: !sshkey_names_valid2(*arg == '+' ? arg + 1 : arg, 1))
1.238 markus 1204: fatal("%s line %d: Bad key types '%s'.",
1205: filename, linenum, arg ? arg : "<NONE>");
1206: if (*activep && *charptr == NULL)
1207: *charptr = xstrdup(arg);
1.76 markus 1208: break;
1209:
1.298 ! djm 1210: case oCASignatureAlgorithms:
! 1211: charptr = &options->ca_sign_algorithms;
! 1212: goto parse_keytypes;
! 1213:
1.17 markus 1214: case oLogLevel:
1.164 dtucker 1215: log_level_ptr = &options->log_level;
1.42 provos 1216: arg = strdelim(&s);
1.38 provos 1217: value = log_level_number(arg);
1.95 markus 1218: if (value == SYSLOG_LEVEL_NOT_SET)
1.64 millert 1219: fatal("%.200s line %d: unsupported log level '%s'",
1.93 deraadt 1220: filename, linenum, arg ? arg : "<NONE>");
1.164 dtucker 1221: if (*activep && *log_level_ptr == SYSLOG_LEVEL_NOT_SET)
1222: *log_level_ptr = (LogLevel) value;
1.17 markus 1223: break;
1224:
1.271 dtucker 1225: case oLogFacility:
1226: log_facility_ptr = &options->log_facility;
1227: arg = strdelim(&s);
1228: value = log_facility_number(arg);
1229: if (value == SYSLOG_FACILITY_NOT_SET)
1230: fatal("%.200s line %d: unsupported log facility '%s'",
1231: filename, linenum, arg ? arg : "<NONE>");
1232: if (*log_facility_ptr == -1)
1233: *log_facility_ptr = (SyslogFacility) value;
1234: break;
1235:
1.88 stevesk 1236: case oLocalForward:
1.17 markus 1237: case oRemoteForward:
1.168 stevesk 1238: case oDynamicForward:
1.42 provos 1239: arg = strdelim(&s);
1.135 djm 1240: if (arg == NULL || *arg == '\0')
1.88 stevesk 1241: fatal("%.200s line %d: Missing port argument.",
1242: filename, linenum);
1.135 djm 1243:
1.279 markus 1244: remotefwd = (opcode == oRemoteForward);
1245: dynamicfwd = (opcode == oDynamicForward);
1246:
1247: if (!dynamicfwd) {
1.168 stevesk 1248: arg2 = strdelim(&s);
1.279 markus 1249: if (arg2 == NULL || *arg2 == '\0') {
1250: if (remotefwd)
1251: dynamicfwd = 1;
1252: else
1253: fatal("%.200s line %d: Missing target "
1254: "argument.", filename, linenum);
1255: } else {
1256: /* construct a string for parse_forward */
1257: snprintf(fwdarg, sizeof(fwdarg), "%s:%s", arg,
1258: arg2);
1259: }
1260: }
1261: if (dynamicfwd)
1.168 stevesk 1262: strlcpy(fwdarg, arg, sizeof(fwdarg));
1263:
1.279 markus 1264: if (parse_forward(&fwd, fwdarg, dynamicfwd, remotefwd) == 0)
1.88 stevesk 1265: fatal("%.200s line %d: Bad forwarding specification.",
1266: filename, linenum);
1.135 djm 1267:
1.88 stevesk 1268: if (*activep) {
1.279 markus 1269: if (remotefwd) {
1270: add_remote_forward(options, &fwd);
1271: } else {
1.135 djm 1272: add_local_forward(options, &fwd);
1.279 markus 1273: }
1.88 stevesk 1274: }
1.17 markus 1275: break;
1.71 markus 1276:
1.90 stevesk 1277: case oClearAllForwardings:
1278: intptr = &options->clear_forwardings;
1279: goto parse_flag;
1280:
1.17 markus 1281: case oHost:
1.206 djm 1282: if (cmdline)
1283: fatal("Host directive not supported as a command-line "
1284: "option");
1.17 markus 1285: *activep = 0;
1.191 djm 1286: arg2 = NULL;
1287: while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1.252 djm 1288: if ((flags & SSHCONF_NEVERMATCH) != 0)
1289: break;
1.191 djm 1290: negated = *arg == '!';
1291: if (negated)
1292: arg++;
1.38 provos 1293: if (match_pattern(host, arg)) {
1.191 djm 1294: if (negated) {
1295: debug("%.200s line %d: Skipping Host "
1296: "block because of negated match "
1297: "for %.100s", filename, linenum,
1298: arg);
1299: *activep = 0;
1300: break;
1301: }
1302: if (!*activep)
1303: arg2 = arg; /* logged below */
1.17 markus 1304: *activep = 1;
1305: }
1.191 djm 1306: }
1307: if (*activep)
1308: debug("%.200s line %d: Applying options for %.100s",
1309: filename, linenum, arg2);
1.42 provos 1310: /* Avoid garbage check below, as strdelim is done. */
1.17 markus 1311: return 0;
1312:
1.206 djm 1313: case oMatch:
1314: if (cmdline)
1315: fatal("Host directive not supported as a command-line "
1316: "option");
1.221 djm 1317: value = match_cfg_line(options, &s, pw, host, original_host,
1318: flags & SSHCONF_POSTCANON, filename, linenum);
1.206 djm 1319: if (value < 0)
1320: fatal("%.200s line %d: Bad Match condition", filename,
1321: linenum);
1.252 djm 1322: *activep = (flags & SSHCONF_NEVERMATCH) ? 0 : value;
1.206 djm 1323: break;
1324:
1.17 markus 1325: case oEscapeChar:
1326: intptr = &options->escape_char;
1.42 provos 1327: arg = strdelim(&s);
1.40 ho 1328: if (!arg || *arg == '\0')
1.17 markus 1329: fatal("%.200s line %d: Missing argument.", filename, linenum);
1.236 djm 1330: if (strcmp(arg, "none") == 0)
1331: value = SSH_ESCAPECHAR_NONE;
1332: else if (arg[1] == '\0')
1333: value = (u_char) arg[0];
1334: else if (arg[0] == '^' && arg[2] == 0 &&
1.51 markus 1335: (u_char) arg[1] >= 64 && (u_char) arg[1] < 128)
1336: value = (u_char) arg[1] & 31;
1.17 markus 1337: else {
1338: fatal("%.200s line %d: Bad escape character.",
1.93 deraadt 1339: filename, linenum);
1.17 markus 1340: /* NOTREACHED */
1341: value = 0; /* Avoid compiler warning. */
1342: }
1343: if (*activep && *intptr == -1)
1344: *intptr = value;
1.112 djm 1345: break;
1346:
1347: case oAddressFamily:
1.114 djm 1348: intptr = &options->address_family;
1.207 djm 1349: multistate_ptr = multistate_addressfamily;
1350: goto parse_multistate;
1.17 markus 1351:
1.101 markus 1352: case oEnableSSHKeysign:
1353: intptr = &options->enable_ssh_keysign;
1354: goto parse_flag;
1355:
1.128 markus 1356: case oIdentitiesOnly:
1357: intptr = &options->identities_only;
1358: goto parse_flag;
1359:
1.127 markus 1360: case oServerAliveInterval:
1361: intptr = &options->server_alive_interval;
1362: goto parse_time;
1363:
1364: case oServerAliveCountMax:
1365: intptr = &options->server_alive_count_max;
1366: goto parse_int;
1367:
1.130 djm 1368: case oSendEnv:
1369: while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1370: if (strchr(arg, '=') != NULL)
1371: fatal("%s line %d: Invalid environment name.",
1372: filename, linenum);
1.137 djm 1373: if (!*activep)
1374: continue;
1.286 djm 1375: if (*arg == '-') {
1376: /* Removing an env var */
1377: rm_env(options, arg, filename, linenum);
1378: continue;
1379: } else {
1380: /* Adding an env var */
1.290 djm 1381: if (options->num_send_env >= INT_MAX)
1.286 djm 1382: fatal("%s line %d: too many send env.",
1383: filename, linenum);
1.290 djm 1384: options->send_env = xrecallocarray(
1385: options->send_env, options->num_send_env,
1.291 djm 1386: options->num_send_env + 1,
1.290 djm 1387: sizeof(*options->send_env));
1.286 djm 1388: options->send_env[options->num_send_env++] =
1389: xstrdup(arg);
1390: }
1.130 djm 1391: }
1392: break;
1393:
1.290 djm 1394: case oSetEnv:
1395: value = options->num_setenv;
1396: while ((arg = strdelimw(&s)) != NULL && *arg != '\0') {
1397: if (strchr(arg, '=') == NULL)
1398: fatal("%s line %d: Invalid SetEnv.",
1399: filename, linenum);
1400: if (!*activep || value != 0)
1401: continue;
1402: /* Adding a setenv var */
1403: if (options->num_setenv >= INT_MAX)
1404: fatal("%s line %d: too many SetEnv.",
1405: filename, linenum);
1406: options->setenv = xrecallocarray(
1407: options->setenv, options->num_setenv,
1408: options->num_setenv + 1, sizeof(*options->setenv));
1409: options->setenv[options->num_setenv++] = xstrdup(arg);
1410: }
1411: break;
1412:
1.132 djm 1413: case oControlPath:
1414: charptr = &options->control_path;
1415: goto parse_string;
1416:
1417: case oControlMaster:
1418: intptr = &options->control_master;
1.207 djm 1419: multistate_ptr = multistate_controlmaster;
1420: goto parse_multistate;
1.132 djm 1421:
1.187 djm 1422: case oControlPersist:
1423: /* no/false/yes/true, or a time spec */
1424: intptr = &options->control_persist;
1425: arg = strdelim(&s);
1426: if (!arg || *arg == '\0')
1427: fatal("%.200s line %d: Missing ControlPersist"
1428: " argument.", filename, linenum);
1429: value = 0;
1430: value2 = 0; /* timeout */
1431: if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
1432: value = 0;
1433: else if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
1434: value = 1;
1435: else if ((value2 = convtime(arg)) >= 0)
1436: value = 1;
1437: else
1438: fatal("%.200s line %d: Bad ControlPersist argument.",
1439: filename, linenum);
1440: if (*activep && *intptr == -1) {
1441: *intptr = value;
1442: options->control_persist_timeout = value2;
1443: }
1444: break;
1445:
1.136 djm 1446: case oHashKnownHosts:
1447: intptr = &options->hash_known_hosts;
1448: goto parse_flag;
1449:
1.144 reyk 1450: case oTunnel:
1451: intptr = &options->tun_open;
1.207 djm 1452: multistate_ptr = multistate_tunnel;
1453: goto parse_multistate;
1.144 reyk 1454:
1455: case oTunnelDevice:
1456: arg = strdelim(&s);
1457: if (!arg || *arg == '\0')
1458: fatal("%.200s line %d: Missing argument.", filename, linenum);
1459: value = a2tun(arg, &value2);
1.145 reyk 1460: if (value == SSH_TUNID_ERR)
1.144 reyk 1461: fatal("%.200s line %d: Bad tun device.", filename, linenum);
1462: if (*activep) {
1463: options->tun_local = value;
1464: options->tun_remote = value2;
1465: }
1466: break;
1467:
1468: case oLocalCommand:
1469: charptr = &options->local_command;
1470: goto parse_command;
1471:
1472: case oPermitLocalCommand:
1473: intptr = &options->permit_local_command;
1474: goto parse_flag;
1475:
1.277 bluhm 1476: case oRemoteCommand:
1477: charptr = &options->remote_command;
1478: goto parse_command;
1479:
1.167 grunk 1480: case oVisualHostKey:
1481: intptr = &options->visual_host_key;
1482: goto parse_flag;
1483:
1.252 djm 1484: case oInclude:
1485: if (cmdline)
1486: fatal("Include directive not supported as a "
1487: "command-line option");
1488: value = 0;
1489: while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1490: /*
1491: * Ensure all paths are anchored. User configuration
1492: * files may begin with '~/' but system configurations
1493: * must not. If the path is relative, then treat it
1494: * as living in ~/.ssh for user configurations or
1495: * /etc/ssh for system ones.
1496: */
1497: if (*arg == '~' && (flags & SSHCONF_USERCONF) == 0)
1498: fatal("%.200s line %d: bad include path %s.",
1499: filename, linenum, arg);
1500: if (*arg != '/' && *arg != '~') {
1501: xasprintf(&arg2, "%s/%s",
1502: (flags & SSHCONF_USERCONF) ?
1503: "~/" _PATH_SSH_USER_DIR : SSHDIR, arg);
1504: } else
1505: arg2 = xstrdup(arg);
1506: memset(&gl, 0, sizeof(gl));
1507: r = glob(arg2, GLOB_TILDE, NULL, &gl);
1508: if (r == GLOB_NOMATCH) {
1509: debug("%.200s line %d: include %s matched no "
1510: "files",filename, linenum, arg2);
1.269 dtucker 1511: free(arg2);
1.252 djm 1512: continue;
1513: } else if (r != 0 || gl.gl_pathc < 0)
1514: fatal("%.200s line %d: glob failed for %s.",
1515: filename, linenum, arg2);
1516: free(arg2);
1517: oactive = *activep;
1518: for (i = 0; i < (u_int)gl.gl_pathc; i++) {
1519: debug3("%.200s line %d: Including file %s "
1520: "depth %d%s", filename, linenum,
1521: gl.gl_pathv[i], depth,
1522: oactive ? "" : " (parse only)");
1523: r = read_config_file_depth(gl.gl_pathv[i],
1524: pw, host, original_host, options,
1525: flags | SSHCONF_CHECKPERM |
1526: (oactive ? 0 : SSHCONF_NEVERMATCH),
1527: activep, depth + 1);
1.264 djm 1528: if (r != 1 && errno != ENOENT) {
1.263 djm 1529: fatal("Can't open user config file "
1530: "%.100s: %.100s", gl.gl_pathv[i],
1531: strerror(errno));
1532: }
1.252 djm 1533: /*
1534: * don't let Match in includes clobber the
1535: * containing file's Match state.
1536: */
1537: *activep = oactive;
1538: if (r != 1)
1539: value = -1;
1540: }
1541: globfree(&gl);
1542: }
1543: if (value != 0)
1544: return value;
1545: break;
1546:
1.190 djm 1547: case oIPQoS:
1548: arg = strdelim(&s);
1549: if ((value = parse_ipqos(arg)) == -1)
1550: fatal("%s line %d: Bad IPQoS value: %s",
1551: filename, linenum, arg);
1552: arg = strdelim(&s);
1553: if (arg == NULL)
1554: value2 = value;
1555: else if ((value2 = parse_ipqos(arg)) == -1)
1556: fatal("%s line %d: Bad IPQoS value: %s",
1557: filename, linenum, arg);
1558: if (*activep) {
1559: options->ip_qos_interactive = value;
1560: options->ip_qos_bulk = value2;
1561: }
1562: break;
1563:
1.192 djm 1564: case oRequestTTY:
1565: intptr = &options->request_tty;
1.207 djm 1566: multistate_ptr = multistate_requesttty;
1567: goto parse_multistate;
1.192 djm 1568:
1.199 djm 1569: case oIgnoreUnknown:
1570: charptr = &options->ignored_unknown;
1571: goto parse_string;
1572:
1.205 djm 1573: case oProxyUseFdpass:
1574: intptr = &options->proxy_use_fdpass;
1575: goto parse_flag;
1576:
1.208 djm 1577: case oCanonicalDomains:
1578: value = options->num_canonical_domains != 0;
1579: while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1.280 millert 1580: if (!valid_domain(arg, 1, &errstr)) {
1581: fatal("%s line %d: %s", filename, linenum,
1582: errstr);
1583: }
1.208 djm 1584: if (!*activep || value)
1585: continue;
1586: if (options->num_canonical_domains >= MAX_CANON_DOMAINS)
1587: fatal("%s line %d: too many hostname suffixes.",
1588: filename, linenum);
1589: options->canonical_domains[
1590: options->num_canonical_domains++] = xstrdup(arg);
1591: }
1592: break;
1593:
1.209 djm 1594: case oCanonicalizePermittedCNAMEs:
1.208 djm 1595: value = options->num_permitted_cnames != 0;
1596: while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1597: /* Either '*' for everything or 'list:list' */
1598: if (strcmp(arg, "*") == 0)
1599: arg2 = arg;
1600: else {
1601: lowercase(arg);
1602: if ((arg2 = strchr(arg, ':')) == NULL ||
1603: arg2[1] == '\0') {
1604: fatal("%s line %d: "
1605: "Invalid permitted CNAME \"%s\"",
1606: filename, linenum, arg);
1607: }
1608: *arg2 = '\0';
1609: arg2++;
1610: }
1611: if (!*activep || value)
1612: continue;
1613: if (options->num_permitted_cnames >= MAX_CANON_DOMAINS)
1614: fatal("%s line %d: too many permitted CNAMEs.",
1615: filename, linenum);
1616: cname = options->permitted_cnames +
1617: options->num_permitted_cnames++;
1618: cname->source_list = xstrdup(arg);
1619: cname->target_list = xstrdup(arg2);
1620: }
1621: break;
1622:
1.209 djm 1623: case oCanonicalizeHostname:
1624: intptr = &options->canonicalize_hostname;
1625: multistate_ptr = multistate_canonicalizehostname;
1.208 djm 1626: goto parse_multistate;
1627:
1.209 djm 1628: case oCanonicalizeMaxDots:
1629: intptr = &options->canonicalize_max_dots;
1.208 djm 1630: goto parse_int;
1631:
1.209 djm 1632: case oCanonicalizeFallbackLocal:
1633: intptr = &options->canonicalize_fallback_local;
1.208 djm 1634: goto parse_flag;
1635:
1.220 millert 1636: case oStreamLocalBindMask:
1637: arg = strdelim(&s);
1638: if (!arg || *arg == '\0')
1639: fatal("%.200s line %d: Missing StreamLocalBindMask argument.", filename, linenum);
1640: /* Parse mode in octal format */
1641: value = strtol(arg, &endofnumber, 8);
1642: if (arg == endofnumber || value < 0 || value > 0777)
1643: fatal("%.200s line %d: Bad mask.", filename, linenum);
1644: options->fwd_opts.streamlocal_bind_mask = (mode_t)value;
1645: break;
1646:
1647: case oStreamLocalBindUnlink:
1648: intptr = &options->fwd_opts.streamlocal_bind_unlink;
1649: goto parse_flag;
1650:
1.223 djm 1651: case oRevokedHostKeys:
1652: charptr = &options->revoked_host_keys;
1653: goto parse_string;
1654:
1.224 djm 1655: case oFingerprintHash:
1.225 djm 1656: intptr = &options->fingerprint_hash;
1.224 djm 1657: arg = strdelim(&s);
1658: if (!arg || *arg == '\0')
1659: fatal("%.200s line %d: Missing argument.",
1660: filename, linenum);
1661: if ((value = ssh_digest_alg_by_name(arg)) == -1)
1662: fatal("%.200s line %d: Invalid hash algorithm \"%s\".",
1663: filename, linenum, arg);
1.225 djm 1664: if (*activep && *intptr == -1)
1665: *intptr = value;
1.224 djm 1666: break;
1667:
1.229 djm 1668: case oUpdateHostkeys:
1669: intptr = &options->update_hostkeys;
1.232 djm 1670: multistate_ptr = multistate_yesnoask;
1671: goto parse_multistate;
1.229 djm 1672:
1.230 djm 1673: case oHostbasedKeyTypes:
1674: charptr = &options->hostbased_key_types;
1.238 markus 1675: goto parse_keytypes;
1676:
1677: case oPubkeyAcceptedKeyTypes:
1678: charptr = &options->pubkey_key_types;
1679: goto parse_keytypes;
1.230 djm 1680:
1.246 jcs 1681: case oAddKeysToAgent:
1682: intptr = &options->add_keys_to_agent;
1683: multistate_ptr = multistate_yesnoaskconfirm;
1684: goto parse_multistate;
1685:
1.253 markus 1686: case oIdentityAgent:
1687: charptr = &options->identity_agent;
1688: goto parse_string;
1689:
1.96 markus 1690: case oDeprecated:
1.98 markus 1691: debug("%s line %d: Deprecated option \"%s\"",
1.96 markus 1692: filename, linenum, keyword);
1.98 markus 1693: return 0;
1.96 markus 1694:
1.110 jakob 1695: case oUnsupported:
1696: error("%s line %d: Unsupported option \"%s\"",
1697: filename, linenum, keyword);
1698: return 0;
1699:
1.17 markus 1700: default:
1.221 djm 1701: fatal("%s: Unimplemented opcode %d", __func__, opcode);
1.17 markus 1702: }
1703:
1704: /* Check that there is no garbage at end of line. */
1.57 djm 1705: if ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1.39 ho 1706: fatal("%.200s line %d: garbage at end of line; \"%.200s\".",
1.142 djm 1707: filename, linenum, arg);
1.39 ho 1708: }
1.17 markus 1709: return 0;
1.1 deraadt 1710: }
1711:
1.19 markus 1712: /*
1713: * Reads the config file and modifies the options accordingly. Options
1714: * should already be initialized before this call. This never returns if
1.89 stevesk 1715: * there is an error. If the file does not exist, this returns 0.
1.19 markus 1716: */
1.89 stevesk 1717: int
1.206 djm 1718: read_config_file(const char *filename, struct passwd *pw, const char *host,
1.221 djm 1719: const char *original_host, Options *options, int flags)
1.1 deraadt 1720: {
1.252 djm 1721: int active = 1;
1722:
1723: return read_config_file_depth(filename, pw, host, original_host,
1724: options, flags, &active, 0);
1725: }
1726:
1727: #define READCONF_MAX_DEPTH 16
1728: static int
1729: read_config_file_depth(const char *filename, struct passwd *pw,
1730: const char *host, const char *original_host, Options *options,
1731: int flags, int *activep, int depth)
1732: {
1.17 markus 1733: FILE *f;
1.289 markus 1734: char *line = NULL;
1735: size_t linesize = 0;
1.252 djm 1736: int linenum;
1.17 markus 1737: int bad_options = 0;
1738:
1.252 djm 1739: if (depth < 0 || depth > READCONF_MAX_DEPTH)
1740: fatal("Too many recursive configuration includes");
1741:
1.129 djm 1742: if ((f = fopen(filename, "r")) == NULL)
1.89 stevesk 1743: return 0;
1.129 djm 1744:
1.196 dtucker 1745: if (flags & SSHCONF_CHECKPERM) {
1.129 djm 1746: struct stat sb;
1.134 deraadt 1747:
1.131 dtucker 1748: if (fstat(fileno(f), &sb) == -1)
1.129 djm 1749: fatal("fstat %s: %s", filename, strerror(errno));
1750: if (((sb.st_uid != 0 && sb.st_uid != getuid()) ||
1.131 dtucker 1751: (sb.st_mode & 022) != 0))
1.129 djm 1752: fatal("Bad owner or permissions on %s", filename);
1753: }
1.17 markus 1754:
1755: debug("Reading configuration data %.200s", filename);
1756:
1.19 markus 1757: /*
1758: * Mark that we are now processing the options. This flag is turned
1759: * on/off by Host specifications.
1760: */
1.17 markus 1761: linenum = 0;
1.289 markus 1762: while (getline(&line, &linesize, f) != -1) {
1.17 markus 1763: /* Update line number counter. */
1764: linenum++;
1.252 djm 1765: if (process_config_line_depth(options, pw, host, original_host,
1766: line, filename, linenum, activep, flags, depth) != 0)
1.17 markus 1767: bad_options++;
1768: }
1.289 markus 1769: free(line);
1.17 markus 1770: fclose(f);
1771: if (bad_options > 0)
1.64 millert 1772: fatal("%s: terminating, %d bad configuration options",
1.93 deraadt 1773: filename, bad_options);
1.89 stevesk 1774: return 1;
1.1 deraadt 1775: }
1776:
1.218 djm 1777: /* Returns 1 if a string option is unset or set to "none" or 0 otherwise. */
1778: int
1779: option_clear_or_none(const char *o)
1780: {
1781: return o == NULL || strcasecmp(o, "none") == 0;
1782: }
1783:
1.19 markus 1784: /*
1785: * Initializes options to special values that indicate that they have not yet
1786: * been set. Read_config_file will only set options with this value. Options
1787: * are processed in the following order: command line, user config file,
1788: * system config file. Last, fill_default_options is called.
1789: */
1.1 deraadt 1790:
1.26 markus 1791: void
1.17 markus 1792: initialize_options(Options * options)
1.1 deraadt 1793: {
1.17 markus 1794: memset(options, 'X', sizeof(*options));
1795: options->forward_agent = -1;
1796: options->forward_x11 = -1;
1.123 markus 1797: options->forward_x11_trusted = -1;
1.186 djm 1798: options->forward_x11_timeout = -1;
1.255 dtucker 1799: options->stdio_forward_host = NULL;
1800: options->stdio_forward_port = 0;
1.256 dtucker 1801: options->clear_forwardings = -1;
1.153 markus 1802: options->exit_on_forward_failure = -1;
1.34 markus 1803: options->xauth_location = NULL;
1.220 millert 1804: options->fwd_opts.gateway_ports = -1;
1805: options->fwd_opts.streamlocal_bind_mask = (mode_t)-1;
1806: options->fwd_opts.streamlocal_bind_unlink = -1;
1.50 markus 1807: options->pubkey_authentication = -1;
1.78 markus 1808: options->challenge_response_authentication = -1;
1.118 markus 1809: options->gss_authentication = -1;
1810: options->gss_deleg_creds = -1;
1.17 markus 1811: options->password_authentication = -1;
1.48 markus 1812: options->kbd_interactive_authentication = -1;
1813: options->kbd_interactive_devices = NULL;
1.72 markus 1814: options->hostbased_authentication = -1;
1.17 markus 1815: options->batch_mode = -1;
1816: options->check_host_ip = -1;
1817: options->strict_host_key_checking = -1;
1818: options->compression = -1;
1.126 markus 1819: options->tcp_keep_alive = -1;
1.17 markus 1820: options->port = -1;
1.114 djm 1821: options->address_family = -1;
1.17 markus 1822: options->connection_attempts = -1;
1.111 djm 1823: options->connection_timeout = -1;
1.17 markus 1824: options->number_of_password_prompts = -1;
1.25 markus 1825: options->ciphers = NULL;
1.62 markus 1826: options->macs = NULL;
1.189 djm 1827: options->kex_algorithms = NULL;
1.76 markus 1828: options->hostkeyalgorithms = NULL;
1.298 ! djm 1829: options->ca_sign_algorithms = NULL;
1.17 markus 1830: options->num_identity_files = 0;
1.241 djm 1831: options->num_certificate_files = 0;
1.17 markus 1832: options->hostname = NULL;
1.52 markus 1833: options->host_key_alias = NULL;
1.17 markus 1834: options->proxy_command = NULL;
1.257 djm 1835: options->jump_user = NULL;
1836: options->jump_host = NULL;
1837: options->jump_port = -1;
1838: options->jump_extra = NULL;
1.17 markus 1839: options->user = NULL;
1840: options->escape_char = -1;
1.193 djm 1841: options->num_system_hostfiles = 0;
1842: options->num_user_hostfiles = 0;
1.185 djm 1843: options->local_forwards = NULL;
1.17 markus 1844: options->num_local_forwards = 0;
1.185 djm 1845: options->remote_forwards = NULL;
1.17 markus 1846: options->num_remote_forwards = 0;
1.271 dtucker 1847: options->log_facility = SYSLOG_FACILITY_NOT_SET;
1.95 markus 1848: options->log_level = SYSLOG_LEVEL_NOT_SET;
1.67 markus 1849: options->preferred_authentications = NULL;
1.77 markus 1850: options->bind_address = NULL;
1.282 djm 1851: options->bind_interface = NULL;
1.183 markus 1852: options->pkcs11_provider = NULL;
1.101 markus 1853: options->enable_ssh_keysign = - 1;
1.91 markus 1854: options->no_host_authentication_for_localhost = - 1;
1.128 markus 1855: options->identities_only = - 1;
1.105 markus 1856: options->rekey_limit = - 1;
1.198 dtucker 1857: options->rekey_interval = -1;
1.107 jakob 1858: options->verify_host_key_dns = -1;
1.127 markus 1859: options->server_alive_interval = -1;
1860: options->server_alive_count_max = -1;
1.290 djm 1861: options->send_env = NULL;
1.130 djm 1862: options->num_send_env = 0;
1.290 djm 1863: options->setenv = NULL;
1864: options->num_setenv = 0;
1.132 djm 1865: options->control_path = NULL;
1866: options->control_master = -1;
1.187 djm 1867: options->control_persist = -1;
1868: options->control_persist_timeout = 0;
1.136 djm 1869: options->hash_known_hosts = -1;
1.144 reyk 1870: options->tun_open = -1;
1871: options->tun_local = -1;
1872: options->tun_remote = -1;
1873: options->local_command = NULL;
1874: options->permit_local_command = -1;
1.277 bluhm 1875: options->remote_command = NULL;
1.246 jcs 1876: options->add_keys_to_agent = -1;
1.253 markus 1877: options->identity_agent = NULL;
1.167 grunk 1878: options->visual_host_key = -1;
1.190 djm 1879: options->ip_qos_interactive = -1;
1880: options->ip_qos_bulk = -1;
1.192 djm 1881: options->request_tty = -1;
1.205 djm 1882: options->proxy_use_fdpass = -1;
1.199 djm 1883: options->ignored_unknown = NULL;
1.208 djm 1884: options->num_canonical_domains = 0;
1885: options->num_permitted_cnames = 0;
1.209 djm 1886: options->canonicalize_max_dots = -1;
1887: options->canonicalize_fallback_local = -1;
1888: options->canonicalize_hostname = -1;
1.223 djm 1889: options->revoked_host_keys = NULL;
1.224 djm 1890: options->fingerprint_hash = -1;
1.229 djm 1891: options->update_hostkeys = -1;
1.230 djm 1892: options->hostbased_key_types = NULL;
1.238 markus 1893: options->pubkey_key_types = NULL;
1.1 deraadt 1894: }
1895:
1.19 markus 1896: /*
1.218 djm 1897: * A petite version of fill_default_options() that just fills the options
1898: * needed for hostname canonicalization to proceed.
1899: */
1900: void
1901: fill_default_options_for_canonicalization(Options *options)
1902: {
1903: if (options->canonicalize_max_dots == -1)
1904: options->canonicalize_max_dots = 1;
1905: if (options->canonicalize_fallback_local == -1)
1906: options->canonicalize_fallback_local = 1;
1907: if (options->canonicalize_hostname == -1)
1908: options->canonicalize_hostname = SSH_CANONICALISE_NO;
1909: }
1910:
1911: /*
1.19 markus 1912: * Called after processing other sources of option data, this fills those
1913: * options for which no value has been specified with their default values.
1914: */
1.26 markus 1915: void
1.17 markus 1916: fill_default_options(Options * options)
1.1 deraadt 1917: {
1.298 ! djm 1918: char *all_cipher, *all_mac, *all_kex, *all_key, *all_sig;
1.297 djm 1919: int r;
1.292 djm 1920:
1.17 markus 1921: if (options->forward_agent == -1)
1.33 markus 1922: options->forward_agent = 0;
1.17 markus 1923: if (options->forward_x11 == -1)
1.23 markus 1924: options->forward_x11 = 0;
1.123 markus 1925: if (options->forward_x11_trusted == -1)
1926: options->forward_x11_trusted = 0;
1.186 djm 1927: if (options->forward_x11_timeout == -1)
1928: options->forward_x11_timeout = 1200;
1.256 dtucker 1929: /*
1930: * stdio forwarding (-W) changes the default for these but we defer
1931: * setting the values so they can be overridden.
1932: */
1.153 markus 1933: if (options->exit_on_forward_failure == -1)
1.256 dtucker 1934: options->exit_on_forward_failure =
1935: options->stdio_forward_host != NULL ? 1 : 0;
1936: if (options->clear_forwardings == -1)
1937: options->clear_forwardings =
1938: options->stdio_forward_host != NULL ? 1 : 0;
1939: if (options->clear_forwardings == 1)
1940: clear_forwardings(options);
1941:
1.34 markus 1942: if (options->xauth_location == NULL)
1.80 markus 1943: options->xauth_location = _PATH_XAUTH;
1.220 millert 1944: if (options->fwd_opts.gateway_ports == -1)
1945: options->fwd_opts.gateway_ports = 0;
1946: if (options->fwd_opts.streamlocal_bind_mask == (mode_t)-1)
1947: options->fwd_opts.streamlocal_bind_mask = 0177;
1948: if (options->fwd_opts.streamlocal_bind_unlink == -1)
1949: options->fwd_opts.streamlocal_bind_unlink = 0;
1.50 markus 1950: if (options->pubkey_authentication == -1)
1951: options->pubkey_authentication = 1;
1.78 markus 1952: if (options->challenge_response_authentication == -1)
1.83 markus 1953: options->challenge_response_authentication = 1;
1.118 markus 1954: if (options->gss_authentication == -1)
1.122 markus 1955: options->gss_authentication = 0;
1.118 markus 1956: if (options->gss_deleg_creds == -1)
1957: options->gss_deleg_creds = 0;
1.17 markus 1958: if (options->password_authentication == -1)
1959: options->password_authentication = 1;
1.48 markus 1960: if (options->kbd_interactive_authentication == -1)
1.59 markus 1961: options->kbd_interactive_authentication = 1;
1.72 markus 1962: if (options->hostbased_authentication == -1)
1963: options->hostbased_authentication = 0;
1.17 markus 1964: if (options->batch_mode == -1)
1965: options->batch_mode = 0;
1966: if (options->check_host_ip == -1)
1967: options->check_host_ip = 1;
1968: if (options->strict_host_key_checking == -1)
1.278 djm 1969: options->strict_host_key_checking = SSH_STRICT_HOSTKEY_ASK;
1.17 markus 1970: if (options->compression == -1)
1971: options->compression = 0;
1.126 markus 1972: if (options->tcp_keep_alive == -1)
1973: options->tcp_keep_alive = 1;
1.17 markus 1974: if (options->port == -1)
1975: options->port = 0; /* Filled in ssh_connect. */
1.114 djm 1976: if (options->address_family == -1)
1977: options->address_family = AF_UNSPEC;
1.17 markus 1978: if (options->connection_attempts == -1)
1.84 markus 1979: options->connection_attempts = 1;
1.17 markus 1980: if (options->number_of_password_prompts == -1)
1981: options->number_of_password_prompts = 3;
1.76 markus 1982: /* options->hostkeyalgorithms, default set in myproposals.h */
1.246 jcs 1983: if (options->add_keys_to_agent == -1)
1984: options->add_keys_to_agent = 0;
1.17 markus 1985: if (options->num_identity_files == 0) {
1.273 djm 1986: add_identity_file(options, "~/", _PATH_SSH_CLIENT_ID_RSA, 0);
1987: add_identity_file(options, "~/", _PATH_SSH_CLIENT_ID_DSA, 0);
1988: add_identity_file(options, "~/", _PATH_SSH_CLIENT_ID_ECDSA, 0);
1989: add_identity_file(options, "~/",
1990: _PATH_SSH_CLIENT_ID_ED25519, 0);
1.283 markus 1991: add_identity_file(options, "~/", _PATH_SSH_CLIENT_ID_XMSS, 0);
1.27 markus 1992: }
1.17 markus 1993: if (options->escape_char == -1)
1994: options->escape_char = '~';
1.193 djm 1995: if (options->num_system_hostfiles == 0) {
1996: options->system_hostfiles[options->num_system_hostfiles++] =
1997: xstrdup(_PATH_SSH_SYSTEM_HOSTFILE);
1998: options->system_hostfiles[options->num_system_hostfiles++] =
1999: xstrdup(_PATH_SSH_SYSTEM_HOSTFILE2);
2000: }
2001: if (options->num_user_hostfiles == 0) {
2002: options->user_hostfiles[options->num_user_hostfiles++] =
2003: xstrdup(_PATH_SSH_USER_HOSTFILE);
2004: options->user_hostfiles[options->num_user_hostfiles++] =
2005: xstrdup(_PATH_SSH_USER_HOSTFILE2);
2006: }
1.95 markus 2007: if (options->log_level == SYSLOG_LEVEL_NOT_SET)
1.54 markus 2008: options->log_level = SYSLOG_LEVEL_INFO;
1.271 dtucker 2009: if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
2010: options->log_facility = SYSLOG_FACILITY_USER;
1.91 markus 2011: if (options->no_host_authentication_for_localhost == - 1)
2012: options->no_host_authentication_for_localhost = 0;
1.128 markus 2013: if (options->identities_only == -1)
2014: options->identities_only = 0;
1.101 markus 2015: if (options->enable_ssh_keysign == -1)
2016: options->enable_ssh_keysign = 0;
1.105 markus 2017: if (options->rekey_limit == -1)
2018: options->rekey_limit = 0;
1.198 dtucker 2019: if (options->rekey_interval == -1)
2020: options->rekey_interval = 0;
1.107 jakob 2021: if (options->verify_host_key_dns == -1)
2022: options->verify_host_key_dns = 0;
1.127 markus 2023: if (options->server_alive_interval == -1)
2024: options->server_alive_interval = 0;
2025: if (options->server_alive_count_max == -1)
2026: options->server_alive_count_max = 3;
1.132 djm 2027: if (options->control_master == -1)
2028: options->control_master = 0;
1.187 djm 2029: if (options->control_persist == -1) {
2030: options->control_persist = 0;
2031: options->control_persist_timeout = 0;
2032: }
1.136 djm 2033: if (options->hash_known_hosts == -1)
2034: options->hash_known_hosts = 0;
1.144 reyk 2035: if (options->tun_open == -1)
1.145 reyk 2036: options->tun_open = SSH_TUNMODE_NO;
2037: if (options->tun_local == -1)
2038: options->tun_local = SSH_TUNID_ANY;
2039: if (options->tun_remote == -1)
2040: options->tun_remote = SSH_TUNID_ANY;
1.144 reyk 2041: if (options->permit_local_command == -1)
2042: options->permit_local_command = 0;
1.167 grunk 2043: if (options->visual_host_key == -1)
2044: options->visual_host_key = 0;
1.190 djm 2045: if (options->ip_qos_interactive == -1)
1.284 job 2046: options->ip_qos_interactive = IPTOS_DSCP_AF21;
1.190 djm 2047: if (options->ip_qos_bulk == -1)
1.284 job 2048: options->ip_qos_bulk = IPTOS_DSCP_CS1;
1.192 djm 2049: if (options->request_tty == -1)
2050: options->request_tty = REQUEST_TTY_AUTO;
1.205 djm 2051: if (options->proxy_use_fdpass == -1)
2052: options->proxy_use_fdpass = 0;
1.209 djm 2053: if (options->canonicalize_max_dots == -1)
2054: options->canonicalize_max_dots = 1;
2055: if (options->canonicalize_fallback_local == -1)
2056: options->canonicalize_fallback_local = 1;
2057: if (options->canonicalize_hostname == -1)
2058: options->canonicalize_hostname = SSH_CANONICALISE_NO;
1.224 djm 2059: if (options->fingerprint_hash == -1)
2060: options->fingerprint_hash = SSH_FP_HASH_DEFAULT;
1.229 djm 2061: if (options->update_hostkeys == -1)
1.231 djm 2062: options->update_hostkeys = 0;
1.292 djm 2063:
2064: /* Expand KEX name lists */
2065: all_cipher = cipher_alg_list(',', 0);
2066: all_mac = mac_alg_list(',');
2067: all_kex = kex_alg_list(',');
2068: all_key = sshkey_alg_list(0, 0, 1, ',');
1.298 ! djm 2069: all_sig = sshkey_alg_list(0, 1, 1, ',');
1.297 djm 2070: #define ASSEMBLE(what, defaults, all) \
2071: do { \
2072: if ((r = kex_assemble_names(&options->what, \
2073: defaults, all)) != 0) \
2074: fatal("%s: %s: %s", __func__, #what, ssh_err(r)); \
2075: } while (0)
2076: ASSEMBLE(ciphers, KEX_SERVER_ENCRYPT, all_cipher);
2077: ASSEMBLE(macs, KEX_SERVER_MAC, all_mac);
2078: ASSEMBLE(kex_algorithms, KEX_SERVER_KEX, all_kex);
2079: ASSEMBLE(hostbased_key_types, KEX_DEFAULT_PK_ALG, all_key);
2080: ASSEMBLE(pubkey_key_types, KEX_DEFAULT_PK_ALG, all_key);
1.298 ! djm 2081: ASSEMBLE(ca_sign_algorithms, SSH_ALLOWED_CA_SIGALGS, all_sig);
1.297 djm 2082: #undef ASSEMBLE
1.292 djm 2083: free(all_cipher);
2084: free(all_mac);
2085: free(all_kex);
2086: free(all_key);
1.298 ! djm 2087: free(all_sig);
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(oVerifyHostKeyDNS, o->verify_host_key_dns);
2586: dump_cfg_fmtint(oVisualHostKey, o->visual_host_key);
1.229 djm 2587: dump_cfg_fmtint(oUpdateHostkeys, o->update_hostkeys);
1.221 djm 2588:
2589: /* Integer options */
2590: dump_cfg_int(oCanonicalizeMaxDots, o->canonicalize_max_dots);
2591: dump_cfg_int(oConnectionAttempts, o->connection_attempts);
2592: dump_cfg_int(oForwardX11Timeout, o->forward_x11_timeout);
2593: dump_cfg_int(oNumberOfPasswordPrompts, o->number_of_password_prompts);
2594: dump_cfg_int(oServerAliveCountMax, o->server_alive_count_max);
2595: dump_cfg_int(oServerAliveInterval, o->server_alive_interval);
2596:
2597: /* String options */
2598: dump_cfg_string(oBindAddress, o->bind_address);
1.282 djm 2599: dump_cfg_string(oBindInterface, o->bind_interface);
1.221 djm 2600: dump_cfg_string(oCiphers, o->ciphers ? o->ciphers : KEX_CLIENT_ENCRYPT);
2601: dump_cfg_string(oControlPath, o->control_path);
1.240 djm 2602: dump_cfg_string(oHostKeyAlgorithms, o->hostkeyalgorithms);
1.221 djm 2603: dump_cfg_string(oHostKeyAlias, o->host_key_alias);
1.230 djm 2604: dump_cfg_string(oHostbasedKeyTypes, o->hostbased_key_types);
1.253 markus 2605: dump_cfg_string(oIdentityAgent, o->identity_agent);
1.285 djm 2606: dump_cfg_string(oIgnoreUnknown, o->ignored_unknown);
1.221 djm 2607: dump_cfg_string(oKbdInteractiveDevices, o->kbd_interactive_devices);
2608: dump_cfg_string(oKexAlgorithms, o->kex_algorithms ? o->kex_algorithms : KEX_CLIENT_KEX);
1.298 ! djm 2609: dump_cfg_string(oCASignatureAlgorithms, o->ca_sign_algorithms ? o->ca_sign_algorithms : SSH_ALLOWED_CA_SIGALGS);
1.221 djm 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: }