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