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