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