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