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