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