Annotation of src/usr.bin/ssh/readconf.c, Revision 1.299
1.299 ! djm 1: /* $OpenBSD: readconf.c,v 1.298 2018/09/20 03:30:44 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;
1.299 ! djm 1688: arg = strdelim(&s);
! 1689: if (!arg || *arg == '\0')
! 1690: fatal("%.200s line %d: Missing argument.",
! 1691: filename, linenum);
! 1692: /* Extra validation if the string represents an env var. */
! 1693: if (arg[0] == '$' && !valid_env_name(arg + 1)) {
! 1694: fatal("%.200s line %d: Invalid environment name %s.",
! 1695: filename, linenum, arg);
! 1696: }
! 1697: if (*activep && *charptr == NULL)
! 1698: *charptr = xstrdup(arg);
! 1699: break;
1.253 markus 1700:
1.96 markus 1701: case oDeprecated:
1.98 markus 1702: debug("%s line %d: Deprecated option \"%s\"",
1.96 markus 1703: filename, linenum, keyword);
1.98 markus 1704: return 0;
1.96 markus 1705:
1.110 jakob 1706: case oUnsupported:
1707: error("%s line %d: Unsupported option \"%s\"",
1708: filename, linenum, keyword);
1709: return 0;
1710:
1.17 markus 1711: default:
1.221 djm 1712: fatal("%s: Unimplemented opcode %d", __func__, opcode);
1.17 markus 1713: }
1714:
1715: /* Check that there is no garbage at end of line. */
1.57 djm 1716: if ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1.39 ho 1717: fatal("%.200s line %d: garbage at end of line; \"%.200s\".",
1.142 djm 1718: filename, linenum, arg);
1.39 ho 1719: }
1.17 markus 1720: return 0;
1.1 deraadt 1721: }
1722:
1.19 markus 1723: /*
1724: * Reads the config file and modifies the options accordingly. Options
1725: * should already be initialized before this call. This never returns if
1.89 stevesk 1726: * there is an error. If the file does not exist, this returns 0.
1.19 markus 1727: */
1.89 stevesk 1728: int
1.206 djm 1729: read_config_file(const char *filename, struct passwd *pw, const char *host,
1.221 djm 1730: const char *original_host, Options *options, int flags)
1.1 deraadt 1731: {
1.252 djm 1732: int active = 1;
1733:
1734: return read_config_file_depth(filename, pw, host, original_host,
1735: options, flags, &active, 0);
1736: }
1737:
1738: #define READCONF_MAX_DEPTH 16
1739: static int
1740: read_config_file_depth(const char *filename, struct passwd *pw,
1741: const char *host, const char *original_host, Options *options,
1742: int flags, int *activep, int depth)
1743: {
1.17 markus 1744: FILE *f;
1.289 markus 1745: char *line = NULL;
1746: size_t linesize = 0;
1.252 djm 1747: int linenum;
1.17 markus 1748: int bad_options = 0;
1749:
1.252 djm 1750: if (depth < 0 || depth > READCONF_MAX_DEPTH)
1751: fatal("Too many recursive configuration includes");
1752:
1.129 djm 1753: if ((f = fopen(filename, "r")) == NULL)
1.89 stevesk 1754: return 0;
1.129 djm 1755:
1.196 dtucker 1756: if (flags & SSHCONF_CHECKPERM) {
1.129 djm 1757: struct stat sb;
1.134 deraadt 1758:
1.131 dtucker 1759: if (fstat(fileno(f), &sb) == -1)
1.129 djm 1760: fatal("fstat %s: %s", filename, strerror(errno));
1761: if (((sb.st_uid != 0 && sb.st_uid != getuid()) ||
1.131 dtucker 1762: (sb.st_mode & 022) != 0))
1.129 djm 1763: fatal("Bad owner or permissions on %s", filename);
1764: }
1.17 markus 1765:
1766: debug("Reading configuration data %.200s", filename);
1767:
1.19 markus 1768: /*
1769: * Mark that we are now processing the options. This flag is turned
1770: * on/off by Host specifications.
1771: */
1.17 markus 1772: linenum = 0;
1.289 markus 1773: while (getline(&line, &linesize, f) != -1) {
1.17 markus 1774: /* Update line number counter. */
1775: linenum++;
1.252 djm 1776: if (process_config_line_depth(options, pw, host, original_host,
1777: line, filename, linenum, activep, flags, depth) != 0)
1.17 markus 1778: bad_options++;
1779: }
1.289 markus 1780: free(line);
1.17 markus 1781: fclose(f);
1782: if (bad_options > 0)
1.64 millert 1783: fatal("%s: terminating, %d bad configuration options",
1.93 deraadt 1784: filename, bad_options);
1.89 stevesk 1785: return 1;
1.1 deraadt 1786: }
1787:
1.218 djm 1788: /* Returns 1 if a string option is unset or set to "none" or 0 otherwise. */
1789: int
1790: option_clear_or_none(const char *o)
1791: {
1792: return o == NULL || strcasecmp(o, "none") == 0;
1793: }
1794:
1.19 markus 1795: /*
1796: * Initializes options to special values that indicate that they have not yet
1797: * been set. Read_config_file will only set options with this value. Options
1798: * are processed in the following order: command line, user config file,
1799: * system config file. Last, fill_default_options is called.
1800: */
1.1 deraadt 1801:
1.26 markus 1802: void
1.17 markus 1803: initialize_options(Options * options)
1.1 deraadt 1804: {
1.17 markus 1805: memset(options, 'X', sizeof(*options));
1806: options->forward_agent = -1;
1807: options->forward_x11 = -1;
1.123 markus 1808: options->forward_x11_trusted = -1;
1.186 djm 1809: options->forward_x11_timeout = -1;
1.255 dtucker 1810: options->stdio_forward_host = NULL;
1811: options->stdio_forward_port = 0;
1.256 dtucker 1812: options->clear_forwardings = -1;
1.153 markus 1813: options->exit_on_forward_failure = -1;
1.34 markus 1814: options->xauth_location = NULL;
1.220 millert 1815: options->fwd_opts.gateway_ports = -1;
1816: options->fwd_opts.streamlocal_bind_mask = (mode_t)-1;
1817: options->fwd_opts.streamlocal_bind_unlink = -1;
1.50 markus 1818: options->pubkey_authentication = -1;
1.78 markus 1819: options->challenge_response_authentication = -1;
1.118 markus 1820: options->gss_authentication = -1;
1821: options->gss_deleg_creds = -1;
1.17 markus 1822: options->password_authentication = -1;
1.48 markus 1823: options->kbd_interactive_authentication = -1;
1824: options->kbd_interactive_devices = NULL;
1.72 markus 1825: options->hostbased_authentication = -1;
1.17 markus 1826: options->batch_mode = -1;
1827: options->check_host_ip = -1;
1828: options->strict_host_key_checking = -1;
1829: options->compression = -1;
1.126 markus 1830: options->tcp_keep_alive = -1;
1.17 markus 1831: options->port = -1;
1.114 djm 1832: options->address_family = -1;
1.17 markus 1833: options->connection_attempts = -1;
1.111 djm 1834: options->connection_timeout = -1;
1.17 markus 1835: options->number_of_password_prompts = -1;
1.25 markus 1836: options->ciphers = NULL;
1.62 markus 1837: options->macs = NULL;
1.189 djm 1838: options->kex_algorithms = NULL;
1.76 markus 1839: options->hostkeyalgorithms = NULL;
1.298 djm 1840: options->ca_sign_algorithms = NULL;
1.17 markus 1841: options->num_identity_files = 0;
1.241 djm 1842: options->num_certificate_files = 0;
1.17 markus 1843: options->hostname = NULL;
1.52 markus 1844: options->host_key_alias = NULL;
1.17 markus 1845: options->proxy_command = NULL;
1.257 djm 1846: options->jump_user = NULL;
1847: options->jump_host = NULL;
1848: options->jump_port = -1;
1849: options->jump_extra = NULL;
1.17 markus 1850: options->user = NULL;
1851: options->escape_char = -1;
1.193 djm 1852: options->num_system_hostfiles = 0;
1853: options->num_user_hostfiles = 0;
1.185 djm 1854: options->local_forwards = NULL;
1.17 markus 1855: options->num_local_forwards = 0;
1.185 djm 1856: options->remote_forwards = NULL;
1.17 markus 1857: options->num_remote_forwards = 0;
1.271 dtucker 1858: options->log_facility = SYSLOG_FACILITY_NOT_SET;
1.95 markus 1859: options->log_level = SYSLOG_LEVEL_NOT_SET;
1.67 markus 1860: options->preferred_authentications = NULL;
1.77 markus 1861: options->bind_address = NULL;
1.282 djm 1862: options->bind_interface = NULL;
1.183 markus 1863: options->pkcs11_provider = NULL;
1.101 markus 1864: options->enable_ssh_keysign = - 1;
1.91 markus 1865: options->no_host_authentication_for_localhost = - 1;
1.128 markus 1866: options->identities_only = - 1;
1.105 markus 1867: options->rekey_limit = - 1;
1.198 dtucker 1868: options->rekey_interval = -1;
1.107 jakob 1869: options->verify_host_key_dns = -1;
1.127 markus 1870: options->server_alive_interval = -1;
1871: options->server_alive_count_max = -1;
1.290 djm 1872: options->send_env = NULL;
1.130 djm 1873: options->num_send_env = 0;
1.290 djm 1874: options->setenv = NULL;
1875: options->num_setenv = 0;
1.132 djm 1876: options->control_path = NULL;
1877: options->control_master = -1;
1.187 djm 1878: options->control_persist = -1;
1879: options->control_persist_timeout = 0;
1.136 djm 1880: options->hash_known_hosts = -1;
1.144 reyk 1881: options->tun_open = -1;
1882: options->tun_local = -1;
1883: options->tun_remote = -1;
1884: options->local_command = NULL;
1885: options->permit_local_command = -1;
1.277 bluhm 1886: options->remote_command = NULL;
1.246 jcs 1887: options->add_keys_to_agent = -1;
1.253 markus 1888: options->identity_agent = NULL;
1.167 grunk 1889: options->visual_host_key = -1;
1.190 djm 1890: options->ip_qos_interactive = -1;
1891: options->ip_qos_bulk = -1;
1.192 djm 1892: options->request_tty = -1;
1.205 djm 1893: options->proxy_use_fdpass = -1;
1.199 djm 1894: options->ignored_unknown = NULL;
1.208 djm 1895: options->num_canonical_domains = 0;
1896: options->num_permitted_cnames = 0;
1.209 djm 1897: options->canonicalize_max_dots = -1;
1898: options->canonicalize_fallback_local = -1;
1899: options->canonicalize_hostname = -1;
1.223 djm 1900: options->revoked_host_keys = NULL;
1.224 djm 1901: options->fingerprint_hash = -1;
1.229 djm 1902: options->update_hostkeys = -1;
1.230 djm 1903: options->hostbased_key_types = NULL;
1.238 markus 1904: options->pubkey_key_types = NULL;
1.1 deraadt 1905: }
1906:
1.19 markus 1907: /*
1.218 djm 1908: * A petite version of fill_default_options() that just fills the options
1909: * needed for hostname canonicalization to proceed.
1910: */
1911: void
1912: fill_default_options_for_canonicalization(Options *options)
1913: {
1914: if (options->canonicalize_max_dots == -1)
1915: options->canonicalize_max_dots = 1;
1916: if (options->canonicalize_fallback_local == -1)
1917: options->canonicalize_fallback_local = 1;
1918: if (options->canonicalize_hostname == -1)
1919: options->canonicalize_hostname = SSH_CANONICALISE_NO;
1920: }
1921:
1922: /*
1.19 markus 1923: * Called after processing other sources of option data, this fills those
1924: * options for which no value has been specified with their default values.
1925: */
1.26 markus 1926: void
1.17 markus 1927: fill_default_options(Options * options)
1.1 deraadt 1928: {
1.298 djm 1929: char *all_cipher, *all_mac, *all_kex, *all_key, *all_sig;
1.297 djm 1930: int r;
1.292 djm 1931:
1.17 markus 1932: if (options->forward_agent == -1)
1.33 markus 1933: options->forward_agent = 0;
1.17 markus 1934: if (options->forward_x11 == -1)
1.23 markus 1935: options->forward_x11 = 0;
1.123 markus 1936: if (options->forward_x11_trusted == -1)
1937: options->forward_x11_trusted = 0;
1.186 djm 1938: if (options->forward_x11_timeout == -1)
1939: options->forward_x11_timeout = 1200;
1.256 dtucker 1940: /*
1941: * stdio forwarding (-W) changes the default for these but we defer
1942: * setting the values so they can be overridden.
1943: */
1.153 markus 1944: if (options->exit_on_forward_failure == -1)
1.256 dtucker 1945: options->exit_on_forward_failure =
1946: options->stdio_forward_host != NULL ? 1 : 0;
1947: if (options->clear_forwardings == -1)
1948: options->clear_forwardings =
1949: options->stdio_forward_host != NULL ? 1 : 0;
1950: if (options->clear_forwardings == 1)
1951: clear_forwardings(options);
1952:
1.34 markus 1953: if (options->xauth_location == NULL)
1.80 markus 1954: options->xauth_location = _PATH_XAUTH;
1.220 millert 1955: if (options->fwd_opts.gateway_ports == -1)
1956: options->fwd_opts.gateway_ports = 0;
1957: if (options->fwd_opts.streamlocal_bind_mask == (mode_t)-1)
1958: options->fwd_opts.streamlocal_bind_mask = 0177;
1959: if (options->fwd_opts.streamlocal_bind_unlink == -1)
1960: options->fwd_opts.streamlocal_bind_unlink = 0;
1.50 markus 1961: if (options->pubkey_authentication == -1)
1962: options->pubkey_authentication = 1;
1.78 markus 1963: if (options->challenge_response_authentication == -1)
1.83 markus 1964: options->challenge_response_authentication = 1;
1.118 markus 1965: if (options->gss_authentication == -1)
1.122 markus 1966: options->gss_authentication = 0;
1.118 markus 1967: if (options->gss_deleg_creds == -1)
1968: options->gss_deleg_creds = 0;
1.17 markus 1969: if (options->password_authentication == -1)
1970: options->password_authentication = 1;
1.48 markus 1971: if (options->kbd_interactive_authentication == -1)
1.59 markus 1972: options->kbd_interactive_authentication = 1;
1.72 markus 1973: if (options->hostbased_authentication == -1)
1974: options->hostbased_authentication = 0;
1.17 markus 1975: if (options->batch_mode == -1)
1976: options->batch_mode = 0;
1977: if (options->check_host_ip == -1)
1978: options->check_host_ip = 1;
1979: if (options->strict_host_key_checking == -1)
1.278 djm 1980: options->strict_host_key_checking = SSH_STRICT_HOSTKEY_ASK;
1.17 markus 1981: if (options->compression == -1)
1982: options->compression = 0;
1.126 markus 1983: if (options->tcp_keep_alive == -1)
1984: options->tcp_keep_alive = 1;
1.17 markus 1985: if (options->port == -1)
1986: options->port = 0; /* Filled in ssh_connect. */
1.114 djm 1987: if (options->address_family == -1)
1988: options->address_family = AF_UNSPEC;
1.17 markus 1989: if (options->connection_attempts == -1)
1.84 markus 1990: options->connection_attempts = 1;
1.17 markus 1991: if (options->number_of_password_prompts == -1)
1992: options->number_of_password_prompts = 3;
1.76 markus 1993: /* options->hostkeyalgorithms, default set in myproposals.h */
1.246 jcs 1994: if (options->add_keys_to_agent == -1)
1995: options->add_keys_to_agent = 0;
1.17 markus 1996: if (options->num_identity_files == 0) {
1.273 djm 1997: add_identity_file(options, "~/", _PATH_SSH_CLIENT_ID_RSA, 0);
1998: add_identity_file(options, "~/", _PATH_SSH_CLIENT_ID_DSA, 0);
1999: add_identity_file(options, "~/", _PATH_SSH_CLIENT_ID_ECDSA, 0);
2000: add_identity_file(options, "~/",
2001: _PATH_SSH_CLIENT_ID_ED25519, 0);
1.283 markus 2002: add_identity_file(options, "~/", _PATH_SSH_CLIENT_ID_XMSS, 0);
1.27 markus 2003: }
1.17 markus 2004: if (options->escape_char == -1)
2005: options->escape_char = '~';
1.193 djm 2006: if (options->num_system_hostfiles == 0) {
2007: options->system_hostfiles[options->num_system_hostfiles++] =
2008: xstrdup(_PATH_SSH_SYSTEM_HOSTFILE);
2009: options->system_hostfiles[options->num_system_hostfiles++] =
2010: xstrdup(_PATH_SSH_SYSTEM_HOSTFILE2);
2011: }
2012: if (options->num_user_hostfiles == 0) {
2013: options->user_hostfiles[options->num_user_hostfiles++] =
2014: xstrdup(_PATH_SSH_USER_HOSTFILE);
2015: options->user_hostfiles[options->num_user_hostfiles++] =
2016: xstrdup(_PATH_SSH_USER_HOSTFILE2);
2017: }
1.95 markus 2018: if (options->log_level == SYSLOG_LEVEL_NOT_SET)
1.54 markus 2019: options->log_level = SYSLOG_LEVEL_INFO;
1.271 dtucker 2020: if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
2021: options->log_facility = SYSLOG_FACILITY_USER;
1.91 markus 2022: if (options->no_host_authentication_for_localhost == - 1)
2023: options->no_host_authentication_for_localhost = 0;
1.128 markus 2024: if (options->identities_only == -1)
2025: options->identities_only = 0;
1.101 markus 2026: if (options->enable_ssh_keysign == -1)
2027: options->enable_ssh_keysign = 0;
1.105 markus 2028: if (options->rekey_limit == -1)
2029: options->rekey_limit = 0;
1.198 dtucker 2030: if (options->rekey_interval == -1)
2031: options->rekey_interval = 0;
1.107 jakob 2032: if (options->verify_host_key_dns == -1)
2033: options->verify_host_key_dns = 0;
1.127 markus 2034: if (options->server_alive_interval == -1)
2035: options->server_alive_interval = 0;
2036: if (options->server_alive_count_max == -1)
2037: options->server_alive_count_max = 3;
1.132 djm 2038: if (options->control_master == -1)
2039: options->control_master = 0;
1.187 djm 2040: if (options->control_persist == -1) {
2041: options->control_persist = 0;
2042: options->control_persist_timeout = 0;
2043: }
1.136 djm 2044: if (options->hash_known_hosts == -1)
2045: options->hash_known_hosts = 0;
1.144 reyk 2046: if (options->tun_open == -1)
1.145 reyk 2047: options->tun_open = SSH_TUNMODE_NO;
2048: if (options->tun_local == -1)
2049: options->tun_local = SSH_TUNID_ANY;
2050: if (options->tun_remote == -1)
2051: options->tun_remote = SSH_TUNID_ANY;
1.144 reyk 2052: if (options->permit_local_command == -1)
2053: options->permit_local_command = 0;
1.167 grunk 2054: if (options->visual_host_key == -1)
2055: options->visual_host_key = 0;
1.190 djm 2056: if (options->ip_qos_interactive == -1)
1.284 job 2057: options->ip_qos_interactive = IPTOS_DSCP_AF21;
1.190 djm 2058: if (options->ip_qos_bulk == -1)
1.284 job 2059: options->ip_qos_bulk = IPTOS_DSCP_CS1;
1.192 djm 2060: if (options->request_tty == -1)
2061: options->request_tty = REQUEST_TTY_AUTO;
1.205 djm 2062: if (options->proxy_use_fdpass == -1)
2063: options->proxy_use_fdpass = 0;
1.209 djm 2064: if (options->canonicalize_max_dots == -1)
2065: options->canonicalize_max_dots = 1;
2066: if (options->canonicalize_fallback_local == -1)
2067: options->canonicalize_fallback_local = 1;
2068: if (options->canonicalize_hostname == -1)
2069: options->canonicalize_hostname = SSH_CANONICALISE_NO;
1.224 djm 2070: if (options->fingerprint_hash == -1)
2071: options->fingerprint_hash = SSH_FP_HASH_DEFAULT;
1.229 djm 2072: if (options->update_hostkeys == -1)
1.231 djm 2073: options->update_hostkeys = 0;
1.292 djm 2074:
2075: /* Expand KEX name lists */
2076: all_cipher = cipher_alg_list(',', 0);
2077: all_mac = mac_alg_list(',');
2078: all_kex = kex_alg_list(',');
2079: all_key = sshkey_alg_list(0, 0, 1, ',');
1.298 djm 2080: all_sig = sshkey_alg_list(0, 1, 1, ',');
1.297 djm 2081: #define ASSEMBLE(what, defaults, all) \
2082: do { \
2083: if ((r = kex_assemble_names(&options->what, \
2084: defaults, all)) != 0) \
2085: fatal("%s: %s: %s", __func__, #what, ssh_err(r)); \
2086: } while (0)
2087: ASSEMBLE(ciphers, KEX_SERVER_ENCRYPT, all_cipher);
2088: ASSEMBLE(macs, KEX_SERVER_MAC, all_mac);
2089: ASSEMBLE(kex_algorithms, KEX_SERVER_KEX, all_kex);
2090: ASSEMBLE(hostbased_key_types, KEX_DEFAULT_PK_ALG, all_key);
2091: ASSEMBLE(pubkey_key_types, KEX_DEFAULT_PK_ALG, all_key);
1.298 djm 2092: ASSEMBLE(ca_sign_algorithms, SSH_ALLOWED_CA_SIGALGS, all_sig);
1.297 djm 2093: #undef ASSEMBLE
1.292 djm 2094: free(all_cipher);
2095: free(all_mac);
2096: free(all_kex);
2097: free(all_key);
1.298 djm 2098: free(all_sig);
1.224 djm 2099:
1.207 djm 2100: #define CLEAR_ON_NONE(v) \
2101: do { \
1.218 djm 2102: if (option_clear_or_none(v)) { \
1.207 djm 2103: free(v); \
2104: v = NULL; \
2105: } \
2106: } while(0)
2107: CLEAR_ON_NONE(options->local_command);
1.277 bluhm 2108: CLEAR_ON_NONE(options->remote_command);
1.207 djm 2109: CLEAR_ON_NONE(options->proxy_command);
2110: CLEAR_ON_NONE(options->control_path);
1.223 djm 2111: CLEAR_ON_NONE(options->revoked_host_keys);
1.287 djm 2112: if (options->jump_host != NULL &&
2113: strcmp(options->jump_host, "none") == 0 &&
2114: options->jump_port == 0 && options->jump_user == NULL) {
2115: free(options->jump_host);
2116: options->jump_host = NULL;
2117: }
1.254 markus 2118: /* options->identity_agent distinguishes NULL from 'none' */
1.17 markus 2119: /* options->user will be set in the main program if appropriate */
2120: /* options->hostname will be set in the main program if appropriate */
1.52 markus 2121: /* options->host_key_alias should not be set by default */
1.67 markus 2122: /* options->preferred_authentications will be set in ssh */
1.135 djm 2123: }
2124:
1.220 millert 2125: struct fwdarg {
2126: char *arg;
2127: int ispath;
2128: };
2129:
2130: /*
2131: * parse_fwd_field
2132: * parses the next field in a port forwarding specification.
2133: * sets fwd to the parsed field and advances p past the colon
2134: * or sets it to NULL at end of string.
2135: * returns 0 on success, else non-zero.
2136: */
2137: static int
2138: parse_fwd_field(char **p, struct fwdarg *fwd)
2139: {
2140: char *ep, *cp = *p;
2141: int ispath = 0;
2142:
2143: if (*cp == '\0') {
2144: *p = NULL;
2145: return -1; /* end of string */
2146: }
2147:
2148: /*
2149: * A field escaped with square brackets is used literally.
2150: * XXX - allow ']' to be escaped via backslash?
2151: */
2152: if (*cp == '[') {
2153: /* find matching ']' */
2154: for (ep = cp + 1; *ep != ']' && *ep != '\0'; ep++) {
2155: if (*ep == '/')
2156: ispath = 1;
2157: }
2158: /* no matching ']' or not at end of field. */
2159: if (ep[0] != ']' || (ep[1] != ':' && ep[1] != '\0'))
2160: return -1;
2161: /* NUL terminate the field and advance p past the colon */
2162: *ep++ = '\0';
2163: if (*ep != '\0')
2164: *ep++ = '\0';
2165: fwd->arg = cp + 1;
2166: fwd->ispath = ispath;
2167: *p = ep;
2168: return 0;
2169: }
2170:
2171: for (cp = *p; *cp != '\0'; cp++) {
2172: switch (*cp) {
2173: case '\\':
2174: memmove(cp, cp + 1, strlen(cp + 1) + 1);
1.237 djm 2175: if (*cp == '\0')
2176: return -1;
1.220 millert 2177: break;
2178: case '/':
2179: ispath = 1;
2180: break;
2181: case ':':
2182: *cp++ = '\0';
2183: goto done;
2184: }
2185: }
2186: done:
2187: fwd->arg = *p;
2188: fwd->ispath = ispath;
2189: *p = cp;
2190: return 0;
2191: }
2192:
1.135 djm 2193: /*
2194: * parse_forward
2195: * parses a string containing a port forwarding specification of the form:
1.168 stevesk 2196: * dynamicfwd == 0
1.220 millert 2197: * [listenhost:]listenport|listenpath:connecthost:connectport|connectpath
2198: * listenpath:connectpath
1.168 stevesk 2199: * dynamicfwd == 1
2200: * [listenhost:]listenport
1.135 djm 2201: * returns number of arguments parsed or zero on error
2202: */
2203: int
1.220 millert 2204: parse_forward(struct Forward *fwd, const char *fwdspec, int dynamicfwd, int remotefwd)
1.135 djm 2205: {
1.220 millert 2206: struct fwdarg fwdargs[4];
2207: char *p, *cp;
1.135 djm 2208: int i;
2209:
1.220 millert 2210: memset(fwd, 0, sizeof(*fwd));
2211: memset(fwdargs, 0, sizeof(fwdargs));
1.135 djm 2212:
2213: cp = p = xstrdup(fwdspec);
2214:
2215: /* skip leading spaces */
1.214 deraadt 2216: while (isspace((u_char)*cp))
1.135 djm 2217: cp++;
2218:
1.220 millert 2219: for (i = 0; i < 4; ++i) {
2220: if (parse_fwd_field(&cp, &fwdargs[i]) != 0)
1.135 djm 2221: break;
1.220 millert 2222: }
1.135 djm 2223:
1.170 stevesk 2224: /* Check for trailing garbage */
1.220 millert 2225: if (cp != NULL && *cp != '\0') {
1.135 djm 2226: i = 0; /* failure */
1.220 millert 2227: }
1.135 djm 2228:
2229: switch (i) {
1.168 stevesk 2230: case 1:
1.220 millert 2231: if (fwdargs[0].ispath) {
2232: fwd->listen_path = xstrdup(fwdargs[0].arg);
2233: fwd->listen_port = PORT_STREAMLOCAL;
2234: } else {
2235: fwd->listen_host = NULL;
2236: fwd->listen_port = a2port(fwdargs[0].arg);
2237: }
1.168 stevesk 2238: fwd->connect_host = xstrdup("socks");
2239: break;
2240:
2241: case 2:
1.220 millert 2242: if (fwdargs[0].ispath && fwdargs[1].ispath) {
2243: fwd->listen_path = xstrdup(fwdargs[0].arg);
2244: fwd->listen_port = PORT_STREAMLOCAL;
2245: fwd->connect_path = xstrdup(fwdargs[1].arg);
2246: fwd->connect_port = PORT_STREAMLOCAL;
2247: } else if (fwdargs[1].ispath) {
2248: fwd->listen_host = NULL;
2249: fwd->listen_port = a2port(fwdargs[0].arg);
2250: fwd->connect_path = xstrdup(fwdargs[1].arg);
2251: fwd->connect_port = PORT_STREAMLOCAL;
2252: } else {
2253: fwd->listen_host = xstrdup(fwdargs[0].arg);
2254: fwd->listen_port = a2port(fwdargs[1].arg);
2255: fwd->connect_host = xstrdup("socks");
2256: }
1.168 stevesk 2257: break;
2258:
1.135 djm 2259: case 3:
1.220 millert 2260: if (fwdargs[0].ispath) {
2261: fwd->listen_path = xstrdup(fwdargs[0].arg);
2262: fwd->listen_port = PORT_STREAMLOCAL;
2263: fwd->connect_host = xstrdup(fwdargs[1].arg);
2264: fwd->connect_port = a2port(fwdargs[2].arg);
2265: } else if (fwdargs[2].ispath) {
2266: fwd->listen_host = xstrdup(fwdargs[0].arg);
2267: fwd->listen_port = a2port(fwdargs[1].arg);
2268: fwd->connect_path = xstrdup(fwdargs[2].arg);
2269: fwd->connect_port = PORT_STREAMLOCAL;
2270: } else {
2271: fwd->listen_host = NULL;
2272: fwd->listen_port = a2port(fwdargs[0].arg);
2273: fwd->connect_host = xstrdup(fwdargs[1].arg);
2274: fwd->connect_port = a2port(fwdargs[2].arg);
2275: }
1.135 djm 2276: break;
2277:
2278: case 4:
1.220 millert 2279: fwd->listen_host = xstrdup(fwdargs[0].arg);
2280: fwd->listen_port = a2port(fwdargs[1].arg);
2281: fwd->connect_host = xstrdup(fwdargs[2].arg);
2282: fwd->connect_port = a2port(fwdargs[3].arg);
1.135 djm 2283: break;
2284: default:
2285: i = 0; /* failure */
2286: }
2287:
1.202 djm 2288: free(p);
1.135 djm 2289:
1.168 stevesk 2290: if (dynamicfwd) {
2291: if (!(i == 1 || i == 2))
2292: goto fail_free;
2293: } else {
1.220 millert 2294: if (!(i == 3 || i == 4)) {
2295: if (fwd->connect_path == NULL &&
2296: fwd->listen_path == NULL)
2297: goto fail_free;
2298: }
2299: if (fwd->connect_port <= 0 && fwd->connect_path == NULL)
1.168 stevesk 2300: goto fail_free;
2301: }
2302:
1.220 millert 2303: if ((fwd->listen_port < 0 && fwd->listen_path == NULL) ||
2304: (!remotefwd && fwd->listen_port == 0))
1.135 djm 2305: goto fail_free;
2306: if (fwd->connect_host != NULL &&
2307: strlen(fwd->connect_host) >= NI_MAXHOST)
2308: goto fail_free;
1.220 millert 2309: /* XXX - if connecting to a remote socket, max sun len may not match this host */
2310: if (fwd->connect_path != NULL &&
2311: strlen(fwd->connect_path) >= PATH_MAX_SUN)
2312: goto fail_free;
1.176 djm 2313: if (fwd->listen_host != NULL &&
2314: strlen(fwd->listen_host) >= NI_MAXHOST)
2315: goto fail_free;
1.220 millert 2316: if (fwd->listen_path != NULL &&
2317: strlen(fwd->listen_path) >= PATH_MAX_SUN)
2318: goto fail_free;
1.135 djm 2319:
2320: return (i);
2321:
2322: fail_free:
1.202 djm 2323: free(fwd->connect_host);
2324: fwd->connect_host = NULL;
1.220 millert 2325: free(fwd->connect_path);
2326: fwd->connect_path = NULL;
1.202 djm 2327: free(fwd->listen_host);
2328: fwd->listen_host = NULL;
1.220 millert 2329: free(fwd->listen_path);
2330: fwd->listen_path = NULL;
1.135 djm 2331: return (0);
1.221 djm 2332: }
2333:
1.257 djm 2334: int
2335: parse_jump(const char *s, Options *o, int active)
2336: {
2337: char *orig, *sdup, *cp;
2338: char *host = NULL, *user = NULL;
1.258 naddy 2339: int ret = -1, port = -1, first;
1.257 djm 2340:
2341: active &= o->proxy_command == NULL && o->jump_host == NULL;
2342:
2343: orig = sdup = xstrdup(s);
1.258 naddy 2344: first = active;
1.259 djm 2345: do {
1.287 djm 2346: if (strcasecmp(s, "none") == 0)
2347: break;
1.259 djm 2348: if ((cp = strrchr(sdup, ',')) == NULL)
2349: cp = sdup; /* last */
2350: else
2351: *cp++ = '\0';
2352:
1.258 naddy 2353: if (first) {
1.257 djm 2354: /* First argument and configuration is active */
1.280 millert 2355: if (parse_ssh_uri(cp, &user, &host, &port) == -1 ||
2356: parse_user_host_port(cp, &user, &host, &port) != 0)
1.257 djm 2357: goto out;
2358: } else {
2359: /* Subsequent argument or inactive configuration */
1.280 millert 2360: if (parse_ssh_uri(cp, NULL, NULL, NULL) == -1 ||
2361: parse_user_host_port(cp, NULL, NULL, NULL) != 0)
1.257 djm 2362: goto out;
2363: }
1.258 naddy 2364: first = 0; /* only check syntax for subsequent hosts */
1.259 djm 2365: } while (cp != sdup);
1.257 djm 2366: /* success */
1.258 naddy 2367: if (active) {
1.287 djm 2368: if (strcasecmp(s, "none") == 0) {
2369: o->jump_host = xstrdup("none");
2370: o->jump_port = 0;
2371: } else {
2372: o->jump_user = user;
2373: o->jump_host = host;
2374: o->jump_port = port;
2375: o->proxy_command = xstrdup("none");
2376: user = host = NULL;
2377: if ((cp = strrchr(s, ',')) != NULL && cp != s) {
2378: o->jump_extra = xstrdup(s);
2379: o->jump_extra[cp - s] = '\0';
2380: }
1.259 djm 2381: }
1.258 naddy 2382: }
1.257 djm 2383: ret = 0;
2384: out:
1.258 naddy 2385: free(orig);
1.257 djm 2386: free(user);
2387: free(host);
2388: return ret;
1.280 millert 2389: }
2390:
2391: int
2392: parse_ssh_uri(const char *uri, char **userp, char **hostp, int *portp)
2393: {
2394: char *path;
2395: int r;
2396:
2397: r = parse_uri("ssh", uri, userp, hostp, portp, &path);
2398: if (r == 0 && path != NULL)
2399: r = -1; /* path not allowed */
2400: return r;
1.257 djm 2401: }
2402:
1.221 djm 2403: /* XXX the following is a near-vebatim copy from servconf.c; refactor */
2404: static const char *
2405: fmt_multistate_int(int val, const struct multistate *m)
2406: {
2407: u_int i;
2408:
2409: for (i = 0; m[i].key != NULL; i++) {
2410: if (m[i].value == val)
2411: return m[i].key;
2412: }
2413: return "UNKNOWN";
2414: }
2415:
2416: static const char *
2417: fmt_intarg(OpCodes code, int val)
2418: {
2419: if (val == -1)
2420: return "unset";
2421: switch (code) {
2422: case oAddressFamily:
2423: return fmt_multistate_int(val, multistate_addressfamily);
2424: case oVerifyHostKeyDNS:
1.232 djm 2425: case oUpdateHostkeys:
1.221 djm 2426: return fmt_multistate_int(val, multistate_yesnoask);
1.278 djm 2427: case oStrictHostKeyChecking:
2428: return fmt_multistate_int(val, multistate_strict_hostkey);
1.221 djm 2429: case oControlMaster:
2430: return fmt_multistate_int(val, multistate_controlmaster);
2431: case oTunnel:
2432: return fmt_multistate_int(val, multistate_tunnel);
2433: case oRequestTTY:
2434: return fmt_multistate_int(val, multistate_requesttty);
2435: case oCanonicalizeHostname:
2436: return fmt_multistate_int(val, multistate_canonicalizehostname);
1.285 djm 2437: case oAddKeysToAgent:
2438: return fmt_multistate_int(val, multistate_yesnoaskconfirm);
1.224 djm 2439: case oFingerprintHash:
2440: return ssh_digest_alg_name(val);
1.221 djm 2441: default:
2442: switch (val) {
2443: case 0:
2444: return "no";
2445: case 1:
2446: return "yes";
2447: default:
2448: return "UNKNOWN";
2449: }
2450: }
2451: }
2452:
2453: static const char *
2454: lookup_opcode_name(OpCodes code)
2455: {
2456: u_int i;
2457:
2458: for (i = 0; keywords[i].name != NULL; i++)
2459: if (keywords[i].opcode == code)
2460: return(keywords[i].name);
2461: return "UNKNOWN";
2462: }
2463:
2464: static void
2465: dump_cfg_int(OpCodes code, int val)
2466: {
2467: printf("%s %d\n", lookup_opcode_name(code), val);
2468: }
2469:
2470: static void
2471: dump_cfg_fmtint(OpCodes code, int val)
2472: {
2473: printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
2474: }
2475:
2476: static void
2477: dump_cfg_string(OpCodes code, const char *val)
2478: {
2479: if (val == NULL)
2480: return;
2481: printf("%s %s\n", lookup_opcode_name(code), val);
2482: }
2483:
2484: static void
2485: dump_cfg_strarray(OpCodes code, u_int count, char **vals)
2486: {
2487: u_int i;
2488:
2489: for (i = 0; i < count; i++)
2490: printf("%s %s\n", lookup_opcode_name(code), vals[i]);
2491: }
2492:
2493: static void
2494: dump_cfg_strarray_oneline(OpCodes code, u_int count, char **vals)
2495: {
2496: u_int i;
2497:
2498: printf("%s", lookup_opcode_name(code));
2499: for (i = 0; i < count; i++)
2500: printf(" %s", vals[i]);
2501: printf("\n");
2502: }
2503:
2504: static void
2505: dump_cfg_forwards(OpCodes code, u_int count, const struct Forward *fwds)
2506: {
2507: const struct Forward *fwd;
2508: u_int i;
2509:
2510: /* oDynamicForward */
2511: for (i = 0; i < count; i++) {
2512: fwd = &fwds[i];
1.265 djm 2513: if (code == oDynamicForward && fwd->connect_host != NULL &&
1.221 djm 2514: strcmp(fwd->connect_host, "socks") != 0)
2515: continue;
1.265 djm 2516: if (code == oLocalForward && fwd->connect_host != NULL &&
1.221 djm 2517: strcmp(fwd->connect_host, "socks") == 0)
2518: continue;
2519: printf("%s", lookup_opcode_name(code));
2520: if (fwd->listen_port == PORT_STREAMLOCAL)
2521: printf(" %s", fwd->listen_path);
2522: else if (fwd->listen_host == NULL)
2523: printf(" %d", fwd->listen_port);
2524: else {
2525: printf(" [%s]:%d",
2526: fwd->listen_host, fwd->listen_port);
2527: }
2528: if (code != oDynamicForward) {
2529: if (fwd->connect_port == PORT_STREAMLOCAL)
2530: printf(" %s", fwd->connect_path);
2531: else if (fwd->connect_host == NULL)
2532: printf(" %d", fwd->connect_port);
2533: else {
2534: printf(" [%s]:%d",
2535: fwd->connect_host, fwd->connect_port);
2536: }
2537: }
2538: printf("\n");
2539: }
2540: }
2541:
2542: void
2543: dump_client_config(Options *o, const char *host)
2544: {
2545: int i;
1.292 djm 2546: char buf[8], *all_key;
1.221 djm 2547:
1.240 djm 2548: /* This is normally prepared in ssh_kex2 */
1.292 djm 2549: all_key = sshkey_alg_list(0, 0, 1, ',');
2550: if (kex_assemble_names( &o->hostkeyalgorithms,
2551: KEX_DEFAULT_PK_ALG, all_key) != 0)
1.240 djm 2552: fatal("%s: kex_assemble_names failed", __func__);
1.292 djm 2553: free(all_key);
1.240 djm 2554:
1.221 djm 2555: /* Most interesting options first: user, host, port */
2556: dump_cfg_string(oUser, o->user);
2557: dump_cfg_string(oHostName, host);
2558: dump_cfg_int(oPort, o->port);
2559:
2560: /* Flag options */
1.285 djm 2561: dump_cfg_fmtint(oAddKeysToAgent, o->add_keys_to_agent);
1.221 djm 2562: dump_cfg_fmtint(oAddressFamily, o->address_family);
2563: dump_cfg_fmtint(oBatchMode, o->batch_mode);
2564: dump_cfg_fmtint(oCanonicalizeFallbackLocal, o->canonicalize_fallback_local);
2565: dump_cfg_fmtint(oCanonicalizeHostname, o->canonicalize_hostname);
2566: dump_cfg_fmtint(oChallengeResponseAuthentication, o->challenge_response_authentication);
2567: dump_cfg_fmtint(oCheckHostIP, o->check_host_ip);
2568: dump_cfg_fmtint(oCompression, o->compression);
2569: dump_cfg_fmtint(oControlMaster, o->control_master);
2570: dump_cfg_fmtint(oEnableSSHKeysign, o->enable_ssh_keysign);
1.256 dtucker 2571: dump_cfg_fmtint(oClearAllForwardings, o->clear_forwardings);
1.221 djm 2572: dump_cfg_fmtint(oExitOnForwardFailure, o->exit_on_forward_failure);
1.224 djm 2573: dump_cfg_fmtint(oFingerprintHash, o->fingerprint_hash);
1.221 djm 2574: dump_cfg_fmtint(oForwardAgent, o->forward_agent);
2575: dump_cfg_fmtint(oForwardX11, o->forward_x11);
2576: dump_cfg_fmtint(oForwardX11Trusted, o->forward_x11_trusted);
2577: dump_cfg_fmtint(oGatewayPorts, o->fwd_opts.gateway_ports);
2578: #ifdef GSSAPI
2579: dump_cfg_fmtint(oGssAuthentication, o->gss_authentication);
2580: dump_cfg_fmtint(oGssDelegateCreds, o->gss_deleg_creds);
2581: #endif /* GSSAPI */
2582: dump_cfg_fmtint(oHashKnownHosts, o->hash_known_hosts);
2583: dump_cfg_fmtint(oHostbasedAuthentication, o->hostbased_authentication);
2584: dump_cfg_fmtint(oIdentitiesOnly, o->identities_only);
2585: dump_cfg_fmtint(oKbdInteractiveAuthentication, o->kbd_interactive_authentication);
2586: dump_cfg_fmtint(oNoHostAuthenticationForLocalhost, o->no_host_authentication_for_localhost);
2587: dump_cfg_fmtint(oPasswordAuthentication, o->password_authentication);
2588: dump_cfg_fmtint(oPermitLocalCommand, o->permit_local_command);
2589: dump_cfg_fmtint(oProxyUseFdpass, o->proxy_use_fdpass);
2590: dump_cfg_fmtint(oPubkeyAuthentication, o->pubkey_authentication);
2591: dump_cfg_fmtint(oRequestTTY, o->request_tty);
2592: dump_cfg_fmtint(oStreamLocalBindUnlink, o->fwd_opts.streamlocal_bind_unlink);
2593: dump_cfg_fmtint(oStrictHostKeyChecking, o->strict_host_key_checking);
2594: dump_cfg_fmtint(oTCPKeepAlive, o->tcp_keep_alive);
2595: dump_cfg_fmtint(oTunnel, o->tun_open);
2596: dump_cfg_fmtint(oVerifyHostKeyDNS, o->verify_host_key_dns);
2597: dump_cfg_fmtint(oVisualHostKey, o->visual_host_key);
1.229 djm 2598: dump_cfg_fmtint(oUpdateHostkeys, o->update_hostkeys);
1.221 djm 2599:
2600: /* Integer options */
2601: dump_cfg_int(oCanonicalizeMaxDots, o->canonicalize_max_dots);
2602: dump_cfg_int(oConnectionAttempts, o->connection_attempts);
2603: dump_cfg_int(oForwardX11Timeout, o->forward_x11_timeout);
2604: dump_cfg_int(oNumberOfPasswordPrompts, o->number_of_password_prompts);
2605: dump_cfg_int(oServerAliveCountMax, o->server_alive_count_max);
2606: dump_cfg_int(oServerAliveInterval, o->server_alive_interval);
2607:
2608: /* String options */
2609: dump_cfg_string(oBindAddress, o->bind_address);
1.282 djm 2610: dump_cfg_string(oBindInterface, o->bind_interface);
1.221 djm 2611: dump_cfg_string(oCiphers, o->ciphers ? o->ciphers : KEX_CLIENT_ENCRYPT);
2612: dump_cfg_string(oControlPath, o->control_path);
1.240 djm 2613: dump_cfg_string(oHostKeyAlgorithms, o->hostkeyalgorithms);
1.221 djm 2614: dump_cfg_string(oHostKeyAlias, o->host_key_alias);
1.230 djm 2615: dump_cfg_string(oHostbasedKeyTypes, o->hostbased_key_types);
1.253 markus 2616: dump_cfg_string(oIdentityAgent, o->identity_agent);
1.285 djm 2617: dump_cfg_string(oIgnoreUnknown, o->ignored_unknown);
1.221 djm 2618: dump_cfg_string(oKbdInteractiveDevices, o->kbd_interactive_devices);
2619: dump_cfg_string(oKexAlgorithms, o->kex_algorithms ? o->kex_algorithms : KEX_CLIENT_KEX);
1.298 djm 2620: dump_cfg_string(oCASignatureAlgorithms, o->ca_sign_algorithms ? o->ca_sign_algorithms : SSH_ALLOWED_CA_SIGALGS);
1.221 djm 2621: dump_cfg_string(oLocalCommand, o->local_command);
1.277 bluhm 2622: dump_cfg_string(oRemoteCommand, o->remote_command);
1.221 djm 2623: dump_cfg_string(oLogLevel, log_level_name(o->log_level));
2624: dump_cfg_string(oMacs, o->macs ? o->macs : KEX_CLIENT_MAC);
1.266 djm 2625: #ifdef ENABLE_PKCS11
1.221 djm 2626: dump_cfg_string(oPKCS11Provider, o->pkcs11_provider);
1.266 djm 2627: #endif
1.221 djm 2628: dump_cfg_string(oPreferredAuthentications, o->preferred_authentications);
1.242 djm 2629: dump_cfg_string(oPubkeyAcceptedKeyTypes, o->pubkey_key_types);
1.230 djm 2630: dump_cfg_string(oRevokedHostKeys, o->revoked_host_keys);
1.221 djm 2631: dump_cfg_string(oXAuthLocation, o->xauth_location);
2632:
1.230 djm 2633: /* Forwards */
1.221 djm 2634: dump_cfg_forwards(oDynamicForward, o->num_local_forwards, o->local_forwards);
2635: dump_cfg_forwards(oLocalForward, o->num_local_forwards, o->local_forwards);
2636: dump_cfg_forwards(oRemoteForward, o->num_remote_forwards, o->remote_forwards);
2637:
2638: /* String array options */
2639: dump_cfg_strarray(oIdentityFile, o->num_identity_files, o->identity_files);
2640: dump_cfg_strarray_oneline(oCanonicalDomains, o->num_canonical_domains, o->canonical_domains);
1.285 djm 2641: dump_cfg_strarray(oCertificateFile, o->num_certificate_files, o->certificate_files);
1.221 djm 2642: dump_cfg_strarray_oneline(oGlobalKnownHostsFile, o->num_system_hostfiles, o->system_hostfiles);
2643: dump_cfg_strarray_oneline(oUserKnownHostsFile, o->num_user_hostfiles, o->user_hostfiles);
2644: dump_cfg_strarray(oSendEnv, o->num_send_env, o->send_env);
1.290 djm 2645: dump_cfg_strarray(oSetEnv, o->num_setenv, o->setenv);
1.221 djm 2646:
2647: /* Special cases */
2648:
2649: /* oConnectTimeout */
2650: if (o->connection_timeout == -1)
2651: printf("connecttimeout none\n");
2652: else
2653: dump_cfg_int(oConnectTimeout, o->connection_timeout);
2654:
2655: /* oTunnelDevice */
2656: printf("tunneldevice");
2657: if (o->tun_local == SSH_TUNID_ANY)
2658: printf(" any");
2659: else
2660: printf(" %d", o->tun_local);
2661: if (o->tun_remote == SSH_TUNID_ANY)
2662: printf(":any");
2663: else
2664: printf(":%d", o->tun_remote);
2665: printf("\n");
2666:
2667: /* oCanonicalizePermittedCNAMEs */
2668: if ( o->num_permitted_cnames > 0) {
2669: printf("canonicalizePermittedcnames");
2670: for (i = 0; i < o->num_permitted_cnames; i++) {
2671: printf(" %s:%s", o->permitted_cnames[i].source_list,
2672: o->permitted_cnames[i].target_list);
2673: }
2674: printf("\n");
2675: }
2676:
2677: /* oControlPersist */
2678: if (o->control_persist == 0 || o->control_persist_timeout == 0)
2679: dump_cfg_fmtint(oControlPersist, o->control_persist);
2680: else
2681: dump_cfg_int(oControlPersist, o->control_persist_timeout);
2682:
2683: /* oEscapeChar */
2684: if (o->escape_char == SSH_ESCAPECHAR_NONE)
2685: printf("escapechar none\n");
2686: else {
1.257 djm 2687: vis(buf, o->escape_char, VIS_WHITE, 0);
2688: printf("escapechar %s\n", buf);
1.221 djm 2689: }
2690:
2691: /* oIPQoS */
2692: printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
2693: printf("%s\n", iptos2str(o->ip_qos_bulk));
2694:
2695: /* oRekeyLimit */
1.249 dtucker 2696: printf("rekeylimit %llu %d\n",
2697: (unsigned long long)o->rekey_limit, o->rekey_interval);
1.221 djm 2698:
2699: /* oStreamLocalBindMask */
2700: printf("streamlocalbindmask 0%o\n",
2701: o->fwd_opts.streamlocal_bind_mask);
1.285 djm 2702:
2703: /* oLogFacility */
2704: printf("syslogfacility %s\n", log_facility_name(o->log_facility));
1.257 djm 2705:
2706: /* oProxyCommand / oProxyJump */
2707: if (o->jump_host == NULL)
2708: dump_cfg_string(oProxyCommand, o->proxy_command);
2709: else {
2710: /* Check for numeric addresses */
2711: i = strchr(o->jump_host, ':') != NULL ||
2712: strspn(o->jump_host, "1234567890.") == strlen(o->jump_host);
2713: snprintf(buf, sizeof(buf), "%d", o->jump_port);
2714: printf("proxyjump %s%s%s%s%s%s%s%s%s\n",
1.259 djm 2715: /* optional additional jump spec */
2716: o->jump_extra == NULL ? "" : o->jump_extra,
2717: o->jump_extra == NULL ? "" : ",",
1.257 djm 2718: /* optional user */
2719: o->jump_user == NULL ? "" : o->jump_user,
2720: o->jump_user == NULL ? "" : "@",
2721: /* opening [ if hostname is numeric */
2722: i ? "[" : "",
2723: /* mandatory hostname */
2724: o->jump_host,
2725: /* closing ] if hostname is numeric */
2726: i ? "]" : "",
2727: /* optional port number */
2728: o->jump_port <= 0 ? "" : ":",
1.259 djm 2729: o->jump_port <= 0 ? "" : buf);
1.257 djm 2730: }
1.1 deraadt 2731: }