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