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