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