Damien Miller | 7acefbb | 2014-07-18 14:11:24 +1000 | [diff] [blame^] | 1 | /* $OpenBSD: readconf.c,v 1.220 2014/07/15 15:54:14 millert 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> |
Damien Miller | 194fd90 | 2013-10-15 12:13:05 +1100 | [diff] [blame] | 20 | #include <sys/wait.h> |
Damien Miller | 7acefbb | 2014-07-18 14:11:24 +1000 | [diff] [blame^] | 21 | #include <sys/un.h> |
Damien Miller | 8ec8c3e | 2006-07-10 20:35:38 +1000 | [diff] [blame] | 22 | |
| 23 | #include <netinet/in.h> |
Damien Miller | 0dac6fb | 2010-11-20 15:19:38 +1100 | [diff] [blame] | 24 | #include <netinet/in_systm.h> |
| 25 | #include <netinet/ip.h> |
Darren Tucker | 0eeafcd | 2014-01-31 14:18:51 +1100 | [diff] [blame] | 26 | #include <arpa/inet.h> |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 27 | |
Damien Miller | c7b0636 | 2006-03-15 11:53:45 +1100 | [diff] [blame] | 28 | #include <ctype.h> |
Darren Tucker | 3997249 | 2006-07-12 22:22:46 +1000 | [diff] [blame] | 29 | #include <errno.h> |
Damien Miller | 194fd90 | 2013-10-15 12:13:05 +1100 | [diff] [blame] | 30 | #include <fcntl.h> |
Damien Miller | b8fe89c | 2006-07-24 14:51:00 +1000 | [diff] [blame] | 31 | #include <netdb.h> |
Darren Tucker | a335766 | 2014-01-18 00:03:57 +1100 | [diff] [blame] | 32 | #ifdef HAVE_PATHS_H |
| 33 | # include <paths.h> |
| 34 | #endif |
Damien Miller | 194fd90 | 2013-10-15 12:13:05 +1100 | [diff] [blame] | 35 | #include <pwd.h> |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 36 | #include <signal.h> |
Damien Miller | ded319c | 2006-09-01 15:38:36 +1000 | [diff] [blame] | 37 | #include <stdarg.h> |
Damien Miller | a7a73ee | 2006-08-05 11:37:59 +1000 | [diff] [blame] | 38 | #include <stdio.h> |
Damien Miller | e3476ed | 2006-07-24 14:13:33 +1000 | [diff] [blame] | 39 | #include <string.h> |
Damien Miller | e6b3b61 | 2006-07-24 14:01:23 +1000 | [diff] [blame] | 40 | #include <unistd.h> |
Darren Tucker | e194ba4 | 2013-05-16 20:47:31 +1000 | [diff] [blame] | 41 | #ifdef HAVE_UTIL_H |
Darren Tucker | b7ee852 | 2013-05-16 20:33:10 +1000 | [diff] [blame] | 42 | #include <util.h> |
Darren Tucker | e194ba4 | 2013-05-16 20:47:31 +1000 | [diff] [blame] | 43 | #endif |
Damien Miller | c7b0636 | 2006-03-15 11:53:45 +1100 | [diff] [blame] | 44 | |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 45 | #include "xmalloc.h" |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 46 | #include "ssh.h" |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 47 | #include "compat.h" |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 48 | #include "cipher.h" |
| 49 | #include "pathnames.h" |
| 50 | #include "log.h" |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 51 | #include "key.h" |
Damien Miller | 7acefbb | 2014-07-18 14:11:24 +1000 | [diff] [blame^] | 52 | #include "misc.h" |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 53 | #include "readconf.h" |
| 54 | #include "match.h" |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 55 | #include "buffer.h" |
Ben Lindstrom | 06b33aa | 2001-02-15 03:01:59 +0000 | [diff] [blame] | 56 | #include "kex.h" |
| 57 | #include "mac.h" |
Damien Miller | 194fd90 | 2013-10-15 12:13:05 +1100 | [diff] [blame] | 58 | #include "uidswap.h" |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 59 | |
| 60 | /* Format of the configuration file: |
| 61 | |
| 62 | # Configuration data is parsed as follows: |
| 63 | # 1. command line options |
| 64 | # 2. user-specific file |
| 65 | # 3. system-wide file |
| 66 | # Any configuration value is only changed the first time it is set. |
| 67 | # Thus, host-specific definitions should be at the beginning of the |
| 68 | # configuration file, and defaults at the end. |
| 69 | |
| 70 | # Host-specific declarations. These may override anything above. A single |
| 71 | # host may match multiple declarations; these are processed in the order |
| 72 | # that they are given in. |
| 73 | |
| 74 | Host *.ngs.fi ngs.fi |
Ben Lindstrom | 4daea86 | 2002-06-09 20:04:02 +0000 | [diff] [blame] | 75 | User foo |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 76 | |
| 77 | Host fake.com |
| 78 | HostName another.host.name.real.org |
| 79 | User blaah |
| 80 | Port 34289 |
| 81 | ForwardX11 no |
| 82 | ForwardAgent no |
| 83 | |
| 84 | Host books.com |
| 85 | RemoteForward 9999 shadows.cs.hut.fi:9999 |
| 86 | Cipher 3des |
| 87 | |
| 88 | Host fascist.blob.com |
| 89 | Port 23123 |
| 90 | User tylonen |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 91 | PasswordAuthentication no |
| 92 | |
| 93 | Host puukko.hut.fi |
| 94 | User t35124p |
| 95 | ProxyCommand ssh-proxy %h %p |
| 96 | |
| 97 | Host *.fr |
Ben Lindstrom | 4daea86 | 2002-06-09 20:04:02 +0000 | [diff] [blame] | 98 | PublicKeyAuthentication no |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 99 | |
| 100 | Host *.su |
| 101 | Cipher none |
| 102 | PasswordAuthentication no |
| 103 | |
Damien Miller | d27b947 | 2005-12-13 19:29:02 +1100 | [diff] [blame] | 104 | Host vpn.fake.com |
| 105 | Tunnel yes |
| 106 | TunnelDevice 3 |
| 107 | |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 108 | # Defaults for various options |
| 109 | Host * |
| 110 | ForwardAgent no |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 111 | ForwardX11 no |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 112 | PasswordAuthentication yes |
| 113 | RSAAuthentication yes |
| 114 | RhostsRSAAuthentication yes |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 115 | StrictHostKeyChecking yes |
Damien Miller | 12c150e | 2003-12-17 16:31:10 +1100 | [diff] [blame] | 116 | TcpKeepAlive no |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 117 | IdentityFile ~/.ssh/identity |
| 118 | Port 22 |
| 119 | EscapeChar ~ |
| 120 | |
| 121 | */ |
| 122 | |
| 123 | /* Keyword tokens. */ |
| 124 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 125 | typedef enum { |
| 126 | oBadOption, |
Damien Miller | 194fd90 | 2013-10-15 12:13:05 +1100 | [diff] [blame] | 127 | oHost, oMatch, |
Damien Miller | 1ab6a51 | 2010-06-26 10:02:24 +1000 | [diff] [blame] | 128 | oForwardAgent, oForwardX11, oForwardX11Trusted, oForwardX11Timeout, |
| 129 | oGatewayPorts, oExitOnForwardFailure, |
Ben Lindstrom | cb72e4f | 2002-06-21 00:41:51 +0000 | [diff] [blame] | 130 | oPasswordAuthentication, oRSAAuthentication, |
Ben Lindstrom | 95fb2dd | 2001-01-23 03:12:10 +0000 | [diff] [blame] | 131 | oChallengeResponseAuthentication, oXAuthLocation, |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 132 | oIdentityFile, oHostName, oPort, oCipher, oRemoteForward, oLocalForward, |
Damien Miller | 194fd90 | 2013-10-15 12:13:05 +1100 | [diff] [blame] | 133 | oUser, oEscapeChar, oRhostsRSAAuthentication, oProxyCommand, |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 134 | oGlobalKnownHostsFile, oUserKnownHostsFile, oConnectionAttempts, |
| 135 | oBatchMode, oCheckHostIP, oStrictHostKeyChecking, oCompression, |
Damien Miller | 12c150e | 2003-12-17 16:31:10 +1100 | [diff] [blame] | 136 | oCompressionLevel, oTCPKeepAlive, oNumberOfPasswordPrompts, |
Ben Lindstrom | 06b33aa | 2001-02-15 03:01:59 +0000 | [diff] [blame] | 137 | oUsePrivilegedPort, oLogLevel, oCiphers, oProtocol, oMacs, |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 138 | oGlobalKnownHostsFile2, oUserKnownHostsFile2, oPubkeyAuthentication, |
Ben Lindstrom | b9be60a | 2001-03-11 01:49:19 +0000 | [diff] [blame] | 139 | oKbdInteractiveAuthentication, oKbdInteractiveDevices, oHostKeyAlias, |
Ben Lindstrom | 982dbbc | 2001-04-17 18:11:36 +0000 | [diff] [blame] | 140 | oDynamicForward, oPreferredAuthentications, oHostbasedAuthentication, |
Damien Miller | 7ea845e | 2010-02-12 09:21:02 +1100 | [diff] [blame] | 141 | oHostKeyAlgorithms, oBindAddress, oPKCS11Provider, |
Ben Lindstrom | 4daea86 | 2002-06-09 20:04:02 +0000 | [diff] [blame] | 142 | oClearAllForwardings, oNoHostAuthenticationForLocalhost, |
Damien Miller | b78d5eb | 2003-05-16 11:39:04 +1000 | [diff] [blame] | 143 | oEnableSSHKeysign, oRekeyLimit, oVerifyHostKeyDNS, oConnectTimeout, |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 144 | oAddressFamily, oGssAuthentication, oGssDelegateCreds, |
Damien Miller | bd394c3 | 2004-03-08 23:12:36 +1100 | [diff] [blame] | 145 | oServerAliveInterval, oServerAliveCountMax, oIdentitiesOnly, |
Damien Miller | e11e1ea | 2010-08-03 16:04:46 +1000 | [diff] [blame] | 146 | oSendEnv, oControlPath, oControlMaster, oControlPersist, |
| 147 | oHashKnownHosts, |
Damien Miller | d27b947 | 2005-12-13 19:29:02 +1100 | [diff] [blame] | 148 | oTunnel, oTunnelDevice, oLocalCommand, oPermitLocalCommand, |
Damien Miller | 7cc194f | 2014-02-04 11:12:56 +1100 | [diff] [blame] | 149 | oVisualHostKey, oUseRoaming, |
Damien Miller | 1262b66 | 2013-08-21 02:44:24 +1000 | [diff] [blame] | 150 | oKexAlgorithms, oIPQoS, oRequestTTY, oIgnoreUnknown, oProxyUseFdpass, |
Damien Miller | 3850559 | 2013-10-17 11:48:13 +1100 | [diff] [blame] | 151 | oCanonicalDomains, oCanonicalizeHostname, oCanonicalizeMaxDots, |
| 152 | oCanonicalizeFallbackLocal, oCanonicalizePermittedCNAMEs, |
Damien Miller | 7acefbb | 2014-07-18 14:11:24 +1000 | [diff] [blame^] | 153 | oStreamLocalBindMask, oStreamLocalBindUnlink, |
Darren Tucker | 0763698 | 2013-05-16 20:30:03 +1000 | [diff] [blame] | 154 | oIgnoredUnknownOption, oDeprecated, oUnsupported |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 155 | } OpCodes; |
| 156 | |
| 157 | /* Textual representations of the tokens. */ |
| 158 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 159 | static struct { |
| 160 | const char *name; |
| 161 | OpCodes opcode; |
| 162 | } keywords[] = { |
| 163 | { "forwardagent", oForwardAgent }, |
| 164 | { "forwardx11", oForwardX11 }, |
Darren Tucker | 0a118da | 2003-10-15 15:54:32 +1000 | [diff] [blame] | 165 | { "forwardx11trusted", oForwardX11Trusted }, |
Damien Miller | 1ab6a51 | 2010-06-26 10:02:24 +1000 | [diff] [blame] | 166 | { "forwardx11timeout", oForwardX11Timeout }, |
Darren Tucker | e7d4b19 | 2006-07-12 22:17:10 +1000 | [diff] [blame] | 167 | { "exitonforwardfailure", oExitOnForwardFailure }, |
Damien Miller | d3a1857 | 2000-06-07 19:55:44 +1000 | [diff] [blame] | 168 | { "xauthlocation", oXAuthLocation }, |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 169 | { "gatewayports", oGatewayPorts }, |
| 170 | { "useprivilegedport", oUsePrivilegedPort }, |
Darren Tucker | ec960f2 | 2003-08-13 20:37:05 +1000 | [diff] [blame] | 171 | { "rhostsauthentication", oDeprecated }, |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 172 | { "passwordauthentication", oPasswordAuthentication }, |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 173 | { "kbdinteractiveauthentication", oKbdInteractiveAuthentication }, |
| 174 | { "kbdinteractivedevices", oKbdInteractiveDevices }, |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 175 | { "rsaauthentication", oRSAAuthentication }, |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 176 | { "pubkeyauthentication", oPubkeyAuthentication }, |
Ben Lindstrom | 95fb2dd | 2001-01-23 03:12:10 +0000 | [diff] [blame] | 177 | { "dsaauthentication", oPubkeyAuthentication }, /* alias */ |
Ben Lindstrom | 5eabda3 | 2001-04-12 23:34:34 +0000 | [diff] [blame] | 178 | { "rhostsrsaauthentication", oRhostsRSAAuthentication }, |
Ben Lindstrom | d69dab3 | 2001-04-12 23:36:05 +0000 | [diff] [blame] | 179 | { "hostbasedauthentication", oHostbasedAuthentication }, |
Ben Lindstrom | 95fb2dd | 2001-01-23 03:12:10 +0000 | [diff] [blame] | 180 | { "challengeresponseauthentication", oChallengeResponseAuthentication }, |
| 181 | { "skeyauthentication", oChallengeResponseAuthentication }, /* alias */ |
| 182 | { "tisauthentication", oChallengeResponseAuthentication }, /* alias */ |
Damien Miller | f9b3feb | 2003-05-16 11:38:32 +1000 | [diff] [blame] | 183 | { "kerberosauthentication", oUnsupported }, |
| 184 | { "kerberostgtpassing", oUnsupported }, |
Damien Miller | f9b3feb | 2003-05-16 11:38:32 +1000 | [diff] [blame] | 185 | { "afstokenpassing", oUnsupported }, |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 186 | #if defined(GSSAPI) |
| 187 | { "gssapiauthentication", oGssAuthentication }, |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 188 | { "gssapidelegatecredentials", oGssDelegateCreds }, |
| 189 | #else |
| 190 | { "gssapiauthentication", oUnsupported }, |
| 191 | { "gssapidelegatecredentials", oUnsupported }, |
| 192 | #endif |
Ben Lindstrom | 4daea86 | 2002-06-09 20:04:02 +0000 | [diff] [blame] | 193 | { "fallbacktorsh", oDeprecated }, |
| 194 | { "usersh", oDeprecated }, |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 195 | { "identityfile", oIdentityFile }, |
Damien Miller | 5bc6aae | 2009-01-28 16:27:31 +1100 | [diff] [blame] | 196 | { "identityfile2", oIdentityFile }, /* obsolete */ |
Damien Miller | bd394c3 | 2004-03-08 23:12:36 +1100 | [diff] [blame] | 197 | { "identitiesonly", oIdentitiesOnly }, |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 198 | { "hostname", oHostName }, |
Ben Lindstrom | 4dccfa5 | 2000-12-28 16:40:05 +0000 | [diff] [blame] | 199 | { "hostkeyalias", oHostKeyAlias }, |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 200 | { "proxycommand", oProxyCommand }, |
| 201 | { "port", oPort }, |
| 202 | { "cipher", oCipher }, |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 203 | { "ciphers", oCiphers }, |
Ben Lindstrom | 06b33aa | 2001-02-15 03:01:59 +0000 | [diff] [blame] | 204 | { "macs", oMacs }, |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 205 | { "protocol", oProtocol }, |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 206 | { "remoteforward", oRemoteForward }, |
| 207 | { "localforward", oLocalForward }, |
| 208 | { "user", oUser }, |
| 209 | { "host", oHost }, |
Damien Miller | 194fd90 | 2013-10-15 12:13:05 +1100 | [diff] [blame] | 210 | { "match", oMatch }, |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 211 | { "escapechar", oEscapeChar }, |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 212 | { "globalknownhostsfile", oGlobalKnownHostsFile }, |
Damien Miller | 295ee63 | 2011-05-29 21:42:31 +1000 | [diff] [blame] | 213 | { "globalknownhostsfile2", oDeprecated }, |
Damien Miller | 5bc6aae | 2009-01-28 16:27:31 +1100 | [diff] [blame] | 214 | { "userknownhostsfile", oUserKnownHostsFile }, |
Damien Miller | 295ee63 | 2011-05-29 21:42:31 +1000 | [diff] [blame] | 215 | { "userknownhostsfile2", oDeprecated }, |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 216 | { "connectionattempts", oConnectionAttempts }, |
| 217 | { "batchmode", oBatchMode }, |
| 218 | { "checkhostip", oCheckHostIP }, |
| 219 | { "stricthostkeychecking", oStrictHostKeyChecking }, |
| 220 | { "compression", oCompression }, |
| 221 | { "compressionlevel", oCompressionLevel }, |
Damien Miller | 12c150e | 2003-12-17 16:31:10 +1100 | [diff] [blame] | 222 | { "tcpkeepalive", oTCPKeepAlive }, |
| 223 | { "keepalive", oTCPKeepAlive }, /* obsolete */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 224 | { "numberofpasswordprompts", oNumberOfPasswordPrompts }, |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 225 | { "loglevel", oLogLevel }, |
Ben Lindstrom | 3bb4f9d | 2001-04-08 18:30:26 +0000 | [diff] [blame] | 226 | { "dynamicforward", oDynamicForward }, |
Ben Lindstrom | b9be60a | 2001-03-11 01:49:19 +0000 | [diff] [blame] | 227 | { "preferredauthentications", oPreferredAuthentications }, |
Ben Lindstrom | 982dbbc | 2001-04-17 18:11:36 +0000 | [diff] [blame] | 228 | { "hostkeyalgorithms", oHostKeyAlgorithms }, |
Ben Lindstrom | e0f8804 | 2001-04-30 13:06:24 +0000 | [diff] [blame] | 229 | { "bindaddress", oBindAddress }, |
Damien Miller | 7ea845e | 2010-02-12 09:21:02 +1100 | [diff] [blame] | 230 | #ifdef ENABLE_PKCS11 |
| 231 | { "smartcarddevice", oPKCS11Provider }, |
| 232 | { "pkcs11provider", oPKCS11Provider }, |
Damien Miller | f9b3feb | 2003-05-16 11:38:32 +1000 | [diff] [blame] | 233 | #else |
| 234 | { "smartcarddevice", oUnsupported }, |
Damien Miller | 7ea845e | 2010-02-12 09:21:02 +1100 | [diff] [blame] | 235 | { "pkcs11provider", oUnsupported }, |
Damien Miller | f9b3feb | 2003-05-16 11:38:32 +1000 | [diff] [blame] | 236 | #endif |
Damien Miller | 9f0f5c6 | 2001-12-21 14:45:46 +1100 | [diff] [blame] | 237 | { "clearallforwardings", oClearAllForwardings }, |
Ben Lindstrom | b6df73b | 2002-11-09 15:52:31 +0000 | [diff] [blame] | 238 | { "enablesshkeysign", oEnableSSHKeysign }, |
Damien Miller | 37876e9 | 2003-05-15 10:19:46 +1000 | [diff] [blame] | 239 | { "verifyhostkeydns", oVerifyHostKeyDNS }, |
Damien Miller | 9f0f5c6 | 2001-12-21 14:45:46 +1100 | [diff] [blame] | 240 | { "nohostauthenticationforlocalhost", oNoHostAuthenticationForLocalhost }, |
Damien Miller | a5539d2 | 2003-04-09 20:50:06 +1000 | [diff] [blame] | 241 | { "rekeylimit", oRekeyLimit }, |
Damien Miller | b78d5eb | 2003-05-16 11:39:04 +1000 | [diff] [blame] | 242 | { "connecttimeout", oConnectTimeout }, |
Damien Miller | 20a8f97 | 2003-05-18 20:50:30 +1000 | [diff] [blame] | 243 | { "addressfamily", oAddressFamily }, |
Damien Miller | 509b010 | 2003-12-17 16:33:10 +1100 | [diff] [blame] | 244 | { "serveraliveinterval", oServerAliveInterval }, |
| 245 | { "serveralivecountmax", oServerAliveCountMax }, |
Darren Tucker | 46bc075 | 2004-05-02 22:11:30 +1000 | [diff] [blame] | 246 | { "sendenv", oSendEnv }, |
Damien Miller | 0e220db | 2004-06-15 10:34:08 +1000 | [diff] [blame] | 247 | { "controlpath", oControlPath }, |
| 248 | { "controlmaster", oControlMaster }, |
Damien Miller | e11e1ea | 2010-08-03 16:04:46 +1000 | [diff] [blame] | 249 | { "controlpersist", oControlPersist }, |
Damien Miller | e177615 | 2005-03-01 21:47:37 +1100 | [diff] [blame] | 250 | { "hashknownhosts", oHashKnownHosts }, |
Damien Miller | d27b947 | 2005-12-13 19:29:02 +1100 | [diff] [blame] | 251 | { "tunnel", oTunnel }, |
| 252 | { "tunneldevice", oTunnelDevice }, |
| 253 | { "localcommand", oLocalCommand }, |
| 254 | { "permitlocalcommand", oPermitLocalCommand }, |
Damien Miller | 1028824 | 2008-06-30 00:04:03 +1000 | [diff] [blame] | 255 | { "visualhostkey", oVisualHostKey }, |
Darren Tucker | 71e4d54 | 2009-07-06 07:12:27 +1000 | [diff] [blame] | 256 | { "useroaming", oUseRoaming }, |
Damien Miller | d5f62bf | 2010-09-24 22:11:14 +1000 | [diff] [blame] | 257 | { "kexalgorithms", oKexAlgorithms }, |
Damien Miller | 0dac6fb | 2010-11-20 15:19:38 +1100 | [diff] [blame] | 258 | { "ipqos", oIPQoS }, |
Damien Miller | 21771e2 | 2011-05-15 08:45:50 +1000 | [diff] [blame] | 259 | { "requesttty", oRequestTTY }, |
Damien Miller | 1262b66 | 2013-08-21 02:44:24 +1000 | [diff] [blame] | 260 | { "proxyusefdpass", oProxyUseFdpass }, |
Damien Miller | 0faf747 | 2013-10-17 11:47:23 +1100 | [diff] [blame] | 261 | { "canonicaldomains", oCanonicalDomains }, |
Damien Miller | 3850559 | 2013-10-17 11:48:13 +1100 | [diff] [blame] | 262 | { "canonicalizefallbacklocal", oCanonicalizeFallbackLocal }, |
| 263 | { "canonicalizehostname", oCanonicalizeHostname }, |
| 264 | { "canonicalizemaxdots", oCanonicalizeMaxDots }, |
| 265 | { "canonicalizepermittedcnames", oCanonicalizePermittedCNAMEs }, |
Damien Miller | 7acefbb | 2014-07-18 14:11:24 +1000 | [diff] [blame^] | 266 | { "streamlocalbindmask", oStreamLocalBindMask }, |
| 267 | { "streamlocalbindunlink", oStreamLocalBindUnlink }, |
Darren Tucker | 0763698 | 2013-05-16 20:30:03 +1000 | [diff] [blame] | 268 | { "ignoreunknown", oIgnoreUnknown }, |
Damien Miller | 01ed227 | 2008-11-05 16:20:46 +1100 | [diff] [blame] | 269 | |
Ben Lindstrom | 65366a8 | 2001-12-06 16:32:47 +0000 | [diff] [blame] | 270 | { NULL, oBadOption } |
Damien Miller | 5ce662a | 1999-11-11 17:57:39 +1100 | [diff] [blame] | 271 | }; |
| 272 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 273 | /* |
| 274 | * Adds a local TCP/IP port forward to options. Never returns if there is an |
| 275 | * error. |
| 276 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 277 | |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 278 | void |
Damien Miller | 7acefbb | 2014-07-18 14:11:24 +1000 | [diff] [blame^] | 279 | add_local_forward(Options *options, const struct Forward *newfwd) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 280 | { |
Damien Miller | 7acefbb | 2014-07-18 14:11:24 +1000 | [diff] [blame^] | 281 | struct Forward *fwd; |
Ben Lindstrom | 99a4e14 | 2002-07-09 14:06:40 +0000 | [diff] [blame] | 282 | #ifndef NO_IPPORT_RESERVED_CONCEPT |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 283 | extern uid_t original_real_uid; |
Damien Miller | 7acefbb | 2014-07-18 14:11:24 +1000 | [diff] [blame^] | 284 | if (newfwd->listen_port < IPPORT_RESERVED && original_real_uid != 0 && |
| 285 | newfwd->listen_path == NULL) |
Ben Lindstrom | 6df8ef4 | 2001-03-05 07:47:23 +0000 | [diff] [blame] | 286 | fatal("Privileged ports can only be forwarded by root."); |
Damien Miller | bac2d8a | 2000-09-05 16:13:06 +1100 | [diff] [blame] | 287 | #endif |
Damien Miller | 232cfb1 | 2010-06-26 09:50:30 +1000 | [diff] [blame] | 288 | options->local_forwards = xrealloc(options->local_forwards, |
| 289 | options->num_local_forwards + 1, |
| 290 | sizeof(*options->local_forwards)); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 291 | fwd = &options->local_forwards[options->num_local_forwards++]; |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 292 | |
Damien Miller | 1a0442f | 2008-11-05 16:30:06 +1100 | [diff] [blame] | 293 | fwd->listen_host = newfwd->listen_host; |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 294 | fwd->listen_port = newfwd->listen_port; |
Damien Miller | 7acefbb | 2014-07-18 14:11:24 +1000 | [diff] [blame^] | 295 | fwd->listen_path = newfwd->listen_path; |
Damien Miller | 1a0442f | 2008-11-05 16:30:06 +1100 | [diff] [blame] | 296 | fwd->connect_host = newfwd->connect_host; |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 297 | fwd->connect_port = newfwd->connect_port; |
Damien Miller | 7acefbb | 2014-07-18 14:11:24 +1000 | [diff] [blame^] | 298 | fwd->connect_path = newfwd->connect_path; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 299 | } |
| 300 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 301 | /* |
| 302 | * Adds a remote TCP/IP port forward to options. Never returns if there is |
| 303 | * an error. |
| 304 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 305 | |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 306 | void |
Damien Miller | 7acefbb | 2014-07-18 14:11:24 +1000 | [diff] [blame^] | 307 | add_remote_forward(Options *options, const struct Forward *newfwd) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 308 | { |
Damien Miller | 7acefbb | 2014-07-18 14:11:24 +1000 | [diff] [blame^] | 309 | struct Forward *fwd; |
Damien Miller | 232cfb1 | 2010-06-26 09:50:30 +1000 | [diff] [blame] | 310 | |
| 311 | options->remote_forwards = xrealloc(options->remote_forwards, |
| 312 | options->num_remote_forwards + 1, |
| 313 | sizeof(*options->remote_forwards)); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 314 | fwd = &options->remote_forwards[options->num_remote_forwards++]; |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 315 | |
Damien Miller | 1a0442f | 2008-11-05 16:30:06 +1100 | [diff] [blame] | 316 | fwd->listen_host = newfwd->listen_host; |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 317 | fwd->listen_port = newfwd->listen_port; |
Damien Miller | 7acefbb | 2014-07-18 14:11:24 +1000 | [diff] [blame^] | 318 | fwd->listen_path = newfwd->listen_path; |
Damien Miller | 1a0442f | 2008-11-05 16:30:06 +1100 | [diff] [blame] | 319 | fwd->connect_host = newfwd->connect_host; |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 320 | fwd->connect_port = newfwd->connect_port; |
Damien Miller | 7acefbb | 2014-07-18 14:11:24 +1000 | [diff] [blame^] | 321 | fwd->connect_path = newfwd->connect_path; |
Darren Tucker | 68afb8c | 2011-10-02 18:59:03 +1100 | [diff] [blame] | 322 | fwd->handle = newfwd->handle; |
Damien Miller | 388f6fc | 2010-05-21 14:57:35 +1000 | [diff] [blame] | 323 | fwd->allocated_port = 0; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 324 | } |
| 325 | |
Ben Lindstrom | 2b7a0e9 | 2001-09-20 00:57:55 +0000 | [diff] [blame] | 326 | static void |
| 327 | clear_forwardings(Options *options) |
| 328 | { |
| 329 | int i; |
| 330 | |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 331 | for (i = 0; i < options->num_local_forwards; i++) { |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 332 | free(options->local_forwards[i].listen_host); |
Damien Miller | 7acefbb | 2014-07-18 14:11:24 +1000 | [diff] [blame^] | 333 | free(options->local_forwards[i].listen_path); |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 334 | free(options->local_forwards[i].connect_host); |
Damien Miller | 7acefbb | 2014-07-18 14:11:24 +1000 | [diff] [blame^] | 335 | free(options->local_forwards[i].connect_path); |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 336 | } |
Damien Miller | 232cfb1 | 2010-06-26 09:50:30 +1000 | [diff] [blame] | 337 | if (options->num_local_forwards > 0) { |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 338 | free(options->local_forwards); |
Damien Miller | 232cfb1 | 2010-06-26 09:50:30 +1000 | [diff] [blame] | 339 | options->local_forwards = NULL; |
| 340 | } |
Ben Lindstrom | 2b7a0e9 | 2001-09-20 00:57:55 +0000 | [diff] [blame] | 341 | options->num_local_forwards = 0; |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 342 | for (i = 0; i < options->num_remote_forwards; i++) { |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 343 | free(options->remote_forwards[i].listen_host); |
Damien Miller | 7acefbb | 2014-07-18 14:11:24 +1000 | [diff] [blame^] | 344 | free(options->remote_forwards[i].listen_path); |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 345 | free(options->remote_forwards[i].connect_host); |
Damien Miller | 7acefbb | 2014-07-18 14:11:24 +1000 | [diff] [blame^] | 346 | free(options->remote_forwards[i].connect_path); |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 347 | } |
Damien Miller | 232cfb1 | 2010-06-26 09:50:30 +1000 | [diff] [blame] | 348 | if (options->num_remote_forwards > 0) { |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 349 | free(options->remote_forwards); |
Damien Miller | 232cfb1 | 2010-06-26 09:50:30 +1000 | [diff] [blame] | 350 | options->remote_forwards = NULL; |
| 351 | } |
Ben Lindstrom | 2b7a0e9 | 2001-09-20 00:57:55 +0000 | [diff] [blame] | 352 | options->num_remote_forwards = 0; |
Damien Miller | 7b58e80 | 2005-12-13 19:33:19 +1100 | [diff] [blame] | 353 | options->tun_open = SSH_TUNMODE_NO; |
Ben Lindstrom | 2b7a0e9 | 2001-09-20 00:57:55 +0000 | [diff] [blame] | 354 | } |
| 355 | |
Darren Tucker | 1910478 | 2013-04-05 11:13:08 +1100 | [diff] [blame] | 356 | void |
| 357 | add_identity_file(Options *options, const char *dir, const char *filename, |
| 358 | int userprovided) |
| 359 | { |
| 360 | char *path; |
Damien Miller | 1527190 | 2014-05-15 13:47:56 +1000 | [diff] [blame] | 361 | int i; |
Darren Tucker | 1910478 | 2013-04-05 11:13:08 +1100 | [diff] [blame] | 362 | |
| 363 | if (options->num_identity_files >= SSH_MAX_IDENTITY_FILES) |
| 364 | fatal("Too many identity files specified (max %d)", |
| 365 | SSH_MAX_IDENTITY_FILES); |
| 366 | |
| 367 | if (dir == NULL) /* no dir, filename is absolute */ |
| 368 | path = xstrdup(filename); |
| 369 | else |
| 370 | (void)xasprintf(&path, "%.100s%.100s", dir, filename); |
| 371 | |
Damien Miller | 1527190 | 2014-05-15 13:47:56 +1000 | [diff] [blame] | 372 | /* Avoid registering duplicates */ |
| 373 | for (i = 0; i < options->num_identity_files; i++) { |
| 374 | if (options->identity_file_userprovided[i] == userprovided && |
| 375 | strcmp(options->identity_files[i], path) == 0) { |
| 376 | debug2("%s: ignoring duplicate key %s", __func__, path); |
| 377 | free(path); |
| 378 | return; |
| 379 | } |
| 380 | } |
| 381 | |
Darren Tucker | 1910478 | 2013-04-05 11:13:08 +1100 | [diff] [blame] | 382 | options->identity_file_userprovided[options->num_identity_files] = |
| 383 | userprovided; |
| 384 | options->identity_files[options->num_identity_files++] = path; |
| 385 | } |
| 386 | |
Damien Miller | 194fd90 | 2013-10-15 12:13:05 +1100 | [diff] [blame] | 387 | int |
| 388 | default_ssh_port(void) |
| 389 | { |
| 390 | static int port; |
| 391 | struct servent *sp; |
| 392 | |
| 393 | if (port == 0) { |
| 394 | sp = getservbyname(SSH_SERVICE_NAME, "tcp"); |
| 395 | port = sp ? ntohs(sp->s_port) : SSH_DEFAULT_PORT; |
| 396 | } |
| 397 | return port; |
| 398 | } |
| 399 | |
| 400 | /* |
| 401 | * Execute a command in a shell. |
| 402 | * Return its exit status or -1 on abnormal exit. |
| 403 | */ |
| 404 | static int |
| 405 | execute_in_shell(const char *cmd) |
| 406 | { |
| 407 | char *shell, *command_string; |
| 408 | pid_t pid; |
| 409 | int devnull, status; |
| 410 | extern uid_t original_real_uid; |
| 411 | |
| 412 | if ((shell = getenv("SHELL")) == NULL) |
| 413 | shell = _PATH_BSHELL; |
| 414 | |
| 415 | /* |
| 416 | * Use "exec" to avoid "sh -c" processes on some platforms |
| 417 | * (e.g. Solaris) |
| 418 | */ |
| 419 | xasprintf(&command_string, "exec %s", cmd); |
| 420 | |
| 421 | /* Need this to redirect subprocess stdin/out */ |
| 422 | if ((devnull = open(_PATH_DEVNULL, O_RDWR)) == -1) |
| 423 | fatal("open(/dev/null): %s", strerror(errno)); |
| 424 | |
| 425 | debug("Executing command: '%.500s'", cmd); |
| 426 | |
| 427 | /* Fork and execute the command. */ |
| 428 | if ((pid = fork()) == 0) { |
| 429 | char *argv[4]; |
| 430 | |
| 431 | /* Child. Permanently give up superuser privileges. */ |
| 432 | permanently_drop_suid(original_real_uid); |
| 433 | |
| 434 | /* Redirect child stdin and stdout. Leave stderr */ |
| 435 | if (dup2(devnull, STDIN_FILENO) == -1) |
| 436 | fatal("dup2: %s", strerror(errno)); |
| 437 | if (dup2(devnull, STDOUT_FILENO) == -1) |
| 438 | fatal("dup2: %s", strerror(errno)); |
| 439 | if (devnull > STDERR_FILENO) |
| 440 | close(devnull); |
| 441 | closefrom(STDERR_FILENO + 1); |
| 442 | |
| 443 | argv[0] = shell; |
| 444 | argv[1] = "-c"; |
| 445 | argv[2] = command_string; |
| 446 | argv[3] = NULL; |
| 447 | |
| 448 | execv(argv[0], argv); |
| 449 | error("Unable to execute '%.100s': %s", cmd, strerror(errno)); |
| 450 | /* Die with signal to make this error apparent to parent. */ |
| 451 | signal(SIGTERM, SIG_DFL); |
| 452 | kill(getpid(), SIGTERM); |
| 453 | _exit(1); |
| 454 | } |
| 455 | /* Parent. */ |
| 456 | if (pid < 0) |
| 457 | fatal("%s: fork: %.100s", __func__, strerror(errno)); |
| 458 | |
| 459 | close(devnull); |
| 460 | free(command_string); |
| 461 | |
| 462 | while (waitpid(pid, &status, 0) == -1) { |
| 463 | if (errno != EINTR && errno != EAGAIN) |
| 464 | fatal("%s: waitpid: %s", __func__, strerror(errno)); |
| 465 | } |
| 466 | if (!WIFEXITED(status)) { |
| 467 | error("command '%.100s' exited abnormally", cmd); |
| 468 | return -1; |
| 469 | } |
| 470 | debug3("command returned status %d", WEXITSTATUS(status)); |
| 471 | return WEXITSTATUS(status); |
| 472 | } |
| 473 | |
| 474 | /* |
| 475 | * Parse and execute a Match directive. |
| 476 | */ |
| 477 | static int |
| 478 | match_cfg_line(Options *options, char **condition, struct passwd *pw, |
| 479 | const char *host_arg, const char *filename, int linenum) |
| 480 | { |
Damien Miller | 084bcd2 | 2013-10-23 16:30:51 +1100 | [diff] [blame] | 481 | char *arg, *attrib, *cmd, *cp = *condition, *host; |
| 482 | const char *ruser; |
Damien Miller | cf31f38 | 2013-10-24 21:02:56 +1100 | [diff] [blame] | 483 | int r, port, result = 1, attributes = 0; |
Damien Miller | 194fd90 | 2013-10-15 12:13:05 +1100 | [diff] [blame] | 484 | size_t len; |
| 485 | char thishost[NI_MAXHOST], shorthost[NI_MAXHOST], portstr[NI_MAXSERV]; |
| 486 | |
| 487 | /* |
| 488 | * Configuration is likely to be incomplete at this point so we |
| 489 | * must be prepared to use default values. |
| 490 | */ |
| 491 | port = options->port <= 0 ? default_ssh_port() : options->port; |
| 492 | ruser = options->user == NULL ? pw->pw_name : options->user; |
Damien Miller | 084bcd2 | 2013-10-23 16:30:51 +1100 | [diff] [blame] | 493 | if (options->hostname != NULL) { |
Damien Miller | eff5cad | 2013-10-23 16:31:10 +1100 | [diff] [blame] | 494 | /* NB. Please keep in sync with ssh.c:main() */ |
Damien Miller | 084bcd2 | 2013-10-23 16:30:51 +1100 | [diff] [blame] | 495 | host = percent_expand(options->hostname, |
| 496 | "h", host_arg, (char *)NULL); |
| 497 | } else |
| 498 | host = xstrdup(host_arg); |
Damien Miller | 194fd90 | 2013-10-15 12:13:05 +1100 | [diff] [blame] | 499 | |
| 500 | debug3("checking match for '%s' host %s", cp, host); |
| 501 | while ((attrib = strdelim(&cp)) && *attrib != '\0') { |
Damien Miller | cf31f38 | 2013-10-24 21:02:56 +1100 | [diff] [blame] | 502 | attributes++; |
| 503 | if (strcasecmp(attrib, "all") == 0) { |
| 504 | if (attributes != 1 || |
| 505 | ((arg = strdelim(&cp)) != NULL && *arg != '\0')) { |
| 506 | error("'all' cannot be combined with other " |
| 507 | "Match attributes"); |
| 508 | result = -1; |
| 509 | goto out; |
| 510 | } |
| 511 | *condition = cp; |
| 512 | result = 1; |
| 513 | goto out; |
| 514 | } |
Damien Miller | 194fd90 | 2013-10-15 12:13:05 +1100 | [diff] [blame] | 515 | if ((arg = strdelim(&cp)) == NULL || *arg == '\0') { |
| 516 | error("Missing Match criteria for %s", attrib); |
Damien Miller | 084bcd2 | 2013-10-23 16:30:51 +1100 | [diff] [blame] | 517 | result = -1; |
| 518 | goto out; |
Damien Miller | 194fd90 | 2013-10-15 12:13:05 +1100 | [diff] [blame] | 519 | } |
| 520 | len = strlen(arg); |
| 521 | if (strcasecmp(attrib, "host") == 0) { |
| 522 | if (match_hostname(host, arg, len) != 1) |
| 523 | result = 0; |
| 524 | else |
| 525 | debug("%.200s line %d: matched 'Host %.100s' ", |
| 526 | filename, linenum, host); |
| 527 | } else if (strcasecmp(attrib, "originalhost") == 0) { |
| 528 | if (match_hostname(host_arg, arg, len) != 1) |
| 529 | result = 0; |
| 530 | else |
| 531 | debug("%.200s line %d: matched " |
| 532 | "'OriginalHost %.100s' ", |
| 533 | filename, linenum, host_arg); |
| 534 | } else if (strcasecmp(attrib, "user") == 0) { |
| 535 | if (match_pattern_list(ruser, arg, len, 0) != 1) |
| 536 | result = 0; |
| 537 | else |
| 538 | debug("%.200s line %d: matched 'User %.100s' ", |
| 539 | filename, linenum, ruser); |
| 540 | } else if (strcasecmp(attrib, "localuser") == 0) { |
| 541 | if (match_pattern_list(pw->pw_name, arg, len, 0) != 1) |
| 542 | result = 0; |
| 543 | else |
| 544 | debug("%.200s line %d: matched " |
| 545 | "'LocalUser %.100s' ", |
| 546 | filename, linenum, pw->pw_name); |
Damien Miller | 8a04be7 | 2013-10-23 16:29:40 +1100 | [diff] [blame] | 547 | } else if (strcasecmp(attrib, "exec") == 0) { |
Damien Miller | 194fd90 | 2013-10-15 12:13:05 +1100 | [diff] [blame] | 548 | if (gethostname(thishost, sizeof(thishost)) == -1) |
| 549 | fatal("gethostname: %s", strerror(errno)); |
| 550 | strlcpy(shorthost, thishost, sizeof(shorthost)); |
| 551 | shorthost[strcspn(thishost, ".")] = '\0'; |
| 552 | snprintf(portstr, sizeof(portstr), "%d", port); |
| 553 | |
| 554 | cmd = percent_expand(arg, |
| 555 | "L", shorthost, |
| 556 | "d", pw->pw_dir, |
| 557 | "h", host, |
| 558 | "l", thishost, |
| 559 | "n", host_arg, |
| 560 | "p", portstr, |
| 561 | "r", ruser, |
| 562 | "u", pw->pw_name, |
| 563 | (char *)NULL); |
Damien Miller | 0628780 | 2014-02-24 15:56:45 +1100 | [diff] [blame] | 564 | if (result != 1) { |
| 565 | /* skip execution if prior predicate failed */ |
| 566 | debug("%.200s line %d: skipped exec \"%.100s\"", |
Damien Miller | 194fd90 | 2013-10-15 12:13:05 +1100 | [diff] [blame] | 567 | filename, linenum, cmd); |
Damien Miller | 0628780 | 2014-02-24 15:56:45 +1100 | [diff] [blame] | 568 | } else { |
| 569 | r = execute_in_shell(cmd); |
| 570 | if (r == -1) { |
| 571 | fatal("%.200s line %d: match exec " |
| 572 | "'%.100s' error", filename, |
| 573 | linenum, cmd); |
| 574 | } else if (r == 0) { |
| 575 | debug("%.200s line %d: matched " |
| 576 | "'exec \"%.100s\"'", filename, |
| 577 | linenum, cmd); |
| 578 | } else { |
| 579 | debug("%.200s line %d: no match " |
| 580 | "'exec \"%.100s\"'", filename, |
| 581 | linenum, cmd); |
| 582 | result = 0; |
| 583 | } |
| 584 | } |
Damien Miller | 194fd90 | 2013-10-15 12:13:05 +1100 | [diff] [blame] | 585 | free(cmd); |
| 586 | } else { |
| 587 | error("Unsupported Match attribute %s", attrib); |
Damien Miller | 084bcd2 | 2013-10-23 16:30:51 +1100 | [diff] [blame] | 588 | result = -1; |
| 589 | goto out; |
Damien Miller | 194fd90 | 2013-10-15 12:13:05 +1100 | [diff] [blame] | 590 | } |
| 591 | } |
Damien Miller | cf31f38 | 2013-10-24 21:02:56 +1100 | [diff] [blame] | 592 | if (attributes == 0) { |
| 593 | error("One or more attributes required for Match"); |
| 594 | result = -1; |
| 595 | goto out; |
| 596 | } |
Damien Miller | 194fd90 | 2013-10-15 12:13:05 +1100 | [diff] [blame] | 597 | debug3("match %sfound", result ? "" : "not "); |
| 598 | *condition = cp; |
Damien Miller | 084bcd2 | 2013-10-23 16:30:51 +1100 | [diff] [blame] | 599 | out: |
| 600 | free(host); |
Damien Miller | 194fd90 | 2013-10-15 12:13:05 +1100 | [diff] [blame] | 601 | return result; |
| 602 | } |
| 603 | |
Damien Miller | 0faf747 | 2013-10-17 11:47:23 +1100 | [diff] [blame] | 604 | /* Check and prepare a domain name: removes trailing '.' and lowercases */ |
| 605 | static void |
| 606 | valid_domain(char *name, const char *filename, int linenum) |
| 607 | { |
| 608 | size_t i, l = strlen(name); |
| 609 | u_char c, last = '\0'; |
| 610 | |
| 611 | if (l == 0) |
| 612 | fatal("%s line %d: empty hostname suffix", filename, linenum); |
| 613 | if (!isalpha((u_char)name[0]) && !isdigit((u_char)name[0])) |
| 614 | fatal("%s line %d: hostname suffix \"%.100s\" " |
| 615 | "starts with invalid character", filename, linenum, name); |
| 616 | for (i = 0; i < l; i++) { |
| 617 | c = tolower((u_char)name[i]); |
| 618 | name[i] = (char)c; |
| 619 | if (last == '.' && c == '.') |
| 620 | fatal("%s line %d: hostname suffix \"%.100s\" contains " |
| 621 | "consecutive separators", filename, linenum, name); |
| 622 | if (c != '.' && c != '-' && !isalnum(c) && |
| 623 | c != '_') /* technically invalid, but common */ |
| 624 | fatal("%s line %d: hostname suffix \"%.100s\" contains " |
| 625 | "invalid characters", filename, linenum, name); |
| 626 | last = c; |
| 627 | } |
| 628 | if (name[l - 1] == '.') |
| 629 | name[l - 1] = '\0'; |
| 630 | } |
| 631 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 632 | /* |
Ben Lindstrom | 3704c26 | 2001-04-02 18:20:03 +0000 | [diff] [blame] | 633 | * Returns the number of the token pointed to by cp or oBadOption. |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 634 | */ |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 635 | static OpCodes |
Darren Tucker | 0763698 | 2013-05-16 20:30:03 +1000 | [diff] [blame] | 636 | parse_token(const char *cp, const char *filename, int linenum, |
| 637 | const char *ignored_unknown) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 638 | { |
Darren Tucker | 0763698 | 2013-05-16 20:30:03 +1000 | [diff] [blame] | 639 | int i; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 640 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 641 | for (i = 0; keywords[i].name; i++) |
Darren Tucker | 0763698 | 2013-05-16 20:30:03 +1000 | [diff] [blame] | 642 | if (strcmp(cp, keywords[i].name) == 0) |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 643 | return keywords[i].opcode; |
Darren Tucker | 0763698 | 2013-05-16 20:30:03 +1000 | [diff] [blame] | 644 | if (ignored_unknown != NULL && match_pattern_list(cp, ignored_unknown, |
| 645 | strlen(ignored_unknown), 1) == 1) |
| 646 | return oIgnoredUnknownOption; |
Ben Lindstrom | b5cdc66 | 2001-04-16 02:13:26 +0000 | [diff] [blame] | 647 | error("%s: line %d: Bad configuration option: %s", |
| 648 | filename, linenum, cp); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 649 | return oBadOption; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 650 | } |
| 651 | |
Damien Miller | e9fc72e | 2013-10-15 12:14:12 +1100 | [diff] [blame] | 652 | /* Multistate option parsing */ |
| 653 | struct multistate { |
| 654 | char *key; |
| 655 | int value; |
| 656 | }; |
| 657 | static const struct multistate multistate_flag[] = { |
| 658 | { "true", 1 }, |
| 659 | { "false", 0 }, |
| 660 | { "yes", 1 }, |
| 661 | { "no", 0 }, |
| 662 | { NULL, -1 } |
| 663 | }; |
| 664 | static const struct multistate multistate_yesnoask[] = { |
| 665 | { "true", 1 }, |
| 666 | { "false", 0 }, |
| 667 | { "yes", 1 }, |
| 668 | { "no", 0 }, |
| 669 | { "ask", 2 }, |
| 670 | { NULL, -1 } |
| 671 | }; |
| 672 | static const struct multistate multistate_addressfamily[] = { |
| 673 | { "inet", AF_INET }, |
| 674 | { "inet6", AF_INET6 }, |
| 675 | { "any", AF_UNSPEC }, |
| 676 | { NULL, -1 } |
| 677 | }; |
| 678 | static const struct multistate multistate_controlmaster[] = { |
| 679 | { "true", SSHCTL_MASTER_YES }, |
| 680 | { "yes", SSHCTL_MASTER_YES }, |
| 681 | { "false", SSHCTL_MASTER_NO }, |
| 682 | { "no", SSHCTL_MASTER_NO }, |
| 683 | { "auto", SSHCTL_MASTER_AUTO }, |
| 684 | { "ask", SSHCTL_MASTER_ASK }, |
| 685 | { "autoask", SSHCTL_MASTER_AUTO_ASK }, |
| 686 | { NULL, -1 } |
| 687 | }; |
| 688 | static const struct multistate multistate_tunnel[] = { |
| 689 | { "ethernet", SSH_TUNMODE_ETHERNET }, |
| 690 | { "point-to-point", SSH_TUNMODE_POINTOPOINT }, |
| 691 | { "true", SSH_TUNMODE_DEFAULT }, |
| 692 | { "yes", SSH_TUNMODE_DEFAULT }, |
| 693 | { "false", SSH_TUNMODE_NO }, |
| 694 | { "no", SSH_TUNMODE_NO }, |
| 695 | { NULL, -1 } |
| 696 | }; |
| 697 | static const struct multistate multistate_requesttty[] = { |
| 698 | { "true", REQUEST_TTY_YES }, |
| 699 | { "yes", REQUEST_TTY_YES }, |
| 700 | { "false", REQUEST_TTY_NO }, |
| 701 | { "no", REQUEST_TTY_NO }, |
| 702 | { "force", REQUEST_TTY_FORCE }, |
| 703 | { "auto", REQUEST_TTY_AUTO }, |
| 704 | { NULL, -1 } |
| 705 | }; |
Damien Miller | 3850559 | 2013-10-17 11:48:13 +1100 | [diff] [blame] | 706 | static const struct multistate multistate_canonicalizehostname[] = { |
Damien Miller | 0faf747 | 2013-10-17 11:47:23 +1100 | [diff] [blame] | 707 | { "true", SSH_CANONICALISE_YES }, |
| 708 | { "false", SSH_CANONICALISE_NO }, |
| 709 | { "yes", SSH_CANONICALISE_YES }, |
| 710 | { "no", SSH_CANONICALISE_NO }, |
| 711 | { "always", SSH_CANONICALISE_ALWAYS }, |
| 712 | { NULL, -1 } |
| 713 | }; |
Damien Miller | e9fc72e | 2013-10-15 12:14:12 +1100 | [diff] [blame] | 714 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 715 | /* |
| 716 | * Processes a single option line as used in the configuration files. This |
| 717 | * only sets those values that have not already been set. |
| 718 | */ |
Damien Miller | 61f08ac | 2003-02-24 11:56:27 +1100 | [diff] [blame] | 719 | #define WHITESPACE " \t\r\n" |
Damien Miller | 2ccf661 | 1999-11-15 15:25:10 +1100 | [diff] [blame] | 720 | int |
Damien Miller | 194fd90 | 2013-10-15 12:13:05 +1100 | [diff] [blame] | 721 | process_config_line(Options *options, struct passwd *pw, const char *host, |
| 722 | char *line, const char *filename, int linenum, int *activep, int userconfig) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 723 | { |
Damien Miller | 295ee63 | 2011-05-29 21:42:31 +1000 | [diff] [blame] | 724 | char *s, **charptr, *endofnumber, *keyword, *arg, *arg2; |
| 725 | char **cpptr, fwdarg[256]; |
Darren Tucker | 0763698 | 2013-05-16 20:30:03 +1000 | [diff] [blame] | 726 | u_int i, *uintptr, max_entries = 0; |
Damien Miller | 194fd90 | 2013-10-15 12:13:05 +1100 | [diff] [blame] | 727 | int negated, opcode, *intptr, value, value2, cmdline = 0; |
Darren Tucker | 1e44c5d | 2008-01-01 20:32:26 +1100 | [diff] [blame] | 728 | LogLevel *log_level_ptr; |
Darren Tucker | 9113d0c | 2013-05-16 20:48:14 +1000 | [diff] [blame] | 729 | long long val64; |
Damien Miller | 61f08ac | 2003-02-24 11:56:27 +1100 | [diff] [blame] | 730 | size_t len; |
Damien Miller | 7acefbb | 2014-07-18 14:11:24 +1000 | [diff] [blame^] | 731 | struct Forward fwd; |
Damien Miller | e9fc72e | 2013-10-15 12:14:12 +1100 | [diff] [blame] | 732 | const struct multistate *multistate_ptr; |
Damien Miller | 0faf747 | 2013-10-17 11:47:23 +1100 | [diff] [blame] | 733 | struct allowed_cname *cname; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 734 | |
Damien Miller | 194fd90 | 2013-10-15 12:13:05 +1100 | [diff] [blame] | 735 | if (activep == NULL) { /* We are processing a command line directive */ |
| 736 | cmdline = 1; |
| 737 | activep = &cmdline; |
| 738 | } |
| 739 | |
Damien Miller | c652cac | 2003-05-14 13:40:54 +1000 | [diff] [blame] | 740 | /* Strip trailing whitespace */ |
Darren Tucker | 47eede7 | 2005-03-14 23:08:12 +1100 | [diff] [blame] | 741 | for (len = strlen(line) - 1; len > 0; len--) { |
Damien Miller | c652cac | 2003-05-14 13:40:54 +1000 | [diff] [blame] | 742 | if (strchr(WHITESPACE, line[len]) == NULL) |
| 743 | break; |
| 744 | line[len] = '\0'; |
| 745 | } |
| 746 | |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 747 | s = line; |
| 748 | /* Get the keyword. (Each line is supposed to begin with a keyword). */ |
Damien Miller | 928b236 | 2006-03-26 13:53:32 +1100 | [diff] [blame] | 749 | if ((keyword = strdelim(&s)) == NULL) |
| 750 | return 0; |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 751 | /* Ignore leading whitespace. */ |
| 752 | if (*keyword == '\0') |
| 753 | keyword = strdelim(&s); |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 754 | if (keyword == NULL || !*keyword || *keyword == '\n' || *keyword == '#') |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 755 | return 0; |
Darren Tucker | 0763698 | 2013-05-16 20:30:03 +1000 | [diff] [blame] | 756 | /* Match lowercase keyword */ |
Damien Miller | e9fc72e | 2013-10-15 12:14:12 +1100 | [diff] [blame] | 757 | lowercase(keyword); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 758 | |
Darren Tucker | 0763698 | 2013-05-16 20:30:03 +1000 | [diff] [blame] | 759 | opcode = parse_token(keyword, filename, linenum, |
| 760 | options->ignored_unknown); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 761 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 762 | switch (opcode) { |
| 763 | case oBadOption: |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 764 | /* don't panic, but count bad options */ |
| 765 | return -1; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 766 | /* NOTREACHED */ |
Darren Tucker | 0763698 | 2013-05-16 20:30:03 +1000 | [diff] [blame] | 767 | case oIgnoredUnknownOption: |
| 768 | debug("%s line %d: Ignored unknown option \"%s\"", |
| 769 | filename, linenum, keyword); |
| 770 | return 0; |
Damien Miller | b78d5eb | 2003-05-16 11:39:04 +1000 | [diff] [blame] | 771 | case oConnectTimeout: |
| 772 | intptr = &options->connection_timeout; |
Damien Miller | 509b010 | 2003-12-17 16:33:10 +1100 | [diff] [blame] | 773 | parse_time: |
Damien Miller | b78d5eb | 2003-05-16 11:39:04 +1000 | [diff] [blame] | 774 | arg = strdelim(&s); |
| 775 | if (!arg || *arg == '\0') |
| 776 | fatal("%s line %d: missing time value.", |
| 777 | filename, linenum); |
| 778 | if ((value = convtime(arg)) == -1) |
| 779 | fatal("%s line %d: invalid time value.", |
| 780 | filename, linenum); |
Darren Tucker | a52c5b6 | 2007-02-19 22:09:45 +1100 | [diff] [blame] | 781 | if (*activep && *intptr == -1) |
Damien Miller | b78d5eb | 2003-05-16 11:39:04 +1000 | [diff] [blame] | 782 | *intptr = value; |
| 783 | break; |
| 784 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 785 | case oForwardAgent: |
| 786 | intptr = &options->forward_agent; |
Damien Miller | e9fc72e | 2013-10-15 12:14:12 +1100 | [diff] [blame] | 787 | parse_flag: |
| 788 | multistate_ptr = multistate_flag; |
| 789 | parse_multistate: |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 790 | arg = strdelim(&s); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 791 | if (!arg || *arg == '\0') |
Damien Miller | e9fc72e | 2013-10-15 12:14:12 +1100 | [diff] [blame] | 792 | fatal("%s line %d: missing argument.", |
| 793 | filename, linenum); |
| 794 | value = -1; |
| 795 | for (i = 0; multistate_ptr[i].key != NULL; i++) { |
| 796 | if (strcasecmp(arg, multistate_ptr[i].key) == 0) { |
| 797 | value = multistate_ptr[i].value; |
| 798 | break; |
| 799 | } |
| 800 | } |
| 801 | if (value == -1) |
| 802 | fatal("%s line %d: unsupported option \"%s\".", |
| 803 | filename, linenum, arg); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 804 | if (*activep && *intptr == -1) |
| 805 | *intptr = value; |
| 806 | break; |
| 807 | |
| 808 | case oForwardX11: |
| 809 | intptr = &options->forward_x11; |
| 810 | goto parse_flag; |
| 811 | |
Darren Tucker | 0a118da | 2003-10-15 15:54:32 +1000 | [diff] [blame] | 812 | case oForwardX11Trusted: |
| 813 | intptr = &options->forward_x11_trusted; |
| 814 | goto parse_flag; |
Damien Miller | 1ab6a51 | 2010-06-26 10:02:24 +1000 | [diff] [blame] | 815 | |
| 816 | case oForwardX11Timeout: |
| 817 | intptr = &options->forward_x11_timeout; |
| 818 | goto parse_time; |
Darren Tucker | 0a118da | 2003-10-15 15:54:32 +1000 | [diff] [blame] | 819 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 820 | case oGatewayPorts: |
Damien Miller | 7acefbb | 2014-07-18 14:11:24 +1000 | [diff] [blame^] | 821 | intptr = &options->fwd_opts.gateway_ports; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 822 | goto parse_flag; |
| 823 | |
Darren Tucker | e7d4b19 | 2006-07-12 22:17:10 +1000 | [diff] [blame] | 824 | case oExitOnForwardFailure: |
| 825 | intptr = &options->exit_on_forward_failure; |
| 826 | goto parse_flag; |
| 827 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 828 | case oUsePrivilegedPort: |
| 829 | intptr = &options->use_privileged_port; |
| 830 | goto parse_flag; |
| 831 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 832 | case oPasswordAuthentication: |
| 833 | intptr = &options->password_authentication; |
| 834 | goto parse_flag; |
| 835 | |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 836 | case oKbdInteractiveAuthentication: |
| 837 | intptr = &options->kbd_interactive_authentication; |
| 838 | goto parse_flag; |
| 839 | |
| 840 | case oKbdInteractiveDevices: |
| 841 | charptr = &options->kbd_interactive_devices; |
| 842 | goto parse_string; |
| 843 | |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 844 | case oPubkeyAuthentication: |
| 845 | intptr = &options->pubkey_authentication; |
Damien Miller | e247cc4 | 2000-05-07 12:03:14 +1000 | [diff] [blame] | 846 | goto parse_flag; |
| 847 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 848 | case oRSAAuthentication: |
| 849 | intptr = &options->rsa_authentication; |
| 850 | goto parse_flag; |
| 851 | |
| 852 | case oRhostsRSAAuthentication: |
| 853 | intptr = &options->rhosts_rsa_authentication; |
| 854 | goto parse_flag; |
| 855 | |
Ben Lindstrom | 5eabda3 | 2001-04-12 23:34:34 +0000 | [diff] [blame] | 856 | case oHostbasedAuthentication: |
| 857 | intptr = &options->hostbased_authentication; |
| 858 | goto parse_flag; |
| 859 | |
Ben Lindstrom | 95fb2dd | 2001-01-23 03:12:10 +0000 | [diff] [blame] | 860 | case oChallengeResponseAuthentication: |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 861 | intptr = &options->challenge_response_authentication; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 862 | goto parse_flag; |
Damien Miller | 2aa0ab4 | 2003-05-15 12:05:28 +1000 | [diff] [blame] | 863 | |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 864 | case oGssAuthentication: |
| 865 | intptr = &options->gss_authentication; |
| 866 | goto parse_flag; |
| 867 | |
| 868 | case oGssDelegateCreds: |
| 869 | intptr = &options->gss_deleg_creds; |
| 870 | goto parse_flag; |
| 871 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 872 | case oBatchMode: |
| 873 | intptr = &options->batch_mode; |
| 874 | goto parse_flag; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 875 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 876 | case oCheckHostIP: |
| 877 | intptr = &options->check_host_ip; |
Damien Miller | 1028824 | 2008-06-30 00:04:03 +1000 | [diff] [blame] | 878 | goto parse_flag; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 879 | |
Damien Miller | 37876e9 | 2003-05-15 10:19:46 +1000 | [diff] [blame] | 880 | case oVerifyHostKeyDNS: |
| 881 | intptr = &options->verify_host_key_dns; |
Damien Miller | e9fc72e | 2013-10-15 12:14:12 +1100 | [diff] [blame] | 882 | multistate_ptr = multistate_yesnoask; |
| 883 | goto parse_multistate; |
Damien Miller | 37876e9 | 2003-05-15 10:19:46 +1000 | [diff] [blame] | 884 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 885 | case oStrictHostKeyChecking: |
| 886 | intptr = &options->strict_host_key_checking; |
Damien Miller | e9fc72e | 2013-10-15 12:14:12 +1100 | [diff] [blame] | 887 | multistate_ptr = multistate_yesnoask; |
| 888 | goto parse_multistate; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 889 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 890 | case oCompression: |
| 891 | intptr = &options->compression; |
| 892 | goto parse_flag; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 893 | |
Damien Miller | 12c150e | 2003-12-17 16:31:10 +1100 | [diff] [blame] | 894 | case oTCPKeepAlive: |
| 895 | intptr = &options->tcp_keep_alive; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 896 | goto parse_flag; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 897 | |
Ben Lindstrom | 3cecc9a | 2001-10-03 17:39:38 +0000 | [diff] [blame] | 898 | case oNoHostAuthenticationForLocalhost: |
| 899 | intptr = &options->no_host_authentication_for_localhost; |
| 900 | goto parse_flag; |
| 901 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 902 | case oNumberOfPasswordPrompts: |
| 903 | intptr = &options->number_of_password_prompts; |
| 904 | goto parse_int; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 905 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 906 | case oCompressionLevel: |
| 907 | intptr = &options->compression_level; |
| 908 | goto parse_int; |
| 909 | |
Damien Miller | a5539d2 | 2003-04-09 20:50:06 +1000 | [diff] [blame] | 910 | case oRekeyLimit: |
Damien Miller | a5539d2 | 2003-04-09 20:50:06 +1000 | [diff] [blame] | 911 | arg = strdelim(&s); |
| 912 | if (!arg || *arg == '\0') |
Darren Tucker | c53c2af | 2013-05-16 20:28:16 +1000 | [diff] [blame] | 913 | fatal("%.200s line %d: Missing argument.", filename, |
| 914 | linenum); |
| 915 | if (strcmp(arg, "default") == 0) { |
| 916 | val64 = 0; |
| 917 | } else { |
Darren Tucker | b7ee852 | 2013-05-16 20:33:10 +1000 | [diff] [blame] | 918 | if (scan_scaled(arg, &val64) == -1) |
| 919 | fatal("%.200s line %d: Bad number '%s': %s", |
| 920 | filename, linenum, arg, strerror(errno)); |
| 921 | /* check for too-large or too-small limits */ |
| 922 | if (val64 > UINT_MAX) |
Darren Tucker | c53c2af | 2013-05-16 20:28:16 +1000 | [diff] [blame] | 923 | fatal("%.200s line %d: RekeyLimit too large", |
| 924 | filename, linenum); |
| 925 | if (val64 != 0 && val64 < 16) |
| 926 | fatal("%.200s line %d: RekeyLimit too small", |
| 927 | filename, linenum); |
Damien Miller | a5539d2 | 2003-04-09 20:50:06 +1000 | [diff] [blame] | 928 | } |
Damien Miller | 3dff176 | 2008-02-10 22:25:52 +1100 | [diff] [blame] | 929 | if (*activep && options->rekey_limit == -1) |
| 930 | options->rekey_limit = (u_int32_t)val64; |
Darren Tucker | c53c2af | 2013-05-16 20:28:16 +1000 | [diff] [blame] | 931 | if (s != NULL) { /* optional rekey interval present */ |
| 932 | if (strcmp(s, "none") == 0) { |
| 933 | (void)strdelim(&s); /* discard */ |
| 934 | break; |
| 935 | } |
| 936 | intptr = &options->rekey_interval; |
| 937 | goto parse_time; |
| 938 | } |
Damien Miller | a5539d2 | 2003-04-09 20:50:06 +1000 | [diff] [blame] | 939 | break; |
| 940 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 941 | case oIdentityFile: |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 942 | arg = strdelim(&s); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 943 | if (!arg || *arg == '\0') |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 944 | fatal("%.200s line %d: Missing argument.", filename, linenum); |
| 945 | if (*activep) { |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 946 | intptr = &options->num_identity_files; |
Damien Miller | eba71ba | 2000-04-29 23:57:08 +1000 | [diff] [blame] | 947 | if (*intptr >= SSH_MAX_IDENTITY_FILES) |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 948 | fatal("%.200s line %d: Too many identity files specified (max %d).", |
Damien Miller | 9f0f5c6 | 2001-12-21 14:45:46 +1100 | [diff] [blame] | 949 | filename, linenum, SSH_MAX_IDENTITY_FILES); |
Darren Tucker | aefa368 | 2013-04-05 11:18:35 +1100 | [diff] [blame] | 950 | add_identity_file(options, NULL, arg, userconfig); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 951 | } |
| 952 | break; |
| 953 | |
Damien Miller | d3a1857 | 2000-06-07 19:55:44 +1000 | [diff] [blame] | 954 | case oXAuthLocation: |
| 955 | charptr=&options->xauth_location; |
| 956 | goto parse_string; |
| 957 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 958 | case oUser: |
| 959 | charptr = &options->user; |
| 960 | parse_string: |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 961 | arg = strdelim(&s); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 962 | if (!arg || *arg == '\0') |
Damien Miller | 295ee63 | 2011-05-29 21:42:31 +1000 | [diff] [blame] | 963 | fatal("%.200s line %d: Missing argument.", |
| 964 | filename, linenum); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 965 | if (*activep && *charptr == NULL) |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 966 | *charptr = xstrdup(arg); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 967 | break; |
| 968 | |
| 969 | case oGlobalKnownHostsFile: |
Damien Miller | 295ee63 | 2011-05-29 21:42:31 +1000 | [diff] [blame] | 970 | cpptr = (char **)&options->system_hostfiles; |
| 971 | uintptr = &options->num_system_hostfiles; |
| 972 | max_entries = SSH_MAX_HOSTS_FILES; |
| 973 | parse_char_array: |
| 974 | if (*activep && *uintptr == 0) { |
| 975 | while ((arg = strdelim(&s)) != NULL && *arg != '\0') { |
| 976 | if ((*uintptr) >= max_entries) |
| 977 | fatal("%s line %d: " |
| 978 | "too many authorized keys files.", |
| 979 | filename, linenum); |
| 980 | cpptr[(*uintptr)++] = xstrdup(arg); |
| 981 | } |
| 982 | } |
| 983 | return 0; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 984 | |
| 985 | case oUserKnownHostsFile: |
Damien Miller | 295ee63 | 2011-05-29 21:42:31 +1000 | [diff] [blame] | 986 | cpptr = (char **)&options->user_hostfiles; |
| 987 | uintptr = &options->num_user_hostfiles; |
| 988 | max_entries = SSH_MAX_HOSTS_FILES; |
| 989 | goto parse_char_array; |
Damien Miller | eba71ba | 2000-04-29 23:57:08 +1000 | [diff] [blame] | 990 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 991 | case oHostName: |
| 992 | charptr = &options->hostname; |
| 993 | goto parse_string; |
| 994 | |
Ben Lindstrom | 4dccfa5 | 2000-12-28 16:40:05 +0000 | [diff] [blame] | 995 | case oHostKeyAlias: |
| 996 | charptr = &options->host_key_alias; |
| 997 | goto parse_string; |
| 998 | |
Ben Lindstrom | b9be60a | 2001-03-11 01:49:19 +0000 | [diff] [blame] | 999 | case oPreferredAuthentications: |
| 1000 | charptr = &options->preferred_authentications; |
| 1001 | goto parse_string; |
| 1002 | |
Ben Lindstrom | e0f8804 | 2001-04-30 13:06:24 +0000 | [diff] [blame] | 1003 | case oBindAddress: |
| 1004 | charptr = &options->bind_address; |
| 1005 | goto parse_string; |
| 1006 | |
Damien Miller | 7ea845e | 2010-02-12 09:21:02 +1100 | [diff] [blame] | 1007 | case oPKCS11Provider: |
| 1008 | charptr = &options->pkcs11_provider; |
Ben Lindstrom | f7db3bb | 2001-08-06 21:35:51 +0000 | [diff] [blame] | 1009 | goto parse_string; |
Ben Lindstrom | ae996bf | 2001-08-06 21:27:53 +0000 | [diff] [blame] | 1010 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1011 | case oProxyCommand: |
Damien Miller | d27b947 | 2005-12-13 19:29:02 +1100 | [diff] [blame] | 1012 | charptr = &options->proxy_command; |
| 1013 | parse_command: |
Darren Tucker | a99c1b7 | 2003-06-28 12:40:12 +1000 | [diff] [blame] | 1014 | if (s == NULL) |
| 1015 | fatal("%.200s line %d: Missing argument.", filename, linenum); |
Damien Miller | 61f08ac | 2003-02-24 11:56:27 +1100 | [diff] [blame] | 1016 | len = strspn(s, WHITESPACE "="); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1017 | if (*activep && *charptr == NULL) |
Damien Miller | 61f08ac | 2003-02-24 11:56:27 +1100 | [diff] [blame] | 1018 | *charptr = xstrdup(s + len); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1019 | return 0; |
| 1020 | |
| 1021 | case oPort: |
| 1022 | intptr = &options->port; |
| 1023 | parse_int: |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 1024 | arg = strdelim(&s); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 1025 | if (!arg || *arg == '\0') |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1026 | fatal("%.200s line %d: Missing argument.", filename, linenum); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 1027 | if (arg[0] < '0' || arg[0] > '9') |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1028 | fatal("%.200s line %d: Bad number.", filename, linenum); |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 1029 | |
| 1030 | /* Octal, decimal, or hex format? */ |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 1031 | value = strtol(arg, &endofnumber, 0); |
| 1032 | if (arg == endofnumber) |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 1033 | fatal("%.200s line %d: Bad number.", filename, linenum); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1034 | if (*activep && *intptr == -1) |
| 1035 | *intptr = value; |
| 1036 | break; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1037 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1038 | case oConnectionAttempts: |
| 1039 | intptr = &options->connection_attempts; |
| 1040 | goto parse_int; |
Damien Miller | 5ce662a | 1999-11-11 17:57:39 +1100 | [diff] [blame] | 1041 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1042 | case oCipher: |
| 1043 | intptr = &options->cipher; |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 1044 | arg = strdelim(&s); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 1045 | if (!arg || *arg == '\0') |
Damien Miller | b1715dc | 2000-05-30 13:44:51 +1000 | [diff] [blame] | 1046 | fatal("%.200s line %d: Missing argument.", filename, linenum); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 1047 | value = cipher_number(arg); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1048 | if (value == -1) |
| 1049 | fatal("%.200s line %d: Bad cipher '%s'.", |
Damien Miller | 9f0f5c6 | 2001-12-21 14:45:46 +1100 | [diff] [blame] | 1050 | filename, linenum, arg ? arg : "<NONE>"); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1051 | if (*activep && *intptr == -1) |
| 1052 | *intptr = value; |
| 1053 | break; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1054 | |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 1055 | case oCiphers: |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 1056 | arg = strdelim(&s); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 1057 | if (!arg || *arg == '\0') |
Damien Miller | b1715dc | 2000-05-30 13:44:51 +1000 | [diff] [blame] | 1058 | fatal("%.200s line %d: Missing argument.", filename, linenum); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 1059 | if (!ciphers_valid(arg)) |
Damien Miller | 30c3d42 | 2000-05-09 11:02:59 +1000 | [diff] [blame] | 1060 | fatal("%.200s line %d: Bad SSH2 cipher spec '%s'.", |
Damien Miller | 9f0f5c6 | 2001-12-21 14:45:46 +1100 | [diff] [blame] | 1061 | filename, linenum, arg ? arg : "<NONE>"); |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 1062 | if (*activep && options->ciphers == NULL) |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 1063 | options->ciphers = xstrdup(arg); |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 1064 | break; |
| 1065 | |
Ben Lindstrom | 06b33aa | 2001-02-15 03:01:59 +0000 | [diff] [blame] | 1066 | case oMacs: |
| 1067 | arg = strdelim(&s); |
| 1068 | if (!arg || *arg == '\0') |
| 1069 | fatal("%.200s line %d: Missing argument.", filename, linenum); |
| 1070 | if (!mac_valid(arg)) |
| 1071 | fatal("%.200s line %d: Bad SSH2 Mac spec '%s'.", |
Damien Miller | 9f0f5c6 | 2001-12-21 14:45:46 +1100 | [diff] [blame] | 1072 | filename, linenum, arg ? arg : "<NONE>"); |
Ben Lindstrom | 06b33aa | 2001-02-15 03:01:59 +0000 | [diff] [blame] | 1073 | if (*activep && options->macs == NULL) |
| 1074 | options->macs = xstrdup(arg); |
| 1075 | break; |
| 1076 | |
Damien Miller | d5f62bf | 2010-09-24 22:11:14 +1000 | [diff] [blame] | 1077 | case oKexAlgorithms: |
| 1078 | arg = strdelim(&s); |
| 1079 | if (!arg || *arg == '\0') |
| 1080 | fatal("%.200s line %d: Missing argument.", |
| 1081 | filename, linenum); |
| 1082 | if (!kex_names_valid(arg)) |
| 1083 | fatal("%.200s line %d: Bad SSH2 KexAlgorithms '%s'.", |
| 1084 | filename, linenum, arg ? arg : "<NONE>"); |
| 1085 | if (*activep && options->kex_algorithms == NULL) |
| 1086 | options->kex_algorithms = xstrdup(arg); |
| 1087 | break; |
| 1088 | |
Ben Lindstrom | 982dbbc | 2001-04-17 18:11:36 +0000 | [diff] [blame] | 1089 | case oHostKeyAlgorithms: |
| 1090 | arg = strdelim(&s); |
| 1091 | if (!arg || *arg == '\0') |
| 1092 | fatal("%.200s line %d: Missing argument.", filename, linenum); |
| 1093 | if (!key_names_valid2(arg)) |
| 1094 | fatal("%.200s line %d: Bad protocol 2 host key algorithms '%s'.", |
Damien Miller | 9f0f5c6 | 2001-12-21 14:45:46 +1100 | [diff] [blame] | 1095 | filename, linenum, arg ? arg : "<NONE>"); |
Ben Lindstrom | 982dbbc | 2001-04-17 18:11:36 +0000 | [diff] [blame] | 1096 | if (*activep && options->hostkeyalgorithms == NULL) |
| 1097 | options->hostkeyalgorithms = xstrdup(arg); |
| 1098 | break; |
| 1099 | |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 1100 | case oProtocol: |
| 1101 | intptr = &options->protocol; |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 1102 | arg = strdelim(&s); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 1103 | if (!arg || *arg == '\0') |
Damien Miller | b1715dc | 2000-05-30 13:44:51 +1000 | [diff] [blame] | 1104 | fatal("%.200s line %d: Missing argument.", filename, linenum); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 1105 | value = proto_spec(arg); |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 1106 | if (value == SSH_PROTO_UNKNOWN) |
| 1107 | fatal("%.200s line %d: Bad protocol spec '%s'.", |
Damien Miller | 9f0f5c6 | 2001-12-21 14:45:46 +1100 | [diff] [blame] | 1108 | filename, linenum, arg ? arg : "<NONE>"); |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 1109 | if (*activep && *intptr == SSH_PROTO_UNKNOWN) |
| 1110 | *intptr = value; |
| 1111 | break; |
| 1112 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1113 | case oLogLevel: |
Darren Tucker | 1e44c5d | 2008-01-01 20:32:26 +1100 | [diff] [blame] | 1114 | log_level_ptr = &options->log_level; |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 1115 | arg = strdelim(&s); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 1116 | value = log_level_number(arg); |
Damien Miller | fcd9320 | 2002-02-05 12:26:34 +1100 | [diff] [blame] | 1117 | if (value == SYSLOG_LEVEL_NOT_SET) |
Ben Lindstrom | 6df8ef4 | 2001-03-05 07:47:23 +0000 | [diff] [blame] | 1118 | fatal("%.200s line %d: unsupported log level '%s'", |
Damien Miller | 9f0f5c6 | 2001-12-21 14:45:46 +1100 | [diff] [blame] | 1119 | filename, linenum, arg ? arg : "<NONE>"); |
Darren Tucker | 1e44c5d | 2008-01-01 20:32:26 +1100 | [diff] [blame] | 1120 | if (*activep && *log_level_ptr == SYSLOG_LEVEL_NOT_SET) |
| 1121 | *log_level_ptr = (LogLevel) value; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1122 | break; |
| 1123 | |
Ben Lindstrom | 62c25a4 | 2001-09-12 18:01:59 +0000 | [diff] [blame] | 1124 | case oLocalForward: |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1125 | case oRemoteForward: |
Damien Miller | a699d95 | 2008-11-03 19:27:34 +1100 | [diff] [blame] | 1126 | case oDynamicForward: |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 1127 | arg = strdelim(&s); |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 1128 | if (arg == NULL || *arg == '\0') |
Ben Lindstrom | 62c25a4 | 2001-09-12 18:01:59 +0000 | [diff] [blame] | 1129 | fatal("%.200s line %d: Missing port argument.", |
| 1130 | filename, linenum); |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 1131 | |
Damien Miller | a699d95 | 2008-11-03 19:27:34 +1100 | [diff] [blame] | 1132 | if (opcode == oLocalForward || |
| 1133 | opcode == oRemoteForward) { |
| 1134 | arg2 = strdelim(&s); |
| 1135 | if (arg2 == NULL || *arg2 == '\0') |
| 1136 | fatal("%.200s line %d: Missing target argument.", |
| 1137 | filename, linenum); |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 1138 | |
Damien Miller | a699d95 | 2008-11-03 19:27:34 +1100 | [diff] [blame] | 1139 | /* construct a string for parse_forward */ |
| 1140 | snprintf(fwdarg, sizeof(fwdarg), "%s:%s", arg, arg2); |
| 1141 | } else if (opcode == oDynamicForward) { |
| 1142 | strlcpy(fwdarg, arg, sizeof(fwdarg)); |
| 1143 | } |
| 1144 | |
| 1145 | if (parse_forward(&fwd, fwdarg, |
Damien Miller | 4bf648f | 2009-02-14 16:28:21 +1100 | [diff] [blame] | 1146 | opcode == oDynamicForward ? 1 : 0, |
| 1147 | opcode == oRemoteForward ? 1 : 0) == 0) |
Ben Lindstrom | 62c25a4 | 2001-09-12 18:01:59 +0000 | [diff] [blame] | 1148 | fatal("%.200s line %d: Bad forwarding specification.", |
| 1149 | filename, linenum); |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 1150 | |
Ben Lindstrom | 62c25a4 | 2001-09-12 18:01:59 +0000 | [diff] [blame] | 1151 | if (*activep) { |
Damien Miller | a699d95 | 2008-11-03 19:27:34 +1100 | [diff] [blame] | 1152 | if (opcode == oLocalForward || |
| 1153 | opcode == oDynamicForward) |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 1154 | add_local_forward(options, &fwd); |
Ben Lindstrom | 62c25a4 | 2001-09-12 18:01:59 +0000 | [diff] [blame] | 1155 | else if (opcode == oRemoteForward) |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 1156 | add_remote_forward(options, &fwd); |
Ben Lindstrom | 62c25a4 | 2001-09-12 18:01:59 +0000 | [diff] [blame] | 1157 | } |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1158 | break; |
| 1159 | |
Ben Lindstrom | 2b7a0e9 | 2001-09-20 00:57:55 +0000 | [diff] [blame] | 1160 | case oClearAllForwardings: |
| 1161 | intptr = &options->clear_forwardings; |
| 1162 | goto parse_flag; |
| 1163 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1164 | case oHost: |
Damien Miller | 194fd90 | 2013-10-15 12:13:05 +1100 | [diff] [blame] | 1165 | if (cmdline) |
| 1166 | fatal("Host directive not supported as a command-line " |
| 1167 | "option"); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1168 | *activep = 0; |
Damien Miller | fe92421 | 2011-05-15 08:44:45 +1000 | [diff] [blame] | 1169 | arg2 = NULL; |
| 1170 | while ((arg = strdelim(&s)) != NULL && *arg != '\0') { |
| 1171 | negated = *arg == '!'; |
| 1172 | if (negated) |
| 1173 | arg++; |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 1174 | if (match_pattern(host, arg)) { |
Damien Miller | fe92421 | 2011-05-15 08:44:45 +1000 | [diff] [blame] | 1175 | if (negated) { |
| 1176 | debug("%.200s line %d: Skipping Host " |
| 1177 | "block because of negated match " |
| 1178 | "for %.100s", filename, linenum, |
| 1179 | arg); |
| 1180 | *activep = 0; |
| 1181 | break; |
| 1182 | } |
| 1183 | if (!*activep) |
| 1184 | arg2 = arg; /* logged below */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1185 | *activep = 1; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1186 | } |
Damien Miller | fe92421 | 2011-05-15 08:44:45 +1000 | [diff] [blame] | 1187 | } |
| 1188 | if (*activep) |
| 1189 | debug("%.200s line %d: Applying options for %.100s", |
| 1190 | filename, linenum, arg2); |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 1191 | /* Avoid garbage check below, as strdelim is done. */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1192 | return 0; |
| 1193 | |
Damien Miller | 194fd90 | 2013-10-15 12:13:05 +1100 | [diff] [blame] | 1194 | case oMatch: |
| 1195 | if (cmdline) |
| 1196 | fatal("Host directive not supported as a command-line " |
| 1197 | "option"); |
| 1198 | value = match_cfg_line(options, &s, pw, host, |
| 1199 | filename, linenum); |
| 1200 | if (value < 0) |
| 1201 | fatal("%.200s line %d: Bad Match condition", filename, |
| 1202 | linenum); |
| 1203 | *activep = value; |
| 1204 | break; |
| 1205 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1206 | case oEscapeChar: |
| 1207 | intptr = &options->escape_char; |
Damien Miller | be484b5 | 2000-07-15 14:14:16 +1000 | [diff] [blame] | 1208 | arg = strdelim(&s); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 1209 | if (!arg || *arg == '\0') |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1210 | fatal("%.200s line %d: Missing argument.", filename, linenum); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 1211 | if (arg[0] == '^' && arg[2] == 0 && |
Ben Lindstrom | 46c1622 | 2000-12-22 01:43:59 +0000 | [diff] [blame] | 1212 | (u_char) arg[1] >= 64 && (u_char) arg[1] < 128) |
| 1213 | value = (u_char) arg[1] & 31; |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 1214 | else if (strlen(arg) == 1) |
Ben Lindstrom | 46c1622 | 2000-12-22 01:43:59 +0000 | [diff] [blame] | 1215 | value = (u_char) arg[0]; |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 1216 | else if (strcmp(arg, "none") == 0) |
Ben Lindstrom | 2b1f71b | 2001-06-05 20:32:21 +0000 | [diff] [blame] | 1217 | value = SSH_ESCAPECHAR_NONE; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1218 | else { |
| 1219 | fatal("%.200s line %d: Bad escape character.", |
Damien Miller | 9f0f5c6 | 2001-12-21 14:45:46 +1100 | [diff] [blame] | 1220 | filename, linenum); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1221 | /* NOTREACHED */ |
| 1222 | value = 0; /* Avoid compiler warning. */ |
| 1223 | } |
| 1224 | if (*activep && *intptr == -1) |
| 1225 | *intptr = value; |
| 1226 | break; |
| 1227 | |
Damien Miller | 20a8f97 | 2003-05-18 20:50:30 +1000 | [diff] [blame] | 1228 | case oAddressFamily: |
Darren Tucker | 0a4f04b | 2003-07-03 20:37:47 +1000 | [diff] [blame] | 1229 | intptr = &options->address_family; |
Damien Miller | e9fc72e | 2013-10-15 12:14:12 +1100 | [diff] [blame] | 1230 | multistate_ptr = multistate_addressfamily; |
| 1231 | goto parse_multistate; |
Damien Miller | 20a8f97 | 2003-05-18 20:50:30 +1000 | [diff] [blame] | 1232 | |
Ben Lindstrom | b6df73b | 2002-11-09 15:52:31 +0000 | [diff] [blame] | 1233 | case oEnableSSHKeysign: |
| 1234 | intptr = &options->enable_ssh_keysign; |
| 1235 | goto parse_flag; |
| 1236 | |
Damien Miller | bd394c3 | 2004-03-08 23:12:36 +1100 | [diff] [blame] | 1237 | case oIdentitiesOnly: |
| 1238 | intptr = &options->identities_only; |
| 1239 | goto parse_flag; |
| 1240 | |
Damien Miller | 509b010 | 2003-12-17 16:33:10 +1100 | [diff] [blame] | 1241 | case oServerAliveInterval: |
| 1242 | intptr = &options->server_alive_interval; |
| 1243 | goto parse_time; |
| 1244 | |
| 1245 | case oServerAliveCountMax: |
| 1246 | intptr = &options->server_alive_count_max; |
| 1247 | goto parse_int; |
| 1248 | |
Darren Tucker | 46bc075 | 2004-05-02 22:11:30 +1000 | [diff] [blame] | 1249 | case oSendEnv: |
| 1250 | while ((arg = strdelim(&s)) != NULL && *arg != '\0') { |
| 1251 | if (strchr(arg, '=') != NULL) |
| 1252 | fatal("%s line %d: Invalid environment name.", |
| 1253 | filename, linenum); |
Damien Miller | f8e7acc | 2005-03-05 11:22:50 +1100 | [diff] [blame] | 1254 | if (!*activep) |
| 1255 | continue; |
Darren Tucker | 46bc075 | 2004-05-02 22:11:30 +1000 | [diff] [blame] | 1256 | if (options->num_send_env >= MAX_SEND_ENV) |
| 1257 | fatal("%s line %d: too many send env.", |
| 1258 | filename, linenum); |
| 1259 | options->send_env[options->num_send_env++] = |
| 1260 | xstrdup(arg); |
| 1261 | } |
| 1262 | break; |
| 1263 | |
Damien Miller | 0e220db | 2004-06-15 10:34:08 +1000 | [diff] [blame] | 1264 | case oControlPath: |
| 1265 | charptr = &options->control_path; |
| 1266 | goto parse_string; |
| 1267 | |
| 1268 | case oControlMaster: |
| 1269 | intptr = &options->control_master; |
Damien Miller | e9fc72e | 2013-10-15 12:14:12 +1100 | [diff] [blame] | 1270 | multistate_ptr = multistate_controlmaster; |
| 1271 | goto parse_multistate; |
Damien Miller | 0e220db | 2004-06-15 10:34:08 +1000 | [diff] [blame] | 1272 | |
Damien Miller | e11e1ea | 2010-08-03 16:04:46 +1000 | [diff] [blame] | 1273 | case oControlPersist: |
| 1274 | /* no/false/yes/true, or a time spec */ |
| 1275 | intptr = &options->control_persist; |
| 1276 | arg = strdelim(&s); |
| 1277 | if (!arg || *arg == '\0') |
| 1278 | fatal("%.200s line %d: Missing ControlPersist" |
| 1279 | " argument.", filename, linenum); |
| 1280 | value = 0; |
| 1281 | value2 = 0; /* timeout */ |
| 1282 | if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0) |
| 1283 | value = 0; |
| 1284 | else if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0) |
| 1285 | value = 1; |
| 1286 | else if ((value2 = convtime(arg)) >= 0) |
| 1287 | value = 1; |
| 1288 | else |
| 1289 | fatal("%.200s line %d: Bad ControlPersist argument.", |
| 1290 | filename, linenum); |
| 1291 | if (*activep && *intptr == -1) { |
| 1292 | *intptr = value; |
| 1293 | options->control_persist_timeout = value2; |
| 1294 | } |
| 1295 | break; |
| 1296 | |
Damien Miller | e177615 | 2005-03-01 21:47:37 +1100 | [diff] [blame] | 1297 | case oHashKnownHosts: |
| 1298 | intptr = &options->hash_known_hosts; |
| 1299 | goto parse_flag; |
| 1300 | |
Damien Miller | d27b947 | 2005-12-13 19:29:02 +1100 | [diff] [blame] | 1301 | case oTunnel: |
| 1302 | intptr = &options->tun_open; |
Damien Miller | e9fc72e | 2013-10-15 12:14:12 +1100 | [diff] [blame] | 1303 | multistate_ptr = multistate_tunnel; |
| 1304 | goto parse_multistate; |
Damien Miller | d27b947 | 2005-12-13 19:29:02 +1100 | [diff] [blame] | 1305 | |
| 1306 | case oTunnelDevice: |
| 1307 | arg = strdelim(&s); |
| 1308 | if (!arg || *arg == '\0') |
| 1309 | fatal("%.200s line %d: Missing argument.", filename, linenum); |
| 1310 | value = a2tun(arg, &value2); |
Damien Miller | 7b58e80 | 2005-12-13 19:33:19 +1100 | [diff] [blame] | 1311 | if (value == SSH_TUNID_ERR) |
Damien Miller | d27b947 | 2005-12-13 19:29:02 +1100 | [diff] [blame] | 1312 | fatal("%.200s line %d: Bad tun device.", filename, linenum); |
| 1313 | if (*activep) { |
| 1314 | options->tun_local = value; |
| 1315 | options->tun_remote = value2; |
| 1316 | } |
| 1317 | break; |
| 1318 | |
| 1319 | case oLocalCommand: |
| 1320 | charptr = &options->local_command; |
| 1321 | goto parse_command; |
| 1322 | |
| 1323 | case oPermitLocalCommand: |
| 1324 | intptr = &options->permit_local_command; |
| 1325 | goto parse_flag; |
| 1326 | |
Damien Miller | 1028824 | 2008-06-30 00:04:03 +1000 | [diff] [blame] | 1327 | case oVisualHostKey: |
| 1328 | intptr = &options->visual_host_key; |
| 1329 | goto parse_flag; |
| 1330 | |
Damien Miller | 0dac6fb | 2010-11-20 15:19:38 +1100 | [diff] [blame] | 1331 | case oIPQoS: |
| 1332 | arg = strdelim(&s); |
| 1333 | if ((value = parse_ipqos(arg)) == -1) |
| 1334 | fatal("%s line %d: Bad IPQoS value: %s", |
| 1335 | filename, linenum, arg); |
| 1336 | arg = strdelim(&s); |
| 1337 | if (arg == NULL) |
| 1338 | value2 = value; |
| 1339 | else if ((value2 = parse_ipqos(arg)) == -1) |
| 1340 | fatal("%s line %d: Bad IPQoS value: %s", |
| 1341 | filename, linenum, arg); |
| 1342 | if (*activep) { |
| 1343 | options->ip_qos_interactive = value; |
| 1344 | options->ip_qos_bulk = value2; |
| 1345 | } |
| 1346 | break; |
| 1347 | |
Darren Tucker | 71e4d54 | 2009-07-06 07:12:27 +1000 | [diff] [blame] | 1348 | case oUseRoaming: |
| 1349 | intptr = &options->use_roaming; |
| 1350 | goto parse_flag; |
| 1351 | |
Damien Miller | 21771e2 | 2011-05-15 08:45:50 +1000 | [diff] [blame] | 1352 | case oRequestTTY: |
Damien Miller | 21771e2 | 2011-05-15 08:45:50 +1000 | [diff] [blame] | 1353 | intptr = &options->request_tty; |
Damien Miller | e9fc72e | 2013-10-15 12:14:12 +1100 | [diff] [blame] | 1354 | multistate_ptr = multistate_requesttty; |
| 1355 | goto parse_multistate; |
Damien Miller | 21771e2 | 2011-05-15 08:45:50 +1000 | [diff] [blame] | 1356 | |
Darren Tucker | 0763698 | 2013-05-16 20:30:03 +1000 | [diff] [blame] | 1357 | case oIgnoreUnknown: |
| 1358 | charptr = &options->ignored_unknown; |
| 1359 | goto parse_string; |
| 1360 | |
Damien Miller | 1262b66 | 2013-08-21 02:44:24 +1000 | [diff] [blame] | 1361 | case oProxyUseFdpass: |
| 1362 | intptr = &options->proxy_use_fdpass; |
| 1363 | goto parse_flag; |
| 1364 | |
Damien Miller | 0faf747 | 2013-10-17 11:47:23 +1100 | [diff] [blame] | 1365 | case oCanonicalDomains: |
| 1366 | value = options->num_canonical_domains != 0; |
| 1367 | while ((arg = strdelim(&s)) != NULL && *arg != '\0') { |
| 1368 | valid_domain(arg, filename, linenum); |
| 1369 | if (!*activep || value) |
| 1370 | continue; |
| 1371 | if (options->num_canonical_domains >= MAX_CANON_DOMAINS) |
| 1372 | fatal("%s line %d: too many hostname suffixes.", |
| 1373 | filename, linenum); |
| 1374 | options->canonical_domains[ |
| 1375 | options->num_canonical_domains++] = xstrdup(arg); |
| 1376 | } |
| 1377 | break; |
| 1378 | |
Damien Miller | 3850559 | 2013-10-17 11:48:13 +1100 | [diff] [blame] | 1379 | case oCanonicalizePermittedCNAMEs: |
Damien Miller | 0faf747 | 2013-10-17 11:47:23 +1100 | [diff] [blame] | 1380 | value = options->num_permitted_cnames != 0; |
| 1381 | while ((arg = strdelim(&s)) != NULL && *arg != '\0') { |
| 1382 | /* Either '*' for everything or 'list:list' */ |
| 1383 | if (strcmp(arg, "*") == 0) |
| 1384 | arg2 = arg; |
| 1385 | else { |
| 1386 | lowercase(arg); |
| 1387 | if ((arg2 = strchr(arg, ':')) == NULL || |
| 1388 | arg2[1] == '\0') { |
| 1389 | fatal("%s line %d: " |
| 1390 | "Invalid permitted CNAME \"%s\"", |
| 1391 | filename, linenum, arg); |
| 1392 | } |
| 1393 | *arg2 = '\0'; |
| 1394 | arg2++; |
| 1395 | } |
| 1396 | if (!*activep || value) |
| 1397 | continue; |
| 1398 | if (options->num_permitted_cnames >= MAX_CANON_DOMAINS) |
| 1399 | fatal("%s line %d: too many permitted CNAMEs.", |
| 1400 | filename, linenum); |
| 1401 | cname = options->permitted_cnames + |
| 1402 | options->num_permitted_cnames++; |
| 1403 | cname->source_list = xstrdup(arg); |
| 1404 | cname->target_list = xstrdup(arg2); |
| 1405 | } |
| 1406 | break; |
| 1407 | |
Damien Miller | 3850559 | 2013-10-17 11:48:13 +1100 | [diff] [blame] | 1408 | case oCanonicalizeHostname: |
| 1409 | intptr = &options->canonicalize_hostname; |
| 1410 | multistate_ptr = multistate_canonicalizehostname; |
Damien Miller | 0faf747 | 2013-10-17 11:47:23 +1100 | [diff] [blame] | 1411 | goto parse_multistate; |
| 1412 | |
Damien Miller | 3850559 | 2013-10-17 11:48:13 +1100 | [diff] [blame] | 1413 | case oCanonicalizeMaxDots: |
| 1414 | intptr = &options->canonicalize_max_dots; |
Damien Miller | 0faf747 | 2013-10-17 11:47:23 +1100 | [diff] [blame] | 1415 | goto parse_int; |
| 1416 | |
Damien Miller | 3850559 | 2013-10-17 11:48:13 +1100 | [diff] [blame] | 1417 | case oCanonicalizeFallbackLocal: |
| 1418 | intptr = &options->canonicalize_fallback_local; |
Damien Miller | 0faf747 | 2013-10-17 11:47:23 +1100 | [diff] [blame] | 1419 | goto parse_flag; |
| 1420 | |
Damien Miller | 7acefbb | 2014-07-18 14:11:24 +1000 | [diff] [blame^] | 1421 | case oStreamLocalBindMask: |
| 1422 | arg = strdelim(&s); |
| 1423 | if (!arg || *arg == '\0') |
| 1424 | fatal("%.200s line %d: Missing StreamLocalBindMask argument.", filename, linenum); |
| 1425 | /* Parse mode in octal format */ |
| 1426 | value = strtol(arg, &endofnumber, 8); |
| 1427 | if (arg == endofnumber || value < 0 || value > 0777) |
| 1428 | fatal("%.200s line %d: Bad mask.", filename, linenum); |
| 1429 | options->fwd_opts.streamlocal_bind_mask = (mode_t)value; |
| 1430 | break; |
| 1431 | |
| 1432 | case oStreamLocalBindUnlink: |
| 1433 | intptr = &options->fwd_opts.streamlocal_bind_unlink; |
| 1434 | goto parse_flag; |
| 1435 | |
Ben Lindstrom | 4daea86 | 2002-06-09 20:04:02 +0000 | [diff] [blame] | 1436 | case oDeprecated: |
Ben Lindstrom | 2e17b08 | 2002-06-09 20:13:27 +0000 | [diff] [blame] | 1437 | debug("%s line %d: Deprecated option \"%s\"", |
Ben Lindstrom | 4daea86 | 2002-06-09 20:04:02 +0000 | [diff] [blame] | 1438 | filename, linenum, keyword); |
Ben Lindstrom | 2e17b08 | 2002-06-09 20:13:27 +0000 | [diff] [blame] | 1439 | return 0; |
Ben Lindstrom | 4daea86 | 2002-06-09 20:04:02 +0000 | [diff] [blame] | 1440 | |
Damien Miller | f9b3feb | 2003-05-16 11:38:32 +1000 | [diff] [blame] | 1441 | case oUnsupported: |
| 1442 | error("%s line %d: Unsupported option \"%s\"", |
| 1443 | filename, linenum, keyword); |
| 1444 | return 0; |
| 1445 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1446 | default: |
| 1447 | fatal("process_config_line: Unimplemented opcode %d", opcode); |
| 1448 | } |
| 1449 | |
| 1450 | /* Check that there is no garbage at end of line. */ |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 1451 | if ((arg = strdelim(&s)) != NULL && *arg != '\0') { |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 1452 | fatal("%.200s line %d: garbage at end of line; \"%.200s\".", |
Damien Miller | 0dc1bef | 2005-07-17 17:22:45 +1000 | [diff] [blame] | 1453 | filename, linenum, arg); |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 1454 | } |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1455 | return 0; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1456 | } |
| 1457 | |
| 1458 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 1459 | /* |
| 1460 | * Reads the config file and modifies the options accordingly. Options |
| 1461 | * should already be initialized before this call. This never returns if |
Ben Lindstrom | edc0cf2 | 2001-09-12 18:32:20 +0000 | [diff] [blame] | 1462 | * 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] | 1463 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1464 | |
Ben Lindstrom | edc0cf2 | 2001-09-12 18:32:20 +0000 | [diff] [blame] | 1465 | int |
Damien Miller | 194fd90 | 2013-10-15 12:13:05 +1100 | [diff] [blame] | 1466 | read_config_file(const char *filename, struct passwd *pw, const char *host, |
| 1467 | Options *options, int flags) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1468 | { |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1469 | FILE *f; |
| 1470 | char line[1024]; |
| 1471 | int active, linenum; |
| 1472 | int bad_options = 0; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1473 | |
Damien Miller | 57a4476 | 2004-04-20 20:11:57 +1000 | [diff] [blame] | 1474 | if ((f = fopen(filename, "r")) == NULL) |
Ben Lindstrom | edc0cf2 | 2001-09-12 18:32:20 +0000 | [diff] [blame] | 1475 | return 0; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1476 | |
Darren Tucker | aefa368 | 2013-04-05 11:18:35 +1100 | [diff] [blame] | 1477 | if (flags & SSHCONF_CHECKPERM) { |
Damien Miller | 57a4476 | 2004-04-20 20:11:57 +1000 | [diff] [blame] | 1478 | struct stat sb; |
Darren Tucker | fc95970 | 2004-07-17 16:12:08 +1000 | [diff] [blame] | 1479 | |
Damien Miller | 3379385 | 2004-06-15 10:27:55 +1000 | [diff] [blame] | 1480 | if (fstat(fileno(f), &sb) == -1) |
Damien Miller | 57a4476 | 2004-04-20 20:11:57 +1000 | [diff] [blame] | 1481 | fatal("fstat %s: %s", filename, strerror(errno)); |
Damien Miller | 57a4476 | 2004-04-20 20:11:57 +1000 | [diff] [blame] | 1482 | if (((sb.st_uid != 0 && sb.st_uid != getuid()) || |
Damien Miller | 3379385 | 2004-06-15 10:27:55 +1000 | [diff] [blame] | 1483 | (sb.st_mode & 022) != 0)) |
Damien Miller | 57a4476 | 2004-04-20 20:11:57 +1000 | [diff] [blame] | 1484 | fatal("Bad owner or permissions on %s", filename); |
Damien Miller | 57a4476 | 2004-04-20 20:11:57 +1000 | [diff] [blame] | 1485 | } |
| 1486 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1487 | debug("Reading configuration data %.200s", filename); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1488 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 1489 | /* |
| 1490 | * Mark that we are now processing the options. This flag is turned |
| 1491 | * on/off by Host specifications. |
| 1492 | */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1493 | active = 1; |
| 1494 | linenum = 0; |
| 1495 | while (fgets(line, sizeof(line), f)) { |
| 1496 | /* Update line number counter. */ |
| 1497 | linenum++; |
Damien Miller | 194fd90 | 2013-10-15 12:13:05 +1100 | [diff] [blame] | 1498 | if (process_config_line(options, pw, host, line, filename, |
| 1499 | linenum, &active, flags & SSHCONF_USERCONF) != 0) |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1500 | bad_options++; |
| 1501 | } |
| 1502 | fclose(f); |
| 1503 | if (bad_options > 0) |
Ben Lindstrom | 6df8ef4 | 2001-03-05 07:47:23 +0000 | [diff] [blame] | 1504 | fatal("%s: terminating, %d bad configuration options", |
Damien Miller | 9f0f5c6 | 2001-12-21 14:45:46 +1100 | [diff] [blame] | 1505 | filename, bad_options); |
Ben Lindstrom | edc0cf2 | 2001-09-12 18:32:20 +0000 | [diff] [blame] | 1506 | return 1; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1507 | } |
| 1508 | |
Damien Miller | 13f97b2 | 2014-02-24 15:57:55 +1100 | [diff] [blame] | 1509 | /* Returns 1 if a string option is unset or set to "none" or 0 otherwise. */ |
| 1510 | int |
| 1511 | option_clear_or_none(const char *o) |
| 1512 | { |
| 1513 | return o == NULL || strcasecmp(o, "none") == 0; |
| 1514 | } |
| 1515 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 1516 | /* |
| 1517 | * Initializes options to special values that indicate that they have not yet |
| 1518 | * been set. Read_config_file will only set options with this value. Options |
| 1519 | * are processed in the following order: command line, user config file, |
| 1520 | * system config file. Last, fill_default_options is called. |
| 1521 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1522 | |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 1523 | void |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1524 | initialize_options(Options * options) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1525 | { |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1526 | memset(options, 'X', sizeof(*options)); |
| 1527 | options->forward_agent = -1; |
| 1528 | options->forward_x11 = -1; |
Darren Tucker | 0a118da | 2003-10-15 15:54:32 +1000 | [diff] [blame] | 1529 | options->forward_x11_trusted = -1; |
Damien Miller | 1ab6a51 | 2010-06-26 10:02:24 +1000 | [diff] [blame] | 1530 | options->forward_x11_timeout = -1; |
Darren Tucker | e7d4b19 | 2006-07-12 22:17:10 +1000 | [diff] [blame] | 1531 | options->exit_on_forward_failure = -1; |
Damien Miller | d3a1857 | 2000-06-07 19:55:44 +1000 | [diff] [blame] | 1532 | options->xauth_location = NULL; |
Damien Miller | 7acefbb | 2014-07-18 14:11:24 +1000 | [diff] [blame^] | 1533 | options->fwd_opts.gateway_ports = -1; |
| 1534 | options->fwd_opts.streamlocal_bind_mask = (mode_t)-1; |
| 1535 | options->fwd_opts.streamlocal_bind_unlink = -1; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1536 | options->use_privileged_port = -1; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1537 | options->rsa_authentication = -1; |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 1538 | options->pubkey_authentication = -1; |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 1539 | options->challenge_response_authentication = -1; |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 1540 | options->gss_authentication = -1; |
| 1541 | options->gss_deleg_creds = -1; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1542 | options->password_authentication = -1; |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 1543 | options->kbd_interactive_authentication = -1; |
| 1544 | options->kbd_interactive_devices = NULL; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1545 | options->rhosts_rsa_authentication = -1; |
Ben Lindstrom | 5eabda3 | 2001-04-12 23:34:34 +0000 | [diff] [blame] | 1546 | options->hostbased_authentication = -1; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1547 | options->batch_mode = -1; |
| 1548 | options->check_host_ip = -1; |
| 1549 | options->strict_host_key_checking = -1; |
| 1550 | options->compression = -1; |
Damien Miller | 12c150e | 2003-12-17 16:31:10 +1100 | [diff] [blame] | 1551 | options->tcp_keep_alive = -1; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1552 | options->compression_level = -1; |
| 1553 | options->port = -1; |
Darren Tucker | 0a4f04b | 2003-07-03 20:37:47 +1000 | [diff] [blame] | 1554 | options->address_family = -1; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1555 | options->connection_attempts = -1; |
Damien Miller | b78d5eb | 2003-05-16 11:39:04 +1000 | [diff] [blame] | 1556 | options->connection_timeout = -1; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1557 | options->number_of_password_prompts = -1; |
| 1558 | options->cipher = -1; |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 1559 | options->ciphers = NULL; |
Ben Lindstrom | 06b33aa | 2001-02-15 03:01:59 +0000 | [diff] [blame] | 1560 | options->macs = NULL; |
Damien Miller | d5f62bf | 2010-09-24 22:11:14 +1000 | [diff] [blame] | 1561 | options->kex_algorithms = NULL; |
Ben Lindstrom | 982dbbc | 2001-04-17 18:11:36 +0000 | [diff] [blame] | 1562 | options->hostkeyalgorithms = NULL; |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 1563 | options->protocol = SSH_PROTO_UNKNOWN; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1564 | options->num_identity_files = 0; |
| 1565 | options->hostname = NULL; |
Ben Lindstrom | 4dccfa5 | 2000-12-28 16:40:05 +0000 | [diff] [blame] | 1566 | options->host_key_alias = NULL; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1567 | options->proxy_command = NULL; |
| 1568 | options->user = NULL; |
| 1569 | options->escape_char = -1; |
Damien Miller | 295ee63 | 2011-05-29 21:42:31 +1000 | [diff] [blame] | 1570 | options->num_system_hostfiles = 0; |
| 1571 | options->num_user_hostfiles = 0; |
Damien Miller | 232cfb1 | 2010-06-26 09:50:30 +1000 | [diff] [blame] | 1572 | options->local_forwards = NULL; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1573 | options->num_local_forwards = 0; |
Damien Miller | 232cfb1 | 2010-06-26 09:50:30 +1000 | [diff] [blame] | 1574 | options->remote_forwards = NULL; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1575 | options->num_remote_forwards = 0; |
Ben Lindstrom | 2b7a0e9 | 2001-09-20 00:57:55 +0000 | [diff] [blame] | 1576 | options->clear_forwardings = -1; |
Damien Miller | fcd9320 | 2002-02-05 12:26:34 +1100 | [diff] [blame] | 1577 | options->log_level = SYSLOG_LEVEL_NOT_SET; |
Ben Lindstrom | b9be60a | 2001-03-11 01:49:19 +0000 | [diff] [blame] | 1578 | options->preferred_authentications = NULL; |
Ben Lindstrom | e0f8804 | 2001-04-30 13:06:24 +0000 | [diff] [blame] | 1579 | options->bind_address = NULL; |
Damien Miller | 7ea845e | 2010-02-12 09:21:02 +1100 | [diff] [blame] | 1580 | options->pkcs11_provider = NULL; |
Ben Lindstrom | b6df73b | 2002-11-09 15:52:31 +0000 | [diff] [blame] | 1581 | options->enable_ssh_keysign = - 1; |
Ben Lindstrom | 3cecc9a | 2001-10-03 17:39:38 +0000 | [diff] [blame] | 1582 | options->no_host_authentication_for_localhost = - 1; |
Damien Miller | bd394c3 | 2004-03-08 23:12:36 +1100 | [diff] [blame] | 1583 | options->identities_only = - 1; |
Damien Miller | a5539d2 | 2003-04-09 20:50:06 +1000 | [diff] [blame] | 1584 | options->rekey_limit = - 1; |
Darren Tucker | c53c2af | 2013-05-16 20:28:16 +1000 | [diff] [blame] | 1585 | options->rekey_interval = -1; |
Damien Miller | 37876e9 | 2003-05-15 10:19:46 +1000 | [diff] [blame] | 1586 | options->verify_host_key_dns = -1; |
Damien Miller | 509b010 | 2003-12-17 16:33:10 +1100 | [diff] [blame] | 1587 | options->server_alive_interval = -1; |
| 1588 | options->server_alive_count_max = -1; |
Darren Tucker | 46bc075 | 2004-05-02 22:11:30 +1000 | [diff] [blame] | 1589 | options->num_send_env = 0; |
Damien Miller | 0e220db | 2004-06-15 10:34:08 +1000 | [diff] [blame] | 1590 | options->control_path = NULL; |
| 1591 | options->control_master = -1; |
Damien Miller | e11e1ea | 2010-08-03 16:04:46 +1000 | [diff] [blame] | 1592 | options->control_persist = -1; |
| 1593 | options->control_persist_timeout = 0; |
Damien Miller | e177615 | 2005-03-01 21:47:37 +1100 | [diff] [blame] | 1594 | options->hash_known_hosts = -1; |
Damien Miller | d27b947 | 2005-12-13 19:29:02 +1100 | [diff] [blame] | 1595 | options->tun_open = -1; |
| 1596 | options->tun_local = -1; |
| 1597 | options->tun_remote = -1; |
| 1598 | options->local_command = NULL; |
| 1599 | options->permit_local_command = -1; |
Darren Tucker | 71e4d54 | 2009-07-06 07:12:27 +1000 | [diff] [blame] | 1600 | options->use_roaming = -1; |
Damien Miller | 1028824 | 2008-06-30 00:04:03 +1000 | [diff] [blame] | 1601 | options->visual_host_key = -1; |
Damien Miller | 0dac6fb | 2010-11-20 15:19:38 +1100 | [diff] [blame] | 1602 | options->ip_qos_interactive = -1; |
| 1603 | options->ip_qos_bulk = -1; |
Damien Miller | 21771e2 | 2011-05-15 08:45:50 +1000 | [diff] [blame] | 1604 | options->request_tty = -1; |
Damien Miller | 1262b66 | 2013-08-21 02:44:24 +1000 | [diff] [blame] | 1605 | options->proxy_use_fdpass = -1; |
Darren Tucker | 0763698 | 2013-05-16 20:30:03 +1000 | [diff] [blame] | 1606 | options->ignored_unknown = NULL; |
Damien Miller | 0faf747 | 2013-10-17 11:47:23 +1100 | [diff] [blame] | 1607 | options->num_canonical_domains = 0; |
| 1608 | options->num_permitted_cnames = 0; |
Damien Miller | 3850559 | 2013-10-17 11:48:13 +1100 | [diff] [blame] | 1609 | options->canonicalize_max_dots = -1; |
| 1610 | options->canonicalize_fallback_local = -1; |
| 1611 | options->canonicalize_hostname = -1; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1612 | } |
| 1613 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 1614 | /* |
Damien Miller | 13f97b2 | 2014-02-24 15:57:55 +1100 | [diff] [blame] | 1615 | * A petite version of fill_default_options() that just fills the options |
| 1616 | * needed for hostname canonicalization to proceed. |
| 1617 | */ |
| 1618 | void |
| 1619 | fill_default_options_for_canonicalization(Options *options) |
| 1620 | { |
| 1621 | if (options->canonicalize_max_dots == -1) |
| 1622 | options->canonicalize_max_dots = 1; |
| 1623 | if (options->canonicalize_fallback_local == -1) |
| 1624 | options->canonicalize_fallback_local = 1; |
| 1625 | if (options->canonicalize_hostname == -1) |
| 1626 | options->canonicalize_hostname = SSH_CANONICALISE_NO; |
| 1627 | } |
| 1628 | |
| 1629 | /* |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 1630 | * Called after processing other sources of option data, this fills those |
| 1631 | * options for which no value has been specified with their default values. |
| 1632 | */ |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 1633 | void |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1634 | fill_default_options(Options * options) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1635 | { |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1636 | if (options->forward_agent == -1) |
Damien Miller | b1715dc | 2000-05-30 13:44:51 +1000 | [diff] [blame] | 1637 | options->forward_agent = 0; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1638 | if (options->forward_x11 == -1) |
Damien Miller | 98c7ad6 | 2000-03-09 21:27:49 +1100 | [diff] [blame] | 1639 | options->forward_x11 = 0; |
Darren Tucker | 0a118da | 2003-10-15 15:54:32 +1000 | [diff] [blame] | 1640 | if (options->forward_x11_trusted == -1) |
| 1641 | options->forward_x11_trusted = 0; |
Damien Miller | 1ab6a51 | 2010-06-26 10:02:24 +1000 | [diff] [blame] | 1642 | if (options->forward_x11_timeout == -1) |
| 1643 | options->forward_x11_timeout = 1200; |
Darren Tucker | e7d4b19 | 2006-07-12 22:17:10 +1000 | [diff] [blame] | 1644 | if (options->exit_on_forward_failure == -1) |
| 1645 | options->exit_on_forward_failure = 0; |
Damien Miller | d3a1857 | 2000-06-07 19:55:44 +1000 | [diff] [blame] | 1646 | if (options->xauth_location == NULL) |
Ben Lindstrom | 1bf11f6 | 2001-06-09 01:48:01 +0000 | [diff] [blame] | 1647 | options->xauth_location = _PATH_XAUTH; |
Damien Miller | 7acefbb | 2014-07-18 14:11:24 +1000 | [diff] [blame^] | 1648 | if (options->fwd_opts.gateway_ports == -1) |
| 1649 | options->fwd_opts.gateway_ports = 0; |
| 1650 | if (options->fwd_opts.streamlocal_bind_mask == (mode_t)-1) |
| 1651 | options->fwd_opts.streamlocal_bind_mask = 0177; |
| 1652 | if (options->fwd_opts.streamlocal_bind_unlink == -1) |
| 1653 | options->fwd_opts.streamlocal_bind_unlink = 0; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1654 | if (options->use_privileged_port == -1) |
Ben Lindstrom | cebc858 | 2001-03-08 03:39:10 +0000 | [diff] [blame] | 1655 | options->use_privileged_port = 0; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1656 | if (options->rsa_authentication == -1) |
| 1657 | options->rsa_authentication = 1; |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 1658 | if (options->pubkey_authentication == -1) |
| 1659 | options->pubkey_authentication = 1; |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 1660 | if (options->challenge_response_authentication == -1) |
Ben Lindstrom | 0076d75 | 2001-08-06 20:53:26 +0000 | [diff] [blame] | 1661 | options->challenge_response_authentication = 1; |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 1662 | if (options->gss_authentication == -1) |
Darren Tucker | a044f47 | 2003-10-15 15:52:03 +1000 | [diff] [blame] | 1663 | options->gss_authentication = 0; |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 1664 | if (options->gss_deleg_creds == -1) |
| 1665 | options->gss_deleg_creds = 0; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1666 | if (options->password_authentication == -1) |
| 1667 | options->password_authentication = 1; |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 1668 | if (options->kbd_interactive_authentication == -1) |
Ben Lindstrom | 95fb2dd | 2001-01-23 03:12:10 +0000 | [diff] [blame] | 1669 | options->kbd_interactive_authentication = 1; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1670 | if (options->rhosts_rsa_authentication == -1) |
Ben Lindstrom | 2bf8276 | 2002-06-11 15:53:05 +0000 | [diff] [blame] | 1671 | options->rhosts_rsa_authentication = 0; |
Ben Lindstrom | 5eabda3 | 2001-04-12 23:34:34 +0000 | [diff] [blame] | 1672 | if (options->hostbased_authentication == -1) |
| 1673 | options->hostbased_authentication = 0; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1674 | if (options->batch_mode == -1) |
| 1675 | options->batch_mode = 0; |
| 1676 | if (options->check_host_ip == -1) |
| 1677 | options->check_host_ip = 1; |
| 1678 | if (options->strict_host_key_checking == -1) |
| 1679 | options->strict_host_key_checking = 2; /* 2 is default */ |
| 1680 | if (options->compression == -1) |
| 1681 | options->compression = 0; |
Damien Miller | 12c150e | 2003-12-17 16:31:10 +1100 | [diff] [blame] | 1682 | if (options->tcp_keep_alive == -1) |
| 1683 | options->tcp_keep_alive = 1; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1684 | if (options->compression_level == -1) |
| 1685 | options->compression_level = 6; |
| 1686 | if (options->port == -1) |
| 1687 | options->port = 0; /* Filled in ssh_connect. */ |
Darren Tucker | 0a4f04b | 2003-07-03 20:37:47 +1000 | [diff] [blame] | 1688 | if (options->address_family == -1) |
| 1689 | options->address_family = AF_UNSPEC; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1690 | if (options->connection_attempts == -1) |
Ben Lindstrom | f9cedb9 | 2001-08-06 21:07:11 +0000 | [diff] [blame] | 1691 | options->connection_attempts = 1; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1692 | if (options->number_of_password_prompts == -1) |
| 1693 | options->number_of_password_prompts = 3; |
| 1694 | /* Selected in ssh_login(). */ |
| 1695 | if (options->cipher == -1) |
| 1696 | options->cipher = SSH_CIPHER_NOT_SET; |
Damien Miller | 30c3d42 | 2000-05-09 11:02:59 +1000 | [diff] [blame] | 1697 | /* options->ciphers, default set in myproposals.h */ |
Ben Lindstrom | 06b33aa | 2001-02-15 03:01:59 +0000 | [diff] [blame] | 1698 | /* options->macs, default set in myproposals.h */ |
Damien Miller | d5f62bf | 2010-09-24 22:11:14 +1000 | [diff] [blame] | 1699 | /* options->kex_algorithms, default set in myproposals.h */ |
Ben Lindstrom | 982dbbc | 2001-04-17 18:11:36 +0000 | [diff] [blame] | 1700 | /* options->hostkeyalgorithms, default set in myproposals.h */ |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 1701 | if (options->protocol == SSH_PROTO_UNKNOWN) |
Darren Tucker | bad5076 | 2009-10-11 21:51:08 +1100 | [diff] [blame] | 1702 | options->protocol = SSH_PROTO_2; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1703 | if (options->num_identity_files == 0) { |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 1704 | if (options->protocol & SSH_PROTO_1) { |
Darren Tucker | 1910478 | 2013-04-05 11:13:08 +1100 | [diff] [blame] | 1705 | add_identity_file(options, "~/", |
| 1706 | _PATH_SSH_CLIENT_IDENTITY, 0); |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 1707 | } |
| 1708 | if (options->protocol & SSH_PROTO_2) { |
Darren Tucker | 1910478 | 2013-04-05 11:13:08 +1100 | [diff] [blame] | 1709 | add_identity_file(options, "~/", |
| 1710 | _PATH_SSH_CLIENT_ID_RSA, 0); |
| 1711 | add_identity_file(options, "~/", |
| 1712 | _PATH_SSH_CLIENT_ID_DSA, 0); |
Damien Miller | 6af914a | 2010-09-10 11:39:26 +1000 | [diff] [blame] | 1713 | #ifdef OPENSSL_HAS_ECC |
Darren Tucker | 1910478 | 2013-04-05 11:13:08 +1100 | [diff] [blame] | 1714 | add_identity_file(options, "~/", |
| 1715 | _PATH_SSH_CLIENT_ID_ECDSA, 0); |
Damien Miller | 6af914a | 2010-09-10 11:39:26 +1000 | [diff] [blame] | 1716 | #endif |
Damien Miller | 5be9d9e | 2013-12-07 11:24:01 +1100 | [diff] [blame] | 1717 | add_identity_file(options, "~/", |
| 1718 | _PATH_SSH_CLIENT_ID_ED25519, 0); |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 1719 | } |
Damien Miller | eba71ba | 2000-04-29 23:57:08 +1000 | [diff] [blame] | 1720 | } |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1721 | if (options->escape_char == -1) |
| 1722 | options->escape_char = '~'; |
Damien Miller | 295ee63 | 2011-05-29 21:42:31 +1000 | [diff] [blame] | 1723 | if (options->num_system_hostfiles == 0) { |
| 1724 | options->system_hostfiles[options->num_system_hostfiles++] = |
| 1725 | xstrdup(_PATH_SSH_SYSTEM_HOSTFILE); |
| 1726 | options->system_hostfiles[options->num_system_hostfiles++] = |
| 1727 | xstrdup(_PATH_SSH_SYSTEM_HOSTFILE2); |
| 1728 | } |
| 1729 | if (options->num_user_hostfiles == 0) { |
| 1730 | options->user_hostfiles[options->num_user_hostfiles++] = |
| 1731 | xstrdup(_PATH_SSH_USER_HOSTFILE); |
| 1732 | options->user_hostfiles[options->num_user_hostfiles++] = |
| 1733 | xstrdup(_PATH_SSH_USER_HOSTFILE2); |
| 1734 | } |
Damien Miller | fcd9320 | 2002-02-05 12:26:34 +1100 | [diff] [blame] | 1735 | if (options->log_level == SYSLOG_LEVEL_NOT_SET) |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 1736 | options->log_level = SYSLOG_LEVEL_INFO; |
Ben Lindstrom | 2b7a0e9 | 2001-09-20 00:57:55 +0000 | [diff] [blame] | 1737 | if (options->clear_forwardings == 1) |
| 1738 | clear_forwardings(options); |
Ben Lindstrom | 3cecc9a | 2001-10-03 17:39:38 +0000 | [diff] [blame] | 1739 | if (options->no_host_authentication_for_localhost == - 1) |
| 1740 | options->no_host_authentication_for_localhost = 0; |
Damien Miller | bd394c3 | 2004-03-08 23:12:36 +1100 | [diff] [blame] | 1741 | if (options->identities_only == -1) |
| 1742 | options->identities_only = 0; |
Ben Lindstrom | b6df73b | 2002-11-09 15:52:31 +0000 | [diff] [blame] | 1743 | if (options->enable_ssh_keysign == -1) |
| 1744 | options->enable_ssh_keysign = 0; |
Damien Miller | a5539d2 | 2003-04-09 20:50:06 +1000 | [diff] [blame] | 1745 | if (options->rekey_limit == -1) |
| 1746 | options->rekey_limit = 0; |
Darren Tucker | c53c2af | 2013-05-16 20:28:16 +1000 | [diff] [blame] | 1747 | if (options->rekey_interval == -1) |
| 1748 | options->rekey_interval = 0; |
Damien Miller | 37876e9 | 2003-05-15 10:19:46 +1000 | [diff] [blame] | 1749 | if (options->verify_host_key_dns == -1) |
| 1750 | options->verify_host_key_dns = 0; |
Damien Miller | 509b010 | 2003-12-17 16:33:10 +1100 | [diff] [blame] | 1751 | if (options->server_alive_interval == -1) |
| 1752 | options->server_alive_interval = 0; |
| 1753 | if (options->server_alive_count_max == -1) |
| 1754 | options->server_alive_count_max = 3; |
Damien Miller | 0e220db | 2004-06-15 10:34:08 +1000 | [diff] [blame] | 1755 | if (options->control_master == -1) |
| 1756 | options->control_master = 0; |
Damien Miller | e11e1ea | 2010-08-03 16:04:46 +1000 | [diff] [blame] | 1757 | if (options->control_persist == -1) { |
| 1758 | options->control_persist = 0; |
| 1759 | options->control_persist_timeout = 0; |
| 1760 | } |
Damien Miller | e177615 | 2005-03-01 21:47:37 +1100 | [diff] [blame] | 1761 | if (options->hash_known_hosts == -1) |
| 1762 | options->hash_known_hosts = 0; |
Damien Miller | d27b947 | 2005-12-13 19:29:02 +1100 | [diff] [blame] | 1763 | if (options->tun_open == -1) |
Damien Miller | 7b58e80 | 2005-12-13 19:33:19 +1100 | [diff] [blame] | 1764 | options->tun_open = SSH_TUNMODE_NO; |
| 1765 | if (options->tun_local == -1) |
| 1766 | options->tun_local = SSH_TUNID_ANY; |
| 1767 | if (options->tun_remote == -1) |
| 1768 | options->tun_remote = SSH_TUNID_ANY; |
Damien Miller | d27b947 | 2005-12-13 19:29:02 +1100 | [diff] [blame] | 1769 | if (options->permit_local_command == -1) |
| 1770 | options->permit_local_command = 0; |
Darren Tucker | 71e4d54 | 2009-07-06 07:12:27 +1000 | [diff] [blame] | 1771 | if (options->use_roaming == -1) |
| 1772 | options->use_roaming = 1; |
Damien Miller | 1028824 | 2008-06-30 00:04:03 +1000 | [diff] [blame] | 1773 | if (options->visual_host_key == -1) |
| 1774 | options->visual_host_key = 0; |
Damien Miller | 0dac6fb | 2010-11-20 15:19:38 +1100 | [diff] [blame] | 1775 | if (options->ip_qos_interactive == -1) |
| 1776 | options->ip_qos_interactive = IPTOS_LOWDELAY; |
| 1777 | if (options->ip_qos_bulk == -1) |
| 1778 | options->ip_qos_bulk = IPTOS_THROUGHPUT; |
Damien Miller | 21771e2 | 2011-05-15 08:45:50 +1000 | [diff] [blame] | 1779 | if (options->request_tty == -1) |
| 1780 | options->request_tty = REQUEST_TTY_AUTO; |
Damien Miller | 1262b66 | 2013-08-21 02:44:24 +1000 | [diff] [blame] | 1781 | if (options->proxy_use_fdpass == -1) |
| 1782 | options->proxy_use_fdpass = 0; |
Damien Miller | 3850559 | 2013-10-17 11:48:13 +1100 | [diff] [blame] | 1783 | if (options->canonicalize_max_dots == -1) |
| 1784 | options->canonicalize_max_dots = 1; |
| 1785 | if (options->canonicalize_fallback_local == -1) |
| 1786 | options->canonicalize_fallback_local = 1; |
| 1787 | if (options->canonicalize_hostname == -1) |
| 1788 | options->canonicalize_hostname = SSH_CANONICALISE_NO; |
Damien Miller | e9fc72e | 2013-10-15 12:14:12 +1100 | [diff] [blame] | 1789 | #define CLEAR_ON_NONE(v) \ |
| 1790 | do { \ |
Damien Miller | 13f97b2 | 2014-02-24 15:57:55 +1100 | [diff] [blame] | 1791 | if (option_clear_or_none(v)) { \ |
Damien Miller | e9fc72e | 2013-10-15 12:14:12 +1100 | [diff] [blame] | 1792 | free(v); \ |
| 1793 | v = NULL; \ |
| 1794 | } \ |
| 1795 | } while(0) |
| 1796 | CLEAR_ON_NONE(options->local_command); |
| 1797 | CLEAR_ON_NONE(options->proxy_command); |
| 1798 | CLEAR_ON_NONE(options->control_path); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1799 | /* options->user will be set in the main program if appropriate */ |
| 1800 | /* options->hostname will be set in the main program if appropriate */ |
Ben Lindstrom | 4dccfa5 | 2000-12-28 16:40:05 +0000 | [diff] [blame] | 1801 | /* options->host_key_alias should not be set by default */ |
Ben Lindstrom | b9be60a | 2001-03-11 01:49:19 +0000 | [diff] [blame] | 1802 | /* options->preferred_authentications will be set in ssh */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1803 | } |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 1804 | |
Damien Miller | 7acefbb | 2014-07-18 14:11:24 +1000 | [diff] [blame^] | 1805 | struct fwdarg { |
| 1806 | char *arg; |
| 1807 | int ispath; |
| 1808 | }; |
| 1809 | |
| 1810 | /* |
| 1811 | * parse_fwd_field |
| 1812 | * parses the next field in a port forwarding specification. |
| 1813 | * sets fwd to the parsed field and advances p past the colon |
| 1814 | * or sets it to NULL at end of string. |
| 1815 | * returns 0 on success, else non-zero. |
| 1816 | */ |
| 1817 | static int |
| 1818 | parse_fwd_field(char **p, struct fwdarg *fwd) |
| 1819 | { |
| 1820 | char *ep, *cp = *p; |
| 1821 | int ispath = 0; |
| 1822 | |
| 1823 | if (*cp == '\0') { |
| 1824 | *p = NULL; |
| 1825 | return -1; /* end of string */ |
| 1826 | } |
| 1827 | |
| 1828 | /* |
| 1829 | * A field escaped with square brackets is used literally. |
| 1830 | * XXX - allow ']' to be escaped via backslash? |
| 1831 | */ |
| 1832 | if (*cp == '[') { |
| 1833 | /* find matching ']' */ |
| 1834 | for (ep = cp + 1; *ep != ']' && *ep != '\0'; ep++) { |
| 1835 | if (*ep == '/') |
| 1836 | ispath = 1; |
| 1837 | } |
| 1838 | /* no matching ']' or not at end of field. */ |
| 1839 | if (ep[0] != ']' || (ep[1] != ':' && ep[1] != '\0')) |
| 1840 | return -1; |
| 1841 | /* NUL terminate the field and advance p past the colon */ |
| 1842 | *ep++ = '\0'; |
| 1843 | if (*ep != '\0') |
| 1844 | *ep++ = '\0'; |
| 1845 | fwd->arg = cp + 1; |
| 1846 | fwd->ispath = ispath; |
| 1847 | *p = ep; |
| 1848 | return 0; |
| 1849 | } |
| 1850 | |
| 1851 | for (cp = *p; *cp != '\0'; cp++) { |
| 1852 | switch (*cp) { |
| 1853 | case '\\': |
| 1854 | memmove(cp, cp + 1, strlen(cp + 1) + 1); |
| 1855 | cp++; |
| 1856 | break; |
| 1857 | case '/': |
| 1858 | ispath = 1; |
| 1859 | break; |
| 1860 | case ':': |
| 1861 | *cp++ = '\0'; |
| 1862 | goto done; |
| 1863 | } |
| 1864 | } |
| 1865 | done: |
| 1866 | fwd->arg = *p; |
| 1867 | fwd->ispath = ispath; |
| 1868 | *p = cp; |
| 1869 | return 0; |
| 1870 | } |
| 1871 | |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 1872 | /* |
| 1873 | * parse_forward |
| 1874 | * parses a string containing a port forwarding specification of the form: |
Damien Miller | a699d95 | 2008-11-03 19:27:34 +1100 | [diff] [blame] | 1875 | * dynamicfwd == 0 |
Damien Miller | 7acefbb | 2014-07-18 14:11:24 +1000 | [diff] [blame^] | 1876 | * [listenhost:]listenport|listenpath:connecthost:connectport|connectpath |
| 1877 | * listenpath:connectpath |
Damien Miller | a699d95 | 2008-11-03 19:27:34 +1100 | [diff] [blame] | 1878 | * dynamicfwd == 1 |
| 1879 | * [listenhost:]listenport |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 1880 | * returns number of arguments parsed or zero on error |
| 1881 | */ |
| 1882 | int |
Damien Miller | 7acefbb | 2014-07-18 14:11:24 +1000 | [diff] [blame^] | 1883 | parse_forward(struct Forward *fwd, const char *fwdspec, int dynamicfwd, int remotefwd) |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 1884 | { |
Damien Miller | 7acefbb | 2014-07-18 14:11:24 +1000 | [diff] [blame^] | 1885 | struct fwdarg fwdargs[4]; |
| 1886 | char *p, *cp; |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 1887 | int i; |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 1888 | |
Damien Miller | 7acefbb | 2014-07-18 14:11:24 +1000 | [diff] [blame^] | 1889 | memset(fwd, 0, sizeof(*fwd)); |
| 1890 | memset(fwdargs, 0, sizeof(fwdargs)); |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 1891 | |
| 1892 | cp = p = xstrdup(fwdspec); |
| 1893 | |
| 1894 | /* skip leading spaces */ |
Damien Miller | fdb2306 | 2013-11-21 13:57:15 +1100 | [diff] [blame] | 1895 | while (isspace((u_char)*cp)) |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 1896 | cp++; |
| 1897 | |
Damien Miller | 7acefbb | 2014-07-18 14:11:24 +1000 | [diff] [blame^] | 1898 | for (i = 0; i < 4; ++i) { |
| 1899 | if (parse_fwd_field(&cp, &fwdargs[i]) != 0) |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 1900 | break; |
Damien Miller | 7acefbb | 2014-07-18 14:11:24 +1000 | [diff] [blame^] | 1901 | } |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 1902 | |
Damien Miller | f4b3953 | 2008-11-03 19:28:21 +1100 | [diff] [blame] | 1903 | /* Check for trailing garbage */ |
Damien Miller | 7acefbb | 2014-07-18 14:11:24 +1000 | [diff] [blame^] | 1904 | if (cp != NULL && *cp != '\0') { |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 1905 | i = 0; /* failure */ |
Damien Miller | 7acefbb | 2014-07-18 14:11:24 +1000 | [diff] [blame^] | 1906 | } |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 1907 | |
| 1908 | switch (i) { |
Damien Miller | a699d95 | 2008-11-03 19:27:34 +1100 | [diff] [blame] | 1909 | case 1: |
Damien Miller | 7acefbb | 2014-07-18 14:11:24 +1000 | [diff] [blame^] | 1910 | if (fwdargs[0].ispath) { |
| 1911 | fwd->listen_path = xstrdup(fwdargs[0].arg); |
| 1912 | fwd->listen_port = PORT_STREAMLOCAL; |
| 1913 | } else { |
| 1914 | fwd->listen_host = NULL; |
| 1915 | fwd->listen_port = a2port(fwdargs[0].arg); |
| 1916 | } |
Damien Miller | a699d95 | 2008-11-03 19:27:34 +1100 | [diff] [blame] | 1917 | fwd->connect_host = xstrdup("socks"); |
| 1918 | break; |
| 1919 | |
| 1920 | case 2: |
Damien Miller | 7acefbb | 2014-07-18 14:11:24 +1000 | [diff] [blame^] | 1921 | if (fwdargs[0].ispath && fwdargs[1].ispath) { |
| 1922 | fwd->listen_path = xstrdup(fwdargs[0].arg); |
| 1923 | fwd->listen_port = PORT_STREAMLOCAL; |
| 1924 | fwd->connect_path = xstrdup(fwdargs[1].arg); |
| 1925 | fwd->connect_port = PORT_STREAMLOCAL; |
| 1926 | } else if (fwdargs[1].ispath) { |
| 1927 | fwd->listen_host = NULL; |
| 1928 | fwd->listen_port = a2port(fwdargs[0].arg); |
| 1929 | fwd->connect_path = xstrdup(fwdargs[1].arg); |
| 1930 | fwd->connect_port = PORT_STREAMLOCAL; |
| 1931 | } else { |
| 1932 | fwd->listen_host = xstrdup(fwdargs[0].arg); |
| 1933 | fwd->listen_port = a2port(fwdargs[1].arg); |
| 1934 | fwd->connect_host = xstrdup("socks"); |
| 1935 | } |
Damien Miller | a699d95 | 2008-11-03 19:27:34 +1100 | [diff] [blame] | 1936 | break; |
| 1937 | |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 1938 | case 3: |
Damien Miller | 7acefbb | 2014-07-18 14:11:24 +1000 | [diff] [blame^] | 1939 | if (fwdargs[0].ispath) { |
| 1940 | fwd->listen_path = xstrdup(fwdargs[0].arg); |
| 1941 | fwd->listen_port = PORT_STREAMLOCAL; |
| 1942 | fwd->connect_host = xstrdup(fwdargs[1].arg); |
| 1943 | fwd->connect_port = a2port(fwdargs[2].arg); |
| 1944 | } else if (fwdargs[2].ispath) { |
| 1945 | fwd->listen_host = xstrdup(fwdargs[0].arg); |
| 1946 | fwd->listen_port = a2port(fwdargs[1].arg); |
| 1947 | fwd->connect_path = xstrdup(fwdargs[2].arg); |
| 1948 | fwd->connect_port = PORT_STREAMLOCAL; |
| 1949 | } else { |
| 1950 | fwd->listen_host = NULL; |
| 1951 | fwd->listen_port = a2port(fwdargs[0].arg); |
| 1952 | fwd->connect_host = xstrdup(fwdargs[1].arg); |
| 1953 | fwd->connect_port = a2port(fwdargs[2].arg); |
| 1954 | } |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 1955 | break; |
| 1956 | |
| 1957 | case 4: |
Damien Miller | 7acefbb | 2014-07-18 14:11:24 +1000 | [diff] [blame^] | 1958 | fwd->listen_host = xstrdup(fwdargs[0].arg); |
| 1959 | fwd->listen_port = a2port(fwdargs[1].arg); |
| 1960 | fwd->connect_host = xstrdup(fwdargs[2].arg); |
| 1961 | fwd->connect_port = a2port(fwdargs[3].arg); |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 1962 | break; |
| 1963 | default: |
| 1964 | i = 0; /* failure */ |
| 1965 | } |
| 1966 | |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 1967 | free(p); |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 1968 | |
Damien Miller | a699d95 | 2008-11-03 19:27:34 +1100 | [diff] [blame] | 1969 | if (dynamicfwd) { |
| 1970 | if (!(i == 1 || i == 2)) |
| 1971 | goto fail_free; |
| 1972 | } else { |
Damien Miller | 7acefbb | 2014-07-18 14:11:24 +1000 | [diff] [blame^] | 1973 | if (!(i == 3 || i == 4)) { |
| 1974 | if (fwd->connect_path == NULL && |
| 1975 | fwd->listen_path == NULL) |
| 1976 | goto fail_free; |
| 1977 | } |
| 1978 | if (fwd->connect_port <= 0 && fwd->connect_path == NULL) |
Damien Miller | a699d95 | 2008-11-03 19:27:34 +1100 | [diff] [blame] | 1979 | goto fail_free; |
| 1980 | } |
| 1981 | |
Damien Miller | 7acefbb | 2014-07-18 14:11:24 +1000 | [diff] [blame^] | 1982 | if ((fwd->listen_port < 0 && fwd->listen_path == NULL) || |
| 1983 | (!remotefwd && fwd->listen_port == 0)) |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 1984 | goto fail_free; |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 1985 | if (fwd->connect_host != NULL && |
| 1986 | strlen(fwd->connect_host) >= NI_MAXHOST) |
| 1987 | goto fail_free; |
Damien Miller | 7acefbb | 2014-07-18 14:11:24 +1000 | [diff] [blame^] | 1988 | /* XXX - if connecting to a remote socket, max sun len may not match this host */ |
| 1989 | if (fwd->connect_path != NULL && |
| 1990 | strlen(fwd->connect_path) >= PATH_MAX_SUN) |
| 1991 | goto fail_free; |
Damien Miller | 4bf648f | 2009-02-14 16:28:21 +1100 | [diff] [blame] | 1992 | if (fwd->listen_host != NULL && |
| 1993 | strlen(fwd->listen_host) >= NI_MAXHOST) |
| 1994 | goto fail_free; |
Damien Miller | 7acefbb | 2014-07-18 14:11:24 +1000 | [diff] [blame^] | 1995 | if (fwd->listen_path != NULL && |
| 1996 | strlen(fwd->listen_path) >= PATH_MAX_SUN) |
| 1997 | goto fail_free; |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 1998 | |
| 1999 | return (i); |
| 2000 | |
| 2001 | fail_free: |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 2002 | free(fwd->connect_host); |
| 2003 | fwd->connect_host = NULL; |
Damien Miller | 7acefbb | 2014-07-18 14:11:24 +1000 | [diff] [blame^] | 2004 | free(fwd->connect_path); |
| 2005 | fwd->connect_path = NULL; |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 2006 | free(fwd->listen_host); |
| 2007 | fwd->listen_host = NULL; |
Damien Miller | 7acefbb | 2014-07-18 14:11:24 +1000 | [diff] [blame^] | 2008 | free(fwd->listen_path); |
| 2009 | fwd->listen_path = NULL; |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 2010 | return (0); |
| 2011 | } |