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