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