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