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