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