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