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