Annotation of src/usr.bin/ssh/readconf.c, Revision 1.301
1.301 ! djm 1: /* $OpenBSD: readconf.c,v 1.300 2018/10/05 14:26:09 naddy 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:
1.300 naddy 1146: arg = strdelim(&s);
1147: if (!arg || *arg == '\0')
1148: fatal("%.200s line %d: Missing argument.",
1149: filename, linenum);
1150: value = a2port(arg);
1151: if (value <= 0)
1152: fatal("%.200s line %d: Bad port '%s'.",
1153: filename, linenum, arg);
1154: if (*activep && options->port == -1)
1155: options->port = value;
1156: break;
1157:
1158: case oConnectionAttempts:
1159: intptr = &options->connection_attempts;
1.17 markus 1160: parse_int:
1.42 provos 1161: arg = strdelim(&s);
1.281 dtucker 1162: if ((errstr = atoi_err(arg, &value)) != NULL)
1163: fatal("%s line %d: integer value %s.",
1164: filename, linenum, errstr);
1.17 markus 1165: if (*activep && *intptr == -1)
1166: *intptr = value;
1167: break;
1168:
1.25 markus 1169: case oCiphers:
1.42 provos 1170: arg = strdelim(&s);
1.40 ho 1171: if (!arg || *arg == '\0')
1.32 markus 1172: fatal("%.200s line %d: Missing argument.", filename, linenum);
1.268 djm 1173: if (*arg != '-' && !ciphers_valid(*arg == '+' ? arg + 1 : arg))
1.31 markus 1174: fatal("%.200s line %d: Bad SSH2 cipher spec '%s'.",
1.93 deraadt 1175: filename, linenum, arg ? arg : "<NONE>");
1.25 markus 1176: if (*activep && options->ciphers == NULL)
1.38 provos 1177: options->ciphers = xstrdup(arg);
1.25 markus 1178: break;
1179:
1.62 markus 1180: case oMacs:
1181: arg = strdelim(&s);
1182: if (!arg || *arg == '\0')
1183: fatal("%.200s line %d: Missing argument.", filename, linenum);
1.268 djm 1184: if (*arg != '-' && !mac_valid(*arg == '+' ? arg + 1 : arg))
1.62 markus 1185: fatal("%.200s line %d: Bad SSH2 Mac spec '%s'.",
1.93 deraadt 1186: filename, linenum, arg ? arg : "<NONE>");
1.62 markus 1187: if (*activep && options->macs == NULL)
1188: options->macs = xstrdup(arg);
1189: break;
1190:
1.189 djm 1191: case oKexAlgorithms:
1192: arg = strdelim(&s);
1193: if (!arg || *arg == '\0')
1194: fatal("%.200s line %d: Missing argument.",
1195: filename, linenum);
1.268 djm 1196: if (*arg != '-' &&
1197: !kex_names_valid(*arg == '+' ? arg + 1 : arg))
1.189 djm 1198: fatal("%.200s line %d: Bad SSH2 KexAlgorithms '%s'.",
1199: filename, linenum, arg ? arg : "<NONE>");
1200: if (*activep && options->kex_algorithms == NULL)
1201: options->kex_algorithms = xstrdup(arg);
1202: break;
1203:
1.76 markus 1204: case oHostKeyAlgorithms:
1.238 markus 1205: charptr = &options->hostkeyalgorithms;
1206: parse_keytypes:
1.76 markus 1207: arg = strdelim(&s);
1208: if (!arg || *arg == '\0')
1.238 markus 1209: fatal("%.200s line %d: Missing argument.",
1210: filename, linenum);
1.268 djm 1211: if (*arg != '-' &&
1212: !sshkey_names_valid2(*arg == '+' ? arg + 1 : arg, 1))
1.238 markus 1213: fatal("%s line %d: Bad key types '%s'.",
1214: filename, linenum, arg ? arg : "<NONE>");
1215: if (*activep && *charptr == NULL)
1216: *charptr = xstrdup(arg);
1.76 markus 1217: break;
1218:
1.298 djm 1219: case oCASignatureAlgorithms:
1220: charptr = &options->ca_sign_algorithms;
1221: goto parse_keytypes;
1222:
1.17 markus 1223: case oLogLevel:
1.164 dtucker 1224: log_level_ptr = &options->log_level;
1.42 provos 1225: arg = strdelim(&s);
1.38 provos 1226: value = log_level_number(arg);
1.95 markus 1227: if (value == SYSLOG_LEVEL_NOT_SET)
1.64 millert 1228: fatal("%.200s line %d: unsupported log level '%s'",
1.93 deraadt 1229: filename, linenum, arg ? arg : "<NONE>");
1.164 dtucker 1230: if (*activep && *log_level_ptr == SYSLOG_LEVEL_NOT_SET)
1231: *log_level_ptr = (LogLevel) value;
1.17 markus 1232: break;
1233:
1.271 dtucker 1234: case oLogFacility:
1235: log_facility_ptr = &options->log_facility;
1236: arg = strdelim(&s);
1237: value = log_facility_number(arg);
1238: if (value == SYSLOG_FACILITY_NOT_SET)
1239: fatal("%.200s line %d: unsupported log facility '%s'",
1240: filename, linenum, arg ? arg : "<NONE>");
1241: if (*log_facility_ptr == -1)
1242: *log_facility_ptr = (SyslogFacility) value;
1243: break;
1244:
1.88 stevesk 1245: case oLocalForward:
1.17 markus 1246: case oRemoteForward:
1.168 stevesk 1247: case oDynamicForward:
1.42 provos 1248: arg = strdelim(&s);
1.135 djm 1249: if (arg == NULL || *arg == '\0')
1.88 stevesk 1250: fatal("%.200s line %d: Missing port argument.",
1251: filename, linenum);
1.135 djm 1252:
1.279 markus 1253: remotefwd = (opcode == oRemoteForward);
1254: dynamicfwd = (opcode == oDynamicForward);
1255:
1256: if (!dynamicfwd) {
1.168 stevesk 1257: arg2 = strdelim(&s);
1.279 markus 1258: if (arg2 == NULL || *arg2 == '\0') {
1259: if (remotefwd)
1260: dynamicfwd = 1;
1261: else
1262: fatal("%.200s line %d: Missing target "
1263: "argument.", filename, linenum);
1264: } else {
1265: /* construct a string for parse_forward */
1266: snprintf(fwdarg, sizeof(fwdarg), "%s:%s", arg,
1267: arg2);
1268: }
1269: }
1270: if (dynamicfwd)
1.168 stevesk 1271: strlcpy(fwdarg, arg, sizeof(fwdarg));
1272:
1.279 markus 1273: if (parse_forward(&fwd, fwdarg, dynamicfwd, remotefwd) == 0)
1.88 stevesk 1274: fatal("%.200s line %d: Bad forwarding specification.",
1275: filename, linenum);
1.135 djm 1276:
1.88 stevesk 1277: if (*activep) {
1.279 markus 1278: if (remotefwd) {
1279: add_remote_forward(options, &fwd);
1280: } else {
1.135 djm 1281: add_local_forward(options, &fwd);
1.279 markus 1282: }
1.88 stevesk 1283: }
1.17 markus 1284: break;
1.71 markus 1285:
1.90 stevesk 1286: case oClearAllForwardings:
1287: intptr = &options->clear_forwardings;
1288: goto parse_flag;
1289:
1.17 markus 1290: case oHost:
1.206 djm 1291: if (cmdline)
1292: fatal("Host directive not supported as a command-line "
1293: "option");
1.17 markus 1294: *activep = 0;
1.191 djm 1295: arg2 = NULL;
1296: while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1.252 djm 1297: if ((flags & SSHCONF_NEVERMATCH) != 0)
1298: break;
1.191 djm 1299: negated = *arg == '!';
1300: if (negated)
1301: arg++;
1.38 provos 1302: if (match_pattern(host, arg)) {
1.191 djm 1303: if (negated) {
1304: debug("%.200s line %d: Skipping Host "
1305: "block because of negated match "
1306: "for %.100s", filename, linenum,
1307: arg);
1308: *activep = 0;
1309: break;
1310: }
1311: if (!*activep)
1312: arg2 = arg; /* logged below */
1.17 markus 1313: *activep = 1;
1314: }
1.191 djm 1315: }
1316: if (*activep)
1317: debug("%.200s line %d: Applying options for %.100s",
1318: filename, linenum, arg2);
1.42 provos 1319: /* Avoid garbage check below, as strdelim is done. */
1.17 markus 1320: return 0;
1321:
1.206 djm 1322: case oMatch:
1323: if (cmdline)
1324: fatal("Host directive not supported as a command-line "
1325: "option");
1.221 djm 1326: value = match_cfg_line(options, &s, pw, host, original_host,
1327: flags & SSHCONF_POSTCANON, filename, linenum);
1.206 djm 1328: if (value < 0)
1329: fatal("%.200s line %d: Bad Match condition", filename,
1330: linenum);
1.252 djm 1331: *activep = (flags & SSHCONF_NEVERMATCH) ? 0 : value;
1.206 djm 1332: break;
1333:
1.17 markus 1334: case oEscapeChar:
1335: intptr = &options->escape_char;
1.42 provos 1336: arg = strdelim(&s);
1.40 ho 1337: if (!arg || *arg == '\0')
1.17 markus 1338: fatal("%.200s line %d: Missing argument.", filename, linenum);
1.236 djm 1339: if (strcmp(arg, "none") == 0)
1340: value = SSH_ESCAPECHAR_NONE;
1341: else if (arg[1] == '\0')
1342: value = (u_char) arg[0];
1343: else if (arg[0] == '^' && arg[2] == 0 &&
1.51 markus 1344: (u_char) arg[1] >= 64 && (u_char) arg[1] < 128)
1345: value = (u_char) arg[1] & 31;
1.17 markus 1346: else {
1347: fatal("%.200s line %d: Bad escape character.",
1.93 deraadt 1348: filename, linenum);
1.17 markus 1349: /* NOTREACHED */
1350: value = 0; /* Avoid compiler warning. */
1351: }
1352: if (*activep && *intptr == -1)
1353: *intptr = value;
1.112 djm 1354: break;
1355:
1356: case oAddressFamily:
1.114 djm 1357: intptr = &options->address_family;
1.207 djm 1358: multistate_ptr = multistate_addressfamily;
1359: goto parse_multistate;
1.17 markus 1360:
1.101 markus 1361: case oEnableSSHKeysign:
1362: intptr = &options->enable_ssh_keysign;
1363: goto parse_flag;
1364:
1.128 markus 1365: case oIdentitiesOnly:
1366: intptr = &options->identities_only;
1367: goto parse_flag;
1368:
1.127 markus 1369: case oServerAliveInterval:
1370: intptr = &options->server_alive_interval;
1371: goto parse_time;
1372:
1373: case oServerAliveCountMax:
1374: intptr = &options->server_alive_count_max;
1375: goto parse_int;
1376:
1.130 djm 1377: case oSendEnv:
1378: while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1379: if (strchr(arg, '=') != NULL)
1380: fatal("%s line %d: Invalid environment name.",
1381: filename, linenum);
1.137 djm 1382: if (!*activep)
1383: continue;
1.286 djm 1384: if (*arg == '-') {
1385: /* Removing an env var */
1386: rm_env(options, arg, filename, linenum);
1387: continue;
1388: } else {
1389: /* Adding an env var */
1.290 djm 1390: if (options->num_send_env >= INT_MAX)
1.286 djm 1391: fatal("%s line %d: too many send env.",
1392: filename, linenum);
1.290 djm 1393: options->send_env = xrecallocarray(
1394: options->send_env, options->num_send_env,
1.291 djm 1395: options->num_send_env + 1,
1.290 djm 1396: sizeof(*options->send_env));
1.286 djm 1397: options->send_env[options->num_send_env++] =
1398: xstrdup(arg);
1399: }
1.130 djm 1400: }
1401: break;
1402:
1.290 djm 1403: case oSetEnv:
1404: value = options->num_setenv;
1405: while ((arg = strdelimw(&s)) != NULL && *arg != '\0') {
1406: if (strchr(arg, '=') == NULL)
1407: fatal("%s line %d: Invalid SetEnv.",
1408: filename, linenum);
1409: if (!*activep || value != 0)
1410: continue;
1411: /* Adding a setenv var */
1412: if (options->num_setenv >= INT_MAX)
1413: fatal("%s line %d: too many SetEnv.",
1414: filename, linenum);
1415: options->setenv = xrecallocarray(
1416: options->setenv, options->num_setenv,
1417: options->num_setenv + 1, sizeof(*options->setenv));
1418: options->setenv[options->num_setenv++] = xstrdup(arg);
1419: }
1420: break;
1421:
1.132 djm 1422: case oControlPath:
1423: charptr = &options->control_path;
1424: goto parse_string;
1425:
1426: case oControlMaster:
1427: intptr = &options->control_master;
1.207 djm 1428: multistate_ptr = multistate_controlmaster;
1429: goto parse_multistate;
1.132 djm 1430:
1.187 djm 1431: case oControlPersist:
1432: /* no/false/yes/true, or a time spec */
1433: intptr = &options->control_persist;
1434: arg = strdelim(&s);
1435: if (!arg || *arg == '\0')
1436: fatal("%.200s line %d: Missing ControlPersist"
1437: " argument.", filename, linenum);
1438: value = 0;
1439: value2 = 0; /* timeout */
1440: if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
1441: value = 0;
1442: else if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
1443: value = 1;
1444: else if ((value2 = convtime(arg)) >= 0)
1445: value = 1;
1446: else
1447: fatal("%.200s line %d: Bad ControlPersist argument.",
1448: filename, linenum);
1449: if (*activep && *intptr == -1) {
1450: *intptr = value;
1451: options->control_persist_timeout = value2;
1452: }
1453: break;
1454:
1.136 djm 1455: case oHashKnownHosts:
1456: intptr = &options->hash_known_hosts;
1457: goto parse_flag;
1458:
1.144 reyk 1459: case oTunnel:
1460: intptr = &options->tun_open;
1.207 djm 1461: multistate_ptr = multistate_tunnel;
1462: goto parse_multistate;
1.144 reyk 1463:
1464: case oTunnelDevice:
1465: arg = strdelim(&s);
1466: if (!arg || *arg == '\0')
1467: fatal("%.200s line %d: Missing argument.", filename, linenum);
1468: value = a2tun(arg, &value2);
1.145 reyk 1469: if (value == SSH_TUNID_ERR)
1.144 reyk 1470: fatal("%.200s line %d: Bad tun device.", filename, linenum);
1471: if (*activep) {
1472: options->tun_local = value;
1473: options->tun_remote = value2;
1474: }
1475: break;
1476:
1477: case oLocalCommand:
1478: charptr = &options->local_command;
1479: goto parse_command;
1480:
1481: case oPermitLocalCommand:
1482: intptr = &options->permit_local_command;
1483: goto parse_flag;
1484:
1.277 bluhm 1485: case oRemoteCommand:
1486: charptr = &options->remote_command;
1487: goto parse_command;
1488:
1.167 grunk 1489: case oVisualHostKey:
1490: intptr = &options->visual_host_key;
1491: goto parse_flag;
1492:
1.252 djm 1493: case oInclude:
1494: if (cmdline)
1495: fatal("Include directive not supported as a "
1496: "command-line option");
1497: value = 0;
1498: while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1499: /*
1500: * Ensure all paths are anchored. User configuration
1501: * files may begin with '~/' but system configurations
1502: * must not. If the path is relative, then treat it
1503: * as living in ~/.ssh for user configurations or
1504: * /etc/ssh for system ones.
1505: */
1506: if (*arg == '~' && (flags & SSHCONF_USERCONF) == 0)
1507: fatal("%.200s line %d: bad include path %s.",
1508: filename, linenum, arg);
1.301 ! djm 1509: if (!path_absolute(arg) && *arg != '~') {
1.252 djm 1510: xasprintf(&arg2, "%s/%s",
1511: (flags & SSHCONF_USERCONF) ?
1512: "~/" _PATH_SSH_USER_DIR : SSHDIR, arg);
1513: } else
1514: arg2 = xstrdup(arg);
1515: memset(&gl, 0, sizeof(gl));
1516: r = glob(arg2, GLOB_TILDE, NULL, &gl);
1517: if (r == GLOB_NOMATCH) {
1518: debug("%.200s line %d: include %s matched no "
1519: "files",filename, linenum, arg2);
1.269 dtucker 1520: free(arg2);
1.252 djm 1521: continue;
1522: } else if (r != 0 || gl.gl_pathc < 0)
1523: fatal("%.200s line %d: glob failed for %s.",
1524: filename, linenum, arg2);
1525: free(arg2);
1526: oactive = *activep;
1527: for (i = 0; i < (u_int)gl.gl_pathc; i++) {
1528: debug3("%.200s line %d: Including file %s "
1529: "depth %d%s", filename, linenum,
1530: gl.gl_pathv[i], depth,
1531: oactive ? "" : " (parse only)");
1532: r = read_config_file_depth(gl.gl_pathv[i],
1533: pw, host, original_host, options,
1534: flags | SSHCONF_CHECKPERM |
1535: (oactive ? 0 : SSHCONF_NEVERMATCH),
1536: activep, depth + 1);
1.264 djm 1537: if (r != 1 && errno != ENOENT) {
1.263 djm 1538: fatal("Can't open user config file "
1539: "%.100s: %.100s", gl.gl_pathv[i],
1540: strerror(errno));
1541: }
1.252 djm 1542: /*
1543: * don't let Match in includes clobber the
1544: * containing file's Match state.
1545: */
1546: *activep = oactive;
1547: if (r != 1)
1548: value = -1;
1549: }
1550: globfree(&gl);
1551: }
1552: if (value != 0)
1553: return value;
1554: break;
1555:
1.190 djm 1556: case oIPQoS:
1557: arg = strdelim(&s);
1558: if ((value = parse_ipqos(arg)) == -1)
1559: fatal("%s line %d: Bad IPQoS value: %s",
1560: filename, linenum, arg);
1561: arg = strdelim(&s);
1562: if (arg == NULL)
1563: value2 = value;
1564: else if ((value2 = parse_ipqos(arg)) == -1)
1565: fatal("%s line %d: Bad IPQoS value: %s",
1566: filename, linenum, arg);
1567: if (*activep) {
1568: options->ip_qos_interactive = value;
1569: options->ip_qos_bulk = value2;
1570: }
1571: break;
1572:
1.192 djm 1573: case oRequestTTY:
1574: intptr = &options->request_tty;
1.207 djm 1575: multistate_ptr = multistate_requesttty;
1576: goto parse_multistate;
1.192 djm 1577:
1.199 djm 1578: case oIgnoreUnknown:
1579: charptr = &options->ignored_unknown;
1580: goto parse_string;
1581:
1.205 djm 1582: case oProxyUseFdpass:
1583: intptr = &options->proxy_use_fdpass;
1584: goto parse_flag;
1585:
1.208 djm 1586: case oCanonicalDomains:
1587: value = options->num_canonical_domains != 0;
1588: while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1.280 millert 1589: if (!valid_domain(arg, 1, &errstr)) {
1590: fatal("%s line %d: %s", filename, linenum,
1591: errstr);
1592: }
1.208 djm 1593: if (!*activep || value)
1594: continue;
1595: if (options->num_canonical_domains >= MAX_CANON_DOMAINS)
1596: fatal("%s line %d: too many hostname suffixes.",
1597: filename, linenum);
1598: options->canonical_domains[
1599: options->num_canonical_domains++] = xstrdup(arg);
1600: }
1601: break;
1602:
1.209 djm 1603: case oCanonicalizePermittedCNAMEs:
1.208 djm 1604: value = options->num_permitted_cnames != 0;
1605: while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1606: /* Either '*' for everything or 'list:list' */
1607: if (strcmp(arg, "*") == 0)
1608: arg2 = arg;
1609: else {
1610: lowercase(arg);
1611: if ((arg2 = strchr(arg, ':')) == NULL ||
1612: arg2[1] == '\0') {
1613: fatal("%s line %d: "
1614: "Invalid permitted CNAME \"%s\"",
1615: filename, linenum, arg);
1616: }
1617: *arg2 = '\0';
1618: arg2++;
1619: }
1620: if (!*activep || value)
1621: continue;
1622: if (options->num_permitted_cnames >= MAX_CANON_DOMAINS)
1623: fatal("%s line %d: too many permitted CNAMEs.",
1624: filename, linenum);
1625: cname = options->permitted_cnames +
1626: options->num_permitted_cnames++;
1627: cname->source_list = xstrdup(arg);
1628: cname->target_list = xstrdup(arg2);
1629: }
1630: break;
1631:
1.209 djm 1632: case oCanonicalizeHostname:
1633: intptr = &options->canonicalize_hostname;
1634: multistate_ptr = multistate_canonicalizehostname;
1.208 djm 1635: goto parse_multistate;
1636:
1.209 djm 1637: case oCanonicalizeMaxDots:
1638: intptr = &options->canonicalize_max_dots;
1.208 djm 1639: goto parse_int;
1640:
1.209 djm 1641: case oCanonicalizeFallbackLocal:
1642: intptr = &options->canonicalize_fallback_local;
1.208 djm 1643: goto parse_flag;
1644:
1.220 millert 1645: case oStreamLocalBindMask:
1646: arg = strdelim(&s);
1647: if (!arg || *arg == '\0')
1648: fatal("%.200s line %d: Missing StreamLocalBindMask argument.", filename, linenum);
1649: /* Parse mode in octal format */
1650: value = strtol(arg, &endofnumber, 8);
1651: if (arg == endofnumber || value < 0 || value > 0777)
1652: fatal("%.200s line %d: Bad mask.", filename, linenum);
1653: options->fwd_opts.streamlocal_bind_mask = (mode_t)value;
1654: break;
1655:
1656: case oStreamLocalBindUnlink:
1657: intptr = &options->fwd_opts.streamlocal_bind_unlink;
1658: goto parse_flag;
1659:
1.223 djm 1660: case oRevokedHostKeys:
1661: charptr = &options->revoked_host_keys;
1662: goto parse_string;
1663:
1.224 djm 1664: case oFingerprintHash:
1.225 djm 1665: intptr = &options->fingerprint_hash;
1.224 djm 1666: arg = strdelim(&s);
1667: if (!arg || *arg == '\0')
1668: fatal("%.200s line %d: Missing argument.",
1669: filename, linenum);
1670: if ((value = ssh_digest_alg_by_name(arg)) == -1)
1671: fatal("%.200s line %d: Invalid hash algorithm \"%s\".",
1672: filename, linenum, arg);
1.225 djm 1673: if (*activep && *intptr == -1)
1674: *intptr = value;
1.224 djm 1675: break;
1676:
1.229 djm 1677: case oUpdateHostkeys:
1678: intptr = &options->update_hostkeys;
1.232 djm 1679: multistate_ptr = multistate_yesnoask;
1680: goto parse_multistate;
1.229 djm 1681:
1.230 djm 1682: case oHostbasedKeyTypes:
1683: charptr = &options->hostbased_key_types;
1.238 markus 1684: goto parse_keytypes;
1685:
1686: case oPubkeyAcceptedKeyTypes:
1687: charptr = &options->pubkey_key_types;
1688: goto parse_keytypes;
1.230 djm 1689:
1.246 jcs 1690: case oAddKeysToAgent:
1691: intptr = &options->add_keys_to_agent;
1692: multistate_ptr = multistate_yesnoaskconfirm;
1693: goto parse_multistate;
1694:
1.253 markus 1695: case oIdentityAgent:
1696: charptr = &options->identity_agent;
1.299 djm 1697: arg = strdelim(&s);
1698: if (!arg || *arg == '\0')
1699: fatal("%.200s line %d: Missing argument.",
1700: filename, linenum);
1701: /* Extra validation if the string represents an env var. */
1702: if (arg[0] == '$' && !valid_env_name(arg + 1)) {
1703: fatal("%.200s line %d: Invalid environment name %s.",
1704: filename, linenum, arg);
1705: }
1706: if (*activep && *charptr == NULL)
1707: *charptr = xstrdup(arg);
1708: break;
1.253 markus 1709:
1.96 markus 1710: case oDeprecated:
1.98 markus 1711: debug("%s line %d: Deprecated option \"%s\"",
1.96 markus 1712: filename, linenum, keyword);
1.98 markus 1713: return 0;
1.96 markus 1714:
1.110 jakob 1715: case oUnsupported:
1716: error("%s line %d: Unsupported option \"%s\"",
1717: filename, linenum, keyword);
1718: return 0;
1719:
1.17 markus 1720: default:
1.221 djm 1721: fatal("%s: Unimplemented opcode %d", __func__, opcode);
1.17 markus 1722: }
1723:
1724: /* Check that there is no garbage at end of line. */
1.57 djm 1725: if ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1.39 ho 1726: fatal("%.200s line %d: garbage at end of line; \"%.200s\".",
1.142 djm 1727: filename, linenum, arg);
1.39 ho 1728: }
1.17 markus 1729: return 0;
1.1 deraadt 1730: }
1731:
1.19 markus 1732: /*
1733: * Reads the config file and modifies the options accordingly. Options
1734: * should already be initialized before this call. This never returns if
1.89 stevesk 1735: * there is an error. If the file does not exist, this returns 0.
1.19 markus 1736: */
1.89 stevesk 1737: int
1.206 djm 1738: read_config_file(const char *filename, struct passwd *pw, const char *host,
1.221 djm 1739: const char *original_host, Options *options, int flags)
1.1 deraadt 1740: {
1.252 djm 1741: int active = 1;
1742:
1743: return read_config_file_depth(filename, pw, host, original_host,
1744: options, flags, &active, 0);
1745: }
1746:
1747: #define READCONF_MAX_DEPTH 16
1748: static int
1749: read_config_file_depth(const char *filename, struct passwd *pw,
1750: const char *host, const char *original_host, Options *options,
1751: int flags, int *activep, int depth)
1752: {
1.17 markus 1753: FILE *f;
1.289 markus 1754: char *line = NULL;
1755: size_t linesize = 0;
1.252 djm 1756: int linenum;
1.17 markus 1757: int bad_options = 0;
1758:
1.252 djm 1759: if (depth < 0 || depth > READCONF_MAX_DEPTH)
1760: fatal("Too many recursive configuration includes");
1761:
1.129 djm 1762: if ((f = fopen(filename, "r")) == NULL)
1.89 stevesk 1763: return 0;
1.129 djm 1764:
1.196 dtucker 1765: if (flags & SSHCONF_CHECKPERM) {
1.129 djm 1766: struct stat sb;
1.134 deraadt 1767:
1.131 dtucker 1768: if (fstat(fileno(f), &sb) == -1)
1.129 djm 1769: fatal("fstat %s: %s", filename, strerror(errno));
1770: if (((sb.st_uid != 0 && sb.st_uid != getuid()) ||
1.131 dtucker 1771: (sb.st_mode & 022) != 0))
1.129 djm 1772: fatal("Bad owner or permissions on %s", filename);
1773: }
1.17 markus 1774:
1775: debug("Reading configuration data %.200s", filename);
1776:
1.19 markus 1777: /*
1778: * Mark that we are now processing the options. This flag is turned
1779: * on/off by Host specifications.
1780: */
1.17 markus 1781: linenum = 0;
1.289 markus 1782: while (getline(&line, &linesize, f) != -1) {
1.17 markus 1783: /* Update line number counter. */
1784: linenum++;
1.252 djm 1785: if (process_config_line_depth(options, pw, host, original_host,
1786: line, filename, linenum, activep, flags, depth) != 0)
1.17 markus 1787: bad_options++;
1788: }
1.289 markus 1789: free(line);
1.17 markus 1790: fclose(f);
1791: if (bad_options > 0)
1.64 millert 1792: fatal("%s: terminating, %d bad configuration options",
1.93 deraadt 1793: filename, bad_options);
1.89 stevesk 1794: return 1;
1.1 deraadt 1795: }
1796:
1.218 djm 1797: /* Returns 1 if a string option is unset or set to "none" or 0 otherwise. */
1798: int
1799: option_clear_or_none(const char *o)
1800: {
1801: return o == NULL || strcasecmp(o, "none") == 0;
1802: }
1803:
1.19 markus 1804: /*
1805: * Initializes options to special values that indicate that they have not yet
1806: * been set. Read_config_file will only set options with this value. Options
1807: * are processed in the following order: command line, user config file,
1808: * system config file. Last, fill_default_options is called.
1809: */
1.1 deraadt 1810:
1.26 markus 1811: void
1.17 markus 1812: initialize_options(Options * options)
1.1 deraadt 1813: {
1.17 markus 1814: memset(options, 'X', sizeof(*options));
1815: options->forward_agent = -1;
1816: options->forward_x11 = -1;
1.123 markus 1817: options->forward_x11_trusted = -1;
1.186 djm 1818: options->forward_x11_timeout = -1;
1.255 dtucker 1819: options->stdio_forward_host = NULL;
1820: options->stdio_forward_port = 0;
1.256 dtucker 1821: options->clear_forwardings = -1;
1.153 markus 1822: options->exit_on_forward_failure = -1;
1.34 markus 1823: options->xauth_location = NULL;
1.220 millert 1824: options->fwd_opts.gateway_ports = -1;
1825: options->fwd_opts.streamlocal_bind_mask = (mode_t)-1;
1826: options->fwd_opts.streamlocal_bind_unlink = -1;
1.50 markus 1827: options->pubkey_authentication = -1;
1.78 markus 1828: options->challenge_response_authentication = -1;
1.118 markus 1829: options->gss_authentication = -1;
1830: options->gss_deleg_creds = -1;
1.17 markus 1831: options->password_authentication = -1;
1.48 markus 1832: options->kbd_interactive_authentication = -1;
1833: options->kbd_interactive_devices = NULL;
1.72 markus 1834: options->hostbased_authentication = -1;
1.17 markus 1835: options->batch_mode = -1;
1836: options->check_host_ip = -1;
1837: options->strict_host_key_checking = -1;
1838: options->compression = -1;
1.126 markus 1839: options->tcp_keep_alive = -1;
1.17 markus 1840: options->port = -1;
1.114 djm 1841: options->address_family = -1;
1.17 markus 1842: options->connection_attempts = -1;
1.111 djm 1843: options->connection_timeout = -1;
1.17 markus 1844: options->number_of_password_prompts = -1;
1.25 markus 1845: options->ciphers = NULL;
1.62 markus 1846: options->macs = NULL;
1.189 djm 1847: options->kex_algorithms = NULL;
1.76 markus 1848: options->hostkeyalgorithms = NULL;
1.298 djm 1849: options->ca_sign_algorithms = NULL;
1.17 markus 1850: options->num_identity_files = 0;
1.241 djm 1851: options->num_certificate_files = 0;
1.17 markus 1852: options->hostname = NULL;
1.52 markus 1853: options->host_key_alias = NULL;
1.17 markus 1854: options->proxy_command = NULL;
1.257 djm 1855: options->jump_user = NULL;
1856: options->jump_host = NULL;
1857: options->jump_port = -1;
1858: options->jump_extra = NULL;
1.17 markus 1859: options->user = NULL;
1860: options->escape_char = -1;
1.193 djm 1861: options->num_system_hostfiles = 0;
1862: options->num_user_hostfiles = 0;
1.185 djm 1863: options->local_forwards = NULL;
1.17 markus 1864: options->num_local_forwards = 0;
1.185 djm 1865: options->remote_forwards = NULL;
1.17 markus 1866: options->num_remote_forwards = 0;
1.271 dtucker 1867: options->log_facility = SYSLOG_FACILITY_NOT_SET;
1.95 markus 1868: options->log_level = SYSLOG_LEVEL_NOT_SET;
1.67 markus 1869: options->preferred_authentications = NULL;
1.77 markus 1870: options->bind_address = NULL;
1.282 djm 1871: options->bind_interface = NULL;
1.183 markus 1872: options->pkcs11_provider = NULL;
1.101 markus 1873: options->enable_ssh_keysign = - 1;
1.91 markus 1874: options->no_host_authentication_for_localhost = - 1;
1.128 markus 1875: options->identities_only = - 1;
1.105 markus 1876: options->rekey_limit = - 1;
1.198 dtucker 1877: options->rekey_interval = -1;
1.107 jakob 1878: options->verify_host_key_dns = -1;
1.127 markus 1879: options->server_alive_interval = -1;
1880: options->server_alive_count_max = -1;
1.290 djm 1881: options->send_env = NULL;
1.130 djm 1882: options->num_send_env = 0;
1.290 djm 1883: options->setenv = NULL;
1884: options->num_setenv = 0;
1.132 djm 1885: options->control_path = NULL;
1886: options->control_master = -1;
1.187 djm 1887: options->control_persist = -1;
1888: options->control_persist_timeout = 0;
1.136 djm 1889: options->hash_known_hosts = -1;
1.144 reyk 1890: options->tun_open = -1;
1891: options->tun_local = -1;
1892: options->tun_remote = -1;
1893: options->local_command = NULL;
1894: options->permit_local_command = -1;
1.277 bluhm 1895: options->remote_command = NULL;
1.246 jcs 1896: options->add_keys_to_agent = -1;
1.253 markus 1897: options->identity_agent = NULL;
1.167 grunk 1898: options->visual_host_key = -1;
1.190 djm 1899: options->ip_qos_interactive = -1;
1900: options->ip_qos_bulk = -1;
1.192 djm 1901: options->request_tty = -1;
1.205 djm 1902: options->proxy_use_fdpass = -1;
1.199 djm 1903: options->ignored_unknown = NULL;
1.208 djm 1904: options->num_canonical_domains = 0;
1905: options->num_permitted_cnames = 0;
1.209 djm 1906: options->canonicalize_max_dots = -1;
1907: options->canonicalize_fallback_local = -1;
1908: options->canonicalize_hostname = -1;
1.223 djm 1909: options->revoked_host_keys = NULL;
1.224 djm 1910: options->fingerprint_hash = -1;
1.229 djm 1911: options->update_hostkeys = -1;
1.230 djm 1912: options->hostbased_key_types = NULL;
1.238 markus 1913: options->pubkey_key_types = NULL;
1.1 deraadt 1914: }
1915:
1.19 markus 1916: /*
1.218 djm 1917: * A petite version of fill_default_options() that just fills the options
1918: * needed for hostname canonicalization to proceed.
1919: */
1920: void
1921: fill_default_options_for_canonicalization(Options *options)
1922: {
1923: if (options->canonicalize_max_dots == -1)
1924: options->canonicalize_max_dots = 1;
1925: if (options->canonicalize_fallback_local == -1)
1926: options->canonicalize_fallback_local = 1;
1927: if (options->canonicalize_hostname == -1)
1928: options->canonicalize_hostname = SSH_CANONICALISE_NO;
1929: }
1930:
1931: /*
1.19 markus 1932: * Called after processing other sources of option data, this fills those
1933: * options for which no value has been specified with their default values.
1934: */
1.26 markus 1935: void
1.17 markus 1936: fill_default_options(Options * options)
1.1 deraadt 1937: {
1.298 djm 1938: char *all_cipher, *all_mac, *all_kex, *all_key, *all_sig;
1.297 djm 1939: int r;
1.292 djm 1940:
1.17 markus 1941: if (options->forward_agent == -1)
1.33 markus 1942: options->forward_agent = 0;
1.17 markus 1943: if (options->forward_x11 == -1)
1.23 markus 1944: options->forward_x11 = 0;
1.123 markus 1945: if (options->forward_x11_trusted == -1)
1946: options->forward_x11_trusted = 0;
1.186 djm 1947: if (options->forward_x11_timeout == -1)
1948: options->forward_x11_timeout = 1200;
1.256 dtucker 1949: /*
1950: * stdio forwarding (-W) changes the default for these but we defer
1951: * setting the values so they can be overridden.
1952: */
1.153 markus 1953: if (options->exit_on_forward_failure == -1)
1.256 dtucker 1954: options->exit_on_forward_failure =
1955: options->stdio_forward_host != NULL ? 1 : 0;
1956: if (options->clear_forwardings == -1)
1957: options->clear_forwardings =
1958: options->stdio_forward_host != NULL ? 1 : 0;
1959: if (options->clear_forwardings == 1)
1960: clear_forwardings(options);
1961:
1.34 markus 1962: if (options->xauth_location == NULL)
1.80 markus 1963: options->xauth_location = _PATH_XAUTH;
1.220 millert 1964: if (options->fwd_opts.gateway_ports == -1)
1965: options->fwd_opts.gateway_ports = 0;
1966: if (options->fwd_opts.streamlocal_bind_mask == (mode_t)-1)
1967: options->fwd_opts.streamlocal_bind_mask = 0177;
1968: if (options->fwd_opts.streamlocal_bind_unlink == -1)
1969: options->fwd_opts.streamlocal_bind_unlink = 0;
1.50 markus 1970: if (options->pubkey_authentication == -1)
1971: options->pubkey_authentication = 1;
1.78 markus 1972: if (options->challenge_response_authentication == -1)
1.83 markus 1973: options->challenge_response_authentication = 1;
1.118 markus 1974: if (options->gss_authentication == -1)
1.122 markus 1975: options->gss_authentication = 0;
1.118 markus 1976: if (options->gss_deleg_creds == -1)
1977: options->gss_deleg_creds = 0;
1.17 markus 1978: if (options->password_authentication == -1)
1979: options->password_authentication = 1;
1.48 markus 1980: if (options->kbd_interactive_authentication == -1)
1.59 markus 1981: options->kbd_interactive_authentication = 1;
1.72 markus 1982: if (options->hostbased_authentication == -1)
1983: options->hostbased_authentication = 0;
1.17 markus 1984: if (options->batch_mode == -1)
1985: options->batch_mode = 0;
1986: if (options->check_host_ip == -1)
1987: options->check_host_ip = 1;
1988: if (options->strict_host_key_checking == -1)
1.278 djm 1989: options->strict_host_key_checking = SSH_STRICT_HOSTKEY_ASK;
1.17 markus 1990: if (options->compression == -1)
1991: options->compression = 0;
1.126 markus 1992: if (options->tcp_keep_alive == -1)
1993: options->tcp_keep_alive = 1;
1.17 markus 1994: if (options->port == -1)
1995: options->port = 0; /* Filled in ssh_connect. */
1.114 djm 1996: if (options->address_family == -1)
1997: options->address_family = AF_UNSPEC;
1.17 markus 1998: if (options->connection_attempts == -1)
1.84 markus 1999: options->connection_attempts = 1;
1.17 markus 2000: if (options->number_of_password_prompts == -1)
2001: options->number_of_password_prompts = 3;
1.76 markus 2002: /* options->hostkeyalgorithms, default set in myproposals.h */
1.246 jcs 2003: if (options->add_keys_to_agent == -1)
2004: options->add_keys_to_agent = 0;
1.17 markus 2005: if (options->num_identity_files == 0) {
1.273 djm 2006: add_identity_file(options, "~/", _PATH_SSH_CLIENT_ID_RSA, 0);
2007: add_identity_file(options, "~/", _PATH_SSH_CLIENT_ID_DSA, 0);
2008: add_identity_file(options, "~/", _PATH_SSH_CLIENT_ID_ECDSA, 0);
2009: add_identity_file(options, "~/",
2010: _PATH_SSH_CLIENT_ID_ED25519, 0);
1.283 markus 2011: add_identity_file(options, "~/", _PATH_SSH_CLIENT_ID_XMSS, 0);
1.27 markus 2012: }
1.17 markus 2013: if (options->escape_char == -1)
2014: options->escape_char = '~';
1.193 djm 2015: if (options->num_system_hostfiles == 0) {
2016: options->system_hostfiles[options->num_system_hostfiles++] =
2017: xstrdup(_PATH_SSH_SYSTEM_HOSTFILE);
2018: options->system_hostfiles[options->num_system_hostfiles++] =
2019: xstrdup(_PATH_SSH_SYSTEM_HOSTFILE2);
2020: }
2021: if (options->num_user_hostfiles == 0) {
2022: options->user_hostfiles[options->num_user_hostfiles++] =
2023: xstrdup(_PATH_SSH_USER_HOSTFILE);
2024: options->user_hostfiles[options->num_user_hostfiles++] =
2025: xstrdup(_PATH_SSH_USER_HOSTFILE2);
2026: }
1.95 markus 2027: if (options->log_level == SYSLOG_LEVEL_NOT_SET)
1.54 markus 2028: options->log_level = SYSLOG_LEVEL_INFO;
1.271 dtucker 2029: if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
2030: options->log_facility = SYSLOG_FACILITY_USER;
1.91 markus 2031: if (options->no_host_authentication_for_localhost == - 1)
2032: options->no_host_authentication_for_localhost = 0;
1.128 markus 2033: if (options->identities_only == -1)
2034: options->identities_only = 0;
1.101 markus 2035: if (options->enable_ssh_keysign == -1)
2036: options->enable_ssh_keysign = 0;
1.105 markus 2037: if (options->rekey_limit == -1)
2038: options->rekey_limit = 0;
1.198 dtucker 2039: if (options->rekey_interval == -1)
2040: options->rekey_interval = 0;
1.107 jakob 2041: if (options->verify_host_key_dns == -1)
2042: options->verify_host_key_dns = 0;
1.127 markus 2043: if (options->server_alive_interval == -1)
2044: options->server_alive_interval = 0;
2045: if (options->server_alive_count_max == -1)
2046: options->server_alive_count_max = 3;
1.132 djm 2047: if (options->control_master == -1)
2048: options->control_master = 0;
1.187 djm 2049: if (options->control_persist == -1) {
2050: options->control_persist = 0;
2051: options->control_persist_timeout = 0;
2052: }
1.136 djm 2053: if (options->hash_known_hosts == -1)
2054: options->hash_known_hosts = 0;
1.144 reyk 2055: if (options->tun_open == -1)
1.145 reyk 2056: options->tun_open = SSH_TUNMODE_NO;
2057: if (options->tun_local == -1)
2058: options->tun_local = SSH_TUNID_ANY;
2059: if (options->tun_remote == -1)
2060: options->tun_remote = SSH_TUNID_ANY;
1.144 reyk 2061: if (options->permit_local_command == -1)
2062: options->permit_local_command = 0;
1.167 grunk 2063: if (options->visual_host_key == -1)
2064: options->visual_host_key = 0;
1.190 djm 2065: if (options->ip_qos_interactive == -1)
1.284 job 2066: options->ip_qos_interactive = IPTOS_DSCP_AF21;
1.190 djm 2067: if (options->ip_qos_bulk == -1)
1.284 job 2068: options->ip_qos_bulk = IPTOS_DSCP_CS1;
1.192 djm 2069: if (options->request_tty == -1)
2070: options->request_tty = REQUEST_TTY_AUTO;
1.205 djm 2071: if (options->proxy_use_fdpass == -1)
2072: options->proxy_use_fdpass = 0;
1.209 djm 2073: if (options->canonicalize_max_dots == -1)
2074: options->canonicalize_max_dots = 1;
2075: if (options->canonicalize_fallback_local == -1)
2076: options->canonicalize_fallback_local = 1;
2077: if (options->canonicalize_hostname == -1)
2078: options->canonicalize_hostname = SSH_CANONICALISE_NO;
1.224 djm 2079: if (options->fingerprint_hash == -1)
2080: options->fingerprint_hash = SSH_FP_HASH_DEFAULT;
1.229 djm 2081: if (options->update_hostkeys == -1)
1.231 djm 2082: options->update_hostkeys = 0;
1.292 djm 2083:
2084: /* Expand KEX name lists */
2085: all_cipher = cipher_alg_list(',', 0);
2086: all_mac = mac_alg_list(',');
2087: all_kex = kex_alg_list(',');
2088: all_key = sshkey_alg_list(0, 0, 1, ',');
1.298 djm 2089: all_sig = sshkey_alg_list(0, 1, 1, ',');
1.297 djm 2090: #define ASSEMBLE(what, defaults, all) \
2091: do { \
2092: if ((r = kex_assemble_names(&options->what, \
2093: defaults, all)) != 0) \
2094: fatal("%s: %s: %s", __func__, #what, ssh_err(r)); \
2095: } while (0)
2096: ASSEMBLE(ciphers, KEX_SERVER_ENCRYPT, all_cipher);
2097: ASSEMBLE(macs, KEX_SERVER_MAC, all_mac);
2098: ASSEMBLE(kex_algorithms, KEX_SERVER_KEX, all_kex);
2099: ASSEMBLE(hostbased_key_types, KEX_DEFAULT_PK_ALG, all_key);
2100: ASSEMBLE(pubkey_key_types, KEX_DEFAULT_PK_ALG, all_key);
1.298 djm 2101: ASSEMBLE(ca_sign_algorithms, SSH_ALLOWED_CA_SIGALGS, all_sig);
1.297 djm 2102: #undef ASSEMBLE
1.292 djm 2103: free(all_cipher);
2104: free(all_mac);
2105: free(all_kex);
2106: free(all_key);
1.298 djm 2107: free(all_sig);
1.224 djm 2108:
1.207 djm 2109: #define CLEAR_ON_NONE(v) \
2110: do { \
1.218 djm 2111: if (option_clear_or_none(v)) { \
1.207 djm 2112: free(v); \
2113: v = NULL; \
2114: } \
2115: } while(0)
2116: CLEAR_ON_NONE(options->local_command);
1.277 bluhm 2117: CLEAR_ON_NONE(options->remote_command);
1.207 djm 2118: CLEAR_ON_NONE(options->proxy_command);
2119: CLEAR_ON_NONE(options->control_path);
1.223 djm 2120: CLEAR_ON_NONE(options->revoked_host_keys);
1.287 djm 2121: if (options->jump_host != NULL &&
2122: strcmp(options->jump_host, "none") == 0 &&
2123: options->jump_port == 0 && options->jump_user == NULL) {
2124: free(options->jump_host);
2125: options->jump_host = NULL;
2126: }
1.254 markus 2127: /* options->identity_agent distinguishes NULL from 'none' */
1.17 markus 2128: /* options->user will be set in the main program if appropriate */
2129: /* options->hostname will be set in the main program if appropriate */
1.52 markus 2130: /* options->host_key_alias should not be set by default */
1.67 markus 2131: /* options->preferred_authentications will be set in ssh */
1.135 djm 2132: }
2133:
1.220 millert 2134: struct fwdarg {
2135: char *arg;
2136: int ispath;
2137: };
2138:
2139: /*
2140: * parse_fwd_field
2141: * parses the next field in a port forwarding specification.
2142: * sets fwd to the parsed field and advances p past the colon
2143: * or sets it to NULL at end of string.
2144: * returns 0 on success, else non-zero.
2145: */
2146: static int
2147: parse_fwd_field(char **p, struct fwdarg *fwd)
2148: {
2149: char *ep, *cp = *p;
2150: int ispath = 0;
2151:
2152: if (*cp == '\0') {
2153: *p = NULL;
2154: return -1; /* end of string */
2155: }
2156:
2157: /*
2158: * A field escaped with square brackets is used literally.
2159: * XXX - allow ']' to be escaped via backslash?
2160: */
2161: if (*cp == '[') {
2162: /* find matching ']' */
2163: for (ep = cp + 1; *ep != ']' && *ep != '\0'; ep++) {
2164: if (*ep == '/')
2165: ispath = 1;
2166: }
2167: /* no matching ']' or not at end of field. */
2168: if (ep[0] != ']' || (ep[1] != ':' && ep[1] != '\0'))
2169: return -1;
2170: /* NUL terminate the field and advance p past the colon */
2171: *ep++ = '\0';
2172: if (*ep != '\0')
2173: *ep++ = '\0';
2174: fwd->arg = cp + 1;
2175: fwd->ispath = ispath;
2176: *p = ep;
2177: return 0;
2178: }
2179:
2180: for (cp = *p; *cp != '\0'; cp++) {
2181: switch (*cp) {
2182: case '\\':
2183: memmove(cp, cp + 1, strlen(cp + 1) + 1);
1.237 djm 2184: if (*cp == '\0')
2185: return -1;
1.220 millert 2186: break;
2187: case '/':
2188: ispath = 1;
2189: break;
2190: case ':':
2191: *cp++ = '\0';
2192: goto done;
2193: }
2194: }
2195: done:
2196: fwd->arg = *p;
2197: fwd->ispath = ispath;
2198: *p = cp;
2199: return 0;
2200: }
2201:
1.135 djm 2202: /*
2203: * parse_forward
2204: * parses a string containing a port forwarding specification of the form:
1.168 stevesk 2205: * dynamicfwd == 0
1.220 millert 2206: * [listenhost:]listenport|listenpath:connecthost:connectport|connectpath
2207: * listenpath:connectpath
1.168 stevesk 2208: * dynamicfwd == 1
2209: * [listenhost:]listenport
1.135 djm 2210: * returns number of arguments parsed or zero on error
2211: */
2212: int
1.220 millert 2213: parse_forward(struct Forward *fwd, const char *fwdspec, int dynamicfwd, int remotefwd)
1.135 djm 2214: {
1.220 millert 2215: struct fwdarg fwdargs[4];
2216: char *p, *cp;
1.135 djm 2217: int i;
2218:
1.220 millert 2219: memset(fwd, 0, sizeof(*fwd));
2220: memset(fwdargs, 0, sizeof(fwdargs));
1.135 djm 2221:
2222: cp = p = xstrdup(fwdspec);
2223:
2224: /* skip leading spaces */
1.214 deraadt 2225: while (isspace((u_char)*cp))
1.135 djm 2226: cp++;
2227:
1.220 millert 2228: for (i = 0; i < 4; ++i) {
2229: if (parse_fwd_field(&cp, &fwdargs[i]) != 0)
1.135 djm 2230: break;
1.220 millert 2231: }
1.135 djm 2232:
1.170 stevesk 2233: /* Check for trailing garbage */
1.220 millert 2234: if (cp != NULL && *cp != '\0') {
1.135 djm 2235: i = 0; /* failure */
1.220 millert 2236: }
1.135 djm 2237:
2238: switch (i) {
1.168 stevesk 2239: case 1:
1.220 millert 2240: if (fwdargs[0].ispath) {
2241: fwd->listen_path = xstrdup(fwdargs[0].arg);
2242: fwd->listen_port = PORT_STREAMLOCAL;
2243: } else {
2244: fwd->listen_host = NULL;
2245: fwd->listen_port = a2port(fwdargs[0].arg);
2246: }
1.168 stevesk 2247: fwd->connect_host = xstrdup("socks");
2248: break;
2249:
2250: case 2:
1.220 millert 2251: if (fwdargs[0].ispath && fwdargs[1].ispath) {
2252: fwd->listen_path = xstrdup(fwdargs[0].arg);
2253: fwd->listen_port = PORT_STREAMLOCAL;
2254: fwd->connect_path = xstrdup(fwdargs[1].arg);
2255: fwd->connect_port = PORT_STREAMLOCAL;
2256: } else if (fwdargs[1].ispath) {
2257: fwd->listen_host = NULL;
2258: fwd->listen_port = a2port(fwdargs[0].arg);
2259: fwd->connect_path = xstrdup(fwdargs[1].arg);
2260: fwd->connect_port = PORT_STREAMLOCAL;
2261: } else {
2262: fwd->listen_host = xstrdup(fwdargs[0].arg);
2263: fwd->listen_port = a2port(fwdargs[1].arg);
2264: fwd->connect_host = xstrdup("socks");
2265: }
1.168 stevesk 2266: break;
2267:
1.135 djm 2268: case 3:
1.220 millert 2269: if (fwdargs[0].ispath) {
2270: fwd->listen_path = xstrdup(fwdargs[0].arg);
2271: fwd->listen_port = PORT_STREAMLOCAL;
2272: fwd->connect_host = xstrdup(fwdargs[1].arg);
2273: fwd->connect_port = a2port(fwdargs[2].arg);
2274: } else if (fwdargs[2].ispath) {
2275: fwd->listen_host = xstrdup(fwdargs[0].arg);
2276: fwd->listen_port = a2port(fwdargs[1].arg);
2277: fwd->connect_path = xstrdup(fwdargs[2].arg);
2278: fwd->connect_port = PORT_STREAMLOCAL;
2279: } else {
2280: fwd->listen_host = NULL;
2281: fwd->listen_port = a2port(fwdargs[0].arg);
2282: fwd->connect_host = xstrdup(fwdargs[1].arg);
2283: fwd->connect_port = a2port(fwdargs[2].arg);
2284: }
1.135 djm 2285: break;
2286:
2287: case 4:
1.220 millert 2288: fwd->listen_host = xstrdup(fwdargs[0].arg);
2289: fwd->listen_port = a2port(fwdargs[1].arg);
2290: fwd->connect_host = xstrdup(fwdargs[2].arg);
2291: fwd->connect_port = a2port(fwdargs[3].arg);
1.135 djm 2292: break;
2293: default:
2294: i = 0; /* failure */
2295: }
2296:
1.202 djm 2297: free(p);
1.135 djm 2298:
1.168 stevesk 2299: if (dynamicfwd) {
2300: if (!(i == 1 || i == 2))
2301: goto fail_free;
2302: } else {
1.220 millert 2303: if (!(i == 3 || i == 4)) {
2304: if (fwd->connect_path == NULL &&
2305: fwd->listen_path == NULL)
2306: goto fail_free;
2307: }
2308: if (fwd->connect_port <= 0 && fwd->connect_path == NULL)
1.168 stevesk 2309: goto fail_free;
2310: }
2311:
1.220 millert 2312: if ((fwd->listen_port < 0 && fwd->listen_path == NULL) ||
2313: (!remotefwd && fwd->listen_port == 0))
1.135 djm 2314: goto fail_free;
2315: if (fwd->connect_host != NULL &&
2316: strlen(fwd->connect_host) >= NI_MAXHOST)
2317: goto fail_free;
1.220 millert 2318: /* XXX - if connecting to a remote socket, max sun len may not match this host */
2319: if (fwd->connect_path != NULL &&
2320: strlen(fwd->connect_path) >= PATH_MAX_SUN)
2321: goto fail_free;
1.176 djm 2322: if (fwd->listen_host != NULL &&
2323: strlen(fwd->listen_host) >= NI_MAXHOST)
2324: goto fail_free;
1.220 millert 2325: if (fwd->listen_path != NULL &&
2326: strlen(fwd->listen_path) >= PATH_MAX_SUN)
2327: goto fail_free;
1.135 djm 2328:
2329: return (i);
2330:
2331: fail_free:
1.202 djm 2332: free(fwd->connect_host);
2333: fwd->connect_host = NULL;
1.220 millert 2334: free(fwd->connect_path);
2335: fwd->connect_path = NULL;
1.202 djm 2336: free(fwd->listen_host);
2337: fwd->listen_host = NULL;
1.220 millert 2338: free(fwd->listen_path);
2339: fwd->listen_path = NULL;
1.135 djm 2340: return (0);
1.221 djm 2341: }
2342:
1.257 djm 2343: int
2344: parse_jump(const char *s, Options *o, int active)
2345: {
2346: char *orig, *sdup, *cp;
2347: char *host = NULL, *user = NULL;
1.258 naddy 2348: int ret = -1, port = -1, first;
1.257 djm 2349:
2350: active &= o->proxy_command == NULL && o->jump_host == NULL;
2351:
2352: orig = sdup = xstrdup(s);
1.258 naddy 2353: first = active;
1.259 djm 2354: do {
1.287 djm 2355: if (strcasecmp(s, "none") == 0)
2356: break;
1.259 djm 2357: if ((cp = strrchr(sdup, ',')) == NULL)
2358: cp = sdup; /* last */
2359: else
2360: *cp++ = '\0';
2361:
1.258 naddy 2362: if (first) {
1.257 djm 2363: /* First argument and configuration is active */
1.280 millert 2364: if (parse_ssh_uri(cp, &user, &host, &port) == -1 ||
2365: parse_user_host_port(cp, &user, &host, &port) != 0)
1.257 djm 2366: goto out;
2367: } else {
2368: /* Subsequent argument or inactive configuration */
1.280 millert 2369: if (parse_ssh_uri(cp, NULL, NULL, NULL) == -1 ||
2370: parse_user_host_port(cp, NULL, NULL, NULL) != 0)
1.257 djm 2371: goto out;
2372: }
1.258 naddy 2373: first = 0; /* only check syntax for subsequent hosts */
1.259 djm 2374: } while (cp != sdup);
1.257 djm 2375: /* success */
1.258 naddy 2376: if (active) {
1.287 djm 2377: if (strcasecmp(s, "none") == 0) {
2378: o->jump_host = xstrdup("none");
2379: o->jump_port = 0;
2380: } else {
2381: o->jump_user = user;
2382: o->jump_host = host;
2383: o->jump_port = port;
2384: o->proxy_command = xstrdup("none");
2385: user = host = NULL;
2386: if ((cp = strrchr(s, ',')) != NULL && cp != s) {
2387: o->jump_extra = xstrdup(s);
2388: o->jump_extra[cp - s] = '\0';
2389: }
1.259 djm 2390: }
1.258 naddy 2391: }
1.257 djm 2392: ret = 0;
2393: out:
1.258 naddy 2394: free(orig);
1.257 djm 2395: free(user);
2396: free(host);
2397: return ret;
1.280 millert 2398: }
2399:
2400: int
2401: parse_ssh_uri(const char *uri, char **userp, char **hostp, int *portp)
2402: {
2403: char *path;
2404: int r;
2405:
2406: r = parse_uri("ssh", uri, userp, hostp, portp, &path);
2407: if (r == 0 && path != NULL)
2408: r = -1; /* path not allowed */
2409: return r;
1.257 djm 2410: }
2411:
1.221 djm 2412: /* XXX the following is a near-vebatim copy from servconf.c; refactor */
2413: static const char *
2414: fmt_multistate_int(int val, const struct multistate *m)
2415: {
2416: u_int i;
2417:
2418: for (i = 0; m[i].key != NULL; i++) {
2419: if (m[i].value == val)
2420: return m[i].key;
2421: }
2422: return "UNKNOWN";
2423: }
2424:
2425: static const char *
2426: fmt_intarg(OpCodes code, int val)
2427: {
2428: if (val == -1)
2429: return "unset";
2430: switch (code) {
2431: case oAddressFamily:
2432: return fmt_multistate_int(val, multistate_addressfamily);
2433: case oVerifyHostKeyDNS:
1.232 djm 2434: case oUpdateHostkeys:
1.221 djm 2435: return fmt_multistate_int(val, multistate_yesnoask);
1.278 djm 2436: case oStrictHostKeyChecking:
2437: return fmt_multistate_int(val, multistate_strict_hostkey);
1.221 djm 2438: case oControlMaster:
2439: return fmt_multistate_int(val, multistate_controlmaster);
2440: case oTunnel:
2441: return fmt_multistate_int(val, multistate_tunnel);
2442: case oRequestTTY:
2443: return fmt_multistate_int(val, multistate_requesttty);
2444: case oCanonicalizeHostname:
2445: return fmt_multistate_int(val, multistate_canonicalizehostname);
1.285 djm 2446: case oAddKeysToAgent:
2447: return fmt_multistate_int(val, multistate_yesnoaskconfirm);
1.224 djm 2448: case oFingerprintHash:
2449: return ssh_digest_alg_name(val);
1.221 djm 2450: default:
2451: switch (val) {
2452: case 0:
2453: return "no";
2454: case 1:
2455: return "yes";
2456: default:
2457: return "UNKNOWN";
2458: }
2459: }
2460: }
2461:
2462: static const char *
2463: lookup_opcode_name(OpCodes code)
2464: {
2465: u_int i;
2466:
2467: for (i = 0; keywords[i].name != NULL; i++)
2468: if (keywords[i].opcode == code)
2469: return(keywords[i].name);
2470: return "UNKNOWN";
2471: }
2472:
2473: static void
2474: dump_cfg_int(OpCodes code, int val)
2475: {
2476: printf("%s %d\n", lookup_opcode_name(code), val);
2477: }
2478:
2479: static void
2480: dump_cfg_fmtint(OpCodes code, int val)
2481: {
2482: printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
2483: }
2484:
2485: static void
2486: dump_cfg_string(OpCodes code, const char *val)
2487: {
2488: if (val == NULL)
2489: return;
2490: printf("%s %s\n", lookup_opcode_name(code), val);
2491: }
2492:
2493: static void
2494: dump_cfg_strarray(OpCodes code, u_int count, char **vals)
2495: {
2496: u_int i;
2497:
2498: for (i = 0; i < count; i++)
2499: printf("%s %s\n", lookup_opcode_name(code), vals[i]);
2500: }
2501:
2502: static void
2503: dump_cfg_strarray_oneline(OpCodes code, u_int count, char **vals)
2504: {
2505: u_int i;
2506:
2507: printf("%s", lookup_opcode_name(code));
2508: for (i = 0; i < count; i++)
2509: printf(" %s", vals[i]);
2510: printf("\n");
2511: }
2512:
2513: static void
2514: dump_cfg_forwards(OpCodes code, u_int count, const struct Forward *fwds)
2515: {
2516: const struct Forward *fwd;
2517: u_int i;
2518:
2519: /* oDynamicForward */
2520: for (i = 0; i < count; i++) {
2521: fwd = &fwds[i];
1.265 djm 2522: if (code == oDynamicForward && fwd->connect_host != NULL &&
1.221 djm 2523: strcmp(fwd->connect_host, "socks") != 0)
2524: continue;
1.265 djm 2525: if (code == oLocalForward && fwd->connect_host != NULL &&
1.221 djm 2526: strcmp(fwd->connect_host, "socks") == 0)
2527: continue;
2528: printf("%s", lookup_opcode_name(code));
2529: if (fwd->listen_port == PORT_STREAMLOCAL)
2530: printf(" %s", fwd->listen_path);
2531: else if (fwd->listen_host == NULL)
2532: printf(" %d", fwd->listen_port);
2533: else {
2534: printf(" [%s]:%d",
2535: fwd->listen_host, fwd->listen_port);
2536: }
2537: if (code != oDynamicForward) {
2538: if (fwd->connect_port == PORT_STREAMLOCAL)
2539: printf(" %s", fwd->connect_path);
2540: else if (fwd->connect_host == NULL)
2541: printf(" %d", fwd->connect_port);
2542: else {
2543: printf(" [%s]:%d",
2544: fwd->connect_host, fwd->connect_port);
2545: }
2546: }
2547: printf("\n");
2548: }
2549: }
2550:
2551: void
2552: dump_client_config(Options *o, const char *host)
2553: {
2554: int i;
1.292 djm 2555: char buf[8], *all_key;
1.221 djm 2556:
1.240 djm 2557: /* This is normally prepared in ssh_kex2 */
1.292 djm 2558: all_key = sshkey_alg_list(0, 0, 1, ',');
2559: if (kex_assemble_names( &o->hostkeyalgorithms,
2560: KEX_DEFAULT_PK_ALG, all_key) != 0)
1.240 djm 2561: fatal("%s: kex_assemble_names failed", __func__);
1.292 djm 2562: free(all_key);
1.240 djm 2563:
1.221 djm 2564: /* Most interesting options first: user, host, port */
2565: dump_cfg_string(oUser, o->user);
2566: dump_cfg_string(oHostName, host);
2567: dump_cfg_int(oPort, o->port);
2568:
2569: /* Flag options */
1.285 djm 2570: dump_cfg_fmtint(oAddKeysToAgent, o->add_keys_to_agent);
1.221 djm 2571: dump_cfg_fmtint(oAddressFamily, o->address_family);
2572: dump_cfg_fmtint(oBatchMode, o->batch_mode);
2573: dump_cfg_fmtint(oCanonicalizeFallbackLocal, o->canonicalize_fallback_local);
2574: dump_cfg_fmtint(oCanonicalizeHostname, o->canonicalize_hostname);
2575: dump_cfg_fmtint(oChallengeResponseAuthentication, o->challenge_response_authentication);
2576: dump_cfg_fmtint(oCheckHostIP, o->check_host_ip);
2577: dump_cfg_fmtint(oCompression, o->compression);
2578: dump_cfg_fmtint(oControlMaster, o->control_master);
2579: dump_cfg_fmtint(oEnableSSHKeysign, o->enable_ssh_keysign);
1.256 dtucker 2580: dump_cfg_fmtint(oClearAllForwardings, o->clear_forwardings);
1.221 djm 2581: dump_cfg_fmtint(oExitOnForwardFailure, o->exit_on_forward_failure);
1.224 djm 2582: dump_cfg_fmtint(oFingerprintHash, o->fingerprint_hash);
1.221 djm 2583: dump_cfg_fmtint(oForwardAgent, o->forward_agent);
2584: dump_cfg_fmtint(oForwardX11, o->forward_x11);
2585: dump_cfg_fmtint(oForwardX11Trusted, o->forward_x11_trusted);
2586: dump_cfg_fmtint(oGatewayPorts, o->fwd_opts.gateway_ports);
2587: #ifdef GSSAPI
2588: dump_cfg_fmtint(oGssAuthentication, o->gss_authentication);
2589: dump_cfg_fmtint(oGssDelegateCreds, o->gss_deleg_creds);
2590: #endif /* GSSAPI */
2591: dump_cfg_fmtint(oHashKnownHosts, o->hash_known_hosts);
2592: dump_cfg_fmtint(oHostbasedAuthentication, o->hostbased_authentication);
2593: dump_cfg_fmtint(oIdentitiesOnly, o->identities_only);
2594: dump_cfg_fmtint(oKbdInteractiveAuthentication, o->kbd_interactive_authentication);
2595: dump_cfg_fmtint(oNoHostAuthenticationForLocalhost, o->no_host_authentication_for_localhost);
2596: dump_cfg_fmtint(oPasswordAuthentication, o->password_authentication);
2597: dump_cfg_fmtint(oPermitLocalCommand, o->permit_local_command);
2598: dump_cfg_fmtint(oProxyUseFdpass, o->proxy_use_fdpass);
2599: dump_cfg_fmtint(oPubkeyAuthentication, o->pubkey_authentication);
2600: dump_cfg_fmtint(oRequestTTY, o->request_tty);
2601: dump_cfg_fmtint(oStreamLocalBindUnlink, o->fwd_opts.streamlocal_bind_unlink);
2602: dump_cfg_fmtint(oStrictHostKeyChecking, o->strict_host_key_checking);
2603: dump_cfg_fmtint(oTCPKeepAlive, o->tcp_keep_alive);
2604: dump_cfg_fmtint(oTunnel, o->tun_open);
2605: dump_cfg_fmtint(oVerifyHostKeyDNS, o->verify_host_key_dns);
2606: dump_cfg_fmtint(oVisualHostKey, o->visual_host_key);
1.229 djm 2607: dump_cfg_fmtint(oUpdateHostkeys, o->update_hostkeys);
1.221 djm 2608:
2609: /* Integer options */
2610: dump_cfg_int(oCanonicalizeMaxDots, o->canonicalize_max_dots);
2611: dump_cfg_int(oConnectionAttempts, o->connection_attempts);
2612: dump_cfg_int(oForwardX11Timeout, o->forward_x11_timeout);
2613: dump_cfg_int(oNumberOfPasswordPrompts, o->number_of_password_prompts);
2614: dump_cfg_int(oServerAliveCountMax, o->server_alive_count_max);
2615: dump_cfg_int(oServerAliveInterval, o->server_alive_interval);
2616:
2617: /* String options */
2618: dump_cfg_string(oBindAddress, o->bind_address);
1.282 djm 2619: dump_cfg_string(oBindInterface, o->bind_interface);
1.221 djm 2620: dump_cfg_string(oCiphers, o->ciphers ? o->ciphers : KEX_CLIENT_ENCRYPT);
2621: dump_cfg_string(oControlPath, o->control_path);
1.240 djm 2622: dump_cfg_string(oHostKeyAlgorithms, o->hostkeyalgorithms);
1.221 djm 2623: dump_cfg_string(oHostKeyAlias, o->host_key_alias);
1.230 djm 2624: dump_cfg_string(oHostbasedKeyTypes, o->hostbased_key_types);
1.253 markus 2625: dump_cfg_string(oIdentityAgent, o->identity_agent);
1.285 djm 2626: dump_cfg_string(oIgnoreUnknown, o->ignored_unknown);
1.221 djm 2627: dump_cfg_string(oKbdInteractiveDevices, o->kbd_interactive_devices);
2628: dump_cfg_string(oKexAlgorithms, o->kex_algorithms ? o->kex_algorithms : KEX_CLIENT_KEX);
1.298 djm 2629: dump_cfg_string(oCASignatureAlgorithms, o->ca_sign_algorithms ? o->ca_sign_algorithms : SSH_ALLOWED_CA_SIGALGS);
1.221 djm 2630: dump_cfg_string(oLocalCommand, o->local_command);
1.277 bluhm 2631: dump_cfg_string(oRemoteCommand, o->remote_command);
1.221 djm 2632: dump_cfg_string(oLogLevel, log_level_name(o->log_level));
2633: dump_cfg_string(oMacs, o->macs ? o->macs : KEX_CLIENT_MAC);
1.266 djm 2634: #ifdef ENABLE_PKCS11
1.221 djm 2635: dump_cfg_string(oPKCS11Provider, o->pkcs11_provider);
1.266 djm 2636: #endif
1.221 djm 2637: dump_cfg_string(oPreferredAuthentications, o->preferred_authentications);
1.242 djm 2638: dump_cfg_string(oPubkeyAcceptedKeyTypes, o->pubkey_key_types);
1.230 djm 2639: dump_cfg_string(oRevokedHostKeys, o->revoked_host_keys);
1.221 djm 2640: dump_cfg_string(oXAuthLocation, o->xauth_location);
2641:
1.230 djm 2642: /* Forwards */
1.221 djm 2643: dump_cfg_forwards(oDynamicForward, o->num_local_forwards, o->local_forwards);
2644: dump_cfg_forwards(oLocalForward, o->num_local_forwards, o->local_forwards);
2645: dump_cfg_forwards(oRemoteForward, o->num_remote_forwards, o->remote_forwards);
2646:
2647: /* String array options */
2648: dump_cfg_strarray(oIdentityFile, o->num_identity_files, o->identity_files);
2649: dump_cfg_strarray_oneline(oCanonicalDomains, o->num_canonical_domains, o->canonical_domains);
1.285 djm 2650: dump_cfg_strarray(oCertificateFile, o->num_certificate_files, o->certificate_files);
1.221 djm 2651: dump_cfg_strarray_oneline(oGlobalKnownHostsFile, o->num_system_hostfiles, o->system_hostfiles);
2652: dump_cfg_strarray_oneline(oUserKnownHostsFile, o->num_user_hostfiles, o->user_hostfiles);
2653: dump_cfg_strarray(oSendEnv, o->num_send_env, o->send_env);
1.290 djm 2654: dump_cfg_strarray(oSetEnv, o->num_setenv, o->setenv);
1.221 djm 2655:
2656: /* Special cases */
2657:
2658: /* oConnectTimeout */
2659: if (o->connection_timeout == -1)
2660: printf("connecttimeout none\n");
2661: else
2662: dump_cfg_int(oConnectTimeout, o->connection_timeout);
2663:
2664: /* oTunnelDevice */
2665: printf("tunneldevice");
2666: if (o->tun_local == SSH_TUNID_ANY)
2667: printf(" any");
2668: else
2669: printf(" %d", o->tun_local);
2670: if (o->tun_remote == SSH_TUNID_ANY)
2671: printf(":any");
2672: else
2673: printf(":%d", o->tun_remote);
2674: printf("\n");
2675:
2676: /* oCanonicalizePermittedCNAMEs */
2677: if ( o->num_permitted_cnames > 0) {
2678: printf("canonicalizePermittedcnames");
2679: for (i = 0; i < o->num_permitted_cnames; i++) {
2680: printf(" %s:%s", o->permitted_cnames[i].source_list,
2681: o->permitted_cnames[i].target_list);
2682: }
2683: printf("\n");
2684: }
2685:
2686: /* oControlPersist */
2687: if (o->control_persist == 0 || o->control_persist_timeout == 0)
2688: dump_cfg_fmtint(oControlPersist, o->control_persist);
2689: else
2690: dump_cfg_int(oControlPersist, o->control_persist_timeout);
2691:
2692: /* oEscapeChar */
2693: if (o->escape_char == SSH_ESCAPECHAR_NONE)
2694: printf("escapechar none\n");
2695: else {
1.257 djm 2696: vis(buf, o->escape_char, VIS_WHITE, 0);
2697: printf("escapechar %s\n", buf);
1.221 djm 2698: }
2699:
2700: /* oIPQoS */
2701: printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
2702: printf("%s\n", iptos2str(o->ip_qos_bulk));
2703:
2704: /* oRekeyLimit */
1.249 dtucker 2705: printf("rekeylimit %llu %d\n",
2706: (unsigned long long)o->rekey_limit, o->rekey_interval);
1.221 djm 2707:
2708: /* oStreamLocalBindMask */
2709: printf("streamlocalbindmask 0%o\n",
2710: o->fwd_opts.streamlocal_bind_mask);
1.285 djm 2711:
2712: /* oLogFacility */
2713: printf("syslogfacility %s\n", log_facility_name(o->log_facility));
1.257 djm 2714:
2715: /* oProxyCommand / oProxyJump */
2716: if (o->jump_host == NULL)
2717: dump_cfg_string(oProxyCommand, o->proxy_command);
2718: else {
2719: /* Check for numeric addresses */
2720: i = strchr(o->jump_host, ':') != NULL ||
2721: strspn(o->jump_host, "1234567890.") == strlen(o->jump_host);
2722: snprintf(buf, sizeof(buf), "%d", o->jump_port);
2723: printf("proxyjump %s%s%s%s%s%s%s%s%s\n",
1.259 djm 2724: /* optional additional jump spec */
2725: o->jump_extra == NULL ? "" : o->jump_extra,
2726: o->jump_extra == NULL ? "" : ",",
1.257 djm 2727: /* optional user */
2728: o->jump_user == NULL ? "" : o->jump_user,
2729: o->jump_user == NULL ? "" : "@",
2730: /* opening [ if hostname is numeric */
2731: i ? "[" : "",
2732: /* mandatory hostname */
2733: o->jump_host,
2734: /* closing ] if hostname is numeric */
2735: i ? "]" : "",
2736: /* optional port number */
2737: o->jump_port <= 0 ? "" : ":",
1.259 djm 2738: o->jump_port <= 0 ? "" : buf);
1.257 djm 2739: }
1.1 deraadt 2740: }