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