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