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