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