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