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