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