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