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