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