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