Damien Miller | 57c3011 | 2006-03-26 14:24:48 +1100 | [diff] [blame] | 1 | /* $OpenBSD: readconf.c,v 1.151 2006/03/25 13:17:02 djm Exp $ */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 2 | /* |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
| 5 | * All rights reserved |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 6 | * Functions for reading the configuration files. |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 7 | * |
Damien Miller | e4340be | 2000-09-16 13:29:08 +1100 | [diff] [blame] | 8 | * As far as I am concerned, the code I have written for this software |
| 9 | * can be used freely for any purpose. Any derived versions of this |
| 10 | * software must be clearly marked as such, and if the derived work is |
| 11 | * incompatible with the protocol description in the RFC file, it must be |
| 12 | * called by a name other than "ssh" or "Secure Shell". |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 13 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 14 | |
| 15 | #include "includes.h" |
Damien Miller | f17883e | 2006-03-15 11:45:54 +1100 | [diff] [blame] | 16 | |
| 17 | #include <sys/types.h> |
| 18 | #include <sys/stat.h> |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 19 | |
Damien Miller | c7b0636 | 2006-03-15 11:53:45 +1100 | [diff] [blame] | 20 | #include <ctype.h> |
| 21 | |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 22 | #include "ssh.h" |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 23 | #include "xmalloc.h" |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 24 | #include "compat.h" |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 25 | #include "cipher.h" |
| 26 | #include "pathnames.h" |
| 27 | #include "log.h" |
| 28 | #include "readconf.h" |
| 29 | #include "match.h" |
| 30 | #include "misc.h" |
Ben Lindstrom | 06b33aa | 2001-02-15 03:01:59 +0000 | [diff] [blame] | 31 | #include "kex.h" |
| 32 | #include "mac.h" |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 33 | |
| 34 | /* Format of the configuration file: |
| 35 | |
| 36 | # Configuration data is parsed as follows: |
| 37 | # 1. command line options |
| 38 | # 2. user-specific file |
| 39 | # 3. system-wide file |
| 40 | # Any configuration value is only changed the first time it is set. |
| 41 | # Thus, host-specific definitions should be at the beginning of the |
| 42 | # configuration file, and defaults at the end. |
| 43 | |
| 44 | # Host-specific declarations. These may override anything above. A single |
| 45 | # host may match multiple declarations; these are processed in the order |
| 46 | # that they are given in. |
| 47 | |
| 48 | Host *.ngs.fi ngs.fi |
Ben Lindstrom | 4daea86 | 2002-06-09 20:04:02 +0000 | [diff] [blame] | 49 | User foo |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 50 | |
| 51 | Host fake.com |
| 52 | HostName another.host.name.real.org |
| 53 | User blaah |
| 54 | Port 34289 |
| 55 | ForwardX11 no |
| 56 | ForwardAgent no |
| 57 | |
| 58 | Host books.com |
| 59 | RemoteForward 9999 shadows.cs.hut.fi:9999 |
| 60 | Cipher 3des |
| 61 | |
| 62 | Host fascist.blob.com |
| 63 | Port 23123 |
| 64 | User tylonen |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 65 | PasswordAuthentication no |
| 66 | |
| 67 | Host puukko.hut.fi |
| 68 | User t35124p |
| 69 | ProxyCommand ssh-proxy %h %p |
| 70 | |
| 71 | Host *.fr |
Ben Lindstrom | 4daea86 | 2002-06-09 20:04:02 +0000 | [diff] [blame] | 72 | PublicKeyAuthentication no |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 73 | |
| 74 | Host *.su |
| 75 | Cipher none |
| 76 | PasswordAuthentication no |
| 77 | |
Damien Miller | d27b947 | 2005-12-13 19:29:02 +1100 | [diff] [blame] | 78 | Host vpn.fake.com |
| 79 | Tunnel yes |
| 80 | TunnelDevice 3 |
| 81 | |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 82 | # Defaults for various options |
| 83 | Host * |
| 84 | ForwardAgent no |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 85 | ForwardX11 no |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 86 | PasswordAuthentication yes |
| 87 | RSAAuthentication yes |
| 88 | RhostsRSAAuthentication yes |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 89 | StrictHostKeyChecking yes |
Damien Miller | 12c150e | 2003-12-17 16:31:10 +1100 | [diff] [blame] | 90 | TcpKeepAlive no |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 91 | IdentityFile ~/.ssh/identity |
| 92 | Port 22 |
| 93 | EscapeChar ~ |
| 94 | |
| 95 | */ |
| 96 | |
| 97 | /* Keyword tokens. */ |
| 98 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 99 | typedef enum { |
| 100 | oBadOption, |
Darren Tucker | 0a118da | 2003-10-15 15:54:32 +1000 | [diff] [blame] | 101 | oForwardAgent, oForwardX11, oForwardX11Trusted, oGatewayPorts, |
Ben Lindstrom | cb72e4f | 2002-06-21 00:41:51 +0000 | [diff] [blame] | 102 | oPasswordAuthentication, oRSAAuthentication, |
Ben Lindstrom | 95fb2dd | 2001-01-23 03:12:10 +0000 | [diff] [blame] | 103 | oChallengeResponseAuthentication, oXAuthLocation, |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 104 | oIdentityFile, oHostName, oPort, oCipher, oRemoteForward, oLocalForward, |
| 105 | oUser, oHost, oEscapeChar, oRhostsRSAAuthentication, oProxyCommand, |
| 106 | oGlobalKnownHostsFile, oUserKnownHostsFile, oConnectionAttempts, |
| 107 | oBatchMode, oCheckHostIP, oStrictHostKeyChecking, oCompression, |
Damien Miller | 12c150e | 2003-12-17 16:31:10 +1100 | [diff] [blame] | 108 | oCompressionLevel, oTCPKeepAlive, oNumberOfPasswordPrompts, |
Ben Lindstrom | 06b33aa | 2001-02-15 03:01:59 +0000 | [diff] [blame] | 109 | oUsePrivilegedPort, oLogLevel, oCiphers, oProtocol, oMacs, |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 110 | oGlobalKnownHostsFile2, oUserKnownHostsFile2, oPubkeyAuthentication, |
Ben Lindstrom | b9be60a | 2001-03-11 01:49:19 +0000 | [diff] [blame] | 111 | oKbdInteractiveAuthentication, oKbdInteractiveDevices, oHostKeyAlias, |
Ben Lindstrom | 982dbbc | 2001-04-17 18:11:36 +0000 | [diff] [blame] | 112 | oDynamicForward, oPreferredAuthentications, oHostbasedAuthentication, |
Ben Lindstrom | 2b7a0e9 | 2001-09-20 00:57:55 +0000 | [diff] [blame] | 113 | oHostKeyAlgorithms, oBindAddress, oSmartcardDevice, |
Ben Lindstrom | 4daea86 | 2002-06-09 20:04:02 +0000 | [diff] [blame] | 114 | oClearAllForwardings, oNoHostAuthenticationForLocalhost, |
Damien Miller | b78d5eb | 2003-05-16 11:39:04 +1000 | [diff] [blame] | 115 | oEnableSSHKeysign, oRekeyLimit, oVerifyHostKeyDNS, oConnectTimeout, |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 116 | oAddressFamily, oGssAuthentication, oGssDelegateCreds, |
Damien Miller | bd394c3 | 2004-03-08 23:12:36 +1100 | [diff] [blame] | 117 | oServerAliveInterval, oServerAliveCountMax, oIdentitiesOnly, |
Damien Miller | e177615 | 2005-03-01 21:47:37 +1100 | [diff] [blame] | 118 | oSendEnv, oControlPath, oControlMaster, oHashKnownHosts, |
Damien Miller | d27b947 | 2005-12-13 19:29:02 +1100 | [diff] [blame] | 119 | oTunnel, oTunnelDevice, oLocalCommand, oPermitLocalCommand, |
Damien Miller | f9b3feb | 2003-05-16 11:38:32 +1000 | [diff] [blame] | 120 | oDeprecated, oUnsupported |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 121 | } OpCodes; |
| 122 | |
| 123 | /* Textual representations of the tokens. */ |
| 124 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 125 | static struct { |
| 126 | const char *name; |
| 127 | OpCodes opcode; |
| 128 | } keywords[] = { |
| 129 | { "forwardagent", oForwardAgent }, |
| 130 | { "forwardx11", oForwardX11 }, |
Darren Tucker | 0a118da | 2003-10-15 15:54:32 +1000 | [diff] [blame] | 131 | { "forwardx11trusted", oForwardX11Trusted }, |
Damien Miller | d3a1857 | 2000-06-07 19:55:44 +1000 | [diff] [blame] | 132 | { "xauthlocation", oXAuthLocation }, |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 133 | { "gatewayports", oGatewayPorts }, |
| 134 | { "useprivilegedport", oUsePrivilegedPort }, |
Darren Tucker | ec960f2 | 2003-08-13 20:37:05 +1000 | [diff] [blame] | 135 | { "rhostsauthentication", oDeprecated }, |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 136 | { "passwordauthentication", oPasswordAuthentication }, |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 137 | { "kbdinteractiveauthentication", oKbdInteractiveAuthentication }, |
| 138 | { "kbdinteractivedevices", oKbdInteractiveDevices }, |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 139 | { "rsaauthentication", oRSAAuthentication }, |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 140 | { "pubkeyauthentication", oPubkeyAuthentication }, |
Ben Lindstrom | 95fb2dd | 2001-01-23 03:12:10 +0000 | [diff] [blame] | 141 | { "dsaauthentication", oPubkeyAuthentication }, /* alias */ |
Ben Lindstrom | 5eabda3 | 2001-04-12 23:34:34 +0000 | [diff] [blame] | 142 | { "rhostsrsaauthentication", oRhostsRSAAuthentication }, |
Ben Lindstrom | d69dab3 | 2001-04-12 23:36:05 +0000 | [diff] [blame] | 143 | { "hostbasedauthentication", oHostbasedAuthentication }, |
Ben Lindstrom | 95fb2dd | 2001-01-23 03:12:10 +0000 | [diff] [blame] | 144 | { "challengeresponseauthentication", oChallengeResponseAuthentication }, |
| 145 | { "skeyauthentication", oChallengeResponseAuthentication }, /* alias */ |
| 146 | { "tisauthentication", oChallengeResponseAuthentication }, /* alias */ |
Damien Miller | f9b3feb | 2003-05-16 11:38:32 +1000 | [diff] [blame] | 147 | { "kerberosauthentication", oUnsupported }, |
| 148 | { "kerberostgtpassing", oUnsupported }, |
Damien Miller | f9b3feb | 2003-05-16 11:38:32 +1000 | [diff] [blame] | 149 | { "afstokenpassing", oUnsupported }, |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 150 | #if defined(GSSAPI) |
| 151 | { "gssapiauthentication", oGssAuthentication }, |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 152 | { "gssapidelegatecredentials", oGssDelegateCreds }, |
| 153 | #else |
| 154 | { "gssapiauthentication", oUnsupported }, |
| 155 | { "gssapidelegatecredentials", oUnsupported }, |
| 156 | #endif |
Ben Lindstrom | 4daea86 | 2002-06-09 20:04:02 +0000 | [diff] [blame] | 157 | { "fallbacktorsh", oDeprecated }, |
| 158 | { "usersh", oDeprecated }, |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 159 | { "identityfile", oIdentityFile }, |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 160 | { "identityfile2", oIdentityFile }, /* alias */ |
Damien Miller | bd394c3 | 2004-03-08 23:12:36 +1100 | [diff] [blame] | 161 | { "identitiesonly", oIdentitiesOnly }, |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 162 | { "hostname", oHostName }, |
Ben Lindstrom | 4dccfa5 | 2000-12-28 16:40:05 +0000 | [diff] [blame] | 163 | { "hostkeyalias", oHostKeyAlias }, |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 164 | { "proxycommand", oProxyCommand }, |
| 165 | { "port", oPort }, |
| 166 | { "cipher", oCipher }, |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 167 | { "ciphers", oCiphers }, |
Ben Lindstrom | 06b33aa | 2001-02-15 03:01:59 +0000 | [diff] [blame] | 168 | { "macs", oMacs }, |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 169 | { "protocol", oProtocol }, |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 170 | { "remoteforward", oRemoteForward }, |
| 171 | { "localforward", oLocalForward }, |
| 172 | { "user", oUser }, |
| 173 | { "host", oHost }, |
| 174 | { "escapechar", oEscapeChar }, |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 175 | { "globalknownhostsfile", oGlobalKnownHostsFile }, |
Ben Lindstrom | d6481ea | 2001-06-25 04:37:41 +0000 | [diff] [blame] | 176 | { "userknownhostsfile", oUserKnownHostsFile }, /* obsolete */ |
Damien Miller | eba71ba | 2000-04-29 23:57:08 +1000 | [diff] [blame] | 177 | { "globalknownhostsfile2", oGlobalKnownHostsFile2 }, |
Ben Lindstrom | d6481ea | 2001-06-25 04:37:41 +0000 | [diff] [blame] | 178 | { "userknownhostsfile2", oUserKnownHostsFile2 }, /* obsolete */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 179 | { "connectionattempts", oConnectionAttempts }, |
| 180 | { "batchmode", oBatchMode }, |
| 181 | { "checkhostip", oCheckHostIP }, |
| 182 | { "stricthostkeychecking", oStrictHostKeyChecking }, |
| 183 | { "compression", oCompression }, |
| 184 | { "compressionlevel", oCompressionLevel }, |
Damien Miller | 12c150e | 2003-12-17 16:31:10 +1100 | [diff] [blame] | 185 | { "tcpkeepalive", oTCPKeepAlive }, |
| 186 | { "keepalive", oTCPKeepAlive }, /* obsolete */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 187 | { "numberofpasswordprompts", oNumberOfPasswordPrompts }, |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 188 | { "loglevel", oLogLevel }, |
Ben Lindstrom | 3bb4f9d | 2001-04-08 18:30:26 +0000 | [diff] [blame] | 189 | { "dynamicforward", oDynamicForward }, |
Ben Lindstrom | b9be60a | 2001-03-11 01:49:19 +0000 | [diff] [blame] | 190 | { "preferredauthentications", oPreferredAuthentications }, |
Ben Lindstrom | 982dbbc | 2001-04-17 18:11:36 +0000 | [diff] [blame] | 191 | { "hostkeyalgorithms", oHostKeyAlgorithms }, |
Ben Lindstrom | e0f8804 | 2001-04-30 13:06:24 +0000 | [diff] [blame] | 192 | { "bindaddress", oBindAddress }, |
Damien Miller | f9b3feb | 2003-05-16 11:38:32 +1000 | [diff] [blame] | 193 | #ifdef SMARTCARD |
Ben Lindstrom | ae996bf | 2001-08-06 21:27:53 +0000 | [diff] [blame] | 194 | { "smartcarddevice", oSmartcardDevice }, |
Damien Miller | f9b3feb | 2003-05-16 11:38:32 +1000 | [diff] [blame] | 195 | #else |
| 196 | { "smartcarddevice", oUnsupported }, |
| 197 | #endif |
Damien Miller | 9f0f5c6 | 2001-12-21 14:45:46 +1100 | [diff] [blame] | 198 | { "clearallforwardings", oClearAllForwardings }, |
Ben Lindstrom | b6df73b | 2002-11-09 15:52:31 +0000 | [diff] [blame] | 199 | { "enablesshkeysign", oEnableSSHKeysign }, |
Damien Miller | 37876e9 | 2003-05-15 10:19:46 +1000 | [diff] [blame] | 200 | { "verifyhostkeydns", oVerifyHostKeyDNS }, |
Damien Miller | 9f0f5c6 | 2001-12-21 14:45:46 +1100 | [diff] [blame] | 201 | { "nohostauthenticationforlocalhost", oNoHostAuthenticationForLocalhost }, |
Damien Miller | a5539d2 | 2003-04-09 20:50:06 +1000 | [diff] [blame] | 202 | { "rekeylimit", oRekeyLimit }, |
Damien Miller | b78d5eb | 2003-05-16 11:39:04 +1000 | [diff] [blame] | 203 | { "connecttimeout", oConnectTimeout }, |
Damien Miller | 20a8f97 | 2003-05-18 20:50:30 +1000 | [diff] [blame] | 204 | { "addressfamily", oAddressFamily }, |
Damien Miller | 509b010 | 2003-12-17 16:33:10 +1100 | [diff] [blame] | 205 | { "serveraliveinterval", oServerAliveInterval }, |
| 206 | { "serveralivecountmax", oServerAliveCountMax }, |
Darren Tucker | 46bc075 | 2004-05-02 22:11:30 +1000 | [diff] [blame] | 207 | { "sendenv", oSendEnv }, |
Damien Miller | 0e220db | 2004-06-15 10:34:08 +1000 | [diff] [blame] | 208 | { "controlpath", oControlPath }, |
| 209 | { "controlmaster", oControlMaster }, |
Damien Miller | e177615 | 2005-03-01 21:47:37 +1100 | [diff] [blame] | 210 | { "hashknownhosts", oHashKnownHosts }, |
Damien Miller | d27b947 | 2005-12-13 19:29:02 +1100 | [diff] [blame] | 211 | { "tunnel", oTunnel }, |
| 212 | { "tunneldevice", oTunnelDevice }, |
| 213 | { "localcommand", oLocalCommand }, |
| 214 | { "permitlocalcommand", oPermitLocalCommand }, |
Ben Lindstrom | 65366a8 | 2001-12-06 16:32:47 +0000 | [diff] [blame] | 215 | { NULL, oBadOption } |
Damien Miller | 5ce662a | 1999-11-11 17:57:39 +1100 | [diff] [blame] | 216 | }; |
| 217 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 218 | /* |
| 219 | * Adds a local TCP/IP port forward to options. Never returns if there is an |
| 220 | * error. |
| 221 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 222 | |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 223 | void |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 224 | add_local_forward(Options *options, const Forward *newfwd) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 225 | { |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 226 | Forward *fwd; |
Ben Lindstrom | 99a4e14 | 2002-07-09 14:06:40 +0000 | [diff] [blame] | 227 | #ifndef NO_IPPORT_RESERVED_CONCEPT |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 228 | extern uid_t original_real_uid; |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 229 | if (newfwd->listen_port < IPPORT_RESERVED && original_real_uid != 0) |
Ben Lindstrom | 6df8ef4 | 2001-03-05 07:47:23 +0000 | [diff] [blame] | 230 | fatal("Privileged ports can only be forwarded by root."); |
Damien Miller | bac2d8a | 2000-09-05 16:13:06 +1100 | [diff] [blame] | 231 | #endif |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 232 | if (options->num_local_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION) |
| 233 | fatal("Too many local forwards (max %d).", SSH_MAX_FORWARDS_PER_DIRECTION); |
| 234 | fwd = &options->local_forwards[options->num_local_forwards++]; |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 235 | |
| 236 | fwd->listen_host = (newfwd->listen_host == NULL) ? |
| 237 | NULL : xstrdup(newfwd->listen_host); |
| 238 | fwd->listen_port = newfwd->listen_port; |
| 239 | fwd->connect_host = xstrdup(newfwd->connect_host); |
| 240 | fwd->connect_port = newfwd->connect_port; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 241 | } |
| 242 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 243 | /* |
| 244 | * Adds a remote TCP/IP port forward to options. Never returns if there is |
| 245 | * an error. |
| 246 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 247 | |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 248 | void |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 249 | add_remote_forward(Options *options, const Forward *newfwd) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 250 | { |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 251 | Forward *fwd; |
| 252 | if (options->num_remote_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION) |
| 253 | fatal("Too many remote forwards (max %d).", |
Damien Miller | 9f0f5c6 | 2001-12-21 14:45:46 +1100 | [diff] [blame] | 254 | SSH_MAX_FORWARDS_PER_DIRECTION); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 255 | fwd = &options->remote_forwards[options->num_remote_forwards++]; |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 256 | |
| 257 | fwd->listen_host = (newfwd->listen_host == NULL) ? |
| 258 | NULL : xstrdup(newfwd->listen_host); |
| 259 | fwd->listen_port = newfwd->listen_port; |
| 260 | fwd->connect_host = xstrdup(newfwd->connect_host); |
| 261 | fwd->connect_port = newfwd->connect_port; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 262 | } |
| 263 | |
Ben Lindstrom | 2b7a0e9 | 2001-09-20 00:57:55 +0000 | [diff] [blame] | 264 | static void |
| 265 | clear_forwardings(Options *options) |
| 266 | { |
| 267 | int i; |
| 268 | |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 269 | for (i = 0; i < options->num_local_forwards; i++) { |
Darren Tucker | 1d55ca7 | 2005-03-14 22:58:40 +1100 | [diff] [blame] | 270 | if (options->local_forwards[i].listen_host != NULL) |
| 271 | xfree(options->local_forwards[i].listen_host); |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 272 | xfree(options->local_forwards[i].connect_host); |
| 273 | } |
Ben Lindstrom | 2b7a0e9 | 2001-09-20 00:57:55 +0000 | [diff] [blame] | 274 | options->num_local_forwards = 0; |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 275 | for (i = 0; i < options->num_remote_forwards; i++) { |
Darren Tucker | 1d55ca7 | 2005-03-14 22:58:40 +1100 | [diff] [blame] | 276 | if (options->remote_forwards[i].listen_host != NULL) |
| 277 | xfree(options->remote_forwards[i].listen_host); |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 278 | xfree(options->remote_forwards[i].connect_host); |
| 279 | } |
Ben Lindstrom | 2b7a0e9 | 2001-09-20 00:57:55 +0000 | [diff] [blame] | 280 | options->num_remote_forwards = 0; |
Damien Miller | 7b58e80 | 2005-12-13 19:33:19 +1100 | [diff] [blame] | 281 | options->tun_open = SSH_TUNMODE_NO; |
Ben Lindstrom | 2b7a0e9 | 2001-09-20 00:57:55 +0000 | [diff] [blame] | 282 | } |
| 283 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 284 | /* |
Ben Lindstrom | 3704c26 | 2001-04-02 18:20:03 +0000 | [diff] [blame] | 285 | * Returns the number of the token pointed to by cp or oBadOption. |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 286 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 287 | |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 288 | static OpCodes |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 289 | parse_token(const char *cp, const char *filename, int linenum) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 290 | { |
Ben Lindstrom | 46c1622 | 2000-12-22 01:43:59 +0000 | [diff] [blame] | 291 | u_int i; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 292 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 293 | for (i = 0; keywords[i].name; i++) |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 294 | if (strcasecmp(cp, keywords[i].name) == 0) |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 295 | return keywords[i].opcode; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 296 | |
Ben Lindstrom | b5cdc66 | 2001-04-16 02:13:26 +0000 | [diff] [blame] | 297 | error("%s: line %d: Bad configuration option: %s", |
| 298 | filename, linenum, cp); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 299 | return oBadOption; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 300 | } |
| 301 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 302 | /* |
| 303 | * Processes a single option line as used in the configuration files. This |
| 304 | * only sets those values that have not already been set. |
| 305 | */ |
Damien Miller | 61f08ac | 2003-02-24 11:56:27 +1100 | [diff] [blame] | 306 | #define WHITESPACE " \t\r\n" |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 307 | |
Damien Miller | 2ccf661 | 1999-11-15 15:25:10 +1100 | [diff] [blame] | 308 | int |
| 309 | process_config_line(Options *options, const char *host, |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 310 | char *line, const char *filename, int linenum, |
| 311 | int *activep) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 312 | { |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 313 | char *s, **charptr, *endofnumber, *keyword, *arg, *arg2, fwdarg[256]; |
Damien Miller | b59d4fe | 2006-03-15 11:30:38 +1100 | [diff] [blame] | 314 | int opcode, *intptr, value, value2, scale; |
| 315 | long long orig, val64; |
Damien Miller | 61f08ac | 2003-02-24 11:56:27 +1100 | [diff] [blame] | 316 | size_t len; |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 317 | Forward fwd; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 318 | |
Damien Miller | c652cac | 2003-05-14 13:40:54 +1000 | [diff] [blame] | 319 | /* Strip trailing whitespace */ |
Darren Tucker | 47eede7 | 2005-03-14 23:08:12 +1100 | [diff] [blame] | 320 | for (len = strlen(line) - 1; len > 0; len--) { |
Damien Miller | c652cac | 2003-05-14 13:40:54 +1000 | [diff] [blame] | 321 | if (strchr(WHITESPACE, line[len]) == NULL) |
| 322 | break; |
| 323 | line[len] = '\0'; |
| 324 | } |
| 325 | |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 326 | s = line; |
| 327 | /* Get the keyword. (Each line is supposed to begin with a keyword). */ |
Damien Miller | 928b236 | 2006-03-26 13:53:32 +1100 | [diff] [blame] | 328 | if ((keyword = strdelim(&s)) == NULL) |
| 329 | return 0; |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 330 | /* Ignore leading whitespace. */ |
| 331 | if (*keyword == '\0') |
| 332 | keyword = strdelim(&s); |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 333 | if (keyword == NULL || !*keyword || *keyword == '\n' || *keyword == '#') |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 334 | return 0; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 335 | |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 336 | opcode = parse_token(keyword, filename, linenum); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 337 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 338 | switch (opcode) { |
| 339 | case oBadOption: |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 340 | /* don't panic, but count bad options */ |
| 341 | return -1; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 342 | /* NOTREACHED */ |
Damien Miller | b78d5eb | 2003-05-16 11:39:04 +1000 | [diff] [blame] | 343 | case oConnectTimeout: |
| 344 | intptr = &options->connection_timeout; |
Damien Miller | 509b010 | 2003-12-17 16:33:10 +1100 | [diff] [blame] | 345 | parse_time: |
Damien Miller | b78d5eb | 2003-05-16 11:39:04 +1000 | [diff] [blame] | 346 | arg = strdelim(&s); |
| 347 | if (!arg || *arg == '\0') |
| 348 | fatal("%s line %d: missing time value.", |
| 349 | filename, linenum); |
| 350 | if ((value = convtime(arg)) == -1) |
| 351 | fatal("%s line %d: invalid time value.", |
| 352 | filename, linenum); |
| 353 | if (*intptr == -1) |
| 354 | *intptr = value; |
| 355 | break; |
| 356 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 357 | case oForwardAgent: |
| 358 | intptr = &options->forward_agent; |
| 359 | parse_flag: |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 360 | arg = strdelim(&s); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 361 | if (!arg || *arg == '\0') |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 362 | fatal("%.200s line %d: Missing yes/no argument.", filename, linenum); |
| 363 | value = 0; /* To avoid compiler warning... */ |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 364 | if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0) |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 365 | value = 1; |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 366 | else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0) |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 367 | value = 0; |
| 368 | else |
| 369 | fatal("%.200s line %d: Bad yes/no argument.", filename, linenum); |
| 370 | if (*activep && *intptr == -1) |
| 371 | *intptr = value; |
| 372 | break; |
| 373 | |
| 374 | case oForwardX11: |
| 375 | intptr = &options->forward_x11; |
| 376 | goto parse_flag; |
| 377 | |
Darren Tucker | 0a118da | 2003-10-15 15:54:32 +1000 | [diff] [blame] | 378 | case oForwardX11Trusted: |
| 379 | intptr = &options->forward_x11_trusted; |
| 380 | goto parse_flag; |
| 381 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 382 | case oGatewayPorts: |
| 383 | intptr = &options->gateway_ports; |
| 384 | goto parse_flag; |
| 385 | |
| 386 | case oUsePrivilegedPort: |
| 387 | intptr = &options->use_privileged_port; |
| 388 | goto parse_flag; |
| 389 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 390 | case oPasswordAuthentication: |
| 391 | intptr = &options->password_authentication; |
| 392 | goto parse_flag; |
| 393 | |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 394 | case oKbdInteractiveAuthentication: |
| 395 | intptr = &options->kbd_interactive_authentication; |
| 396 | goto parse_flag; |
| 397 | |
| 398 | case oKbdInteractiveDevices: |
| 399 | charptr = &options->kbd_interactive_devices; |
| 400 | goto parse_string; |
| 401 | |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 402 | case oPubkeyAuthentication: |
| 403 | intptr = &options->pubkey_authentication; |
Damien Miller | e247cc4 | 2000-05-07 12:03:14 +1000 | [diff] [blame] | 404 | goto parse_flag; |
| 405 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 406 | case oRSAAuthentication: |
| 407 | intptr = &options->rsa_authentication; |
| 408 | goto parse_flag; |
| 409 | |
| 410 | case oRhostsRSAAuthentication: |
| 411 | intptr = &options->rhosts_rsa_authentication; |
| 412 | goto parse_flag; |
| 413 | |
Ben Lindstrom | 5eabda3 | 2001-04-12 23:34:34 +0000 | [diff] [blame] | 414 | case oHostbasedAuthentication: |
| 415 | intptr = &options->hostbased_authentication; |
| 416 | goto parse_flag; |
| 417 | |
Ben Lindstrom | 95fb2dd | 2001-01-23 03:12:10 +0000 | [diff] [blame] | 418 | case oChallengeResponseAuthentication: |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 419 | intptr = &options->challenge_response_authentication; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 420 | goto parse_flag; |
Damien Miller | 2aa0ab4 | 2003-05-15 12:05:28 +1000 | [diff] [blame] | 421 | |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 422 | case oGssAuthentication: |
| 423 | intptr = &options->gss_authentication; |
| 424 | goto parse_flag; |
| 425 | |
| 426 | case oGssDelegateCreds: |
| 427 | intptr = &options->gss_deleg_creds; |
| 428 | goto parse_flag; |
| 429 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 430 | case oBatchMode: |
| 431 | intptr = &options->batch_mode; |
| 432 | goto parse_flag; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 433 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 434 | case oCheckHostIP: |
| 435 | intptr = &options->check_host_ip; |
| 436 | goto parse_flag; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 437 | |
Damien Miller | 37876e9 | 2003-05-15 10:19:46 +1000 | [diff] [blame] | 438 | case oVerifyHostKeyDNS: |
| 439 | intptr = &options->verify_host_key_dns; |
Damien Miller | 150b557 | 2003-11-17 21:19:29 +1100 | [diff] [blame] | 440 | goto parse_yesnoask; |
Damien Miller | 37876e9 | 2003-05-15 10:19:46 +1000 | [diff] [blame] | 441 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 442 | case oStrictHostKeyChecking: |
| 443 | intptr = &options->strict_host_key_checking; |
Damien Miller | 150b557 | 2003-11-17 21:19:29 +1100 | [diff] [blame] | 444 | parse_yesnoask: |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 445 | arg = strdelim(&s); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 446 | if (!arg || *arg == '\0') |
Ben Lindstrom | 5ed8acd | 2001-01-29 08:00:54 +0000 | [diff] [blame] | 447 | fatal("%.200s line %d: Missing yes/no/ask argument.", |
Damien Miller | 9f0f5c6 | 2001-12-21 14:45:46 +1100 | [diff] [blame] | 448 | filename, linenum); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 449 | value = 0; /* To avoid compiler warning... */ |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 450 | if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0) |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 451 | value = 1; |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 452 | else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0) |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 453 | value = 0; |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 454 | else if (strcmp(arg, "ask") == 0) |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 455 | value = 2; |
| 456 | else |
| 457 | fatal("%.200s line %d: Bad yes/no/ask argument.", filename, linenum); |
| 458 | if (*activep && *intptr == -1) |
| 459 | *intptr = value; |
| 460 | break; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 461 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 462 | case oCompression: |
| 463 | intptr = &options->compression; |
| 464 | goto parse_flag; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 465 | |
Damien Miller | 12c150e | 2003-12-17 16:31:10 +1100 | [diff] [blame] | 466 | case oTCPKeepAlive: |
| 467 | intptr = &options->tcp_keep_alive; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 468 | goto parse_flag; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 469 | |
Ben Lindstrom | 3cecc9a | 2001-10-03 17:39:38 +0000 | [diff] [blame] | 470 | case oNoHostAuthenticationForLocalhost: |
| 471 | intptr = &options->no_host_authentication_for_localhost; |
| 472 | goto parse_flag; |
| 473 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 474 | case oNumberOfPasswordPrompts: |
| 475 | intptr = &options->number_of_password_prompts; |
| 476 | goto parse_int; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 477 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 478 | case oCompressionLevel: |
| 479 | intptr = &options->compression_level; |
| 480 | goto parse_int; |
| 481 | |
Damien Miller | a5539d2 | 2003-04-09 20:50:06 +1000 | [diff] [blame] | 482 | case oRekeyLimit: |
| 483 | intptr = &options->rekey_limit; |
| 484 | arg = strdelim(&s); |
| 485 | if (!arg || *arg == '\0') |
| 486 | fatal("%.200s line %d: Missing argument.", filename, linenum); |
| 487 | if (arg[0] < '0' || arg[0] > '9') |
| 488 | fatal("%.200s line %d: Bad number.", filename, linenum); |
Damien Miller | b59d4fe | 2006-03-15 11:30:38 +1100 | [diff] [blame] | 489 | orig = val64 = strtoll(arg, &endofnumber, 10); |
Damien Miller | a5539d2 | 2003-04-09 20:50:06 +1000 | [diff] [blame] | 490 | if (arg == endofnumber) |
| 491 | fatal("%.200s line %d: Bad number.", filename, linenum); |
| 492 | switch (toupper(*endofnumber)) { |
Damien Miller | b59d4fe | 2006-03-15 11:30:38 +1100 | [diff] [blame] | 493 | case '\0': |
| 494 | scale = 1; |
| 495 | break; |
Damien Miller | a5539d2 | 2003-04-09 20:50:06 +1000 | [diff] [blame] | 496 | case 'K': |
Damien Miller | b59d4fe | 2006-03-15 11:30:38 +1100 | [diff] [blame] | 497 | scale = 1<<10; |
Damien Miller | a5539d2 | 2003-04-09 20:50:06 +1000 | [diff] [blame] | 498 | break; |
| 499 | case 'M': |
Damien Miller | b59d4fe | 2006-03-15 11:30:38 +1100 | [diff] [blame] | 500 | scale = 1<<20; |
Damien Miller | a5539d2 | 2003-04-09 20:50:06 +1000 | [diff] [blame] | 501 | break; |
| 502 | case 'G': |
Damien Miller | b59d4fe | 2006-03-15 11:30:38 +1100 | [diff] [blame] | 503 | scale = 1<<30; |
Damien Miller | a5539d2 | 2003-04-09 20:50:06 +1000 | [diff] [blame] | 504 | break; |
Damien Miller | b59d4fe | 2006-03-15 11:30:38 +1100 | [diff] [blame] | 505 | default: |
| 506 | fatal("%.200s line %d: Invalid RekeyLimit suffix", |
| 507 | filename, linenum); |
Damien Miller | a5539d2 | 2003-04-09 20:50:06 +1000 | [diff] [blame] | 508 | } |
Damien Miller | b59d4fe | 2006-03-15 11:30:38 +1100 | [diff] [blame] | 509 | val64 *= scale; |
| 510 | /* detect integer wrap and too-large limits */ |
| 511 | if ((val64 / scale) != orig || val64 > INT_MAX) |
| 512 | fatal("%.200s line %d: RekeyLimit too large", |
| 513 | filename, linenum); |
| 514 | if (val64 < 16) |
| 515 | fatal("%.200s line %d: RekeyLimit too small", |
| 516 | filename, linenum); |
Damien Miller | a5539d2 | 2003-04-09 20:50:06 +1000 | [diff] [blame] | 517 | if (*activep && *intptr == -1) |
Damien Miller | b59d4fe | 2006-03-15 11:30:38 +1100 | [diff] [blame] | 518 | *intptr = (int)val64; |
Damien Miller | a5539d2 | 2003-04-09 20:50:06 +1000 | [diff] [blame] | 519 | break; |
| 520 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 521 | case oIdentityFile: |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 522 | arg = strdelim(&s); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 523 | if (!arg || *arg == '\0') |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 524 | fatal("%.200s line %d: Missing argument.", filename, linenum); |
| 525 | if (*activep) { |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 526 | intptr = &options->num_identity_files; |
Damien Miller | eba71ba | 2000-04-29 23:57:08 +1000 | [diff] [blame] | 527 | if (*intptr >= SSH_MAX_IDENTITY_FILES) |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 528 | fatal("%.200s line %d: Too many identity files specified (max %d).", |
Damien Miller | 9f0f5c6 | 2001-12-21 14:45:46 +1100 | [diff] [blame] | 529 | filename, linenum, SSH_MAX_IDENTITY_FILES); |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 530 | charptr = &options->identity_files[*intptr]; |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 531 | *charptr = xstrdup(arg); |
Damien Miller | eba71ba | 2000-04-29 23:57:08 +1000 | [diff] [blame] | 532 | *intptr = *intptr + 1; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 533 | } |
| 534 | break; |
| 535 | |
Damien Miller | d3a1857 | 2000-06-07 19:55:44 +1000 | [diff] [blame] | 536 | case oXAuthLocation: |
| 537 | charptr=&options->xauth_location; |
| 538 | goto parse_string; |
| 539 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 540 | case oUser: |
| 541 | charptr = &options->user; |
| 542 | parse_string: |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 543 | arg = strdelim(&s); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 544 | if (!arg || *arg == '\0') |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 545 | fatal("%.200s line %d: Missing argument.", filename, linenum); |
| 546 | if (*activep && *charptr == NULL) |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 547 | *charptr = xstrdup(arg); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 548 | break; |
| 549 | |
| 550 | case oGlobalKnownHostsFile: |
| 551 | charptr = &options->system_hostfile; |
| 552 | goto parse_string; |
| 553 | |
| 554 | case oUserKnownHostsFile: |
| 555 | charptr = &options->user_hostfile; |
| 556 | goto parse_string; |
| 557 | |
Damien Miller | eba71ba | 2000-04-29 23:57:08 +1000 | [diff] [blame] | 558 | case oGlobalKnownHostsFile2: |
| 559 | charptr = &options->system_hostfile2; |
| 560 | goto parse_string; |
| 561 | |
| 562 | case oUserKnownHostsFile2: |
| 563 | charptr = &options->user_hostfile2; |
| 564 | goto parse_string; |
| 565 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 566 | case oHostName: |
| 567 | charptr = &options->hostname; |
| 568 | goto parse_string; |
| 569 | |
Ben Lindstrom | 4dccfa5 | 2000-12-28 16:40:05 +0000 | [diff] [blame] | 570 | case oHostKeyAlias: |
| 571 | charptr = &options->host_key_alias; |
| 572 | goto parse_string; |
| 573 | |
Ben Lindstrom | b9be60a | 2001-03-11 01:49:19 +0000 | [diff] [blame] | 574 | case oPreferredAuthentications: |
| 575 | charptr = &options->preferred_authentications; |
| 576 | goto parse_string; |
| 577 | |
Ben Lindstrom | e0f8804 | 2001-04-30 13:06:24 +0000 | [diff] [blame] | 578 | case oBindAddress: |
| 579 | charptr = &options->bind_address; |
| 580 | goto parse_string; |
| 581 | |
Ben Lindstrom | ae996bf | 2001-08-06 21:27:53 +0000 | [diff] [blame] | 582 | case oSmartcardDevice: |
Ben Lindstrom | f7db3bb | 2001-08-06 21:35:51 +0000 | [diff] [blame] | 583 | charptr = &options->smartcard_device; |
| 584 | goto parse_string; |
Ben Lindstrom | ae996bf | 2001-08-06 21:27:53 +0000 | [diff] [blame] | 585 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 586 | case oProxyCommand: |
Damien Miller | d27b947 | 2005-12-13 19:29:02 +1100 | [diff] [blame] | 587 | charptr = &options->proxy_command; |
| 588 | parse_command: |
Darren Tucker | a99c1b7 | 2003-06-28 12:40:12 +1000 | [diff] [blame] | 589 | if (s == NULL) |
| 590 | fatal("%.200s line %d: Missing argument.", filename, linenum); |
Damien Miller | 61f08ac | 2003-02-24 11:56:27 +1100 | [diff] [blame] | 591 | len = strspn(s, WHITESPACE "="); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 592 | if (*activep && *charptr == NULL) |
Damien Miller | 61f08ac | 2003-02-24 11:56:27 +1100 | [diff] [blame] | 593 | *charptr = xstrdup(s + len); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 594 | return 0; |
| 595 | |
| 596 | case oPort: |
| 597 | intptr = &options->port; |
| 598 | parse_int: |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 599 | arg = strdelim(&s); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 600 | if (!arg || *arg == '\0') |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 601 | fatal("%.200s line %d: Missing argument.", filename, linenum); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 602 | if (arg[0] < '0' || arg[0] > '9') |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 603 | fatal("%.200s line %d: Bad number.", filename, linenum); |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 604 | |
| 605 | /* Octal, decimal, or hex format? */ |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 606 | value = strtol(arg, &endofnumber, 0); |
| 607 | if (arg == endofnumber) |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 608 | fatal("%.200s line %d: Bad number.", filename, linenum); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 609 | if (*activep && *intptr == -1) |
| 610 | *intptr = value; |
| 611 | break; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 612 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 613 | case oConnectionAttempts: |
| 614 | intptr = &options->connection_attempts; |
| 615 | goto parse_int; |
Damien Miller | 5ce662a | 1999-11-11 17:57:39 +1100 | [diff] [blame] | 616 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 617 | case oCipher: |
| 618 | intptr = &options->cipher; |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 619 | arg = strdelim(&s); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 620 | if (!arg || *arg == '\0') |
Damien Miller | b1715dc | 2000-05-30 13:44:51 +1000 | [diff] [blame] | 621 | fatal("%.200s line %d: Missing argument.", filename, linenum); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 622 | value = cipher_number(arg); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 623 | if (value == -1) |
| 624 | fatal("%.200s line %d: Bad cipher '%s'.", |
Damien Miller | 9f0f5c6 | 2001-12-21 14:45:46 +1100 | [diff] [blame] | 625 | filename, linenum, arg ? arg : "<NONE>"); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 626 | if (*activep && *intptr == -1) |
| 627 | *intptr = value; |
| 628 | break; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 629 | |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 630 | case oCiphers: |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 631 | arg = strdelim(&s); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 632 | if (!arg || *arg == '\0') |
Damien Miller | b1715dc | 2000-05-30 13:44:51 +1000 | [diff] [blame] | 633 | fatal("%.200s line %d: Missing argument.", filename, linenum); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 634 | if (!ciphers_valid(arg)) |
Damien Miller | 30c3d42 | 2000-05-09 11:02:59 +1000 | [diff] [blame] | 635 | fatal("%.200s line %d: Bad SSH2 cipher spec '%s'.", |
Damien Miller | 9f0f5c6 | 2001-12-21 14:45:46 +1100 | [diff] [blame] | 636 | filename, linenum, arg ? arg : "<NONE>"); |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 637 | if (*activep && options->ciphers == NULL) |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 638 | options->ciphers = xstrdup(arg); |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 639 | break; |
| 640 | |
Ben Lindstrom | 06b33aa | 2001-02-15 03:01:59 +0000 | [diff] [blame] | 641 | case oMacs: |
| 642 | arg = strdelim(&s); |
| 643 | if (!arg || *arg == '\0') |
| 644 | fatal("%.200s line %d: Missing argument.", filename, linenum); |
| 645 | if (!mac_valid(arg)) |
| 646 | fatal("%.200s line %d: Bad SSH2 Mac spec '%s'.", |
Damien Miller | 9f0f5c6 | 2001-12-21 14:45:46 +1100 | [diff] [blame] | 647 | filename, linenum, arg ? arg : "<NONE>"); |
Ben Lindstrom | 06b33aa | 2001-02-15 03:01:59 +0000 | [diff] [blame] | 648 | if (*activep && options->macs == NULL) |
| 649 | options->macs = xstrdup(arg); |
| 650 | break; |
| 651 | |
Ben Lindstrom | 982dbbc | 2001-04-17 18:11:36 +0000 | [diff] [blame] | 652 | case oHostKeyAlgorithms: |
| 653 | arg = strdelim(&s); |
| 654 | if (!arg || *arg == '\0') |
| 655 | fatal("%.200s line %d: Missing argument.", filename, linenum); |
| 656 | if (!key_names_valid2(arg)) |
| 657 | fatal("%.200s line %d: Bad protocol 2 host key algorithms '%s'.", |
Damien Miller | 9f0f5c6 | 2001-12-21 14:45:46 +1100 | [diff] [blame] | 658 | filename, linenum, arg ? arg : "<NONE>"); |
Ben Lindstrom | 982dbbc | 2001-04-17 18:11:36 +0000 | [diff] [blame] | 659 | if (*activep && options->hostkeyalgorithms == NULL) |
| 660 | options->hostkeyalgorithms = xstrdup(arg); |
| 661 | break; |
| 662 | |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 663 | case oProtocol: |
| 664 | intptr = &options->protocol; |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 665 | arg = strdelim(&s); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 666 | if (!arg || *arg == '\0') |
Damien Miller | b1715dc | 2000-05-30 13:44:51 +1000 | [diff] [blame] | 667 | fatal("%.200s line %d: Missing argument.", filename, linenum); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 668 | value = proto_spec(arg); |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 669 | if (value == SSH_PROTO_UNKNOWN) |
| 670 | fatal("%.200s line %d: Bad protocol spec '%s'.", |
Damien Miller | 9f0f5c6 | 2001-12-21 14:45:46 +1100 | [diff] [blame] | 671 | filename, linenum, arg ? arg : "<NONE>"); |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 672 | if (*activep && *intptr == SSH_PROTO_UNKNOWN) |
| 673 | *intptr = value; |
| 674 | break; |
| 675 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 676 | case oLogLevel: |
| 677 | intptr = (int *) &options->log_level; |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 678 | arg = strdelim(&s); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 679 | value = log_level_number(arg); |
Damien Miller | fcd9320 | 2002-02-05 12:26:34 +1100 | [diff] [blame] | 680 | if (value == SYSLOG_LEVEL_NOT_SET) |
Ben Lindstrom | 6df8ef4 | 2001-03-05 07:47:23 +0000 | [diff] [blame] | 681 | fatal("%.200s line %d: unsupported log level '%s'", |
Damien Miller | 9f0f5c6 | 2001-12-21 14:45:46 +1100 | [diff] [blame] | 682 | filename, linenum, arg ? arg : "<NONE>"); |
Damien Miller | fcd9320 | 2002-02-05 12:26:34 +1100 | [diff] [blame] | 683 | if (*activep && (LogLevel) *intptr == SYSLOG_LEVEL_NOT_SET) |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 684 | *intptr = (LogLevel) value; |
| 685 | break; |
| 686 | |
Ben Lindstrom | 62c25a4 | 2001-09-12 18:01:59 +0000 | [diff] [blame] | 687 | case oLocalForward: |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 688 | case oRemoteForward: |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 689 | arg = strdelim(&s); |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 690 | if (arg == NULL || *arg == '\0') |
Ben Lindstrom | 62c25a4 | 2001-09-12 18:01:59 +0000 | [diff] [blame] | 691 | fatal("%.200s line %d: Missing port argument.", |
| 692 | filename, linenum); |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 693 | arg2 = strdelim(&s); |
| 694 | if (arg2 == NULL || *arg2 == '\0') |
| 695 | fatal("%.200s line %d: Missing target argument.", |
Ben Lindstrom | 62c25a4 | 2001-09-12 18:01:59 +0000 | [diff] [blame] | 696 | filename, linenum); |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 697 | |
| 698 | /* construct a string for parse_forward */ |
| 699 | snprintf(fwdarg, sizeof(fwdarg), "%s:%s", arg, arg2); |
| 700 | |
| 701 | if (parse_forward(&fwd, fwdarg) == 0) |
Ben Lindstrom | 62c25a4 | 2001-09-12 18:01:59 +0000 | [diff] [blame] | 702 | fatal("%.200s line %d: Bad forwarding specification.", |
| 703 | filename, linenum); |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 704 | |
Ben Lindstrom | 62c25a4 | 2001-09-12 18:01:59 +0000 | [diff] [blame] | 705 | if (*activep) { |
| 706 | if (opcode == oLocalForward) |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 707 | add_local_forward(options, &fwd); |
Ben Lindstrom | 62c25a4 | 2001-09-12 18:01:59 +0000 | [diff] [blame] | 708 | else if (opcode == oRemoteForward) |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 709 | add_remote_forward(options, &fwd); |
Ben Lindstrom | 62c25a4 | 2001-09-12 18:01:59 +0000 | [diff] [blame] | 710 | } |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 711 | break; |
| 712 | |
Ben Lindstrom | 3bb4f9d | 2001-04-08 18:30:26 +0000 | [diff] [blame] | 713 | case oDynamicForward: |
| 714 | arg = strdelim(&s); |
| 715 | if (!arg || *arg == '\0') |
| 716 | fatal("%.200s line %d: Missing port argument.", |
| 717 | filename, linenum); |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 718 | memset(&fwd, '\0', sizeof(fwd)); |
| 719 | fwd.connect_host = "socks"; |
| 720 | fwd.listen_host = hpdelim(&arg); |
| 721 | if (fwd.listen_host == NULL || |
| 722 | strlen(fwd.listen_host) >= NI_MAXHOST) |
| 723 | fatal("%.200s line %d: Bad forwarding specification.", |
| 724 | filename, linenum); |
| 725 | if (arg) { |
| 726 | fwd.listen_port = a2port(arg); |
| 727 | fwd.listen_host = cleanhostname(fwd.listen_host); |
| 728 | } else { |
| 729 | fwd.listen_port = a2port(fwd.listen_host); |
Damien Miller | 43f6db6 | 2005-08-12 22:11:18 +1000 | [diff] [blame] | 730 | fwd.listen_host = NULL; |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 731 | } |
| 732 | if (fwd.listen_port == 0) |
Ben Lindstrom | 3bb4f9d | 2001-04-08 18:30:26 +0000 | [diff] [blame] | 733 | fatal("%.200s line %d: Badly formatted port number.", |
| 734 | filename, linenum); |
Ben Lindstrom | 525a093 | 2001-09-12 17:35:27 +0000 | [diff] [blame] | 735 | if (*activep) |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 736 | add_local_forward(options, &fwd); |
Ben Lindstrom | 5eabda3 | 2001-04-12 23:34:34 +0000 | [diff] [blame] | 737 | break; |
Ben Lindstrom | 3bb4f9d | 2001-04-08 18:30:26 +0000 | [diff] [blame] | 738 | |
Ben Lindstrom | 2b7a0e9 | 2001-09-20 00:57:55 +0000 | [diff] [blame] | 739 | case oClearAllForwardings: |
| 740 | intptr = &options->clear_forwardings; |
| 741 | goto parse_flag; |
| 742 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 743 | case oHost: |
| 744 | *activep = 0; |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 745 | while ((arg = strdelim(&s)) != NULL && *arg != '\0') |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 746 | if (match_pattern(host, arg)) { |
| 747 | debug("Applying options for %.100s", arg); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 748 | *activep = 1; |
| 749 | break; |
| 750 | } |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 751 | /* Avoid garbage check below, as strdelim is done. */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 752 | return 0; |
| 753 | |
| 754 | case oEscapeChar: |
| 755 | intptr = &options->escape_char; |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 756 | arg = strdelim(&s); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 757 | if (!arg || *arg == '\0') |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 758 | fatal("%.200s line %d: Missing argument.", filename, linenum); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 759 | if (arg[0] == '^' && arg[2] == 0 && |
Ben Lindstrom | 46c1622 | 2000-12-22 01:43:59 +0000 | [diff] [blame] | 760 | (u_char) arg[1] >= 64 && (u_char) arg[1] < 128) |
| 761 | value = (u_char) arg[1] & 31; |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 762 | else if (strlen(arg) == 1) |
Ben Lindstrom | 46c1622 | 2000-12-22 01:43:59 +0000 | [diff] [blame] | 763 | value = (u_char) arg[0]; |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 764 | else if (strcmp(arg, "none") == 0) |
Ben Lindstrom | 2b1f71b | 2001-06-05 20:32:21 +0000 | [diff] [blame] | 765 | value = SSH_ESCAPECHAR_NONE; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 766 | else { |
| 767 | fatal("%.200s line %d: Bad escape character.", |
Damien Miller | 9f0f5c6 | 2001-12-21 14:45:46 +1100 | [diff] [blame] | 768 | filename, linenum); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 769 | /* NOTREACHED */ |
| 770 | value = 0; /* Avoid compiler warning. */ |
| 771 | } |
| 772 | if (*activep && *intptr == -1) |
| 773 | *intptr = value; |
| 774 | break; |
| 775 | |
Damien Miller | 20a8f97 | 2003-05-18 20:50:30 +1000 | [diff] [blame] | 776 | case oAddressFamily: |
| 777 | arg = strdelim(&s); |
Damien Miller | 17b23d8 | 2005-05-26 12:11:56 +1000 | [diff] [blame] | 778 | if (!arg || *arg == '\0') |
| 779 | fatal("%s line %d: missing address family.", |
| 780 | filename, linenum); |
Darren Tucker | 0a4f04b | 2003-07-03 20:37:47 +1000 | [diff] [blame] | 781 | intptr = &options->address_family; |
Damien Miller | 20a8f97 | 2003-05-18 20:50:30 +1000 | [diff] [blame] | 782 | if (strcasecmp(arg, "inet") == 0) |
Darren Tucker | 0a4f04b | 2003-07-03 20:37:47 +1000 | [diff] [blame] | 783 | value = AF_INET; |
Damien Miller | 20a8f97 | 2003-05-18 20:50:30 +1000 | [diff] [blame] | 784 | else if (strcasecmp(arg, "inet6") == 0) |
Darren Tucker | 0a4f04b | 2003-07-03 20:37:47 +1000 | [diff] [blame] | 785 | value = AF_INET6; |
Damien Miller | 20a8f97 | 2003-05-18 20:50:30 +1000 | [diff] [blame] | 786 | else if (strcasecmp(arg, "any") == 0) |
Darren Tucker | 0a4f04b | 2003-07-03 20:37:47 +1000 | [diff] [blame] | 787 | value = AF_UNSPEC; |
Damien Miller | 20a8f97 | 2003-05-18 20:50:30 +1000 | [diff] [blame] | 788 | else |
| 789 | fatal("Unsupported AddressFamily \"%s\"", arg); |
Darren Tucker | 0a4f04b | 2003-07-03 20:37:47 +1000 | [diff] [blame] | 790 | if (*activep && *intptr == -1) |
| 791 | *intptr = value; |
Damien Miller | 20a8f97 | 2003-05-18 20:50:30 +1000 | [diff] [blame] | 792 | break; |
| 793 | |
Ben Lindstrom | b6df73b | 2002-11-09 15:52:31 +0000 | [diff] [blame] | 794 | case oEnableSSHKeysign: |
| 795 | intptr = &options->enable_ssh_keysign; |
| 796 | goto parse_flag; |
| 797 | |
Damien Miller | bd394c3 | 2004-03-08 23:12:36 +1100 | [diff] [blame] | 798 | case oIdentitiesOnly: |
| 799 | intptr = &options->identities_only; |
| 800 | goto parse_flag; |
| 801 | |
Damien Miller | 509b010 | 2003-12-17 16:33:10 +1100 | [diff] [blame] | 802 | case oServerAliveInterval: |
| 803 | intptr = &options->server_alive_interval; |
| 804 | goto parse_time; |
| 805 | |
| 806 | case oServerAliveCountMax: |
| 807 | intptr = &options->server_alive_count_max; |
| 808 | goto parse_int; |
| 809 | |
Darren Tucker | 46bc075 | 2004-05-02 22:11:30 +1000 | [diff] [blame] | 810 | case oSendEnv: |
| 811 | while ((arg = strdelim(&s)) != NULL && *arg != '\0') { |
| 812 | if (strchr(arg, '=') != NULL) |
| 813 | fatal("%s line %d: Invalid environment name.", |
| 814 | filename, linenum); |
Damien Miller | f8e7acc | 2005-03-05 11:22:50 +1100 | [diff] [blame] | 815 | if (!*activep) |
| 816 | continue; |
Darren Tucker | 46bc075 | 2004-05-02 22:11:30 +1000 | [diff] [blame] | 817 | if (options->num_send_env >= MAX_SEND_ENV) |
| 818 | fatal("%s line %d: too many send env.", |
| 819 | filename, linenum); |
| 820 | options->send_env[options->num_send_env++] = |
| 821 | xstrdup(arg); |
| 822 | } |
| 823 | break; |
| 824 | |
Damien Miller | 0e220db | 2004-06-15 10:34:08 +1000 | [diff] [blame] | 825 | case oControlPath: |
| 826 | charptr = &options->control_path; |
| 827 | goto parse_string; |
| 828 | |
| 829 | case oControlMaster: |
| 830 | intptr = &options->control_master; |
Damien Miller | d14b1e7 | 2005-06-16 13:19:41 +1000 | [diff] [blame] | 831 | arg = strdelim(&s); |
| 832 | if (!arg || *arg == '\0') |
| 833 | fatal("%.200s line %d: Missing ControlMaster argument.", |
| 834 | filename, linenum); |
| 835 | value = 0; /* To avoid compiler warning... */ |
| 836 | if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0) |
| 837 | value = SSHCTL_MASTER_YES; |
| 838 | else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0) |
| 839 | value = SSHCTL_MASTER_NO; |
| 840 | else if (strcmp(arg, "auto") == 0) |
| 841 | value = SSHCTL_MASTER_AUTO; |
| 842 | else if (strcmp(arg, "ask") == 0) |
| 843 | value = SSHCTL_MASTER_ASK; |
| 844 | else if (strcmp(arg, "autoask") == 0) |
| 845 | value = SSHCTL_MASTER_AUTO_ASK; |
| 846 | else |
| 847 | fatal("%.200s line %d: Bad ControlMaster argument.", |
| 848 | filename, linenum); |
| 849 | if (*activep && *intptr == -1) |
| 850 | *intptr = value; |
| 851 | break; |
Damien Miller | 0e220db | 2004-06-15 10:34:08 +1000 | [diff] [blame] | 852 | |
Damien Miller | e177615 | 2005-03-01 21:47:37 +1100 | [diff] [blame] | 853 | case oHashKnownHosts: |
| 854 | intptr = &options->hash_known_hosts; |
| 855 | goto parse_flag; |
| 856 | |
Damien Miller | d27b947 | 2005-12-13 19:29:02 +1100 | [diff] [blame] | 857 | case oTunnel: |
| 858 | intptr = &options->tun_open; |
Damien Miller | 7b58e80 | 2005-12-13 19:33:19 +1100 | [diff] [blame] | 859 | arg = strdelim(&s); |
| 860 | if (!arg || *arg == '\0') |
| 861 | fatal("%s line %d: Missing yes/point-to-point/" |
| 862 | "ethernet/no argument.", filename, linenum); |
| 863 | value = 0; /* silence compiler */ |
| 864 | if (strcasecmp(arg, "ethernet") == 0) |
| 865 | value = SSH_TUNMODE_ETHERNET; |
| 866 | else if (strcasecmp(arg, "point-to-point") == 0) |
| 867 | value = SSH_TUNMODE_POINTOPOINT; |
| 868 | else if (strcasecmp(arg, "yes") == 0) |
| 869 | value = SSH_TUNMODE_DEFAULT; |
| 870 | else if (strcasecmp(arg, "no") == 0) |
| 871 | value = SSH_TUNMODE_NO; |
| 872 | else |
| 873 | fatal("%s line %d: Bad yes/point-to-point/ethernet/" |
| 874 | "no argument: %s", filename, linenum, arg); |
| 875 | if (*activep) |
| 876 | *intptr = value; |
| 877 | break; |
Damien Miller | d27b947 | 2005-12-13 19:29:02 +1100 | [diff] [blame] | 878 | |
| 879 | case oTunnelDevice: |
| 880 | arg = strdelim(&s); |
| 881 | if (!arg || *arg == '\0') |
| 882 | fatal("%.200s line %d: Missing argument.", filename, linenum); |
| 883 | value = a2tun(arg, &value2); |
Damien Miller | 7b58e80 | 2005-12-13 19:33:19 +1100 | [diff] [blame] | 884 | if (value == SSH_TUNID_ERR) |
Damien Miller | d27b947 | 2005-12-13 19:29:02 +1100 | [diff] [blame] | 885 | fatal("%.200s line %d: Bad tun device.", filename, linenum); |
| 886 | if (*activep) { |
| 887 | options->tun_local = value; |
| 888 | options->tun_remote = value2; |
| 889 | } |
| 890 | break; |
| 891 | |
| 892 | case oLocalCommand: |
| 893 | charptr = &options->local_command; |
| 894 | goto parse_command; |
| 895 | |
| 896 | case oPermitLocalCommand: |
| 897 | intptr = &options->permit_local_command; |
| 898 | goto parse_flag; |
| 899 | |
Ben Lindstrom | 4daea86 | 2002-06-09 20:04:02 +0000 | [diff] [blame] | 900 | case oDeprecated: |
Ben Lindstrom | 2e17b08 | 2002-06-09 20:13:27 +0000 | [diff] [blame] | 901 | debug("%s line %d: Deprecated option \"%s\"", |
Ben Lindstrom | 4daea86 | 2002-06-09 20:04:02 +0000 | [diff] [blame] | 902 | filename, linenum, keyword); |
Ben Lindstrom | 2e17b08 | 2002-06-09 20:13:27 +0000 | [diff] [blame] | 903 | return 0; |
Ben Lindstrom | 4daea86 | 2002-06-09 20:04:02 +0000 | [diff] [blame] | 904 | |
Damien Miller | f9b3feb | 2003-05-16 11:38:32 +1000 | [diff] [blame] | 905 | case oUnsupported: |
| 906 | error("%s line %d: Unsupported option \"%s\"", |
| 907 | filename, linenum, keyword); |
| 908 | return 0; |
| 909 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 910 | default: |
| 911 | fatal("process_config_line: Unimplemented opcode %d", opcode); |
| 912 | } |
| 913 | |
| 914 | /* Check that there is no garbage at end of line. */ |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 915 | if ((arg = strdelim(&s)) != NULL && *arg != '\0') { |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 916 | fatal("%.200s line %d: garbage at end of line; \"%.200s\".", |
Damien Miller | 0dc1bef | 2005-07-17 17:22:45 +1000 | [diff] [blame] | 917 | filename, linenum, arg); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 918 | } |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 919 | return 0; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 920 | } |
| 921 | |
| 922 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 923 | /* |
| 924 | * Reads the config file and modifies the options accordingly. Options |
| 925 | * should already be initialized before this call. This never returns if |
Ben Lindstrom | edc0cf2 | 2001-09-12 18:32:20 +0000 | [diff] [blame] | 926 | * 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] | 927 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 928 | |
Ben Lindstrom | edc0cf2 | 2001-09-12 18:32:20 +0000 | [diff] [blame] | 929 | int |
Darren Tucker | fc95970 | 2004-07-17 16:12:08 +1000 | [diff] [blame] | 930 | read_config_file(const char *filename, const char *host, Options *options, |
Damien Miller | 57a4476 | 2004-04-20 20:11:57 +1000 | [diff] [blame] | 931 | int checkperm) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 932 | { |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 933 | FILE *f; |
| 934 | char line[1024]; |
| 935 | int active, linenum; |
| 936 | int bad_options = 0; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 937 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 938 | /* Open the file. */ |
Damien Miller | 57a4476 | 2004-04-20 20:11:57 +1000 | [diff] [blame] | 939 | if ((f = fopen(filename, "r")) == NULL) |
Ben Lindstrom | edc0cf2 | 2001-09-12 18:32:20 +0000 | [diff] [blame] | 940 | return 0; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 941 | |
Damien Miller | 57a4476 | 2004-04-20 20:11:57 +1000 | [diff] [blame] | 942 | if (checkperm) { |
| 943 | struct stat sb; |
Darren Tucker | fc95970 | 2004-07-17 16:12:08 +1000 | [diff] [blame] | 944 | |
Damien Miller | 3379385 | 2004-06-15 10:27:55 +1000 | [diff] [blame] | 945 | if (fstat(fileno(f), &sb) == -1) |
Damien Miller | 57a4476 | 2004-04-20 20:11:57 +1000 | [diff] [blame] | 946 | fatal("fstat %s: %s", filename, strerror(errno)); |
Damien Miller | 57a4476 | 2004-04-20 20:11:57 +1000 | [diff] [blame] | 947 | if (((sb.st_uid != 0 && sb.st_uid != getuid()) || |
Damien Miller | 3379385 | 2004-06-15 10:27:55 +1000 | [diff] [blame] | 948 | (sb.st_mode & 022) != 0)) |
Damien Miller | 57a4476 | 2004-04-20 20:11:57 +1000 | [diff] [blame] | 949 | fatal("Bad owner or permissions on %s", filename); |
Damien Miller | 57a4476 | 2004-04-20 20:11:57 +1000 | [diff] [blame] | 950 | } |
| 951 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 952 | debug("Reading configuration data %.200s", filename); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 953 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 954 | /* |
| 955 | * Mark that we are now processing the options. This flag is turned |
| 956 | * on/off by Host specifications. |
| 957 | */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 958 | active = 1; |
| 959 | linenum = 0; |
| 960 | while (fgets(line, sizeof(line), f)) { |
| 961 | /* Update line number counter. */ |
| 962 | linenum++; |
| 963 | if (process_config_line(options, host, line, filename, linenum, &active) != 0) |
| 964 | bad_options++; |
| 965 | } |
| 966 | fclose(f); |
| 967 | if (bad_options > 0) |
Ben Lindstrom | 6df8ef4 | 2001-03-05 07:47:23 +0000 | [diff] [blame] | 968 | fatal("%s: terminating, %d bad configuration options", |
Damien Miller | 9f0f5c6 | 2001-12-21 14:45:46 +1100 | [diff] [blame] | 969 | filename, bad_options); |
Ben Lindstrom | edc0cf2 | 2001-09-12 18:32:20 +0000 | [diff] [blame] | 970 | return 1; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 971 | } |
| 972 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 973 | /* |
| 974 | * Initializes options to special values that indicate that they have not yet |
| 975 | * been set. Read_config_file will only set options with this value. Options |
| 976 | * are processed in the following order: command line, user config file, |
| 977 | * system config file. Last, fill_default_options is called. |
| 978 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 979 | |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 980 | void |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 981 | initialize_options(Options * options) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 982 | { |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 983 | memset(options, 'X', sizeof(*options)); |
| 984 | options->forward_agent = -1; |
| 985 | options->forward_x11 = -1; |
Darren Tucker | 0a118da | 2003-10-15 15:54:32 +1000 | [diff] [blame] | 986 | options->forward_x11_trusted = -1; |
Damien Miller | d3a1857 | 2000-06-07 19:55:44 +1000 | [diff] [blame] | 987 | options->xauth_location = NULL; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 988 | options->gateway_ports = -1; |
| 989 | options->use_privileged_port = -1; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 990 | options->rsa_authentication = -1; |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 991 | options->pubkey_authentication = -1; |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 992 | options->challenge_response_authentication = -1; |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 993 | options->gss_authentication = -1; |
| 994 | options->gss_deleg_creds = -1; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 995 | options->password_authentication = -1; |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 996 | options->kbd_interactive_authentication = -1; |
| 997 | options->kbd_interactive_devices = NULL; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 998 | options->rhosts_rsa_authentication = -1; |
Ben Lindstrom | 5eabda3 | 2001-04-12 23:34:34 +0000 | [diff] [blame] | 999 | options->hostbased_authentication = -1; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1000 | options->batch_mode = -1; |
| 1001 | options->check_host_ip = -1; |
| 1002 | options->strict_host_key_checking = -1; |
| 1003 | options->compression = -1; |
Damien Miller | 12c150e | 2003-12-17 16:31:10 +1100 | [diff] [blame] | 1004 | options->tcp_keep_alive = -1; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1005 | options->compression_level = -1; |
| 1006 | options->port = -1; |
Darren Tucker | 0a4f04b | 2003-07-03 20:37:47 +1000 | [diff] [blame] | 1007 | options->address_family = -1; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1008 | options->connection_attempts = -1; |
Damien Miller | b78d5eb | 2003-05-16 11:39:04 +1000 | [diff] [blame] | 1009 | options->connection_timeout = -1; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1010 | options->number_of_password_prompts = -1; |
| 1011 | options->cipher = -1; |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 1012 | options->ciphers = NULL; |
Ben Lindstrom | 06b33aa | 2001-02-15 03:01:59 +0000 | [diff] [blame] | 1013 | options->macs = NULL; |
Ben Lindstrom | 982dbbc | 2001-04-17 18:11:36 +0000 | [diff] [blame] | 1014 | options->hostkeyalgorithms = NULL; |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 1015 | options->protocol = SSH_PROTO_UNKNOWN; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1016 | options->num_identity_files = 0; |
| 1017 | options->hostname = NULL; |
Ben Lindstrom | 4dccfa5 | 2000-12-28 16:40:05 +0000 | [diff] [blame] | 1018 | options->host_key_alias = NULL; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1019 | options->proxy_command = NULL; |
| 1020 | options->user = NULL; |
| 1021 | options->escape_char = -1; |
| 1022 | options->system_hostfile = NULL; |
| 1023 | options->user_hostfile = NULL; |
Damien Miller | eba71ba | 2000-04-29 23:57:08 +1000 | [diff] [blame] | 1024 | options->system_hostfile2 = NULL; |
| 1025 | options->user_hostfile2 = NULL; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1026 | options->num_local_forwards = 0; |
| 1027 | options->num_remote_forwards = 0; |
Ben Lindstrom | 2b7a0e9 | 2001-09-20 00:57:55 +0000 | [diff] [blame] | 1028 | options->clear_forwardings = -1; |
Damien Miller | fcd9320 | 2002-02-05 12:26:34 +1100 | [diff] [blame] | 1029 | options->log_level = SYSLOG_LEVEL_NOT_SET; |
Ben Lindstrom | b9be60a | 2001-03-11 01:49:19 +0000 | [diff] [blame] | 1030 | options->preferred_authentications = NULL; |
Ben Lindstrom | e0f8804 | 2001-04-30 13:06:24 +0000 | [diff] [blame] | 1031 | options->bind_address = NULL; |
Ben Lindstrom | f7db3bb | 2001-08-06 21:35:51 +0000 | [diff] [blame] | 1032 | options->smartcard_device = NULL; |
Ben Lindstrom | b6df73b | 2002-11-09 15:52:31 +0000 | [diff] [blame] | 1033 | options->enable_ssh_keysign = - 1; |
Ben Lindstrom | 3cecc9a | 2001-10-03 17:39:38 +0000 | [diff] [blame] | 1034 | options->no_host_authentication_for_localhost = - 1; |
Damien Miller | bd394c3 | 2004-03-08 23:12:36 +1100 | [diff] [blame] | 1035 | options->identities_only = - 1; |
Damien Miller | a5539d2 | 2003-04-09 20:50:06 +1000 | [diff] [blame] | 1036 | options->rekey_limit = - 1; |
Damien Miller | 37876e9 | 2003-05-15 10:19:46 +1000 | [diff] [blame] | 1037 | options->verify_host_key_dns = -1; |
Damien Miller | 509b010 | 2003-12-17 16:33:10 +1100 | [diff] [blame] | 1038 | options->server_alive_interval = -1; |
| 1039 | options->server_alive_count_max = -1; |
Darren Tucker | 46bc075 | 2004-05-02 22:11:30 +1000 | [diff] [blame] | 1040 | options->num_send_env = 0; |
Damien Miller | 0e220db | 2004-06-15 10:34:08 +1000 | [diff] [blame] | 1041 | options->control_path = NULL; |
| 1042 | options->control_master = -1; |
Damien Miller | e177615 | 2005-03-01 21:47:37 +1100 | [diff] [blame] | 1043 | options->hash_known_hosts = -1; |
Damien Miller | d27b947 | 2005-12-13 19:29:02 +1100 | [diff] [blame] | 1044 | options->tun_open = -1; |
| 1045 | options->tun_local = -1; |
| 1046 | options->tun_remote = -1; |
| 1047 | options->local_command = NULL; |
| 1048 | options->permit_local_command = -1; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1049 | } |
| 1050 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 1051 | /* |
| 1052 | * Called after processing other sources of option data, this fills those |
| 1053 | * options for which no value has been specified with their default values. |
| 1054 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1055 | |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 1056 | void |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1057 | fill_default_options(Options * options) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1058 | { |
Ben Lindstrom | 4f7a64a | 2001-02-10 22:50:09 +0000 | [diff] [blame] | 1059 | int len; |
| 1060 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1061 | if (options->forward_agent == -1) |
Damien Miller | b1715dc | 2000-05-30 13:44:51 +1000 | [diff] [blame] | 1062 | options->forward_agent = 0; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1063 | if (options->forward_x11 == -1) |
Damien Miller | 98c7ad6 | 2000-03-09 21:27:49 +1100 | [diff] [blame] | 1064 | options->forward_x11 = 0; |
Darren Tucker | 0a118da | 2003-10-15 15:54:32 +1000 | [diff] [blame] | 1065 | if (options->forward_x11_trusted == -1) |
| 1066 | options->forward_x11_trusted = 0; |
Damien Miller | d3a1857 | 2000-06-07 19:55:44 +1000 | [diff] [blame] | 1067 | if (options->xauth_location == NULL) |
Ben Lindstrom | 1bf11f6 | 2001-06-09 01:48:01 +0000 | [diff] [blame] | 1068 | options->xauth_location = _PATH_XAUTH; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1069 | if (options->gateway_ports == -1) |
| 1070 | options->gateway_ports = 0; |
| 1071 | if (options->use_privileged_port == -1) |
Ben Lindstrom | cebc858 | 2001-03-08 03:39:10 +0000 | [diff] [blame] | 1072 | options->use_privileged_port = 0; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1073 | if (options->rsa_authentication == -1) |
| 1074 | options->rsa_authentication = 1; |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 1075 | if (options->pubkey_authentication == -1) |
| 1076 | options->pubkey_authentication = 1; |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 1077 | if (options->challenge_response_authentication == -1) |
Ben Lindstrom | 0076d75 | 2001-08-06 20:53:26 +0000 | [diff] [blame] | 1078 | options->challenge_response_authentication = 1; |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 1079 | if (options->gss_authentication == -1) |
Darren Tucker | a044f47 | 2003-10-15 15:52:03 +1000 | [diff] [blame] | 1080 | options->gss_authentication = 0; |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 1081 | if (options->gss_deleg_creds == -1) |
| 1082 | options->gss_deleg_creds = 0; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1083 | if (options->password_authentication == -1) |
| 1084 | options->password_authentication = 1; |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 1085 | if (options->kbd_interactive_authentication == -1) |
Ben Lindstrom | 95fb2dd | 2001-01-23 03:12:10 +0000 | [diff] [blame] | 1086 | options->kbd_interactive_authentication = 1; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1087 | if (options->rhosts_rsa_authentication == -1) |
Ben Lindstrom | 2bf8276 | 2002-06-11 15:53:05 +0000 | [diff] [blame] | 1088 | options->rhosts_rsa_authentication = 0; |
Ben Lindstrom | 5eabda3 | 2001-04-12 23:34:34 +0000 | [diff] [blame] | 1089 | if (options->hostbased_authentication == -1) |
| 1090 | options->hostbased_authentication = 0; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1091 | if (options->batch_mode == -1) |
| 1092 | options->batch_mode = 0; |
| 1093 | if (options->check_host_ip == -1) |
| 1094 | options->check_host_ip = 1; |
| 1095 | if (options->strict_host_key_checking == -1) |
| 1096 | options->strict_host_key_checking = 2; /* 2 is default */ |
| 1097 | if (options->compression == -1) |
| 1098 | options->compression = 0; |
Damien Miller | 12c150e | 2003-12-17 16:31:10 +1100 | [diff] [blame] | 1099 | if (options->tcp_keep_alive == -1) |
| 1100 | options->tcp_keep_alive = 1; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1101 | if (options->compression_level == -1) |
| 1102 | options->compression_level = 6; |
| 1103 | if (options->port == -1) |
| 1104 | options->port = 0; /* Filled in ssh_connect. */ |
Darren Tucker | 0a4f04b | 2003-07-03 20:37:47 +1000 | [diff] [blame] | 1105 | if (options->address_family == -1) |
| 1106 | options->address_family = AF_UNSPEC; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1107 | if (options->connection_attempts == -1) |
Ben Lindstrom | f9cedb9 | 2001-08-06 21:07:11 +0000 | [diff] [blame] | 1108 | options->connection_attempts = 1; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1109 | if (options->number_of_password_prompts == -1) |
| 1110 | options->number_of_password_prompts = 3; |
| 1111 | /* Selected in ssh_login(). */ |
| 1112 | if (options->cipher == -1) |
| 1113 | options->cipher = SSH_CIPHER_NOT_SET; |
Damien Miller | 30c3d42 | 2000-05-09 11:02:59 +1000 | [diff] [blame] | 1114 | /* options->ciphers, default set in myproposals.h */ |
Ben Lindstrom | 06b33aa | 2001-02-15 03:01:59 +0000 | [diff] [blame] | 1115 | /* options->macs, default set in myproposals.h */ |
Ben Lindstrom | 982dbbc | 2001-04-17 18:11:36 +0000 | [diff] [blame] | 1116 | /* options->hostkeyalgorithms, default set in myproposals.h */ |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 1117 | if (options->protocol == SSH_PROTO_UNKNOWN) |
Ben Lindstrom | 6b77643 | 2001-03-22 01:24:04 +0000 | [diff] [blame] | 1118 | options->protocol = SSH_PROTO_1|SSH_PROTO_2; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1119 | if (options->num_identity_files == 0) { |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 1120 | if (options->protocol & SSH_PROTO_1) { |
Ben Lindstrom | 4f7a64a | 2001-02-10 22:50:09 +0000 | [diff] [blame] | 1121 | len = 2 + strlen(_PATH_SSH_CLIENT_IDENTITY) + 1; |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 1122 | options->identity_files[options->num_identity_files] = |
Ben Lindstrom | 4f7a64a | 2001-02-10 22:50:09 +0000 | [diff] [blame] | 1123 | xmalloc(len); |
| 1124 | snprintf(options->identity_files[options->num_identity_files++], |
| 1125 | len, "~/%.100s", _PATH_SSH_CLIENT_IDENTITY); |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 1126 | } |
| 1127 | if (options->protocol & SSH_PROTO_2) { |
Ben Lindstrom | b00d4fb | 2001-03-05 06:03:03 +0000 | [diff] [blame] | 1128 | len = 2 + strlen(_PATH_SSH_CLIENT_ID_RSA) + 1; |
| 1129 | options->identity_files[options->num_identity_files] = |
| 1130 | xmalloc(len); |
| 1131 | snprintf(options->identity_files[options->num_identity_files++], |
| 1132 | len, "~/%.100s", _PATH_SSH_CLIENT_ID_RSA); |
| 1133 | |
Ben Lindstrom | 4f7a64a | 2001-02-10 22:50:09 +0000 | [diff] [blame] | 1134 | len = 2 + strlen(_PATH_SSH_CLIENT_ID_DSA) + 1; |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 1135 | options->identity_files[options->num_identity_files] = |
Ben Lindstrom | 4f7a64a | 2001-02-10 22:50:09 +0000 | [diff] [blame] | 1136 | xmalloc(len); |
| 1137 | snprintf(options->identity_files[options->num_identity_files++], |
| 1138 | len, "~/%.100s", _PATH_SSH_CLIENT_ID_DSA); |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 1139 | } |
Damien Miller | eba71ba | 2000-04-29 23:57:08 +1000 | [diff] [blame] | 1140 | } |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1141 | if (options->escape_char == -1) |
| 1142 | options->escape_char = '~'; |
| 1143 | if (options->system_hostfile == NULL) |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 1144 | options->system_hostfile = _PATH_SSH_SYSTEM_HOSTFILE; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1145 | if (options->user_hostfile == NULL) |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 1146 | options->user_hostfile = _PATH_SSH_USER_HOSTFILE; |
Damien Miller | eba71ba | 2000-04-29 23:57:08 +1000 | [diff] [blame] | 1147 | if (options->system_hostfile2 == NULL) |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 1148 | options->system_hostfile2 = _PATH_SSH_SYSTEM_HOSTFILE2; |
Damien Miller | eba71ba | 2000-04-29 23:57:08 +1000 | [diff] [blame] | 1149 | if (options->user_hostfile2 == NULL) |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 1150 | options->user_hostfile2 = _PATH_SSH_USER_HOSTFILE2; |
Damien Miller | fcd9320 | 2002-02-05 12:26:34 +1100 | [diff] [blame] | 1151 | if (options->log_level == SYSLOG_LEVEL_NOT_SET) |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 1152 | options->log_level = SYSLOG_LEVEL_INFO; |
Ben Lindstrom | 2b7a0e9 | 2001-09-20 00:57:55 +0000 | [diff] [blame] | 1153 | if (options->clear_forwardings == 1) |
| 1154 | clear_forwardings(options); |
Ben Lindstrom | 3cecc9a | 2001-10-03 17:39:38 +0000 | [diff] [blame] | 1155 | if (options->no_host_authentication_for_localhost == - 1) |
| 1156 | options->no_host_authentication_for_localhost = 0; |
Damien Miller | bd394c3 | 2004-03-08 23:12:36 +1100 | [diff] [blame] | 1157 | if (options->identities_only == -1) |
| 1158 | options->identities_only = 0; |
Ben Lindstrom | b6df73b | 2002-11-09 15:52:31 +0000 | [diff] [blame] | 1159 | if (options->enable_ssh_keysign == -1) |
| 1160 | options->enable_ssh_keysign = 0; |
Damien Miller | a5539d2 | 2003-04-09 20:50:06 +1000 | [diff] [blame] | 1161 | if (options->rekey_limit == -1) |
| 1162 | options->rekey_limit = 0; |
Damien Miller | 37876e9 | 2003-05-15 10:19:46 +1000 | [diff] [blame] | 1163 | if (options->verify_host_key_dns == -1) |
| 1164 | options->verify_host_key_dns = 0; |
Damien Miller | 509b010 | 2003-12-17 16:33:10 +1100 | [diff] [blame] | 1165 | if (options->server_alive_interval == -1) |
| 1166 | options->server_alive_interval = 0; |
| 1167 | if (options->server_alive_count_max == -1) |
| 1168 | options->server_alive_count_max = 3; |
Damien Miller | 0e220db | 2004-06-15 10:34:08 +1000 | [diff] [blame] | 1169 | if (options->control_master == -1) |
| 1170 | options->control_master = 0; |
Damien Miller | e177615 | 2005-03-01 21:47:37 +1100 | [diff] [blame] | 1171 | if (options->hash_known_hosts == -1) |
| 1172 | options->hash_known_hosts = 0; |
Damien Miller | d27b947 | 2005-12-13 19:29:02 +1100 | [diff] [blame] | 1173 | if (options->tun_open == -1) |
Damien Miller | 7b58e80 | 2005-12-13 19:33:19 +1100 | [diff] [blame] | 1174 | options->tun_open = SSH_TUNMODE_NO; |
| 1175 | if (options->tun_local == -1) |
| 1176 | options->tun_local = SSH_TUNID_ANY; |
| 1177 | if (options->tun_remote == -1) |
| 1178 | options->tun_remote = SSH_TUNID_ANY; |
Damien Miller | d27b947 | 2005-12-13 19:29:02 +1100 | [diff] [blame] | 1179 | if (options->permit_local_command == -1) |
| 1180 | options->permit_local_command = 0; |
| 1181 | /* options->local_command should not be set by default */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1182 | /* options->proxy_command should not be set by default */ |
| 1183 | /* options->user will be set in the main program if appropriate */ |
| 1184 | /* options->hostname will be set in the main program if appropriate */ |
Ben Lindstrom | 4dccfa5 | 2000-12-28 16:40:05 +0000 | [diff] [blame] | 1185 | /* options->host_key_alias should not be set by default */ |
Ben Lindstrom | b9be60a | 2001-03-11 01:49:19 +0000 | [diff] [blame] | 1186 | /* options->preferred_authentications will be set in ssh */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1187 | } |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 1188 | |
| 1189 | /* |
| 1190 | * parse_forward |
| 1191 | * parses a string containing a port forwarding specification of the form: |
| 1192 | * [listenhost:]listenport:connecthost:connectport |
| 1193 | * returns number of arguments parsed or zero on error |
| 1194 | */ |
| 1195 | int |
| 1196 | parse_forward(Forward *fwd, const char *fwdspec) |
| 1197 | { |
| 1198 | int i; |
| 1199 | char *p, *cp, *fwdarg[4]; |
| 1200 | |
| 1201 | memset(fwd, '\0', sizeof(*fwd)); |
| 1202 | |
| 1203 | cp = p = xstrdup(fwdspec); |
| 1204 | |
| 1205 | /* skip leading spaces */ |
| 1206 | while (*cp && isspace(*cp)) |
| 1207 | cp++; |
| 1208 | |
| 1209 | for (i = 0; i < 4; ++i) |
| 1210 | if ((fwdarg[i] = hpdelim(&cp)) == NULL) |
| 1211 | break; |
| 1212 | |
| 1213 | /* Check for trailing garbage in 4-arg case*/ |
| 1214 | if (cp != NULL) |
| 1215 | i = 0; /* failure */ |
| 1216 | |
| 1217 | switch (i) { |
| 1218 | case 3: |
| 1219 | fwd->listen_host = NULL; |
| 1220 | fwd->listen_port = a2port(fwdarg[0]); |
| 1221 | fwd->connect_host = xstrdup(cleanhostname(fwdarg[1])); |
| 1222 | fwd->connect_port = a2port(fwdarg[2]); |
| 1223 | break; |
| 1224 | |
| 1225 | case 4: |
| 1226 | fwd->listen_host = xstrdup(cleanhostname(fwdarg[0])); |
| 1227 | fwd->listen_port = a2port(fwdarg[1]); |
| 1228 | fwd->connect_host = xstrdup(cleanhostname(fwdarg[2])); |
| 1229 | fwd->connect_port = a2port(fwdarg[3]); |
| 1230 | break; |
| 1231 | default: |
| 1232 | i = 0; /* failure */ |
| 1233 | } |
| 1234 | |
| 1235 | xfree(p); |
| 1236 | |
| 1237 | if (fwd->listen_port == 0 && fwd->connect_port == 0) |
| 1238 | goto fail_free; |
| 1239 | |
| 1240 | if (fwd->connect_host != NULL && |
| 1241 | strlen(fwd->connect_host) >= NI_MAXHOST) |
| 1242 | goto fail_free; |
| 1243 | |
| 1244 | return (i); |
| 1245 | |
| 1246 | fail_free: |
| 1247 | if (fwd->connect_host != NULL) |
| 1248 | xfree(fwd->connect_host); |
| 1249 | if (fwd->listen_host != NULL) |
| 1250 | xfree(fwd->listen_host); |
| 1251 | return (0); |
| 1252 | } |