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