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