Annotation of src/usr.bin/ssh/readconf.c, Revision 1.357
1.357 ! djm 1: /* $OpenBSD: readconf.c,v 1.356 2021/06/08 07:07:15 djm 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;
1.357 ! djm 1232: value = *uintptr == 0; /* was array empty when we started? */
1.356 djm 1233: while ((arg = argv_next(&ac, &av)) != NULL) {
1234: if (*arg == '\0') {
1235: error("%s line %d: keyword %s empty argument",
1236: filename, linenum, keyword);
1237: goto out;
1238: }
1239: /* Allow "none" only in first position */
1240: if (strcasecmp(arg, "none") == 0) {
1241: if (i > 0 || ac > 0) {
1242: error("%s line %d: keyword %s \"none\" "
1243: "argument must appear alone.",
1244: filename, linenum, keyword);
1245: goto out;
1246: }
1247: }
1248: i++;
1.357 ! djm 1249: if (*activep && value) {
1.344 djm 1250: if ((*uintptr) >= max_entries) {
1.356 djm 1251: error("%s line %d: too many %s "
1252: "entries.", filename, linenum,
1253: keyword);
1254: goto out;
1.344 djm 1255: }
1.193 djm 1256: cpptr[(*uintptr)++] = xstrdup(arg);
1257: }
1258: }
1.356 djm 1259: break;
1.17 markus 1260:
1261: case oUserKnownHostsFile:
1.193 djm 1262: cpptr = (char **)&options->user_hostfiles;
1263: uintptr = &options->num_user_hostfiles;
1264: max_entries = SSH_MAX_HOSTS_FILES;
1265: goto parse_char_array;
1.27 markus 1266:
1.306 jmc 1267: case oHostname:
1.17 markus 1268: charptr = &options->hostname;
1269: goto parse_string;
1270:
1.52 markus 1271: case oHostKeyAlias:
1272: charptr = &options->host_key_alias;
1273: goto parse_string;
1274:
1.67 markus 1275: case oPreferredAuthentications:
1276: charptr = &options->preferred_authentications;
1277: goto parse_string;
1278:
1.77 markus 1279: case oBindAddress:
1280: charptr = &options->bind_address;
1281: goto parse_string;
1282:
1.282 djm 1283: case oBindInterface:
1284: charptr = &options->bind_interface;
1285: goto parse_string;
1286:
1.183 markus 1287: case oPKCS11Provider:
1288: charptr = &options->pkcs11_provider;
1.86 markus 1289: goto parse_string;
1.85 jakob 1290:
1.310 djm 1291: case oSecurityKeyProvider:
1292: charptr = &options->sk_provider;
1293: goto parse_string;
1294:
1.346 djm 1295: case oKnownHostsCommand:
1296: charptr = &options->known_hosts_command;
1297: goto parse_command;
1298:
1.17 markus 1299: case oProxyCommand:
1.144 reyk 1300: charptr = &options->proxy_command;
1.257 djm 1301: /* Ignore ProxyCommand if ProxyJump already specified */
1302: if (options->jump_host != NULL)
1303: charptr = &options->jump_host; /* Skip below */
1.144 reyk 1304: parse_command:
1.356 djm 1305: if (str == NULL) {
1.344 djm 1306: error("%.200s line %d: Missing argument.",
1307: filename, linenum);
1.356 djm 1308: goto out;
1.344 djm 1309: }
1.356 djm 1310: len = strspn(str, WHITESPACE "=");
1.17 markus 1311: if (*activep && *charptr == NULL)
1.356 djm 1312: *charptr = xstrdup(str + len);
1313: argv_consume(&ac);
1314: break;
1.17 markus 1315:
1.257 djm 1316: case oProxyJump:
1.356 djm 1317: if (str == NULL) {
1.344 djm 1318: error("%.200s line %d: Missing argument.",
1.257 djm 1319: filename, linenum);
1.356 djm 1320: goto out;
1.257 djm 1321: }
1.356 djm 1322: len = strspn(str, WHITESPACE "=");
1323: /* XXX use argv? */
1324: if (parse_jump(str + len, options, *activep) == -1) {
1.344 djm 1325: error("%.200s line %d: Invalid ProxyJump \"%s\"",
1.356 djm 1326: filename, linenum, str + len);
1327: goto out;
1.257 djm 1328: }
1.356 djm 1329: argv_consume(&ac);
1330: break;
1.257 djm 1331:
1.17 markus 1332: case oPort:
1.356 djm 1333: arg = argv_next(&ac, &av);
1.344 djm 1334: if (!arg || *arg == '\0') {
1335: error("%.200s line %d: Missing argument.",
1.300 naddy 1336: filename, linenum);
1.356 djm 1337: goto out;
1.344 djm 1338: }
1.300 naddy 1339: value = a2port(arg);
1.344 djm 1340: if (value <= 0) {
1341: error("%.200s line %d: Bad port '%s'.",
1.300 naddy 1342: filename, linenum, arg);
1.356 djm 1343: goto out;
1.344 djm 1344: }
1.300 naddy 1345: if (*activep && options->port == -1)
1346: options->port = value;
1347: break;
1348:
1349: case oConnectionAttempts:
1350: intptr = &options->connection_attempts;
1.17 markus 1351: parse_int:
1.356 djm 1352: arg = argv_next(&ac, &av);
1.344 djm 1353: if ((errstr = atoi_err(arg, &value)) != NULL) {
1354: error("%s line %d: integer value %s.",
1.281 dtucker 1355: filename, linenum, errstr);
1.356 djm 1356: goto out;
1.344 djm 1357: }
1.17 markus 1358: if (*activep && *intptr == -1)
1359: *intptr = value;
1360: break;
1361:
1.25 markus 1362: case oCiphers:
1.356 djm 1363: arg = argv_next(&ac, &av);
1.344 djm 1364: if (!arg || *arg == '\0') {
1365: error("%.200s line %d: Missing argument.",
1366: filename, linenum);
1.356 djm 1367: goto out;
1.344 djm 1368: }
1.309 naddy 1369: if (*arg != '-' &&
1.344 djm 1370: !ciphers_valid(*arg == '+' || *arg == '^' ? arg + 1 : arg)){
1371: error("%.200s line %d: Bad SSH2 cipher spec '%s'.",
1.93 deraadt 1372: filename, linenum, arg ? arg : "<NONE>");
1.356 djm 1373: goto out;
1.344 djm 1374: }
1.25 markus 1375: if (*activep && options->ciphers == NULL)
1.38 provos 1376: options->ciphers = xstrdup(arg);
1.25 markus 1377: break;
1378:
1.62 markus 1379: case oMacs:
1.356 djm 1380: arg = argv_next(&ac, &av);
1.344 djm 1381: if (!arg || *arg == '\0') {
1382: error("%.200s line %d: Missing argument.",
1383: filename, linenum);
1.356 djm 1384: goto out;
1.344 djm 1385: }
1.309 naddy 1386: if (*arg != '-' &&
1.344 djm 1387: !mac_valid(*arg == '+' || *arg == '^' ? arg + 1 : arg)) {
1388: error("%.200s line %d: Bad SSH2 MAC spec '%s'.",
1.93 deraadt 1389: filename, linenum, arg ? arg : "<NONE>");
1.356 djm 1390: goto out;
1.344 djm 1391: }
1.62 markus 1392: if (*activep && options->macs == NULL)
1393: options->macs = xstrdup(arg);
1394: break;
1395:
1.189 djm 1396: case oKexAlgorithms:
1.356 djm 1397: arg = argv_next(&ac, &av);
1.344 djm 1398: if (!arg || *arg == '\0') {
1399: error("%.200s line %d: Missing argument.",
1.189 djm 1400: filename, linenum);
1.356 djm 1401: goto out;
1.344 djm 1402: }
1.268 djm 1403: if (*arg != '-' &&
1.309 naddy 1404: !kex_names_valid(*arg == '+' || *arg == '^' ?
1.344 djm 1405: arg + 1 : arg)) {
1406: error("%.200s line %d: Bad SSH2 KexAlgorithms '%s'.",
1.189 djm 1407: filename, linenum, arg ? arg : "<NONE>");
1.356 djm 1408: goto out;
1.344 djm 1409: }
1.189 djm 1410: if (*activep && options->kex_algorithms == NULL)
1411: options->kex_algorithms = xstrdup(arg);
1412: break;
1413:
1.76 markus 1414: case oHostKeyAlgorithms:
1.238 markus 1415: charptr = &options->hostkeyalgorithms;
1.349 dtucker 1416: parse_pubkey_algos:
1.356 djm 1417: arg = argv_next(&ac, &av);
1.344 djm 1418: if (!arg || *arg == '\0') {
1419: error("%.200s line %d: Missing argument.",
1.238 markus 1420: filename, linenum);
1.356 djm 1421: goto out;
1.344 djm 1422: }
1.268 djm 1423: if (*arg != '-' &&
1.309 naddy 1424: !sshkey_names_valid2(*arg == '+' || *arg == '^' ?
1.344 djm 1425: arg + 1 : arg, 1)) {
1426: error("%s line %d: Bad key types '%s'.",
1427: filename, linenum, arg ? arg : "<NONE>");
1.356 djm 1428: goto out;
1.344 djm 1429: }
1.238 markus 1430: if (*activep && *charptr == NULL)
1431: *charptr = xstrdup(arg);
1.76 markus 1432: break;
1433:
1.298 djm 1434: case oCASignatureAlgorithms:
1435: charptr = &options->ca_sign_algorithms;
1.349 dtucker 1436: goto parse_pubkey_algos;
1.298 djm 1437:
1.17 markus 1438: case oLogLevel:
1.164 dtucker 1439: log_level_ptr = &options->log_level;
1.356 djm 1440: arg = argv_next(&ac, &av);
1.38 provos 1441: value = log_level_number(arg);
1.344 djm 1442: if (value == SYSLOG_LEVEL_NOT_SET) {
1443: error("%.200s line %d: unsupported log level '%s'",
1.93 deraadt 1444: filename, linenum, arg ? arg : "<NONE>");
1.356 djm 1445: goto out;
1.344 djm 1446: }
1.164 dtucker 1447: if (*activep && *log_level_ptr == SYSLOG_LEVEL_NOT_SET)
1448: *log_level_ptr = (LogLevel) value;
1.17 markus 1449: break;
1450:
1.271 dtucker 1451: case oLogFacility:
1452: log_facility_ptr = &options->log_facility;
1.356 djm 1453: arg = argv_next(&ac, &av);
1.271 dtucker 1454: value = log_facility_number(arg);
1.344 djm 1455: if (value == SYSLOG_FACILITY_NOT_SET) {
1456: error("%.200s line %d: unsupported log facility '%s'",
1.271 dtucker 1457: filename, linenum, arg ? arg : "<NONE>");
1.356 djm 1458: goto out;
1.344 djm 1459: }
1.271 dtucker 1460: if (*log_facility_ptr == -1)
1461: *log_facility_ptr = (SyslogFacility) value;
1462: break;
1463:
1.339 djm 1464: case oLogVerbose:
1465: cppptr = &options->log_verbose;
1466: uintptr = &options->num_log_verbose;
1.356 djm 1467: i = 0;
1468: while ((arg = argv_next(&ac, &av)) != NULL) {
1469: if (*arg == '\0') {
1470: error("%s line %d: keyword %s empty argument",
1471: filename, linenum, keyword);
1472: goto out;
1473: }
1474: /* Allow "none" only in first position */
1475: if (strcasecmp(arg, "none") == 0) {
1476: if (i > 0 || ac > 0) {
1477: error("%s line %d: keyword %s \"none\" "
1478: "argument must appear alone.",
1479: filename, linenum, keyword);
1480: goto out;
1481: }
1482: }
1483: i++;
1484: if (*activep && *uintptr == 0) {
1.339 djm 1485: *cppptr = xrecallocarray(*cppptr, *uintptr,
1486: *uintptr + 1, sizeof(**cppptr));
1487: (*cppptr)[(*uintptr)++] = xstrdup(arg);
1488: }
1489: }
1.356 djm 1490: break;
1.339 djm 1491:
1.88 stevesk 1492: case oLocalForward:
1.17 markus 1493: case oRemoteForward:
1.168 stevesk 1494: case oDynamicForward:
1.356 djm 1495: arg = argv_next(&ac, &av);
1.344 djm 1496: if (!arg || *arg == '\0') {
1497: error("%.200s line %d: Missing argument.",
1.88 stevesk 1498: filename, linenum);
1.356 djm 1499: goto out;
1.344 djm 1500: }
1.135 djm 1501:
1.279 markus 1502: remotefwd = (opcode == oRemoteForward);
1503: dynamicfwd = (opcode == oDynamicForward);
1504:
1505: if (!dynamicfwd) {
1.356 djm 1506: arg2 = argv_next(&ac, &av);
1.279 markus 1507: if (arg2 == NULL || *arg2 == '\0') {
1508: if (remotefwd)
1509: dynamicfwd = 1;
1.344 djm 1510: else {
1511: error("%.200s line %d: Missing target "
1.279 markus 1512: "argument.", filename, linenum);
1.356 djm 1513: goto out;
1.344 djm 1514: }
1.279 markus 1515: } else {
1516: /* construct a string for parse_forward */
1517: snprintf(fwdarg, sizeof(fwdarg), "%s:%s", arg,
1518: arg2);
1519: }
1520: }
1521: if (dynamicfwd)
1.168 stevesk 1522: strlcpy(fwdarg, arg, sizeof(fwdarg));
1523:
1.344 djm 1524: if (parse_forward(&fwd, fwdarg, dynamicfwd, remotefwd) == 0) {
1525: error("%.200s line %d: Bad forwarding specification.",
1.88 stevesk 1526: filename, linenum);
1.356 djm 1527: goto out;
1.344 djm 1528: }
1.135 djm 1529:
1.88 stevesk 1530: if (*activep) {
1.279 markus 1531: if (remotefwd) {
1532: add_remote_forward(options, &fwd);
1533: } else {
1.135 djm 1534: add_local_forward(options, &fwd);
1.279 markus 1535: }
1.88 stevesk 1536: }
1.17 markus 1537: break;
1.71 markus 1538:
1.351 markus 1539: case oPermitRemoteOpen:
1540: uintptr = &options->num_permitted_remote_opens;
1541: cppptr = &options->permitted_remote_opens;
1.356 djm 1542: arg = argv_next(&ac, &av);
1.351 markus 1543: if (!arg || *arg == '\0')
1544: fatal("%s line %d: missing %s specification",
1545: filename, linenum, lookup_opcode_name(opcode));
1546: uvalue = *uintptr; /* modified later */
1547: if (strcmp(arg, "any") == 0 || strcmp(arg, "none") == 0) {
1548: if (*activep && uvalue == 0) {
1549: *uintptr = 1;
1550: *cppptr = xcalloc(1, sizeof(**cppptr));
1551: (*cppptr)[0] = xstrdup(arg);
1552: }
1553: break;
1554: }
1.356 djm 1555: while ((arg = argv_next(&ac, &av)) != NULL) {
1.351 markus 1556: arg2 = xstrdup(arg);
1557: ch = '\0';
1558: p = hpdelim2(&arg, &ch);
1559: if (p == NULL || ch == '/') {
1560: fatal("%s line %d: missing host in %s",
1561: filename, linenum,
1562: lookup_opcode_name(opcode));
1563: }
1564: p = cleanhostname(p);
1565: /*
1566: * don't want to use permitopen_port to avoid
1567: * dependency on channels.[ch] here.
1568: */
1569: if (arg == NULL ||
1570: (strcmp(arg, "*") != 0 && a2port(arg) <= 0)) {
1571: fatal("%s line %d: bad port number in %s",
1572: filename, linenum,
1573: lookup_opcode_name(opcode));
1574: }
1575: if (*activep && uvalue == 0) {
1576: opt_array_append(filename, linenum,
1577: lookup_opcode_name(opcode),
1578: cppptr, uintptr, arg2);
1579: }
1580: free(arg2);
1581: }
1582: break;
1583:
1.90 stevesk 1584: case oClearAllForwardings:
1585: intptr = &options->clear_forwardings;
1586: goto parse_flag;
1587:
1.17 markus 1588: case oHost:
1.344 djm 1589: if (cmdline) {
1590: error("Host directive not supported as a command-line "
1.206 djm 1591: "option");
1.356 djm 1592: goto out;
1.344 djm 1593: }
1.17 markus 1594: *activep = 0;
1.191 djm 1595: arg2 = NULL;
1.356 djm 1596: while ((arg = argv_next(&ac, &av)) != NULL) {
1597: if (*arg == '\0') {
1598: error("%s line %d: keyword %s empty argument",
1599: filename, linenum, keyword);
1600: goto out;
1601: }
1602: if ((flags & SSHCONF_NEVERMATCH) != 0) {
1603: argv_consume(&ac);
1.252 djm 1604: break;
1.356 djm 1605: }
1.191 djm 1606: negated = *arg == '!';
1607: if (negated)
1608: arg++;
1.38 provos 1609: if (match_pattern(host, arg)) {
1.191 djm 1610: if (negated) {
1611: debug("%.200s line %d: Skipping Host "
1612: "block because of negated match "
1613: "for %.100s", filename, linenum,
1614: arg);
1615: *activep = 0;
1.356 djm 1616: argv_consume(&ac);
1.191 djm 1617: break;
1618: }
1619: if (!*activep)
1620: arg2 = arg; /* logged below */
1.17 markus 1621: *activep = 1;
1622: }
1.191 djm 1623: }
1624: if (*activep)
1625: debug("%.200s line %d: Applying options for %.100s",
1626: filename, linenum, arg2);
1.356 djm 1627: break;
1.17 markus 1628:
1.206 djm 1629: case oMatch:
1.344 djm 1630: if (cmdline) {
1631: error("Host directive not supported as a command-line "
1.206 djm 1632: "option");
1.356 djm 1633: goto out;
1.344 djm 1634: }
1.356 djm 1635: value = match_cfg_line(options, &str, pw, host, original_host,
1.302 djm 1636: flags & SSHCONF_FINAL, want_final_pass,
1637: filename, linenum);
1.344 djm 1638: if (value < 0) {
1639: error("%.200s line %d: Bad Match condition", filename,
1.206 djm 1640: linenum);
1.356 djm 1641: goto out;
1.344 djm 1642: }
1.252 djm 1643: *activep = (flags & SSHCONF_NEVERMATCH) ? 0 : value;
1.356 djm 1644: /*
1645: * If match_cfg_line() didn't consume all its arguments then
1646: * arrange for the extra arguments check below to fail.
1647: */
1648:
1649: if (str == NULL || *str == '\0')
1650: argv_consume(&ac);
1.206 djm 1651: break;
1652:
1.17 markus 1653: case oEscapeChar:
1654: intptr = &options->escape_char;
1.356 djm 1655: arg = argv_next(&ac, &av);
1.344 djm 1656: if (!arg || *arg == '\0') {
1657: error("%.200s line %d: Missing argument.",
1658: filename, linenum);
1.356 djm 1659: goto out;
1.344 djm 1660: }
1.236 djm 1661: if (strcmp(arg, "none") == 0)
1662: value = SSH_ESCAPECHAR_NONE;
1663: else if (arg[1] == '\0')
1664: value = (u_char) arg[0];
1665: else if (arg[0] == '^' && arg[2] == 0 &&
1.51 markus 1666: (u_char) arg[1] >= 64 && (u_char) arg[1] < 128)
1667: value = (u_char) arg[1] & 31;
1.17 markus 1668: else {
1.344 djm 1669: error("%.200s line %d: Bad escape character.",
1.93 deraadt 1670: filename, linenum);
1.356 djm 1671: goto out;
1.17 markus 1672: }
1673: if (*activep && *intptr == -1)
1674: *intptr = value;
1.112 djm 1675: break;
1676:
1677: case oAddressFamily:
1.114 djm 1678: intptr = &options->address_family;
1.207 djm 1679: multistate_ptr = multistate_addressfamily;
1680: goto parse_multistate;
1.17 markus 1681:
1.101 markus 1682: case oEnableSSHKeysign:
1683: intptr = &options->enable_ssh_keysign;
1684: goto parse_flag;
1685:
1.128 markus 1686: case oIdentitiesOnly:
1687: intptr = &options->identities_only;
1688: goto parse_flag;
1689:
1.127 markus 1690: case oServerAliveInterval:
1691: intptr = &options->server_alive_interval;
1692: goto parse_time;
1693:
1694: case oServerAliveCountMax:
1695: intptr = &options->server_alive_count_max;
1696: goto parse_int;
1697:
1.130 djm 1698: case oSendEnv:
1.356 djm 1699: while ((arg = argv_next(&ac, &av)) != NULL) {
1700: if (*arg == '\0' || strchr(arg, '=') != NULL) {
1.344 djm 1701: error("%s line %d: Invalid environment name.",
1.130 djm 1702: filename, linenum);
1.356 djm 1703: goto out;
1.344 djm 1704: }
1.137 djm 1705: if (!*activep)
1706: continue;
1.286 djm 1707: if (*arg == '-') {
1708: /* Removing an env var */
1709: rm_env(options, arg, filename, linenum);
1710: continue;
1711: } else {
1712: /* Adding an env var */
1.344 djm 1713: if (options->num_send_env >= INT_MAX) {
1714: error("%s line %d: too many send env.",
1.286 djm 1715: filename, linenum);
1.356 djm 1716: goto out;
1.344 djm 1717: }
1.290 djm 1718: options->send_env = xrecallocarray(
1719: options->send_env, options->num_send_env,
1.291 djm 1720: options->num_send_env + 1,
1.290 djm 1721: sizeof(*options->send_env));
1.286 djm 1722: options->send_env[options->num_send_env++] =
1723: xstrdup(arg);
1724: }
1.130 djm 1725: }
1726: break;
1727:
1.290 djm 1728: case oSetEnv:
1729: value = options->num_setenv;
1.356 djm 1730: while ((arg = argv_next(&ac, &av)) != NULL) {
1.344 djm 1731: if (strchr(arg, '=') == NULL) {
1732: error("%s line %d: Invalid SetEnv.",
1.290 djm 1733: filename, linenum);
1.356 djm 1734: goto out;
1.344 djm 1735: }
1.290 djm 1736: if (!*activep || value != 0)
1737: continue;
1738: /* Adding a setenv var */
1.344 djm 1739: if (options->num_setenv >= INT_MAX) {
1740: error("%s line %d: too many SetEnv.",
1.290 djm 1741: filename, linenum);
1.356 djm 1742: goto out;
1.344 djm 1743: }
1.290 djm 1744: options->setenv = xrecallocarray(
1745: options->setenv, options->num_setenv,
1746: options->num_setenv + 1, sizeof(*options->setenv));
1747: options->setenv[options->num_setenv++] = xstrdup(arg);
1748: }
1749: break;
1750:
1.132 djm 1751: case oControlPath:
1752: charptr = &options->control_path;
1753: goto parse_string;
1754:
1755: case oControlMaster:
1756: intptr = &options->control_master;
1.207 djm 1757: multistate_ptr = multistate_controlmaster;
1758: goto parse_multistate;
1.132 djm 1759:
1.187 djm 1760: case oControlPersist:
1761: /* no/false/yes/true, or a time spec */
1762: intptr = &options->control_persist;
1.356 djm 1763: arg = argv_next(&ac, &av);
1.344 djm 1764: if (!arg || *arg == '\0') {
1765: error("%.200s line %d: Missing ControlPersist"
1.187 djm 1766: " argument.", filename, linenum);
1.356 djm 1767: goto out;
1.344 djm 1768: }
1.187 djm 1769: value = 0;
1770: value2 = 0; /* timeout */
1771: if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
1772: value = 0;
1773: else if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
1774: value = 1;
1775: else if ((value2 = convtime(arg)) >= 0)
1776: value = 1;
1.344 djm 1777: else {
1778: error("%.200s line %d: Bad ControlPersist argument.",
1.187 djm 1779: filename, linenum);
1.356 djm 1780: goto out;
1.344 djm 1781: }
1.187 djm 1782: if (*activep && *intptr == -1) {
1783: *intptr = value;
1784: options->control_persist_timeout = value2;
1785: }
1786: break;
1787:
1.136 djm 1788: case oHashKnownHosts:
1789: intptr = &options->hash_known_hosts;
1790: goto parse_flag;
1791:
1.144 reyk 1792: case oTunnel:
1793: intptr = &options->tun_open;
1.207 djm 1794: multistate_ptr = multistate_tunnel;
1795: goto parse_multistate;
1.144 reyk 1796:
1797: case oTunnelDevice:
1.356 djm 1798: arg = argv_next(&ac, &av);
1.344 djm 1799: if (!arg || *arg == '\0') {
1800: error("%.200s line %d: Missing argument.",
1801: filename, linenum);
1.356 djm 1802: goto out;
1.344 djm 1803: }
1.144 reyk 1804: value = a2tun(arg, &value2);
1.344 djm 1805: if (value == SSH_TUNID_ERR) {
1806: error("%.200s line %d: Bad tun device.",
1807: filename, linenum);
1.356 djm 1808: goto out;
1.344 djm 1809: }
1.355 dtucker 1810: if (*activep && options->tun_local == -1) {
1.144 reyk 1811: options->tun_local = value;
1812: options->tun_remote = value2;
1813: }
1814: break;
1815:
1816: case oLocalCommand:
1817: charptr = &options->local_command;
1818: goto parse_command;
1819:
1820: case oPermitLocalCommand:
1821: intptr = &options->permit_local_command;
1822: goto parse_flag;
1823:
1.277 bluhm 1824: case oRemoteCommand:
1825: charptr = &options->remote_command;
1826: goto parse_command;
1827:
1.167 grunk 1828: case oVisualHostKey:
1829: intptr = &options->visual_host_key;
1830: goto parse_flag;
1831:
1.252 djm 1832: case oInclude:
1.344 djm 1833: if (cmdline) {
1834: error("Include directive not supported as a "
1.252 djm 1835: "command-line option");
1.356 djm 1836: goto out;
1.344 djm 1837: }
1.252 djm 1838: value = 0;
1.356 djm 1839: while ((arg = argv_next(&ac, &av)) != NULL) {
1840: if (*arg == '\0') {
1841: error("%s line %d: keyword %s empty argument",
1842: filename, linenum, keyword);
1843: goto out;
1844: }
1.252 djm 1845: /*
1846: * Ensure all paths are anchored. User configuration
1847: * files may begin with '~/' but system configurations
1848: * must not. If the path is relative, then treat it
1849: * as living in ~/.ssh for user configurations or
1850: * /etc/ssh for system ones.
1851: */
1.344 djm 1852: if (*arg == '~' && (flags & SSHCONF_USERCONF) == 0) {
1853: error("%.200s line %d: bad include path %s.",
1.252 djm 1854: filename, linenum, arg);
1.356 djm 1855: goto out;
1.344 djm 1856: }
1.301 djm 1857: if (!path_absolute(arg) && *arg != '~') {
1.252 djm 1858: xasprintf(&arg2, "%s/%s",
1859: (flags & SSHCONF_USERCONF) ?
1860: "~/" _PATH_SSH_USER_DIR : SSHDIR, arg);
1861: } else
1862: arg2 = xstrdup(arg);
1863: memset(&gl, 0, sizeof(gl));
1864: r = glob(arg2, GLOB_TILDE, NULL, &gl);
1865: if (r == GLOB_NOMATCH) {
1866: debug("%.200s line %d: include %s matched no "
1867: "files",filename, linenum, arg2);
1.269 dtucker 1868: free(arg2);
1.252 djm 1869: continue;
1.344 djm 1870: } else if (r != 0) {
1871: error("%.200s line %d: glob failed for %s.",
1.252 djm 1872: filename, linenum, arg2);
1.356 djm 1873: goto out;
1.344 djm 1874: }
1.252 djm 1875: free(arg2);
1876: oactive = *activep;
1.313 deraadt 1877: for (i = 0; i < gl.gl_pathc; i++) {
1.252 djm 1878: debug3("%.200s line %d: Including file %s "
1879: "depth %d%s", filename, linenum,
1880: gl.gl_pathv[i], depth,
1881: oactive ? "" : " (parse only)");
1882: r = read_config_file_depth(gl.gl_pathv[i],
1883: pw, host, original_host, options,
1884: flags | SSHCONF_CHECKPERM |
1885: (oactive ? 0 : SSHCONF_NEVERMATCH),
1.302 djm 1886: activep, want_final_pass, depth + 1);
1.264 djm 1887: if (r != 1 && errno != ENOENT) {
1.344 djm 1888: error("Can't open user config file "
1.263 djm 1889: "%.100s: %.100s", gl.gl_pathv[i],
1890: strerror(errno));
1.344 djm 1891: globfree(&gl);
1.356 djm 1892: goto out;
1.263 djm 1893: }
1.252 djm 1894: /*
1895: * don't let Match in includes clobber the
1896: * containing file's Match state.
1897: */
1898: *activep = oactive;
1899: if (r != 1)
1900: value = -1;
1901: }
1902: globfree(&gl);
1903: }
1904: if (value != 0)
1.356 djm 1905: ret = value;
1.252 djm 1906: break;
1907:
1.190 djm 1908: case oIPQoS:
1.356 djm 1909: arg = argv_next(&ac, &av);
1.344 djm 1910: if ((value = parse_ipqos(arg)) == -1) {
1911: error("%s line %d: Bad IPQoS value: %s",
1.190 djm 1912: filename, linenum, arg);
1.356 djm 1913: goto out;
1.344 djm 1914: }
1.356 djm 1915: arg = argv_next(&ac, &av);
1.190 djm 1916: if (arg == NULL)
1917: value2 = value;
1.344 djm 1918: else if ((value2 = parse_ipqos(arg)) == -1) {
1919: error("%s line %d: Bad IPQoS value: %s",
1.190 djm 1920: filename, linenum, arg);
1.356 djm 1921: goto out;
1.344 djm 1922: }
1.355 dtucker 1923: if (*activep && options->ip_qos_interactive == -1) {
1.190 djm 1924: options->ip_qos_interactive = value;
1925: options->ip_qos_bulk = value2;
1926: }
1927: break;
1928:
1.192 djm 1929: case oRequestTTY:
1930: intptr = &options->request_tty;
1.207 djm 1931: multistate_ptr = multistate_requesttty;
1932: goto parse_multistate;
1.192 djm 1933:
1.199 djm 1934: case oIgnoreUnknown:
1935: charptr = &options->ignored_unknown;
1936: goto parse_string;
1937:
1.205 djm 1938: case oProxyUseFdpass:
1939: intptr = &options->proxy_use_fdpass;
1940: goto parse_flag;
1941:
1.208 djm 1942: case oCanonicalDomains:
1943: value = options->num_canonical_domains != 0;
1.356 djm 1944: i = 0;
1945: while ((arg = argv_next(&ac, &av)) != NULL) {
1946: if (*arg == '\0') {
1947: error("%s line %d: keyword %s empty argument",
1948: filename, linenum, keyword);
1949: goto out;
1950: }
1951: /* Allow "none" only in first position */
1952: if (strcasecmp(arg, "none") == 0) {
1953: if (i > 0 || ac > 0) {
1954: error("%s line %d: keyword %s \"none\" "
1955: "argument must appear alone.",
1956: filename, linenum, keyword);
1957: goto out;
1958: }
1959: }
1960: i++;
1.280 millert 1961: if (!valid_domain(arg, 1, &errstr)) {
1.344 djm 1962: error("%s line %d: %s", filename, linenum,
1.280 millert 1963: errstr);
1.356 djm 1964: goto out;
1.280 millert 1965: }
1.208 djm 1966: if (!*activep || value)
1967: continue;
1.344 djm 1968: if (options->num_canonical_domains >=
1969: MAX_CANON_DOMAINS) {
1970: error("%s line %d: too many hostname suffixes.",
1.208 djm 1971: filename, linenum);
1.356 djm 1972: goto out;
1.344 djm 1973: }
1.208 djm 1974: options->canonical_domains[
1975: options->num_canonical_domains++] = xstrdup(arg);
1976: }
1977: break;
1978:
1.209 djm 1979: case oCanonicalizePermittedCNAMEs:
1.208 djm 1980: value = options->num_permitted_cnames != 0;
1.356 djm 1981: while ((arg = argv_next(&ac, &av)) != NULL) {
1.208 djm 1982: /* Either '*' for everything or 'list:list' */
1983: if (strcmp(arg, "*") == 0)
1984: arg2 = arg;
1985: else {
1986: lowercase(arg);
1987: if ((arg2 = strchr(arg, ':')) == NULL ||
1988: arg2[1] == '\0') {
1.344 djm 1989: error("%s line %d: "
1.208 djm 1990: "Invalid permitted CNAME \"%s\"",
1991: filename, linenum, arg);
1.356 djm 1992: goto out;
1.208 djm 1993: }
1994: *arg2 = '\0';
1995: arg2++;
1996: }
1997: if (!*activep || value)
1998: continue;
1.344 djm 1999: if (options->num_permitted_cnames >=
2000: MAX_CANON_DOMAINS) {
2001: error("%s line %d: too many permitted CNAMEs.",
1.208 djm 2002: filename, linenum);
1.356 djm 2003: goto out;
1.344 djm 2004: }
1.208 djm 2005: cname = options->permitted_cnames +
2006: options->num_permitted_cnames++;
2007: cname->source_list = xstrdup(arg);
2008: cname->target_list = xstrdup(arg2);
2009: }
2010: break;
2011:
1.209 djm 2012: case oCanonicalizeHostname:
2013: intptr = &options->canonicalize_hostname;
2014: multistate_ptr = multistate_canonicalizehostname;
1.208 djm 2015: goto parse_multistate;
2016:
1.209 djm 2017: case oCanonicalizeMaxDots:
2018: intptr = &options->canonicalize_max_dots;
1.208 djm 2019: goto parse_int;
2020:
1.209 djm 2021: case oCanonicalizeFallbackLocal:
2022: intptr = &options->canonicalize_fallback_local;
1.208 djm 2023: goto parse_flag;
2024:
1.220 millert 2025: case oStreamLocalBindMask:
1.356 djm 2026: arg = argv_next(&ac, &av);
1.344 djm 2027: if (!arg || *arg == '\0') {
2028: error("%.200s line %d: Missing StreamLocalBindMask "
2029: "argument.", filename, linenum);
1.356 djm 2030: goto out;
1.344 djm 2031: }
1.220 millert 2032: /* Parse mode in octal format */
2033: value = strtol(arg, &endofnumber, 8);
1.344 djm 2034: if (arg == endofnumber || value < 0 || value > 0777) {
2035: error("%.200s line %d: Bad mask.", filename, linenum);
1.356 djm 2036: goto out;
1.344 djm 2037: }
1.220 millert 2038: options->fwd_opts.streamlocal_bind_mask = (mode_t)value;
2039: break;
2040:
2041: case oStreamLocalBindUnlink:
2042: intptr = &options->fwd_opts.streamlocal_bind_unlink;
2043: goto parse_flag;
2044:
1.223 djm 2045: case oRevokedHostKeys:
2046: charptr = &options->revoked_host_keys;
2047: goto parse_string;
2048:
1.224 djm 2049: case oFingerprintHash:
1.225 djm 2050: intptr = &options->fingerprint_hash;
1.356 djm 2051: arg = argv_next(&ac, &av);
1.344 djm 2052: if (!arg || *arg == '\0') {
2053: error("%.200s line %d: Missing argument.",
1.224 djm 2054: filename, linenum);
1.356 djm 2055: goto out;
1.344 djm 2056: }
2057: if ((value = ssh_digest_alg_by_name(arg)) == -1) {
2058: error("%.200s line %d: Invalid hash algorithm \"%s\".",
1.224 djm 2059: filename, linenum, arg);
1.356 djm 2060: goto out;
1.344 djm 2061: }
1.225 djm 2062: if (*activep && *intptr == -1)
2063: *intptr = value;
1.224 djm 2064: break;
2065:
1.229 djm 2066: case oUpdateHostkeys:
2067: intptr = &options->update_hostkeys;
1.232 djm 2068: multistate_ptr = multistate_yesnoask;
2069: goto parse_multistate;
1.229 djm 2070:
1.350 dtucker 2071: case oHostbasedAcceptedAlgorithms:
2072: charptr = &options->hostbased_accepted_algos;
1.349 dtucker 2073: goto parse_pubkey_algos;
1.238 markus 2074:
1.349 dtucker 2075: case oPubkeyAcceptedAlgorithms:
2076: charptr = &options->pubkey_accepted_algos;
2077: goto parse_pubkey_algos;
1.230 djm 2078:
1.246 jcs 2079: case oAddKeysToAgent:
1.356 djm 2080: arg = argv_next(&ac, &av);
2081: arg2 = argv_next(&ac, &av);
1.334 djm 2082: value = parse_multistate_value(arg, filename, linenum,
1.353 djm 2083: multistate_yesnoaskconfirm);
1.334 djm 2084: value2 = 0; /* unlimited lifespan by default */
2085: if (value == 3 && arg2 != NULL) {
2086: /* allow "AddKeysToAgent confirm 5m" */
1.344 djm 2087: if ((value2 = convtime(arg2)) == -1 ||
2088: value2 > INT_MAX) {
2089: error("%s line %d: invalid time value.",
1.334 djm 2090: filename, linenum);
1.356 djm 2091: goto out;
1.344 djm 2092: }
1.334 djm 2093: } else if (value == -1 && arg2 == NULL) {
1.344 djm 2094: if ((value2 = convtime(arg)) == -1 ||
2095: value2 > INT_MAX) {
2096: error("%s line %d: unsupported option",
1.334 djm 2097: filename, linenum);
1.356 djm 2098: goto out;
1.344 djm 2099: }
1.334 djm 2100: value = 1; /* yes */
2101: } else if (value == -1 || arg2 != NULL) {
1.344 djm 2102: error("%s line %d: unsupported option",
1.334 djm 2103: filename, linenum);
1.356 djm 2104: goto out;
1.334 djm 2105: }
2106: if (*activep && options->add_keys_to_agent == -1) {
2107: options->add_keys_to_agent = value;
2108: options->add_keys_to_agent_lifespan = value2;
2109: }
2110: break;
1.246 jcs 2111:
1.253 markus 2112: case oIdentityAgent:
2113: charptr = &options->identity_agent;
1.356 djm 2114: arg = argv_next(&ac, &av);
1.344 djm 2115: if (!arg || *arg == '\0') {
2116: error("%.200s line %d: Missing argument.",
1.299 djm 2117: filename, linenum);
1.356 djm 2118: goto out;
1.344 djm 2119: }
1.319 djm 2120: parse_agent_path:
1.299 djm 2121: /* Extra validation if the string represents an env var. */
1.344 djm 2122: if ((arg2 = dollar_expand(&r, arg)) == NULL || r) {
2123: error("%.200s line %d: Invalid environment expansion "
1.331 dtucker 2124: "%s.", filename, linenum, arg);
1.356 djm 2125: goto out;
1.344 djm 2126: }
1.331 dtucker 2127: free(arg2);
2128: /* check for legacy environment format */
1.344 djm 2129: if (arg[0] == '$' && arg[1] != '{' &&
2130: !valid_env_name(arg + 1)) {
2131: error("%.200s line %d: Invalid environment name %s.",
1.299 djm 2132: filename, linenum, arg);
1.356 djm 2133: goto out;
1.299 djm 2134: }
2135: if (*activep && *charptr == NULL)
2136: *charptr = xstrdup(arg);
2137: break;
1.253 markus 2138:
1.96 markus 2139: case oDeprecated:
1.98 markus 2140: debug("%s line %d: Deprecated option \"%s\"",
1.96 markus 2141: filename, linenum, keyword);
1.356 djm 2142: argv_consume(&ac);
2143: break;
1.96 markus 2144:
1.110 jakob 2145: case oUnsupported:
2146: error("%s line %d: Unsupported option \"%s\"",
2147: filename, linenum, keyword);
1.356 djm 2148: argv_consume(&ac);
2149: break;
1.110 jakob 2150:
1.17 markus 2151: default:
1.344 djm 2152: error("%s line %d: Unimplemented opcode %d",
2153: filename, linenum, opcode);
1.356 djm 2154: goto out;
1.17 markus 2155: }
2156:
2157: /* Check that there is no garbage at end of line. */
1.356 djm 2158: if (ac > 0) {
2159: error("%.200s line %d: keyword %s extra arguments "
2160: "at end of line", filename, linenum, keyword);
2161: goto out;
1.39 ho 2162: }
1.356 djm 2163:
2164: /* success */
2165: ret = 0;
2166: out:
2167: argv_free(oav, oac);
2168: return ret;
1.1 deraadt 2169: }
2170:
1.19 markus 2171: /*
2172: * Reads the config file and modifies the options accordingly. Options
2173: * should already be initialized before this call. This never returns if
1.89 stevesk 2174: * there is an error. If the file does not exist, this returns 0.
1.19 markus 2175: */
1.89 stevesk 2176: int
1.206 djm 2177: read_config_file(const char *filename, struct passwd *pw, const char *host,
1.302 djm 2178: const char *original_host, Options *options, int flags,
2179: int *want_final_pass)
1.1 deraadt 2180: {
1.252 djm 2181: int active = 1;
2182:
2183: return read_config_file_depth(filename, pw, host, original_host,
1.302 djm 2184: options, flags, &active, want_final_pass, 0);
1.252 djm 2185: }
2186:
2187: #define READCONF_MAX_DEPTH 16
2188: static int
2189: read_config_file_depth(const char *filename, struct passwd *pw,
2190: const char *host, const char *original_host, Options *options,
1.302 djm 2191: int flags, int *activep, int *want_final_pass, int depth)
1.252 djm 2192: {
1.17 markus 2193: FILE *f;
1.356 djm 2194: char *line = NULL;
1.289 markus 2195: size_t linesize = 0;
1.252 djm 2196: int linenum;
1.17 markus 2197: int bad_options = 0;
2198:
1.252 djm 2199: if (depth < 0 || depth > READCONF_MAX_DEPTH)
2200: fatal("Too many recursive configuration includes");
2201:
1.129 djm 2202: if ((f = fopen(filename, "r")) == NULL)
1.89 stevesk 2203: return 0;
1.129 djm 2204:
1.196 dtucker 2205: if (flags & SSHCONF_CHECKPERM) {
1.129 djm 2206: struct stat sb;
1.134 deraadt 2207:
1.131 dtucker 2208: if (fstat(fileno(f), &sb) == -1)
1.129 djm 2209: fatal("fstat %s: %s", filename, strerror(errno));
2210: if (((sb.st_uid != 0 && sb.st_uid != getuid()) ||
1.131 dtucker 2211: (sb.st_mode & 022) != 0))
1.129 djm 2212: fatal("Bad owner or permissions on %s", filename);
2213: }
1.17 markus 2214:
2215: debug("Reading configuration data %.200s", filename);
2216:
1.19 markus 2217: /*
2218: * Mark that we are now processing the options. This flag is turned
2219: * on/off by Host specifications.
2220: */
1.17 markus 2221: linenum = 0;
1.289 markus 2222: while (getline(&line, &linesize, f) != -1) {
1.17 markus 2223: /* Update line number counter. */
2224: linenum++;
1.343 dtucker 2225: /*
2226: * Trim out comments and strip whitespace.
2227: * NB - preserve newlines, they are needed to reproduce
2228: * line numbers later for error messages.
2229: */
1.252 djm 2230: if (process_config_line_depth(options, pw, host, original_host,
1.302 djm 2231: line, filename, linenum, activep, flags, want_final_pass,
2232: depth) != 0)
1.17 markus 2233: bad_options++;
2234: }
1.289 markus 2235: free(line);
1.17 markus 2236: fclose(f);
2237: if (bad_options > 0)
1.64 millert 2238: fatal("%s: terminating, %d bad configuration options",
1.93 deraadt 2239: filename, bad_options);
1.89 stevesk 2240: return 1;
1.1 deraadt 2241: }
2242:
1.218 djm 2243: /* Returns 1 if a string option is unset or set to "none" or 0 otherwise. */
2244: int
2245: option_clear_or_none(const char *o)
2246: {
2247: return o == NULL || strcasecmp(o, "none") == 0;
2248: }
2249:
1.19 markus 2250: /*
2251: * Initializes options to special values that indicate that they have not yet
2252: * been set. Read_config_file will only set options with this value. Options
2253: * are processed in the following order: command line, user config file,
2254: * system config file. Last, fill_default_options is called.
2255: */
1.1 deraadt 2256:
1.26 markus 2257: void
1.17 markus 2258: initialize_options(Options * options)
1.1 deraadt 2259: {
1.17 markus 2260: memset(options, 'X', sizeof(*options));
2261: options->forward_agent = -1;
1.319 djm 2262: options->forward_agent_sock_path = NULL;
1.17 markus 2263: options->forward_x11 = -1;
1.123 markus 2264: options->forward_x11_trusted = -1;
1.186 djm 2265: options->forward_x11_timeout = -1;
1.255 dtucker 2266: options->stdio_forward_host = NULL;
2267: options->stdio_forward_port = 0;
1.256 dtucker 2268: options->clear_forwardings = -1;
1.153 markus 2269: options->exit_on_forward_failure = -1;
1.34 markus 2270: options->xauth_location = NULL;
1.220 millert 2271: options->fwd_opts.gateway_ports = -1;
2272: options->fwd_opts.streamlocal_bind_mask = (mode_t)-1;
2273: options->fwd_opts.streamlocal_bind_unlink = -1;
1.50 markus 2274: options->pubkey_authentication = -1;
1.78 markus 2275: options->challenge_response_authentication = -1;
1.118 markus 2276: options->gss_authentication = -1;
2277: options->gss_deleg_creds = -1;
1.17 markus 2278: options->password_authentication = -1;
1.48 markus 2279: options->kbd_interactive_authentication = -1;
2280: options->kbd_interactive_devices = NULL;
1.72 markus 2281: options->hostbased_authentication = -1;
1.17 markus 2282: options->batch_mode = -1;
2283: options->check_host_ip = -1;
2284: options->strict_host_key_checking = -1;
2285: options->compression = -1;
1.126 markus 2286: options->tcp_keep_alive = -1;
1.17 markus 2287: options->port = -1;
1.114 djm 2288: options->address_family = -1;
1.17 markus 2289: options->connection_attempts = -1;
1.111 djm 2290: options->connection_timeout = -1;
1.17 markus 2291: options->number_of_password_prompts = -1;
1.25 markus 2292: options->ciphers = NULL;
1.62 markus 2293: options->macs = NULL;
1.189 djm 2294: options->kex_algorithms = NULL;
1.76 markus 2295: options->hostkeyalgorithms = NULL;
1.298 djm 2296: options->ca_sign_algorithms = NULL;
1.17 markus 2297: options->num_identity_files = 0;
1.344 djm 2298: memset(options->identity_keys, 0, sizeof(options->identity_keys));
1.241 djm 2299: options->num_certificate_files = 0;
1.344 djm 2300: memset(options->certificates, 0, sizeof(options->certificates));
1.17 markus 2301: options->hostname = NULL;
1.52 markus 2302: options->host_key_alias = NULL;
1.17 markus 2303: options->proxy_command = NULL;
1.257 djm 2304: options->jump_user = NULL;
2305: options->jump_host = NULL;
2306: options->jump_port = -1;
2307: options->jump_extra = NULL;
1.17 markus 2308: options->user = NULL;
2309: options->escape_char = -1;
1.193 djm 2310: options->num_system_hostfiles = 0;
2311: options->num_user_hostfiles = 0;
1.185 djm 2312: options->local_forwards = NULL;
1.17 markus 2313: options->num_local_forwards = 0;
1.185 djm 2314: options->remote_forwards = NULL;
1.17 markus 2315: options->num_remote_forwards = 0;
1.351 markus 2316: options->permitted_remote_opens = NULL;
2317: options->num_permitted_remote_opens = 0;
1.271 dtucker 2318: options->log_facility = SYSLOG_FACILITY_NOT_SET;
1.95 markus 2319: options->log_level = SYSLOG_LEVEL_NOT_SET;
1.339 djm 2320: options->num_log_verbose = 0;
2321: options->log_verbose = NULL;
1.67 markus 2322: options->preferred_authentications = NULL;
1.77 markus 2323: options->bind_address = NULL;
1.282 djm 2324: options->bind_interface = NULL;
1.183 markus 2325: options->pkcs11_provider = NULL;
1.310 djm 2326: options->sk_provider = NULL;
1.101 markus 2327: options->enable_ssh_keysign = - 1;
1.91 markus 2328: options->no_host_authentication_for_localhost = - 1;
1.128 markus 2329: options->identities_only = - 1;
1.105 markus 2330: options->rekey_limit = - 1;
1.198 dtucker 2331: options->rekey_interval = -1;
1.107 jakob 2332: options->verify_host_key_dns = -1;
1.127 markus 2333: options->server_alive_interval = -1;
2334: options->server_alive_count_max = -1;
1.290 djm 2335: options->send_env = NULL;
1.130 djm 2336: options->num_send_env = 0;
1.290 djm 2337: options->setenv = NULL;
2338: options->num_setenv = 0;
1.132 djm 2339: options->control_path = NULL;
2340: options->control_master = -1;
1.187 djm 2341: options->control_persist = -1;
2342: options->control_persist_timeout = 0;
1.136 djm 2343: options->hash_known_hosts = -1;
1.144 reyk 2344: options->tun_open = -1;
2345: options->tun_local = -1;
2346: options->tun_remote = -1;
2347: options->local_command = NULL;
2348: options->permit_local_command = -1;
1.277 bluhm 2349: options->remote_command = NULL;
1.246 jcs 2350: options->add_keys_to_agent = -1;
1.334 djm 2351: options->add_keys_to_agent_lifespan = -1;
1.253 markus 2352: options->identity_agent = NULL;
1.167 grunk 2353: options->visual_host_key = -1;
1.190 djm 2354: options->ip_qos_interactive = -1;
2355: options->ip_qos_bulk = -1;
1.192 djm 2356: options->request_tty = -1;
1.205 djm 2357: options->proxy_use_fdpass = -1;
1.199 djm 2358: options->ignored_unknown = NULL;
1.208 djm 2359: options->num_canonical_domains = 0;
2360: options->num_permitted_cnames = 0;
1.209 djm 2361: options->canonicalize_max_dots = -1;
2362: options->canonicalize_fallback_local = -1;
2363: options->canonicalize_hostname = -1;
1.223 djm 2364: options->revoked_host_keys = NULL;
1.224 djm 2365: options->fingerprint_hash = -1;
1.229 djm 2366: options->update_hostkeys = -1;
1.350 dtucker 2367: options->hostbased_accepted_algos = NULL;
1.349 dtucker 2368: options->pubkey_accepted_algos = NULL;
1.346 djm 2369: options->known_hosts_command = NULL;
1.1 deraadt 2370: }
2371:
1.19 markus 2372: /*
1.218 djm 2373: * A petite version of fill_default_options() that just fills the options
2374: * needed for hostname canonicalization to proceed.
2375: */
2376: void
2377: fill_default_options_for_canonicalization(Options *options)
2378: {
2379: if (options->canonicalize_max_dots == -1)
2380: options->canonicalize_max_dots = 1;
2381: if (options->canonicalize_fallback_local == -1)
2382: options->canonicalize_fallback_local = 1;
2383: if (options->canonicalize_hostname == -1)
2384: options->canonicalize_hostname = SSH_CANONICALISE_NO;
2385: }
2386:
2387: /*
1.19 markus 2388: * Called after processing other sources of option data, this fills those
2389: * options for which no value has been specified with their default values.
2390: */
1.344 djm 2391: int
1.17 markus 2392: fill_default_options(Options * options)
1.1 deraadt 2393: {
1.298 djm 2394: char *all_cipher, *all_mac, *all_kex, *all_key, *all_sig;
1.320 dtucker 2395: char *def_cipher, *def_mac, *def_kex, *def_key, *def_sig;
1.344 djm 2396: int ret = 0, r;
1.292 djm 2397:
1.17 markus 2398: if (options->forward_agent == -1)
1.33 markus 2399: options->forward_agent = 0;
1.17 markus 2400: if (options->forward_x11 == -1)
1.23 markus 2401: options->forward_x11 = 0;
1.123 markus 2402: if (options->forward_x11_trusted == -1)
2403: options->forward_x11_trusted = 0;
1.186 djm 2404: if (options->forward_x11_timeout == -1)
2405: options->forward_x11_timeout = 1200;
1.256 dtucker 2406: /*
2407: * stdio forwarding (-W) changes the default for these but we defer
2408: * setting the values so they can be overridden.
2409: */
1.153 markus 2410: if (options->exit_on_forward_failure == -1)
1.256 dtucker 2411: options->exit_on_forward_failure =
2412: options->stdio_forward_host != NULL ? 1 : 0;
2413: if (options->clear_forwardings == -1)
2414: options->clear_forwardings =
2415: options->stdio_forward_host != NULL ? 1 : 0;
2416: if (options->clear_forwardings == 1)
2417: clear_forwardings(options);
2418:
1.34 markus 2419: if (options->xauth_location == NULL)
1.344 djm 2420: options->xauth_location = xstrdup(_PATH_XAUTH);
1.220 millert 2421: if (options->fwd_opts.gateway_ports == -1)
2422: options->fwd_opts.gateway_ports = 0;
2423: if (options->fwd_opts.streamlocal_bind_mask == (mode_t)-1)
2424: options->fwd_opts.streamlocal_bind_mask = 0177;
2425: if (options->fwd_opts.streamlocal_bind_unlink == -1)
2426: options->fwd_opts.streamlocal_bind_unlink = 0;
1.50 markus 2427: if (options->pubkey_authentication == -1)
2428: options->pubkey_authentication = 1;
1.78 markus 2429: if (options->challenge_response_authentication == -1)
1.83 markus 2430: options->challenge_response_authentication = 1;
1.118 markus 2431: if (options->gss_authentication == -1)
1.122 markus 2432: options->gss_authentication = 0;
1.118 markus 2433: if (options->gss_deleg_creds == -1)
2434: options->gss_deleg_creds = 0;
1.17 markus 2435: if (options->password_authentication == -1)
2436: options->password_authentication = 1;
1.48 markus 2437: if (options->kbd_interactive_authentication == -1)
1.59 markus 2438: options->kbd_interactive_authentication = 1;
1.72 markus 2439: if (options->hostbased_authentication == -1)
2440: options->hostbased_authentication = 0;
1.17 markus 2441: if (options->batch_mode == -1)
2442: options->batch_mode = 0;
2443: if (options->check_host_ip == -1)
1.348 djm 2444: options->check_host_ip = 0;
1.17 markus 2445: if (options->strict_host_key_checking == -1)
1.278 djm 2446: options->strict_host_key_checking = SSH_STRICT_HOSTKEY_ASK;
1.17 markus 2447: if (options->compression == -1)
2448: options->compression = 0;
1.126 markus 2449: if (options->tcp_keep_alive == -1)
2450: options->tcp_keep_alive = 1;
1.17 markus 2451: if (options->port == -1)
2452: options->port = 0; /* Filled in ssh_connect. */
1.114 djm 2453: if (options->address_family == -1)
2454: options->address_family = AF_UNSPEC;
1.17 markus 2455: if (options->connection_attempts == -1)
1.84 markus 2456: options->connection_attempts = 1;
1.17 markus 2457: if (options->number_of_password_prompts == -1)
2458: options->number_of_password_prompts = 3;
1.76 markus 2459: /* options->hostkeyalgorithms, default set in myproposals.h */
1.334 djm 2460: if (options->add_keys_to_agent == -1) {
1.246 jcs 2461: options->add_keys_to_agent = 0;
1.334 djm 2462: options->add_keys_to_agent_lifespan = 0;
2463: }
1.17 markus 2464: if (options->num_identity_files == 0) {
1.273 djm 2465: add_identity_file(options, "~/", _PATH_SSH_CLIENT_ID_RSA, 0);
2466: add_identity_file(options, "~/", _PATH_SSH_CLIENT_ID_DSA, 0);
2467: add_identity_file(options, "~/", _PATH_SSH_CLIENT_ID_ECDSA, 0);
2468: add_identity_file(options, "~/",
1.310 djm 2469: _PATH_SSH_CLIENT_ID_ECDSA_SK, 0);
2470: add_identity_file(options, "~/",
1.273 djm 2471: _PATH_SSH_CLIENT_ID_ED25519, 0);
1.311 markus 2472: add_identity_file(options, "~/",
2473: _PATH_SSH_CLIENT_ID_ED25519_SK, 0);
1.283 markus 2474: add_identity_file(options, "~/", _PATH_SSH_CLIENT_ID_XMSS, 0);
1.27 markus 2475: }
1.17 markus 2476: if (options->escape_char == -1)
2477: options->escape_char = '~';
1.193 djm 2478: if (options->num_system_hostfiles == 0) {
2479: options->system_hostfiles[options->num_system_hostfiles++] =
2480: xstrdup(_PATH_SSH_SYSTEM_HOSTFILE);
2481: options->system_hostfiles[options->num_system_hostfiles++] =
2482: xstrdup(_PATH_SSH_SYSTEM_HOSTFILE2);
2483: }
1.336 djm 2484: if (options->update_hostkeys == -1) {
1.338 djm 2485: if (options->verify_host_key_dns <= 0 &&
2486: (options->num_user_hostfiles == 0 ||
1.336 djm 2487: (options->num_user_hostfiles == 1 && strcmp(options->
1.338 djm 2488: user_hostfiles[0], _PATH_SSH_USER_HOSTFILE) == 0)))
1.336 djm 2489: options->update_hostkeys = SSH_UPDATE_HOSTKEYS_YES;
2490: else
1.325 djm 2491: options->update_hostkeys = SSH_UPDATE_HOSTKEYS_NO;
1.336 djm 2492: }
1.193 djm 2493: if (options->num_user_hostfiles == 0) {
2494: options->user_hostfiles[options->num_user_hostfiles++] =
2495: xstrdup(_PATH_SSH_USER_HOSTFILE);
2496: options->user_hostfiles[options->num_user_hostfiles++] =
2497: xstrdup(_PATH_SSH_USER_HOSTFILE2);
2498: }
1.95 markus 2499: if (options->log_level == SYSLOG_LEVEL_NOT_SET)
1.54 markus 2500: options->log_level = SYSLOG_LEVEL_INFO;
1.271 dtucker 2501: if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
2502: options->log_facility = SYSLOG_FACILITY_USER;
1.91 markus 2503: if (options->no_host_authentication_for_localhost == - 1)
2504: options->no_host_authentication_for_localhost = 0;
1.128 markus 2505: if (options->identities_only == -1)
2506: options->identities_only = 0;
1.101 markus 2507: if (options->enable_ssh_keysign == -1)
2508: options->enable_ssh_keysign = 0;
1.105 markus 2509: if (options->rekey_limit == -1)
2510: options->rekey_limit = 0;
1.198 dtucker 2511: if (options->rekey_interval == -1)
2512: options->rekey_interval = 0;
1.107 jakob 2513: if (options->verify_host_key_dns == -1)
2514: options->verify_host_key_dns = 0;
1.127 markus 2515: if (options->server_alive_interval == -1)
2516: options->server_alive_interval = 0;
2517: if (options->server_alive_count_max == -1)
2518: options->server_alive_count_max = 3;
1.132 djm 2519: if (options->control_master == -1)
2520: options->control_master = 0;
1.187 djm 2521: if (options->control_persist == -1) {
2522: options->control_persist = 0;
2523: options->control_persist_timeout = 0;
2524: }
1.136 djm 2525: if (options->hash_known_hosts == -1)
2526: options->hash_known_hosts = 0;
1.144 reyk 2527: if (options->tun_open == -1)
1.145 reyk 2528: options->tun_open = SSH_TUNMODE_NO;
2529: if (options->tun_local == -1)
2530: options->tun_local = SSH_TUNID_ANY;
2531: if (options->tun_remote == -1)
2532: options->tun_remote = SSH_TUNID_ANY;
1.144 reyk 2533: if (options->permit_local_command == -1)
2534: options->permit_local_command = 0;
1.167 grunk 2535: if (options->visual_host_key == -1)
2536: options->visual_host_key = 0;
1.190 djm 2537: if (options->ip_qos_interactive == -1)
1.284 job 2538: options->ip_qos_interactive = IPTOS_DSCP_AF21;
1.190 djm 2539: if (options->ip_qos_bulk == -1)
1.284 job 2540: options->ip_qos_bulk = IPTOS_DSCP_CS1;
1.192 djm 2541: if (options->request_tty == -1)
2542: options->request_tty = REQUEST_TTY_AUTO;
1.205 djm 2543: if (options->proxy_use_fdpass == -1)
2544: options->proxy_use_fdpass = 0;
1.209 djm 2545: if (options->canonicalize_max_dots == -1)
2546: options->canonicalize_max_dots = 1;
2547: if (options->canonicalize_fallback_local == -1)
2548: options->canonicalize_fallback_local = 1;
2549: if (options->canonicalize_hostname == -1)
2550: options->canonicalize_hostname = SSH_CANONICALISE_NO;
1.224 djm 2551: if (options->fingerprint_hash == -1)
2552: options->fingerprint_hash = SSH_FP_HASH_DEFAULT;
1.310 djm 2553: if (options->sk_provider == NULL)
1.314 djm 2554: options->sk_provider = xstrdup("internal");
1.292 djm 2555:
2556: /* Expand KEX name lists */
2557: all_cipher = cipher_alg_list(',', 0);
2558: all_mac = mac_alg_list(',');
2559: all_kex = kex_alg_list(',');
2560: all_key = sshkey_alg_list(0, 0, 1, ',');
1.298 djm 2561: all_sig = sshkey_alg_list(0, 1, 1, ',');
1.320 dtucker 2562: /* remove unsupported algos from default lists */
1.332 djm 2563: def_cipher = match_filter_allowlist(KEX_CLIENT_ENCRYPT, all_cipher);
2564: def_mac = match_filter_allowlist(KEX_CLIENT_MAC, all_mac);
2565: def_kex = match_filter_allowlist(KEX_CLIENT_KEX, all_kex);
2566: def_key = match_filter_allowlist(KEX_DEFAULT_PK_ALG, all_key);
2567: def_sig = match_filter_allowlist(SSH_ALLOWED_CA_SIGALGS, all_sig);
1.297 djm 2568: #define ASSEMBLE(what, defaults, all) \
2569: do { \
2570: if ((r = kex_assemble_names(&options->what, \
1.344 djm 2571: defaults, all)) != 0) { \
2572: error_fr(r, "%s", #what); \
2573: goto fail; \
2574: } \
1.297 djm 2575: } while (0)
1.320 dtucker 2576: ASSEMBLE(ciphers, def_cipher, all_cipher);
2577: ASSEMBLE(macs, def_mac, all_mac);
2578: ASSEMBLE(kex_algorithms, def_kex, all_kex);
1.350 dtucker 2579: ASSEMBLE(hostbased_accepted_algos, def_key, all_key);
1.349 dtucker 2580: ASSEMBLE(pubkey_accepted_algos, def_key, all_key);
1.320 dtucker 2581: ASSEMBLE(ca_sign_algorithms, def_sig, all_sig);
1.297 djm 2582: #undef ASSEMBLE
1.224 djm 2583:
1.207 djm 2584: #define CLEAR_ON_NONE(v) \
2585: do { \
1.218 djm 2586: if (option_clear_or_none(v)) { \
1.207 djm 2587: free(v); \
2588: v = NULL; \
2589: } \
2590: } while(0)
2591: CLEAR_ON_NONE(options->local_command);
1.277 bluhm 2592: CLEAR_ON_NONE(options->remote_command);
1.207 djm 2593: CLEAR_ON_NONE(options->proxy_command);
2594: CLEAR_ON_NONE(options->control_path);
1.223 djm 2595: CLEAR_ON_NONE(options->revoked_host_keys);
1.304 djm 2596: CLEAR_ON_NONE(options->pkcs11_provider);
1.310 djm 2597: CLEAR_ON_NONE(options->sk_provider);
1.346 djm 2598: CLEAR_ON_NONE(options->known_hosts_command);
1.287 djm 2599: if (options->jump_host != NULL &&
2600: strcmp(options->jump_host, "none") == 0 &&
2601: options->jump_port == 0 && options->jump_user == NULL) {
2602: free(options->jump_host);
2603: options->jump_host = NULL;
2604: }
1.254 markus 2605: /* options->identity_agent distinguishes NULL from 'none' */
1.17 markus 2606: /* options->user will be set in the main program if appropriate */
2607: /* options->hostname will be set in the main program if appropriate */
1.52 markus 2608: /* options->host_key_alias should not be set by default */
1.67 markus 2609: /* options->preferred_authentications will be set in ssh */
1.344 djm 2610:
2611: /* success */
2612: ret = 0;
2613: fail:
2614: free(all_cipher);
2615: free(all_mac);
2616: free(all_kex);
2617: free(all_key);
2618: free(all_sig);
2619: free(def_cipher);
2620: free(def_mac);
2621: free(def_kex);
2622: free(def_key);
2623: free(def_sig);
2624: return ret;
2625: }
2626:
2627: void
2628: free_options(Options *o)
2629: {
2630: int i;
2631:
2632: if (o == NULL)
2633: return;
2634:
2635: #define FREE_ARRAY(type, n, a) \
2636: do { \
2637: type _i; \
2638: for (_i = 0; _i < (n); _i++) \
2639: free((a)[_i]); \
2640: } while (0)
2641:
2642: free(o->forward_agent_sock_path);
2643: free(o->xauth_location);
2644: FREE_ARRAY(u_int, o->num_log_verbose, o->log_verbose);
2645: free(o->log_verbose);
2646: free(o->ciphers);
2647: free(o->macs);
2648: free(o->hostkeyalgorithms);
2649: free(o->kex_algorithms);
2650: free(o->ca_sign_algorithms);
2651: free(o->hostname);
2652: free(o->host_key_alias);
2653: free(o->proxy_command);
2654: free(o->user);
2655: FREE_ARRAY(u_int, o->num_system_hostfiles, o->system_hostfiles);
2656: FREE_ARRAY(u_int, o->num_user_hostfiles, o->user_hostfiles);
2657: free(o->preferred_authentications);
2658: free(o->bind_address);
2659: free(o->bind_interface);
2660: free(o->pkcs11_provider);
2661: free(o->sk_provider);
2662: for (i = 0; i < o->num_identity_files; i++) {
2663: free(o->identity_files[i]);
2664: sshkey_free(o->identity_keys[i]);
2665: }
2666: for (i = 0; i < o->num_certificate_files; i++) {
2667: free(o->certificate_files[i]);
2668: sshkey_free(o->certificates[i]);
2669: }
2670: free(o->identity_agent);
2671: for (i = 0; i < o->num_local_forwards; i++) {
2672: free(o->local_forwards[i].listen_host);
2673: free(o->local_forwards[i].listen_path);
2674: free(o->local_forwards[i].connect_host);
2675: free(o->local_forwards[i].connect_path);
2676: }
2677: free(o->local_forwards);
2678: for (i = 0; i < o->num_remote_forwards; i++) {
2679: free(o->remote_forwards[i].listen_host);
2680: free(o->remote_forwards[i].listen_path);
2681: free(o->remote_forwards[i].connect_host);
2682: free(o->remote_forwards[i].connect_path);
2683: }
2684: free(o->remote_forwards);
2685: free(o->stdio_forward_host);
2686: FREE_ARRAY(int, o->num_send_env, o->send_env);
2687: free(o->send_env);
2688: FREE_ARRAY(int, o->num_setenv, o->setenv);
2689: free(o->setenv);
2690: free(o->control_path);
2691: free(o->local_command);
2692: free(o->remote_command);
2693: FREE_ARRAY(int, o->num_canonical_domains, o->canonical_domains);
2694: for (i = 0; i < o->num_permitted_cnames; i++) {
2695: free(o->permitted_cnames[i].source_list);
2696: free(o->permitted_cnames[i].target_list);
2697: }
2698: free(o->revoked_host_keys);
1.350 dtucker 2699: free(o->hostbased_accepted_algos);
1.349 dtucker 2700: free(o->pubkey_accepted_algos);
1.344 djm 2701: free(o->jump_user);
2702: free(o->jump_host);
2703: free(o->jump_extra);
2704: free(o->ignored_unknown);
2705: explicit_bzero(o, sizeof(*o));
2706: #undef FREE_ARRAY
1.135 djm 2707: }
2708:
1.220 millert 2709: struct fwdarg {
2710: char *arg;
2711: int ispath;
2712: };
2713:
2714: /*
2715: * parse_fwd_field
2716: * parses the next field in a port forwarding specification.
2717: * sets fwd to the parsed field and advances p past the colon
2718: * or sets it to NULL at end of string.
2719: * returns 0 on success, else non-zero.
2720: */
2721: static int
2722: parse_fwd_field(char **p, struct fwdarg *fwd)
2723: {
2724: char *ep, *cp = *p;
2725: int ispath = 0;
2726:
2727: if (*cp == '\0') {
2728: *p = NULL;
2729: return -1; /* end of string */
2730: }
2731:
2732: /*
2733: * A field escaped with square brackets is used literally.
2734: * XXX - allow ']' to be escaped via backslash?
2735: */
2736: if (*cp == '[') {
2737: /* find matching ']' */
2738: for (ep = cp + 1; *ep != ']' && *ep != '\0'; ep++) {
2739: if (*ep == '/')
2740: ispath = 1;
2741: }
2742: /* no matching ']' or not at end of field. */
2743: if (ep[0] != ']' || (ep[1] != ':' && ep[1] != '\0'))
2744: return -1;
2745: /* NUL terminate the field and advance p past the colon */
2746: *ep++ = '\0';
2747: if (*ep != '\0')
2748: *ep++ = '\0';
2749: fwd->arg = cp + 1;
2750: fwd->ispath = ispath;
2751: *p = ep;
2752: return 0;
2753: }
2754:
2755: for (cp = *p; *cp != '\0'; cp++) {
2756: switch (*cp) {
2757: case '\\':
2758: memmove(cp, cp + 1, strlen(cp + 1) + 1);
1.237 djm 2759: if (*cp == '\0')
2760: return -1;
1.220 millert 2761: break;
2762: case '/':
2763: ispath = 1;
2764: break;
2765: case ':':
2766: *cp++ = '\0';
2767: goto done;
2768: }
2769: }
2770: done:
2771: fwd->arg = *p;
2772: fwd->ispath = ispath;
2773: *p = cp;
2774: return 0;
2775: }
2776:
1.135 djm 2777: /*
2778: * parse_forward
2779: * parses a string containing a port forwarding specification of the form:
1.168 stevesk 2780: * dynamicfwd == 0
1.220 millert 2781: * [listenhost:]listenport|listenpath:connecthost:connectport|connectpath
2782: * listenpath:connectpath
1.168 stevesk 2783: * dynamicfwd == 1
2784: * [listenhost:]listenport
1.135 djm 2785: * returns number of arguments parsed or zero on error
2786: */
2787: int
1.220 millert 2788: parse_forward(struct Forward *fwd, const char *fwdspec, int dynamicfwd, int remotefwd)
1.135 djm 2789: {
1.220 millert 2790: struct fwdarg fwdargs[4];
2791: char *p, *cp;
1.331 dtucker 2792: int i, err;
1.135 djm 2793:
1.220 millert 2794: memset(fwd, 0, sizeof(*fwd));
2795: memset(fwdargs, 0, sizeof(fwdargs));
1.135 djm 2796:
1.331 dtucker 2797: /*
2798: * We expand environment variables before checking if we think they're
2799: * paths so that if ${VAR} expands to a fully qualified path it is
2800: * treated as a path.
2801: */
2802: cp = p = dollar_expand(&err, fwdspec);
2803: if (p == NULL || err)
2804: return 0;
1.135 djm 2805:
2806: /* skip leading spaces */
1.214 deraadt 2807: while (isspace((u_char)*cp))
1.135 djm 2808: cp++;
2809:
1.220 millert 2810: for (i = 0; i < 4; ++i) {
2811: if (parse_fwd_field(&cp, &fwdargs[i]) != 0)
1.135 djm 2812: break;
1.220 millert 2813: }
1.135 djm 2814:
1.170 stevesk 2815: /* Check for trailing garbage */
1.220 millert 2816: if (cp != NULL && *cp != '\0') {
1.135 djm 2817: i = 0; /* failure */
1.220 millert 2818: }
1.135 djm 2819:
2820: switch (i) {
1.168 stevesk 2821: case 1:
1.220 millert 2822: if (fwdargs[0].ispath) {
2823: fwd->listen_path = xstrdup(fwdargs[0].arg);
2824: fwd->listen_port = PORT_STREAMLOCAL;
2825: } else {
2826: fwd->listen_host = NULL;
2827: fwd->listen_port = a2port(fwdargs[0].arg);
2828: }
1.168 stevesk 2829: fwd->connect_host = xstrdup("socks");
2830: break;
2831:
2832: case 2:
1.220 millert 2833: if (fwdargs[0].ispath && fwdargs[1].ispath) {
2834: fwd->listen_path = xstrdup(fwdargs[0].arg);
2835: fwd->listen_port = PORT_STREAMLOCAL;
2836: fwd->connect_path = xstrdup(fwdargs[1].arg);
2837: fwd->connect_port = PORT_STREAMLOCAL;
2838: } else if (fwdargs[1].ispath) {
2839: fwd->listen_host = NULL;
2840: fwd->listen_port = a2port(fwdargs[0].arg);
2841: fwd->connect_path = xstrdup(fwdargs[1].arg);
2842: fwd->connect_port = PORT_STREAMLOCAL;
2843: } else {
2844: fwd->listen_host = xstrdup(fwdargs[0].arg);
2845: fwd->listen_port = a2port(fwdargs[1].arg);
2846: fwd->connect_host = xstrdup("socks");
2847: }
1.168 stevesk 2848: break;
2849:
1.135 djm 2850: case 3:
1.220 millert 2851: if (fwdargs[0].ispath) {
2852: fwd->listen_path = xstrdup(fwdargs[0].arg);
2853: fwd->listen_port = PORT_STREAMLOCAL;
2854: fwd->connect_host = xstrdup(fwdargs[1].arg);
2855: fwd->connect_port = a2port(fwdargs[2].arg);
2856: } else if (fwdargs[2].ispath) {
2857: fwd->listen_host = xstrdup(fwdargs[0].arg);
2858: fwd->listen_port = a2port(fwdargs[1].arg);
2859: fwd->connect_path = xstrdup(fwdargs[2].arg);
2860: fwd->connect_port = PORT_STREAMLOCAL;
2861: } else {
2862: fwd->listen_host = NULL;
2863: fwd->listen_port = a2port(fwdargs[0].arg);
2864: fwd->connect_host = xstrdup(fwdargs[1].arg);
2865: fwd->connect_port = a2port(fwdargs[2].arg);
2866: }
1.135 djm 2867: break;
2868:
2869: case 4:
1.220 millert 2870: fwd->listen_host = xstrdup(fwdargs[0].arg);
2871: fwd->listen_port = a2port(fwdargs[1].arg);
2872: fwd->connect_host = xstrdup(fwdargs[2].arg);
2873: fwd->connect_port = a2port(fwdargs[3].arg);
1.135 djm 2874: break;
2875: default:
2876: i = 0; /* failure */
2877: }
2878:
1.202 djm 2879: free(p);
1.135 djm 2880:
1.168 stevesk 2881: if (dynamicfwd) {
2882: if (!(i == 1 || i == 2))
2883: goto fail_free;
2884: } else {
1.220 millert 2885: if (!(i == 3 || i == 4)) {
2886: if (fwd->connect_path == NULL &&
2887: fwd->listen_path == NULL)
2888: goto fail_free;
2889: }
2890: if (fwd->connect_port <= 0 && fwd->connect_path == NULL)
1.168 stevesk 2891: goto fail_free;
2892: }
2893:
1.220 millert 2894: if ((fwd->listen_port < 0 && fwd->listen_path == NULL) ||
2895: (!remotefwd && fwd->listen_port == 0))
1.135 djm 2896: goto fail_free;
2897: if (fwd->connect_host != NULL &&
2898: strlen(fwd->connect_host) >= NI_MAXHOST)
2899: goto fail_free;
1.356 djm 2900: /*
2901: * XXX - if connecting to a remote socket, max sun len may not
2902: * match this host
2903: */
1.220 millert 2904: if (fwd->connect_path != NULL &&
2905: strlen(fwd->connect_path) >= PATH_MAX_SUN)
2906: goto fail_free;
1.176 djm 2907: if (fwd->listen_host != NULL &&
2908: strlen(fwd->listen_host) >= NI_MAXHOST)
2909: goto fail_free;
1.220 millert 2910: if (fwd->listen_path != NULL &&
2911: strlen(fwd->listen_path) >= PATH_MAX_SUN)
2912: goto fail_free;
1.135 djm 2913:
2914: return (i);
2915:
2916: fail_free:
1.202 djm 2917: free(fwd->connect_host);
2918: fwd->connect_host = NULL;
1.220 millert 2919: free(fwd->connect_path);
2920: fwd->connect_path = NULL;
1.202 djm 2921: free(fwd->listen_host);
2922: fwd->listen_host = NULL;
1.220 millert 2923: free(fwd->listen_path);
2924: fwd->listen_path = NULL;
1.135 djm 2925: return (0);
1.221 djm 2926: }
2927:
1.257 djm 2928: int
2929: parse_jump(const char *s, Options *o, int active)
2930: {
2931: char *orig, *sdup, *cp;
2932: char *host = NULL, *user = NULL;
1.345 djm 2933: int r, ret = -1, port = -1, first;
1.257 djm 2934:
2935: active &= o->proxy_command == NULL && o->jump_host == NULL;
2936:
2937: orig = sdup = xstrdup(s);
1.356 djm 2938:
2939: /* Remove comment and trailing whitespace */
2940: if ((cp = strchr(orig, '#')) != NULL)
2941: *cp = '\0';
2942: rtrim(orig);
2943:
1.258 naddy 2944: first = active;
1.259 djm 2945: do {
1.287 djm 2946: if (strcasecmp(s, "none") == 0)
2947: break;
1.259 djm 2948: if ((cp = strrchr(sdup, ',')) == NULL)
2949: cp = sdup; /* last */
2950: else
2951: *cp++ = '\0';
2952:
1.258 naddy 2953: if (first) {
1.257 djm 2954: /* First argument and configuration is active */
1.345 djm 2955: r = parse_ssh_uri(cp, &user, &host, &port);
2956: if (r == -1 || (r == 1 &&
2957: parse_user_host_port(cp, &user, &host, &port) != 0))
1.257 djm 2958: goto out;
2959: } else {
2960: /* Subsequent argument or inactive configuration */
1.345 djm 2961: r = parse_ssh_uri(cp, NULL, NULL, NULL);
2962: if (r == -1 || (r == 1 &&
2963: parse_user_host_port(cp, NULL, NULL, NULL) != 0))
1.257 djm 2964: goto out;
2965: }
1.258 naddy 2966: first = 0; /* only check syntax for subsequent hosts */
1.259 djm 2967: } while (cp != sdup);
1.257 djm 2968: /* success */
1.258 naddy 2969: if (active) {
1.287 djm 2970: if (strcasecmp(s, "none") == 0) {
2971: o->jump_host = xstrdup("none");
2972: o->jump_port = 0;
2973: } else {
2974: o->jump_user = user;
2975: o->jump_host = host;
2976: o->jump_port = port;
2977: o->proxy_command = xstrdup("none");
2978: user = host = NULL;
2979: if ((cp = strrchr(s, ',')) != NULL && cp != s) {
2980: o->jump_extra = xstrdup(s);
2981: o->jump_extra[cp - s] = '\0';
2982: }
1.259 djm 2983: }
1.258 naddy 2984: }
1.257 djm 2985: ret = 0;
2986: out:
1.258 naddy 2987: free(orig);
1.257 djm 2988: free(user);
2989: free(host);
2990: return ret;
1.280 millert 2991: }
2992:
2993: int
2994: parse_ssh_uri(const char *uri, char **userp, char **hostp, int *portp)
2995: {
1.344 djm 2996: char *user = NULL, *host = NULL, *path = NULL;
2997: int r, port;
1.280 millert 2998:
1.344 djm 2999: r = parse_uri("ssh", uri, &user, &host, &port, &path);
1.280 millert 3000: if (r == 0 && path != NULL)
3001: r = -1; /* path not allowed */
1.344 djm 3002: if (r == 0) {
3003: if (userp != NULL) {
3004: *userp = user;
3005: user = NULL;
3006: }
3007: if (hostp != NULL) {
3008: *hostp = host;
3009: host = NULL;
3010: }
3011: if (portp != NULL)
3012: *portp = port;
3013: }
3014: free(user);
3015: free(host);
3016: free(path);
1.280 millert 3017: return r;
1.257 djm 3018: }
3019:
1.221 djm 3020: /* XXX the following is a near-vebatim copy from servconf.c; refactor */
3021: static const char *
3022: fmt_multistate_int(int val, const struct multistate *m)
3023: {
3024: u_int i;
3025:
3026: for (i = 0; m[i].key != NULL; i++) {
3027: if (m[i].value == val)
3028: return m[i].key;
3029: }
3030: return "UNKNOWN";
3031: }
3032:
3033: static const char *
3034: fmt_intarg(OpCodes code, int val)
3035: {
3036: if (val == -1)
3037: return "unset";
3038: switch (code) {
3039: case oAddressFamily:
3040: return fmt_multistate_int(val, multistate_addressfamily);
3041: case oVerifyHostKeyDNS:
1.232 djm 3042: case oUpdateHostkeys:
1.221 djm 3043: return fmt_multistate_int(val, multistate_yesnoask);
1.278 djm 3044: case oStrictHostKeyChecking:
3045: return fmt_multistate_int(val, multistate_strict_hostkey);
1.221 djm 3046: case oControlMaster:
3047: return fmt_multistate_int(val, multistate_controlmaster);
3048: case oTunnel:
3049: return fmt_multistate_int(val, multistate_tunnel);
3050: case oRequestTTY:
3051: return fmt_multistate_int(val, multistate_requesttty);
3052: case oCanonicalizeHostname:
3053: return fmt_multistate_int(val, multistate_canonicalizehostname);
1.285 djm 3054: case oAddKeysToAgent:
3055: return fmt_multistate_int(val, multistate_yesnoaskconfirm);
1.224 djm 3056: case oFingerprintHash:
3057: return ssh_digest_alg_name(val);
1.221 djm 3058: default:
3059: switch (val) {
3060: case 0:
3061: return "no";
3062: case 1:
3063: return "yes";
3064: default:
3065: return "UNKNOWN";
3066: }
3067: }
3068: }
3069:
3070: static const char *
3071: lookup_opcode_name(OpCodes code)
3072: {
3073: u_int i;
3074:
3075: for (i = 0; keywords[i].name != NULL; i++)
3076: if (keywords[i].opcode == code)
3077: return(keywords[i].name);
3078: return "UNKNOWN";
3079: }
3080:
3081: static void
3082: dump_cfg_int(OpCodes code, int val)
3083: {
3084: printf("%s %d\n", lookup_opcode_name(code), val);
3085: }
3086:
3087: static void
3088: dump_cfg_fmtint(OpCodes code, int val)
3089: {
3090: printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
3091: }
3092:
3093: static void
3094: dump_cfg_string(OpCodes code, const char *val)
3095: {
3096: if (val == NULL)
3097: return;
3098: printf("%s %s\n", lookup_opcode_name(code), val);
3099: }
3100:
3101: static void
3102: dump_cfg_strarray(OpCodes code, u_int count, char **vals)
3103: {
3104: u_int i;
3105:
3106: for (i = 0; i < count; i++)
3107: printf("%s %s\n", lookup_opcode_name(code), vals[i]);
3108: }
3109:
3110: static void
3111: dump_cfg_strarray_oneline(OpCodes code, u_int count, char **vals)
3112: {
3113: u_int i;
3114:
3115: printf("%s", lookup_opcode_name(code));
1.356 djm 3116: if (count == 0)
3117: printf(" none");
1.221 djm 3118: for (i = 0; i < count; i++)
3119: printf(" %s", vals[i]);
3120: printf("\n");
3121: }
3122:
3123: static void
3124: dump_cfg_forwards(OpCodes code, u_int count, const struct Forward *fwds)
3125: {
3126: const struct Forward *fwd;
3127: u_int i;
3128:
3129: /* oDynamicForward */
3130: for (i = 0; i < count; i++) {
3131: fwd = &fwds[i];
1.265 djm 3132: if (code == oDynamicForward && fwd->connect_host != NULL &&
1.221 djm 3133: strcmp(fwd->connect_host, "socks") != 0)
3134: continue;
1.265 djm 3135: if (code == oLocalForward && fwd->connect_host != NULL &&
1.221 djm 3136: strcmp(fwd->connect_host, "socks") == 0)
3137: continue;
3138: printf("%s", lookup_opcode_name(code));
3139: if (fwd->listen_port == PORT_STREAMLOCAL)
3140: printf(" %s", fwd->listen_path);
3141: else if (fwd->listen_host == NULL)
3142: printf(" %d", fwd->listen_port);
3143: else {
3144: printf(" [%s]:%d",
3145: fwd->listen_host, fwd->listen_port);
3146: }
3147: if (code != oDynamicForward) {
3148: if (fwd->connect_port == PORT_STREAMLOCAL)
3149: printf(" %s", fwd->connect_path);
3150: else if (fwd->connect_host == NULL)
3151: printf(" %d", fwd->connect_port);
3152: else {
3153: printf(" [%s]:%d",
3154: fwd->connect_host, fwd->connect_port);
3155: }
3156: }
3157: printf("\n");
3158: }
3159: }
3160:
3161: void
3162: dump_client_config(Options *o, const char *host)
3163: {
1.326 djm 3164: int i, r;
3165: char buf[8], *all_key;
3166:
3167: /*
3168: * Expand HostKeyAlgorithms name lists. This isn't handled in
3169: * fill_default_options() like the other algorithm lists because
3170: * the host key algorithms are by default dynamically chosen based
3171: * on the host's keys found in known_hosts.
3172: */
3173: all_key = sshkey_alg_list(0, 0, 1, ',');
3174: if ((r = kex_assemble_names(&o->hostkeyalgorithms, kex_default_pk_alg(),
3175: all_key)) != 0)
1.340 djm 3176: fatal_fr(r, "expand HostKeyAlgorithms");
1.326 djm 3177: free(all_key);
1.240 djm 3178:
1.221 djm 3179: /* Most interesting options first: user, host, port */
3180: dump_cfg_string(oUser, o->user);
1.306 jmc 3181: dump_cfg_string(oHostname, host);
1.221 djm 3182: dump_cfg_int(oPort, o->port);
3183:
3184: /* Flag options */
3185: dump_cfg_fmtint(oAddressFamily, o->address_family);
3186: dump_cfg_fmtint(oBatchMode, o->batch_mode);
3187: dump_cfg_fmtint(oCanonicalizeFallbackLocal, o->canonicalize_fallback_local);
3188: dump_cfg_fmtint(oCanonicalizeHostname, o->canonicalize_hostname);
3189: dump_cfg_fmtint(oChallengeResponseAuthentication, o->challenge_response_authentication);
3190: dump_cfg_fmtint(oCheckHostIP, o->check_host_ip);
3191: dump_cfg_fmtint(oCompression, o->compression);
3192: dump_cfg_fmtint(oControlMaster, o->control_master);
3193: dump_cfg_fmtint(oEnableSSHKeysign, o->enable_ssh_keysign);
1.256 dtucker 3194: dump_cfg_fmtint(oClearAllForwardings, o->clear_forwardings);
1.221 djm 3195: dump_cfg_fmtint(oExitOnForwardFailure, o->exit_on_forward_failure);
1.224 djm 3196: dump_cfg_fmtint(oFingerprintHash, o->fingerprint_hash);
1.221 djm 3197: dump_cfg_fmtint(oForwardX11, o->forward_x11);
3198: dump_cfg_fmtint(oForwardX11Trusted, o->forward_x11_trusted);
3199: dump_cfg_fmtint(oGatewayPorts, o->fwd_opts.gateway_ports);
3200: #ifdef GSSAPI
3201: dump_cfg_fmtint(oGssAuthentication, o->gss_authentication);
3202: dump_cfg_fmtint(oGssDelegateCreds, o->gss_deleg_creds);
3203: #endif /* GSSAPI */
3204: dump_cfg_fmtint(oHashKnownHosts, o->hash_known_hosts);
3205: dump_cfg_fmtint(oHostbasedAuthentication, o->hostbased_authentication);
3206: dump_cfg_fmtint(oIdentitiesOnly, o->identities_only);
3207: dump_cfg_fmtint(oKbdInteractiveAuthentication, o->kbd_interactive_authentication);
3208: dump_cfg_fmtint(oNoHostAuthenticationForLocalhost, o->no_host_authentication_for_localhost);
3209: dump_cfg_fmtint(oPasswordAuthentication, o->password_authentication);
3210: dump_cfg_fmtint(oPermitLocalCommand, o->permit_local_command);
3211: dump_cfg_fmtint(oProxyUseFdpass, o->proxy_use_fdpass);
3212: dump_cfg_fmtint(oPubkeyAuthentication, o->pubkey_authentication);
3213: dump_cfg_fmtint(oRequestTTY, o->request_tty);
3214: dump_cfg_fmtint(oStreamLocalBindUnlink, o->fwd_opts.streamlocal_bind_unlink);
3215: dump_cfg_fmtint(oStrictHostKeyChecking, o->strict_host_key_checking);
3216: dump_cfg_fmtint(oTCPKeepAlive, o->tcp_keep_alive);
3217: dump_cfg_fmtint(oTunnel, o->tun_open);
3218: dump_cfg_fmtint(oVerifyHostKeyDNS, o->verify_host_key_dns);
3219: dump_cfg_fmtint(oVisualHostKey, o->visual_host_key);
1.229 djm 3220: dump_cfg_fmtint(oUpdateHostkeys, o->update_hostkeys);
1.221 djm 3221:
3222: /* Integer options */
3223: dump_cfg_int(oCanonicalizeMaxDots, o->canonicalize_max_dots);
3224: dump_cfg_int(oConnectionAttempts, o->connection_attempts);
3225: dump_cfg_int(oForwardX11Timeout, o->forward_x11_timeout);
3226: dump_cfg_int(oNumberOfPasswordPrompts, o->number_of_password_prompts);
3227: dump_cfg_int(oServerAliveCountMax, o->server_alive_count_max);
3228: dump_cfg_int(oServerAliveInterval, o->server_alive_interval);
3229:
3230: /* String options */
3231: dump_cfg_string(oBindAddress, o->bind_address);
1.282 djm 3232: dump_cfg_string(oBindInterface, o->bind_interface);
1.320 dtucker 3233: dump_cfg_string(oCiphers, o->ciphers);
1.221 djm 3234: dump_cfg_string(oControlPath, o->control_path);
1.240 djm 3235: dump_cfg_string(oHostKeyAlgorithms, o->hostkeyalgorithms);
1.221 djm 3236: dump_cfg_string(oHostKeyAlias, o->host_key_alias);
1.350 dtucker 3237: dump_cfg_string(oHostbasedAcceptedAlgorithms, o->hostbased_accepted_algos);
1.253 markus 3238: dump_cfg_string(oIdentityAgent, o->identity_agent);
1.285 djm 3239: dump_cfg_string(oIgnoreUnknown, o->ignored_unknown);
1.221 djm 3240: dump_cfg_string(oKbdInteractiveDevices, o->kbd_interactive_devices);
1.320 dtucker 3241: dump_cfg_string(oKexAlgorithms, o->kex_algorithms);
3242: dump_cfg_string(oCASignatureAlgorithms, o->ca_sign_algorithms);
1.221 djm 3243: dump_cfg_string(oLocalCommand, o->local_command);
1.277 bluhm 3244: dump_cfg_string(oRemoteCommand, o->remote_command);
1.221 djm 3245: dump_cfg_string(oLogLevel, log_level_name(o->log_level));
1.320 dtucker 3246: dump_cfg_string(oMacs, o->macs);
1.266 djm 3247: #ifdef ENABLE_PKCS11
1.221 djm 3248: dump_cfg_string(oPKCS11Provider, o->pkcs11_provider);
1.266 djm 3249: #endif
1.310 djm 3250: dump_cfg_string(oSecurityKeyProvider, o->sk_provider);
1.221 djm 3251: dump_cfg_string(oPreferredAuthentications, o->preferred_authentications);
1.349 dtucker 3252: dump_cfg_string(oPubkeyAcceptedAlgorithms, o->pubkey_accepted_algos);
1.230 djm 3253: dump_cfg_string(oRevokedHostKeys, o->revoked_host_keys);
1.221 djm 3254: dump_cfg_string(oXAuthLocation, o->xauth_location);
1.346 djm 3255: dump_cfg_string(oKnownHostsCommand, o->known_hosts_command);
1.221 djm 3256:
1.230 djm 3257: /* Forwards */
1.221 djm 3258: dump_cfg_forwards(oDynamicForward, o->num_local_forwards, o->local_forwards);
3259: dump_cfg_forwards(oLocalForward, o->num_local_forwards, o->local_forwards);
3260: dump_cfg_forwards(oRemoteForward, o->num_remote_forwards, o->remote_forwards);
3261:
3262: /* String array options */
3263: dump_cfg_strarray(oIdentityFile, o->num_identity_files, o->identity_files);
3264: dump_cfg_strarray_oneline(oCanonicalDomains, o->num_canonical_domains, o->canonical_domains);
1.285 djm 3265: dump_cfg_strarray(oCertificateFile, o->num_certificate_files, o->certificate_files);
1.221 djm 3266: dump_cfg_strarray_oneline(oGlobalKnownHostsFile, o->num_system_hostfiles, o->system_hostfiles);
3267: dump_cfg_strarray_oneline(oUserKnownHostsFile, o->num_user_hostfiles, o->user_hostfiles);
3268: dump_cfg_strarray(oSendEnv, o->num_send_env, o->send_env);
1.290 djm 3269: dump_cfg_strarray(oSetEnv, o->num_setenv, o->setenv);
1.339 djm 3270: dump_cfg_strarray_oneline(oLogVerbose,
3271: o->num_log_verbose, o->log_verbose);
1.221 djm 3272:
3273: /* Special cases */
1.351 markus 3274:
3275: /* PermitRemoteOpen */
3276: if (o->num_permitted_remote_opens == 0)
3277: printf("%s any\n", lookup_opcode_name(oPermitRemoteOpen));
3278: else
3279: dump_cfg_strarray_oneline(oPermitRemoteOpen,
3280: o->num_permitted_remote_opens, o->permitted_remote_opens);
1.334 djm 3281:
3282: /* AddKeysToAgent */
3283: if (o->add_keys_to_agent_lifespan <= 0)
3284: dump_cfg_fmtint(oAddKeysToAgent, o->add_keys_to_agent);
3285: else {
3286: printf("addkeystoagent%s %d\n",
3287: o->add_keys_to_agent == 3 ? " confirm" : "",
3288: o->add_keys_to_agent_lifespan);
3289: }
1.319 djm 3290:
3291: /* oForwardAgent */
3292: if (o->forward_agent_sock_path == NULL)
3293: dump_cfg_fmtint(oForwardAgent, o->forward_agent);
3294: else
3295: dump_cfg_string(oForwardAgent, o->forward_agent_sock_path);
1.221 djm 3296:
3297: /* oConnectTimeout */
3298: if (o->connection_timeout == -1)
3299: printf("connecttimeout none\n");
3300: else
3301: dump_cfg_int(oConnectTimeout, o->connection_timeout);
3302:
3303: /* oTunnelDevice */
3304: printf("tunneldevice");
3305: if (o->tun_local == SSH_TUNID_ANY)
3306: printf(" any");
3307: else
3308: printf(" %d", o->tun_local);
3309: if (o->tun_remote == SSH_TUNID_ANY)
3310: printf(":any");
3311: else
3312: printf(":%d", o->tun_remote);
3313: printf("\n");
3314:
3315: /* oCanonicalizePermittedCNAMEs */
3316: if ( o->num_permitted_cnames > 0) {
3317: printf("canonicalizePermittedcnames");
3318: for (i = 0; i < o->num_permitted_cnames; i++) {
3319: printf(" %s:%s", o->permitted_cnames[i].source_list,
3320: o->permitted_cnames[i].target_list);
3321: }
3322: printf("\n");
3323: }
3324:
3325: /* oControlPersist */
3326: if (o->control_persist == 0 || o->control_persist_timeout == 0)
3327: dump_cfg_fmtint(oControlPersist, o->control_persist);
3328: else
3329: dump_cfg_int(oControlPersist, o->control_persist_timeout);
3330:
3331: /* oEscapeChar */
3332: if (o->escape_char == SSH_ESCAPECHAR_NONE)
3333: printf("escapechar none\n");
3334: else {
1.257 djm 3335: vis(buf, o->escape_char, VIS_WHITE, 0);
3336: printf("escapechar %s\n", buf);
1.221 djm 3337: }
3338:
3339: /* oIPQoS */
3340: printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
3341: printf("%s\n", iptos2str(o->ip_qos_bulk));
3342:
3343: /* oRekeyLimit */
1.249 dtucker 3344: printf("rekeylimit %llu %d\n",
3345: (unsigned long long)o->rekey_limit, o->rekey_interval);
1.221 djm 3346:
3347: /* oStreamLocalBindMask */
3348: printf("streamlocalbindmask 0%o\n",
3349: o->fwd_opts.streamlocal_bind_mask);
1.285 djm 3350:
3351: /* oLogFacility */
3352: printf("syslogfacility %s\n", log_facility_name(o->log_facility));
1.257 djm 3353:
3354: /* oProxyCommand / oProxyJump */
3355: if (o->jump_host == NULL)
3356: dump_cfg_string(oProxyCommand, o->proxy_command);
3357: else {
3358: /* Check for numeric addresses */
3359: i = strchr(o->jump_host, ':') != NULL ||
3360: strspn(o->jump_host, "1234567890.") == strlen(o->jump_host);
3361: snprintf(buf, sizeof(buf), "%d", o->jump_port);
3362: printf("proxyjump %s%s%s%s%s%s%s%s%s\n",
1.259 djm 3363: /* optional additional jump spec */
3364: o->jump_extra == NULL ? "" : o->jump_extra,
3365: o->jump_extra == NULL ? "" : ",",
1.257 djm 3366: /* optional user */
3367: o->jump_user == NULL ? "" : o->jump_user,
3368: o->jump_user == NULL ? "" : "@",
3369: /* opening [ if hostname is numeric */
3370: i ? "[" : "",
3371: /* mandatory hostname */
3372: o->jump_host,
3373: /* closing ] if hostname is numeric */
3374: i ? "]" : "",
3375: /* optional port number */
3376: o->jump_port <= 0 ? "" : ":",
1.259 djm 3377: o->jump_port <= 0 ? "" : buf);
1.257 djm 3378: }
1.1 deraadt 3379: }