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