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