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