blob: 433811521bb10af1de237ab44697071868992e92 [file] [log] [blame]
naddy@openbsd.org25813332018-10-05 14:26:09 +00001/* $OpenBSD: readconf.c,v 1.300 2018/10/05 14:26:09 naddy Exp $ */
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002/*
Damien Miller95def091999-11-25 00:26:21 +11003 * Author: Tatu Ylonen <ylo@cs.hut.fi>
Damien Miller95def091999-11-25 00:26:21 +11004 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
5 * All rights reserved
Damien Miller95def091999-11-25 00:26:21 +11006 * Functions for reading the configuration files.
Damien Miller4af51302000-04-16 11:18:38 +10007 *
Damien Millere4340be2000-09-16 13:29:08 +11008 * 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 Miller95def091999-11-25 00:26:21 +110013 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100014
15#include "includes.h"
Damien Millerf17883e2006-03-15 11:45:54 +110016
17#include <sys/types.h>
18#include <sys/stat.h>
Damien Miller8ec8c3e2006-07-10 20:35:38 +100019#include <sys/socket.h>
Damien Miller194fd902013-10-15 12:13:05 +110020#include <sys/wait.h>
Damien Miller7acefbb2014-07-18 14:11:24 +100021#include <sys/un.h>
Damien Miller8ec8c3e2006-07-10 20:35:38 +100022
23#include <netinet/in.h>
Damien Miller0dac6fb2010-11-20 15:19:38 +110024#include <netinet/in_systm.h>
25#include <netinet/ip.h>
Darren Tucker0eeafcd2014-01-31 14:18:51 +110026#include <arpa/inet.h>
Damien Millerd4a8b7e1999-10-27 13:42:43 +100027
Damien Millerc7b06362006-03-15 11:53:45 +110028#include <ctype.h>
Darren Tucker39972492006-07-12 22:22:46 +100029#include <errno.h>
Damien Miller194fd902013-10-15 12:13:05 +110030#include <fcntl.h>
deraadt@openbsd.org2ae4f332015-01-16 06:40:12 +000031#include <limits.h>
Damien Millerb8fe89c2006-07-24 14:51:00 +100032#include <netdb.h>
Darren Tuckera3357662014-01-18 00:03:57 +110033#ifdef HAVE_PATHS_H
34# include <paths.h>
35#endif
Damien Miller194fd902013-10-15 12:13:05 +110036#include <pwd.h>
Damien Millerd7834352006-08-05 12:39:39 +100037#include <signal.h>
Damien Millerded319c2006-09-01 15:38:36 +100038#include <stdarg.h>
Damien Millera7a73ee2006-08-05 11:37:59 +100039#include <stdio.h>
Damien Millere3476ed2006-07-24 14:13:33 +100040#include <string.h>
Damien Millere6b3b612006-07-24 14:01:23 +100041#include <unistd.h>
djm@openbsd.orgdc7990b2016-04-15 00:30:19 +000042#ifdef USE_SYSTEM_GLOB
43# include <glob.h>
44#else
45# include "openbsd-compat/glob.h"
46#endif
Darren Tuckere194ba42013-05-16 20:47:31 +100047#ifdef HAVE_UTIL_H
Darren Tuckerb7ee8522013-05-16 20:33:10 +100048#include <util.h>
Darren Tuckere194ba42013-05-16 20:47:31 +100049#endif
djm@openbsd.org957fbce2014-10-08 22:20:25 +000050#if defined(HAVE_STRNVIS) && defined(HAVE_VIS_H) && !defined(BROKEN_STRNVIS)
51# include <vis.h>
52#endif
Damien Millerc7b06362006-03-15 11:53:45 +110053
Damien Millerd4a8b7e1999-10-27 13:42:43 +100054#include "xmalloc.h"
Damien Millerd7834352006-08-05 12:39:39 +100055#include "ssh.h"
djm@openbsd.org1b9dd4a2018-08-12 20:19:13 +000056#include "ssherr.h"
Damien Miller78928792000-04-12 20:17:38 +100057#include "compat.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000058#include "cipher.h"
59#include "pathnames.h"
60#include "log.h"
djm@openbsd.org1129dcf2015-01-15 09:40:00 +000061#include "sshkey.h"
Damien Miller7acefbb2014-07-18 14:11:24 +100062#include "misc.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000063#include "readconf.h"
64#include "match.h"
Ben Lindstrom06b33aa2001-02-15 03:01:59 +000065#include "kex.h"
66#include "mac.h"
Damien Miller194fd902013-10-15 12:13:05 +110067#include "uidswap.h"
djm@openbsd.org957fbce2014-10-08 22:20:25 +000068#include "myproposal.h"
djm@openbsd.org56d1c832014-12-21 22:27:55 +000069#include "digest.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100070
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 Lindstrom4daea862002-06-09 20:04:02 +000086 User foo
Damien Millerd4a8b7e1999-10-27 13:42:43 +100087
88 Host fake.com
89 HostName another.host.name.real.org
90 User blaah
91 Port 34289
92 ForwardX11 no
93 ForwardAgent no
94
95 Host books.com
96 RemoteForward 9999 shadows.cs.hut.fi:9999
djm@openbsd.org381a2612017-01-30 00:38:50 +000097 Ciphers 3des-cbc
Damien Millerd4a8b7e1999-10-27 13:42:43 +100098
99 Host fascist.blob.com
100 Port 23123
101 User tylonen
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000102 PasswordAuthentication no
103
104 Host puukko.hut.fi
105 User t35124p
106 ProxyCommand ssh-proxy %h %p
107
108 Host *.fr
Ben Lindstrom4daea862002-06-09 20:04:02 +0000109 PublicKeyAuthentication no
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000110
111 Host *.su
djm@openbsd.org381a2612017-01-30 00:38:50 +0000112 Ciphers aes128-ctr
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000113 PasswordAuthentication no
114
Damien Millerd27b9472005-12-13 19:29:02 +1100115 Host vpn.fake.com
116 Tunnel yes
117 TunnelDevice 3
118
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000119 # Defaults for various options
120 Host *
121 ForwardAgent no
Damien Miller0bc1bd82000-11-13 22:57:25 +1100122 ForwardX11 no
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000123 PasswordAuthentication yes
124 RSAAuthentication yes
125 RhostsRSAAuthentication yes
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000126 StrictHostKeyChecking yes
Damien Miller12c150e2003-12-17 16:31:10 +1100127 TcpKeepAlive no
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000128 IdentityFile ~/.ssh/identity
129 Port 22
130 EscapeChar ~
131
132*/
133
djm@openbsd.orgdc7990b2016-04-15 00:30:19 +0000134static int read_config_file_depth(const char *filename, struct passwd *pw,
135 const char *host, const char *original_host, Options *options,
136 int flags, int *activep, int depth);
137static int process_config_line_depth(Options *options, struct passwd *pw,
138 const char *host, const char *original_host, char *line,
139 const char *filename, int linenum, int *activep, int flags, int depth);
140
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000141/* Keyword tokens. */
142
Damien Miller95def091999-11-25 00:26:21 +1100143typedef enum {
144 oBadOption,
djm@openbsd.orgdc7990b2016-04-15 00:30:19 +0000145 oHost, oMatch, oInclude,
Damien Miller1ab6a512010-06-26 10:02:24 +1000146 oForwardAgent, oForwardX11, oForwardX11Trusted, oForwardX11Timeout,
147 oGatewayPorts, oExitOnForwardFailure,
Ben Lindstromcb72e4f2002-06-21 00:41:51 +0000148 oPasswordAuthentication, oRSAAuthentication,
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000149 oChallengeResponseAuthentication, oXAuthLocation,
Damien Miller95def091999-11-25 00:26:21 +1100150 oIdentityFile, oHostName, oPort, oCipher, oRemoteForward, oLocalForward,
markus@openbsd.orgb02ad1c2016-05-04 12:21:53 +0000151 oCertificateFile, oAddKeysToAgent, oIdentityAgent,
Damien Miller194fd902013-10-15 12:13:05 +1100152 oUser, oEscapeChar, oRhostsRSAAuthentication, oProxyCommand,
Damien Miller95def091999-11-25 00:26:21 +1100153 oGlobalKnownHostsFile, oUserKnownHostsFile, oConnectionAttempts,
154 oBatchMode, oCheckHostIP, oStrictHostKeyChecking, oCompression,
Damien Miller12c150e2003-12-17 16:31:10 +1100155 oCompressionLevel, oTCPKeepAlive, oNumberOfPasswordPrompts,
djm@openbsd.org99f95ba2017-04-30 23:11:45 +0000156 oUsePrivilegedPort, oLogFacility, oLogLevel, oCiphers, oMacs,
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000157 oPubkeyAuthentication,
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000158 oKbdInteractiveAuthentication, oKbdInteractiveDevices, oHostKeyAlias,
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000159 oDynamicForward, oPreferredAuthentications, oHostbasedAuthentication,
djm@openbsd.orgac2e3022018-02-23 02:34:33 +0000160 oHostKeyAlgorithms, oBindAddress, oBindInterface, oPKCS11Provider,
Ben Lindstrom4daea862002-06-09 20:04:02 +0000161 oClearAllForwardings, oNoHostAuthenticationForLocalhost,
Damien Millerb78d5eb2003-05-16 11:39:04 +1000162 oEnableSSHKeysign, oRekeyLimit, oVerifyHostKeyDNS, oConnectTimeout,
Darren Tucker0efd1552003-08-26 11:49:55 +1000163 oAddressFamily, oGssAuthentication, oGssDelegateCreds,
Damien Millerbd394c32004-03-08 23:12:36 +1100164 oServerAliveInterval, oServerAliveCountMax, oIdentitiesOnly,
djm@openbsd.org7082bb52018-06-09 03:01:12 +0000165 oSendEnv, oSetEnv, oControlPath, oControlMaster, oControlPersist,
Damien Millere11e1ea2010-08-03 16:04:46 +1000166 oHashKnownHosts,
bluhm@openbsd.org1112b532017-05-30 18:58:37 +0000167 oTunnel, oTunnelDevice,
168 oLocalCommand, oPermitLocalCommand, oRemoteCommand,
markus@openbsd.orga3068632016-01-14 16:17:39 +0000169 oVisualHostKey,
Damien Miller1262b662013-08-21 02:44:24 +1000170 oKexAlgorithms, oIPQoS, oRequestTTY, oIgnoreUnknown, oProxyUseFdpass,
Damien Miller38505592013-10-17 11:48:13 +1100171 oCanonicalDomains, oCanonicalizeHostname, oCanonicalizeMaxDots,
172 oCanonicalizeFallbackLocal, oCanonicalizePermittedCNAMEs,
djm@openbsd.org5e39a492014-12-04 02:24:32 +0000173 oStreamLocalBindMask, oStreamLocalBindUnlink, oRevokedHostKeys,
djm@openbsd.org46347ed2015-01-30 11:43:14 +0000174 oFingerprintHash, oUpdateHostkeys, oHostbasedKeyTypes,
djm@openbsd.orgecac7e12018-09-20 03:30:44 +0000175 oPubkeyAcceptedKeyTypes, oCASignatureAlgorithms, oProxyJump,
djm@openbsd.org99f95ba2017-04-30 23:11:45 +0000176 oIgnore, oIgnoredUnknownOption, oDeprecated, oUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000177} OpCodes;
178
179/* Textual representations of the tokens. */
180
Damien Miller95def091999-11-25 00:26:21 +1100181static struct {
182 const char *name;
183 OpCodes opcode;
184} keywords[] = {
djm@openbsd.org381a2612017-01-30 00:38:50 +0000185 /* Deprecated options */
djm@openbsd.org99f95ba2017-04-30 23:11:45 +0000186 { "protocol", oIgnore }, /* NB. silently ignored */
djm@openbsd.orgcdccebd2017-04-30 23:15:04 +0000187 { "cipher", oDeprecated },
djm@openbsd.org381a2612017-01-30 00:38:50 +0000188 { "fallbacktorsh", oDeprecated },
189 { "globalknownhostsfile2", oDeprecated },
190 { "rhostsauthentication", oDeprecated },
191 { "userknownhostsfile2", oDeprecated },
192 { "useroaming", oDeprecated },
193 { "usersh", oDeprecated },
dtucker@openbsd.org95d41e92018-07-19 10:28:47 +0000194 { "useprivilegedport", oDeprecated },
djm@openbsd.org381a2612017-01-30 00:38:50 +0000195
196 /* Unsupported options */
197 { "afstokenpassing", oUnsupported },
198 { "kerberosauthentication", oUnsupported },
199 { "kerberostgtpassing", oUnsupported },
200
201 /* Sometimes-unsupported options */
202#if defined(GSSAPI)
203 { "gssapiauthentication", oGssAuthentication },
204 { "gssapidelegatecredentials", oGssDelegateCreds },
205# else
206 { "gssapiauthentication", oUnsupported },
207 { "gssapidelegatecredentials", oUnsupported },
208#endif
209#ifdef ENABLE_PKCS11
210 { "smartcarddevice", oPKCS11Provider },
211 { "pkcs11provider", oPKCS11Provider },
212# else
213 { "smartcarddevice", oUnsupported },
214 { "pkcs11provider", oUnsupported },
215#endif
djm@openbsd.org381a2612017-01-30 00:38:50 +0000216 { "rsaauthentication", oUnsupported },
217 { "rhostsrsaauthentication", oUnsupported },
218 { "compressionlevel", oUnsupported },
djm@openbsd.org381a2612017-01-30 00:38:50 +0000219
Damien Miller95def091999-11-25 00:26:21 +1100220 { "forwardagent", oForwardAgent },
221 { "forwardx11", oForwardX11 },
Darren Tucker0a118da2003-10-15 15:54:32 +1000222 { "forwardx11trusted", oForwardX11Trusted },
Damien Miller1ab6a512010-06-26 10:02:24 +1000223 { "forwardx11timeout", oForwardX11Timeout },
Darren Tuckere7d4b192006-07-12 22:17:10 +1000224 { "exitonforwardfailure", oExitOnForwardFailure },
Damien Millerd3a18572000-06-07 19:55:44 +1000225 { "xauthlocation", oXAuthLocation },
Damien Miller95def091999-11-25 00:26:21 +1100226 { "gatewayports", oGatewayPorts },
Damien Miller95def091999-11-25 00:26:21 +1100227 { "passwordauthentication", oPasswordAuthentication },
Damien Miller874d77b2000-10-14 16:23:11 +1100228 { "kbdinteractiveauthentication", oKbdInteractiveAuthentication },
229 { "kbdinteractivedevices", oKbdInteractiveDevices },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100230 { "pubkeyauthentication", oPubkeyAuthentication },
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000231 { "dsaauthentication", oPubkeyAuthentication }, /* alias */
Ben Lindstromd69dab32001-04-12 23:36:05 +0000232 { "hostbasedauthentication", oHostbasedAuthentication },
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000233 { "challengeresponseauthentication", oChallengeResponseAuthentication },
Damien Miller87f08be2018-07-20 13:18:28 +1000234 { "skeyauthentication", oUnsupported },
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000235 { "tisauthentication", oChallengeResponseAuthentication }, /* alias */
Damien Miller95def091999-11-25 00:26:21 +1100236 { "identityfile", oIdentityFile },
Damien Miller5bc6aae2009-01-28 16:27:31 +1100237 { "identityfile2", oIdentityFile }, /* obsolete */
Damien Millerbd394c32004-03-08 23:12:36 +1100238 { "identitiesonly", oIdentitiesOnly },
djm@openbsd.org4e44a792015-09-24 06:15:11 +0000239 { "certificatefile", oCertificateFile },
jcs@openbsd.orgf361df42015-11-15 22:26:49 +0000240 { "addkeystoagent", oAddKeysToAgent },
markus@openbsd.orgb02ad1c2016-05-04 12:21:53 +0000241 { "identityagent", oIdentityAgent },
Damien Miller95def091999-11-25 00:26:21 +1100242 { "hostname", oHostName },
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000243 { "hostkeyalias", oHostKeyAlias },
Damien Miller95def091999-11-25 00:26:21 +1100244 { "proxycommand", oProxyCommand },
245 { "port", oPort },
Damien Miller78928792000-04-12 20:17:38 +1000246 { "ciphers", oCiphers },
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000247 { "macs", oMacs },
Damien Miller95def091999-11-25 00:26:21 +1100248 { "remoteforward", oRemoteForward },
249 { "localforward", oLocalForward },
250 { "user", oUser },
251 { "host", oHost },
Damien Miller194fd902013-10-15 12:13:05 +1100252 { "match", oMatch },
Damien Miller95def091999-11-25 00:26:21 +1100253 { "escapechar", oEscapeChar },
Damien Miller95def091999-11-25 00:26:21 +1100254 { "globalknownhostsfile", oGlobalKnownHostsFile },
Damien Miller5bc6aae2009-01-28 16:27:31 +1100255 { "userknownhostsfile", oUserKnownHostsFile },
Damien Miller95def091999-11-25 00:26:21 +1100256 { "connectionattempts", oConnectionAttempts },
257 { "batchmode", oBatchMode },
258 { "checkhostip", oCheckHostIP },
259 { "stricthostkeychecking", oStrictHostKeyChecking },
260 { "compression", oCompression },
Damien Miller12c150e2003-12-17 16:31:10 +1100261 { "tcpkeepalive", oTCPKeepAlive },
262 { "keepalive", oTCPKeepAlive }, /* obsolete */
Damien Miller95def091999-11-25 00:26:21 +1100263 { "numberofpasswordprompts", oNumberOfPasswordPrompts },
dtucker@openbsd.org68d3a2a2017-04-28 03:20:27 +0000264 { "syslogfacility", oLogFacility },
Damien Miller95def091999-11-25 00:26:21 +1100265 { "loglevel", oLogLevel },
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000266 { "dynamicforward", oDynamicForward },
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000267 { "preferredauthentications", oPreferredAuthentications },
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000268 { "hostkeyalgorithms", oHostKeyAlgorithms },
djm@openbsd.orgecac7e12018-09-20 03:30:44 +0000269 { "casignaturealgorithms", oCASignatureAlgorithms },
Ben Lindstrome0f88042001-04-30 13:06:24 +0000270 { "bindaddress", oBindAddress },
djm@openbsd.orgac2e3022018-02-23 02:34:33 +0000271 { "bindinterface", oBindInterface },
Damien Miller9f0f5c62001-12-21 14:45:46 +1100272 { "clearallforwardings", oClearAllForwardings },
Ben Lindstromb6df73b2002-11-09 15:52:31 +0000273 { "enablesshkeysign", oEnableSSHKeysign },
Damien Miller37876e92003-05-15 10:19:46 +1000274 { "verifyhostkeydns", oVerifyHostKeyDNS },
Damien Miller9f0f5c62001-12-21 14:45:46 +1100275 { "nohostauthenticationforlocalhost", oNoHostAuthenticationForLocalhost },
Damien Millera5539d22003-04-09 20:50:06 +1000276 { "rekeylimit", oRekeyLimit },
Damien Millerb78d5eb2003-05-16 11:39:04 +1000277 { "connecttimeout", oConnectTimeout },
Damien Miller20a8f972003-05-18 20:50:30 +1000278 { "addressfamily", oAddressFamily },
Damien Miller509b0102003-12-17 16:33:10 +1100279 { "serveraliveinterval", oServerAliveInterval },
280 { "serveralivecountmax", oServerAliveCountMax },
Darren Tucker46bc0752004-05-02 22:11:30 +1000281 { "sendenv", oSendEnv },
djm@openbsd.org7082bb52018-06-09 03:01:12 +0000282 { "setenv", oSetEnv },
Damien Miller0e220db2004-06-15 10:34:08 +1000283 { "controlpath", oControlPath },
284 { "controlmaster", oControlMaster },
Damien Millere11e1ea2010-08-03 16:04:46 +1000285 { "controlpersist", oControlPersist },
Damien Millere1776152005-03-01 21:47:37 +1100286 { "hashknownhosts", oHashKnownHosts },
djm@openbsd.orgdc7990b2016-04-15 00:30:19 +0000287 { "include", oInclude },
Damien Millerd27b9472005-12-13 19:29:02 +1100288 { "tunnel", oTunnel },
289 { "tunneldevice", oTunnelDevice },
290 { "localcommand", oLocalCommand },
291 { "permitlocalcommand", oPermitLocalCommand },
bluhm@openbsd.org1112b532017-05-30 18:58:37 +0000292 { "remotecommand", oRemoteCommand },
Damien Miller10288242008-06-30 00:04:03 +1000293 { "visualhostkey", oVisualHostKey },
Damien Millerd5f62bf2010-09-24 22:11:14 +1000294 { "kexalgorithms", oKexAlgorithms },
Damien Miller0dac6fb2010-11-20 15:19:38 +1100295 { "ipqos", oIPQoS },
Damien Miller21771e22011-05-15 08:45:50 +1000296 { "requesttty", oRequestTTY },
Damien Miller1262b662013-08-21 02:44:24 +1000297 { "proxyusefdpass", oProxyUseFdpass },
Damien Miller0faf7472013-10-17 11:47:23 +1100298 { "canonicaldomains", oCanonicalDomains },
Damien Miller38505592013-10-17 11:48:13 +1100299 { "canonicalizefallbacklocal", oCanonicalizeFallbackLocal },
300 { "canonicalizehostname", oCanonicalizeHostname },
301 { "canonicalizemaxdots", oCanonicalizeMaxDots },
302 { "canonicalizepermittedcnames", oCanonicalizePermittedCNAMEs },
Damien Miller7acefbb2014-07-18 14:11:24 +1000303 { "streamlocalbindmask", oStreamLocalBindMask },
304 { "streamlocalbindunlink", oStreamLocalBindUnlink },
djm@openbsd.org5e39a492014-12-04 02:24:32 +0000305 { "revokedhostkeys", oRevokedHostKeys },
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000306 { "fingerprinthash", oFingerprintHash },
djm@openbsd.org8d4f8722015-01-26 03:04:45 +0000307 { "updatehostkeys", oUpdateHostkeys },
djm@openbsd.org46347ed2015-01-30 11:43:14 +0000308 { "hostbasedkeytypes", oHostbasedKeyTypes },
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000309 { "pubkeyacceptedkeytypes", oPubkeyAcceptedKeyTypes },
Darren Tucker07636982013-05-16 20:30:03 +1000310 { "ignoreunknown", oIgnoreUnknown },
djm@openbsd.orged877ef2016-07-15 00:24:30 +0000311 { "proxyjump", oProxyJump },
Damien Miller01ed2272008-11-05 16:20:46 +1100312
Ben Lindstrom65366a82001-12-06 16:32:47 +0000313 { NULL, oBadOption }
Damien Miller5ce662a1999-11-11 17:57:39 +1100314};
315
Damien Miller5428f641999-11-25 11:54:57 +1100316/*
317 * Adds a local TCP/IP port forward to options. Never returns if there is an
318 * error.
319 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000320
Damien Miller4af51302000-04-16 11:18:38 +1000321void
Damien Miller7acefbb2014-07-18 14:11:24 +1000322add_local_forward(Options *options, const struct Forward *newfwd)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000323{
Damien Miller7acefbb2014-07-18 14:11:24 +1000324 struct Forward *fwd;
Darren Tucker5f41f032016-04-08 21:14:13 +1000325 int i;
djm@openbsd.org0ccbd5e2016-04-06 06:42:17 +0000326
djm@openbsd.org0ccbd5e2016-04-06 06:42:17 +0000327 /* Don't add duplicates */
328 for (i = 0; i < options->num_local_forwards; i++) {
329 if (forward_equals(newfwd, options->local_forwards + i))
330 return;
331 }
deraadt@openbsd.org657a5fb2015-04-24 01:36:00 +0000332 options->local_forwards = xreallocarray(options->local_forwards,
Damien Miller232cfb12010-06-26 09:50:30 +1000333 options->num_local_forwards + 1,
334 sizeof(*options->local_forwards));
Damien Miller95def091999-11-25 00:26:21 +1100335 fwd = &options->local_forwards[options->num_local_forwards++];
Damien Millerf91ee4c2005-03-01 21:24:33 +1100336
Damien Miller1a0442f2008-11-05 16:30:06 +1100337 fwd->listen_host = newfwd->listen_host;
Damien Millerf91ee4c2005-03-01 21:24:33 +1100338 fwd->listen_port = newfwd->listen_port;
Damien Miller7acefbb2014-07-18 14:11:24 +1000339 fwd->listen_path = newfwd->listen_path;
Damien Miller1a0442f2008-11-05 16:30:06 +1100340 fwd->connect_host = newfwd->connect_host;
Damien Millerf91ee4c2005-03-01 21:24:33 +1100341 fwd->connect_port = newfwd->connect_port;
Damien Miller7acefbb2014-07-18 14:11:24 +1000342 fwd->connect_path = newfwd->connect_path;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000343}
344
Damien Miller5428f641999-11-25 11:54:57 +1100345/*
346 * Adds a remote TCP/IP port forward to options. Never returns if there is
347 * an error.
348 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000349
Damien Miller4af51302000-04-16 11:18:38 +1000350void
Damien Miller7acefbb2014-07-18 14:11:24 +1000351add_remote_forward(Options *options, const struct Forward *newfwd)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000352{
Damien Miller7acefbb2014-07-18 14:11:24 +1000353 struct Forward *fwd;
djm@openbsd.org0ccbd5e2016-04-06 06:42:17 +0000354 int i;
Damien Miller232cfb12010-06-26 09:50:30 +1000355
djm@openbsd.org0ccbd5e2016-04-06 06:42:17 +0000356 /* Don't add duplicates */
357 for (i = 0; i < options->num_remote_forwards; i++) {
358 if (forward_equals(newfwd, options->remote_forwards + i))
359 return;
360 }
deraadt@openbsd.org657a5fb2015-04-24 01:36:00 +0000361 options->remote_forwards = xreallocarray(options->remote_forwards,
Damien Miller232cfb12010-06-26 09:50:30 +1000362 options->num_remote_forwards + 1,
363 sizeof(*options->remote_forwards));
Damien Miller95def091999-11-25 00:26:21 +1100364 fwd = &options->remote_forwards[options->num_remote_forwards++];
Damien Millerf91ee4c2005-03-01 21:24:33 +1100365
Damien Miller1a0442f2008-11-05 16:30:06 +1100366 fwd->listen_host = newfwd->listen_host;
Damien Millerf91ee4c2005-03-01 21:24:33 +1100367 fwd->listen_port = newfwd->listen_port;
Damien Miller7acefbb2014-07-18 14:11:24 +1000368 fwd->listen_path = newfwd->listen_path;
Damien Miller1a0442f2008-11-05 16:30:06 +1100369 fwd->connect_host = newfwd->connect_host;
Damien Millerf91ee4c2005-03-01 21:24:33 +1100370 fwd->connect_port = newfwd->connect_port;
Damien Miller7acefbb2014-07-18 14:11:24 +1000371 fwd->connect_path = newfwd->connect_path;
Darren Tucker68afb8c2011-10-02 18:59:03 +1100372 fwd->handle = newfwd->handle;
Damien Miller388f6fc2010-05-21 14:57:35 +1000373 fwd->allocated_port = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000374}
375
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000376static void
377clear_forwardings(Options *options)
378{
379 int i;
380
Damien Millerf91ee4c2005-03-01 21:24:33 +1100381 for (i = 0; i < options->num_local_forwards; i++) {
Darren Tuckera627d422013-06-02 07:31:17 +1000382 free(options->local_forwards[i].listen_host);
Damien Miller7acefbb2014-07-18 14:11:24 +1000383 free(options->local_forwards[i].listen_path);
Darren Tuckera627d422013-06-02 07:31:17 +1000384 free(options->local_forwards[i].connect_host);
Damien Miller7acefbb2014-07-18 14:11:24 +1000385 free(options->local_forwards[i].connect_path);
Damien Millerf91ee4c2005-03-01 21:24:33 +1100386 }
Damien Miller232cfb12010-06-26 09:50:30 +1000387 if (options->num_local_forwards > 0) {
Darren Tuckera627d422013-06-02 07:31:17 +1000388 free(options->local_forwards);
Damien Miller232cfb12010-06-26 09:50:30 +1000389 options->local_forwards = NULL;
390 }
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000391 options->num_local_forwards = 0;
Damien Millerf91ee4c2005-03-01 21:24:33 +1100392 for (i = 0; i < options->num_remote_forwards; i++) {
Darren Tuckera627d422013-06-02 07:31:17 +1000393 free(options->remote_forwards[i].listen_host);
Damien Miller7acefbb2014-07-18 14:11:24 +1000394 free(options->remote_forwards[i].listen_path);
Darren Tuckera627d422013-06-02 07:31:17 +1000395 free(options->remote_forwards[i].connect_host);
Damien Miller7acefbb2014-07-18 14:11:24 +1000396 free(options->remote_forwards[i].connect_path);
Damien Millerf91ee4c2005-03-01 21:24:33 +1100397 }
Damien Miller232cfb12010-06-26 09:50:30 +1000398 if (options->num_remote_forwards > 0) {
Darren Tuckera627d422013-06-02 07:31:17 +1000399 free(options->remote_forwards);
Damien Miller232cfb12010-06-26 09:50:30 +1000400 options->remote_forwards = NULL;
401 }
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000402 options->num_remote_forwards = 0;
Damien Miller7b58e802005-12-13 19:33:19 +1100403 options->tun_open = SSH_TUNMODE_NO;
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000404}
405
Darren Tucker19104782013-04-05 11:13:08 +1100406void
djm@openbsd.org4e44a792015-09-24 06:15:11 +0000407add_certificate_file(Options *options, const char *path, int userprovided)
408{
409 int i;
410
411 if (options->num_certificate_files >= SSH_MAX_CERTIFICATE_FILES)
412 fatal("Too many certificate files specified (max %d)",
413 SSH_MAX_CERTIFICATE_FILES);
414
415 /* Avoid registering duplicates */
416 for (i = 0; i < options->num_certificate_files; i++) {
417 if (options->certificate_file_userprovided[i] == userprovided &&
418 strcmp(options->certificate_files[i], path) == 0) {
419 debug2("%s: ignoring duplicate key %s", __func__, path);
420 return;
421 }
422 }
423
424 options->certificate_file_userprovided[options->num_certificate_files] =
425 userprovided;
426 options->certificate_files[options->num_certificate_files++] =
427 xstrdup(path);
428}
429
430void
Darren Tucker19104782013-04-05 11:13:08 +1100431add_identity_file(Options *options, const char *dir, const char *filename,
432 int userprovided)
433{
434 char *path;
Damien Miller15271902014-05-15 13:47:56 +1000435 int i;
Darren Tucker19104782013-04-05 11:13:08 +1100436
437 if (options->num_identity_files >= SSH_MAX_IDENTITY_FILES)
438 fatal("Too many identity files specified (max %d)",
439 SSH_MAX_IDENTITY_FILES);
440
441 if (dir == NULL) /* no dir, filename is absolute */
442 path = xstrdup(filename);
djm@openbsd.org947a3e82017-05-20 02:35:47 +0000443 else if (xasprintf(&path, "%s%s", dir, filename) >= PATH_MAX)
444 fatal("Identity file path %s too long", path);
Darren Tucker19104782013-04-05 11:13:08 +1100445
Damien Miller15271902014-05-15 13:47:56 +1000446 /* Avoid registering duplicates */
447 for (i = 0; i < options->num_identity_files; i++) {
448 if (options->identity_file_userprovided[i] == userprovided &&
449 strcmp(options->identity_files[i], path) == 0) {
450 debug2("%s: ignoring duplicate key %s", __func__, path);
451 free(path);
452 return;
453 }
454 }
455
Darren Tucker19104782013-04-05 11:13:08 +1100456 options->identity_file_userprovided[options->num_identity_files] =
457 userprovided;
458 options->identity_files[options->num_identity_files++] = path;
459}
460
Damien Miller194fd902013-10-15 12:13:05 +1100461int
462default_ssh_port(void)
463{
464 static int port;
465 struct servent *sp;
466
467 if (port == 0) {
468 sp = getservbyname(SSH_SERVICE_NAME, "tcp");
469 port = sp ? ntohs(sp->s_port) : SSH_DEFAULT_PORT;
470 }
471 return port;
472}
473
474/*
475 * Execute a command in a shell.
476 * Return its exit status or -1 on abnormal exit.
477 */
478static int
479execute_in_shell(const char *cmd)
480{
dtucker@openbsd.org97e184e2015-10-25 23:14:03 +0000481 char *shell;
Damien Miller194fd902013-10-15 12:13:05 +1100482 pid_t pid;
483 int devnull, status;
Damien Miller194fd902013-10-15 12:13:05 +1100484
485 if ((shell = getenv("SHELL")) == NULL)
486 shell = _PATH_BSHELL;
487
Damien Miller194fd902013-10-15 12:13:05 +1100488 /* Need this to redirect subprocess stdin/out */
489 if ((devnull = open(_PATH_DEVNULL, O_RDWR)) == -1)
490 fatal("open(/dev/null): %s", strerror(errno));
491
492 debug("Executing command: '%.500s'", cmd);
493
494 /* Fork and execute the command. */
495 if ((pid = fork()) == 0) {
djm@openbsd.orga4aef3e2015-10-27 08:54:52 +0000496 char *argv[4];
Damien Miller194fd902013-10-15 12:13:05 +1100497
Damien Miller194fd902013-10-15 12:13:05 +1100498 /* Redirect child stdin and stdout. Leave stderr */
499 if (dup2(devnull, STDIN_FILENO) == -1)
500 fatal("dup2: %s", strerror(errno));
501 if (dup2(devnull, STDOUT_FILENO) == -1)
502 fatal("dup2: %s", strerror(errno));
503 if (devnull > STDERR_FILENO)
504 close(devnull);
505 closefrom(STDERR_FILENO + 1);
506
djm@openbsd.orga4aef3e2015-10-27 08:54:52 +0000507 argv[0] = shell;
508 argv[1] = "-c";
509 argv[2] = xstrdup(cmd);
510 argv[3] = NULL;
511
Damien Miller194fd902013-10-15 12:13:05 +1100512 execv(argv[0], argv);
513 error("Unable to execute '%.100s': %s", cmd, strerror(errno));
514 /* Die with signal to make this error apparent to parent. */
515 signal(SIGTERM, SIG_DFL);
516 kill(getpid(), SIGTERM);
517 _exit(1);
518 }
519 /* Parent. */
520 if (pid < 0)
521 fatal("%s: fork: %.100s", __func__, strerror(errno));
522
523 close(devnull);
Damien Miller194fd902013-10-15 12:13:05 +1100524
525 while (waitpid(pid, &status, 0) == -1) {
526 if (errno != EINTR && errno != EAGAIN)
527 fatal("%s: waitpid: %s", __func__, strerror(errno));
528 }
529 if (!WIFEXITED(status)) {
530 error("command '%.100s' exited abnormally", cmd);
531 return -1;
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000532 }
Damien Miller194fd902013-10-15 12:13:05 +1100533 debug3("command returned status %d", WEXITSTATUS(status));
534 return WEXITSTATUS(status);
535}
536
537/*
538 * Parse and execute a Match directive.
539 */
540static int
541match_cfg_line(Options *options, char **condition, struct passwd *pw,
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000542 const char *host_arg, const char *original_host, int post_canon,
543 const char *filename, int linenum)
Damien Miller194fd902013-10-15 12:13:05 +1100544{
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000545 char *arg, *oattrib, *attrib, *cmd, *cp = *condition, *host, *criteria;
Damien Miller084bcd22013-10-23 16:30:51 +1100546 const char *ruser;
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000547 int r, port, this_result, result = 1, attributes = 0, negate;
Damien Miller194fd902013-10-15 12:13:05 +1100548 char thishost[NI_MAXHOST], shorthost[NI_MAXHOST], portstr[NI_MAXSERV];
djm@openbsd.org9c935dd2018-06-01 03:33:53 +0000549 char uidstr[32];
Damien Miller194fd902013-10-15 12:13:05 +1100550
551 /*
552 * Configuration is likely to be incomplete at this point so we
553 * must be prepared to use default values.
554 */
555 port = options->port <= 0 ? default_ssh_port() : options->port;
556 ruser = options->user == NULL ? pw->pw_name : options->user;
djm@openbsd.org5a622842016-02-08 23:40:12 +0000557 if (post_canon) {
558 host = xstrdup(options->hostname);
559 } else if (options->hostname != NULL) {
Damien Millereff5cad2013-10-23 16:31:10 +1100560 /* NB. Please keep in sync with ssh.c:main() */
Damien Miller084bcd22013-10-23 16:30:51 +1100561 host = percent_expand(options->hostname,
562 "h", host_arg, (char *)NULL);
djm@openbsd.org5a622842016-02-08 23:40:12 +0000563 } else {
Damien Miller084bcd22013-10-23 16:30:51 +1100564 host = xstrdup(host_arg);
djm@openbsd.org5a622842016-02-08 23:40:12 +0000565 }
Damien Miller194fd902013-10-15 12:13:05 +1100566
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000567 debug2("checking match for '%s' host %s originally %s",
568 cp, host, original_host);
569 while ((oattrib = attrib = strdelim(&cp)) && *attrib != '\0') {
570 criteria = NULL;
571 this_result = 1;
572 if ((negate = attrib[0] == '!'))
573 attrib++;
574 /* criteria "all" and "canonical" have no argument */
Damien Millercf31f382013-10-24 21:02:56 +1100575 if (strcasecmp(attrib, "all") == 0) {
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000576 if (attributes > 1 ||
Damien Millercf31f382013-10-24 21:02:56 +1100577 ((arg = strdelim(&cp)) != NULL && *arg != '\0')) {
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000578 error("%.200s line %d: '%s' cannot be combined "
579 "with other Match attributes",
580 filename, linenum, oattrib);
Damien Millercf31f382013-10-24 21:02:56 +1100581 result = -1;
582 goto out;
583 }
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000584 if (result)
585 result = negate ? 0 : 1;
Damien Millercf31f382013-10-24 21:02:56 +1100586 goto out;
587 }
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000588 attributes++;
589 if (strcasecmp(attrib, "canonical") == 0) {
590 r = !!post_canon; /* force bitmask member to boolean */
591 if (r == (negate ? 1 : 0))
592 this_result = result = 0;
593 debug3("%.200s line %d: %smatched '%s'",
594 filename, linenum,
595 this_result ? "" : "not ", oattrib);
596 continue;
597 }
598 /* All other criteria require an argument */
Damien Miller194fd902013-10-15 12:13:05 +1100599 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
600 error("Missing Match criteria for %s", attrib);
Damien Miller084bcd22013-10-23 16:30:51 +1100601 result = -1;
602 goto out;
Damien Miller194fd902013-10-15 12:13:05 +1100603 }
Damien Miller194fd902013-10-15 12:13:05 +1100604 if (strcasecmp(attrib, "host") == 0) {
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000605 criteria = xstrdup(host);
djm@openbsd.orge661a862015-05-04 06:10:48 +0000606 r = match_hostname(host, arg) == 1;
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000607 if (r == (negate ? 1 : 0))
608 this_result = result = 0;
Damien Miller194fd902013-10-15 12:13:05 +1100609 } else if (strcasecmp(attrib, "originalhost") == 0) {
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000610 criteria = xstrdup(original_host);
djm@openbsd.orge661a862015-05-04 06:10:48 +0000611 r = match_hostname(original_host, arg) == 1;
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000612 if (r == (negate ? 1 : 0))
613 this_result = result = 0;
Damien Miller194fd902013-10-15 12:13:05 +1100614 } else if (strcasecmp(attrib, "user") == 0) {
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000615 criteria = xstrdup(ruser);
djm@openbsd.orge661a862015-05-04 06:10:48 +0000616 r = match_pattern_list(ruser, arg, 0) == 1;
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000617 if (r == (negate ? 1 : 0))
618 this_result = result = 0;
Damien Miller194fd902013-10-15 12:13:05 +1100619 } else if (strcasecmp(attrib, "localuser") == 0) {
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000620 criteria = xstrdup(pw->pw_name);
djm@openbsd.orge661a862015-05-04 06:10:48 +0000621 r = match_pattern_list(pw->pw_name, arg, 0) == 1;
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000622 if (r == (negate ? 1 : 0))
623 this_result = result = 0;
Damien Miller8a04be72013-10-23 16:29:40 +1100624 } else if (strcasecmp(attrib, "exec") == 0) {
Damien Miller194fd902013-10-15 12:13:05 +1100625 if (gethostname(thishost, sizeof(thishost)) == -1)
626 fatal("gethostname: %s", strerror(errno));
627 strlcpy(shorthost, thishost, sizeof(shorthost));
628 shorthost[strcspn(thishost, ".")] = '\0';
629 snprintf(portstr, sizeof(portstr), "%d", port);
djm@openbsd.org9c935dd2018-06-01 03:33:53 +0000630 snprintf(uidstr, sizeof(uidstr), "%llu",
631 (unsigned long long)pw->pw_uid);
Damien Miller194fd902013-10-15 12:13:05 +1100632
633 cmd = percent_expand(arg,
634 "L", shorthost,
635 "d", pw->pw_dir,
636 "h", host,
637 "l", thishost,
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000638 "n", original_host,
Damien Miller194fd902013-10-15 12:13:05 +1100639 "p", portstr,
640 "r", ruser,
641 "u", pw->pw_name,
djm@openbsd.org9c935dd2018-06-01 03:33:53 +0000642 "i", uidstr,
Damien Miller194fd902013-10-15 12:13:05 +1100643 (char *)NULL);
Damien Miller06287802014-02-24 15:56:45 +1100644 if (result != 1) {
645 /* skip execution if prior predicate failed */
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000646 debug3("%.200s line %d: skipped exec "
647 "\"%.100s\"", filename, linenum, cmd);
648 free(cmd);
649 continue;
Damien Miller06287802014-02-24 15:56:45 +1100650 }
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000651 r = execute_in_shell(cmd);
652 if (r == -1) {
653 fatal("%.200s line %d: match exec "
654 "'%.100s' error", filename,
655 linenum, cmd);
656 }
657 criteria = xstrdup(cmd);
Damien Miller194fd902013-10-15 12:13:05 +1100658 free(cmd);
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000659 /* Force exit status to boolean */
660 r = r == 0;
661 if (r == (negate ? 1 : 0))
662 this_result = result = 0;
Damien Miller194fd902013-10-15 12:13:05 +1100663 } else {
664 error("Unsupported Match attribute %s", attrib);
Damien Miller084bcd22013-10-23 16:30:51 +1100665 result = -1;
666 goto out;
Damien Miller194fd902013-10-15 12:13:05 +1100667 }
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000668 debug3("%.200s line %d: %smatched '%s \"%.100s\"' ",
669 filename, linenum, this_result ? "": "not ",
670 oattrib, criteria);
671 free(criteria);
Damien Miller194fd902013-10-15 12:13:05 +1100672 }
Damien Millercf31f382013-10-24 21:02:56 +1100673 if (attributes == 0) {
674 error("One or more attributes required for Match");
675 result = -1;
676 goto out;
677 }
Damien Miller084bcd22013-10-23 16:30:51 +1100678 out:
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000679 if (result != -1)
680 debug2("match %sfound", result ? "" : "not ");
681 *condition = cp;
Damien Miller084bcd22013-10-23 16:30:51 +1100682 free(host);
Damien Miller194fd902013-10-15 12:13:05 +1100683 return result;
684}
685
djm@openbsd.org555294a2018-04-06 13:02:39 +0000686/* Remove environment variable by pattern */
687static void
688rm_env(Options *options, const char *arg, const char *filename, int linenum)
689{
690 int i, j;
691 char *cp;
692
693 /* Remove an environment variable */
694 for (i = 0; i < options->num_send_env; ) {
695 cp = xstrdup(options->send_env[i]);
696 if (!match_pattern(cp, arg + 1)) {
697 free(cp);
698 i++;
699 continue;
700 }
701 debug3("%s line %d: removing environment %s",
702 filename, linenum, cp);
703 free(cp);
704 free(options->send_env[i]);
705 options->send_env[i] = NULL;
706 for (j = i; j < options->num_send_env - 1; j++) {
707 options->send_env[j] = options->send_env[j + 1];
708 options->send_env[j + 1] = NULL;
709 }
710 options->num_send_env--;
711 /* NB. don't increment i */
712 }
713}
714
Damien Miller5428f641999-11-25 11:54:57 +1100715/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000716 * Returns the number of the token pointed to by cp or oBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100717 */
Damien Miller4af51302000-04-16 11:18:38 +1000718static OpCodes
Darren Tucker07636982013-05-16 20:30:03 +1000719parse_token(const char *cp, const char *filename, int linenum,
720 const char *ignored_unknown)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000721{
Darren Tucker07636982013-05-16 20:30:03 +1000722 int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000723
Damien Miller95def091999-11-25 00:26:21 +1100724 for (i = 0; keywords[i].name; i++)
Darren Tucker07636982013-05-16 20:30:03 +1000725 if (strcmp(cp, keywords[i].name) == 0)
Damien Miller95def091999-11-25 00:26:21 +1100726 return keywords[i].opcode;
djm@openbsd.orge661a862015-05-04 06:10:48 +0000727 if (ignored_unknown != NULL &&
728 match_pattern_list(cp, ignored_unknown, 1) == 1)
Darren Tucker07636982013-05-16 20:30:03 +1000729 return oIgnoredUnknownOption;
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000730 error("%s: line %d: Bad configuration option: %s",
731 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100732 return oBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000733}
734
Damien Millere9fc72e2013-10-15 12:14:12 +1100735/* Multistate option parsing */
736struct multistate {
737 char *key;
738 int value;
739};
740static const struct multistate multistate_flag[] = {
741 { "true", 1 },
742 { "false", 0 },
743 { "yes", 1 },
744 { "no", 0 },
745 { NULL, -1 }
746};
747static const struct multistate multistate_yesnoask[] = {
748 { "true", 1 },
749 { "false", 0 },
750 { "yes", 1 },
751 { "no", 0 },
752 { "ask", 2 },
753 { NULL, -1 }
754};
djm@openbsd.org22376d22017-09-03 23:33:13 +0000755static const struct multistate multistate_strict_hostkey[] = {
756 { "true", SSH_STRICT_HOSTKEY_YES },
757 { "false", SSH_STRICT_HOSTKEY_OFF },
758 { "yes", SSH_STRICT_HOSTKEY_YES },
759 { "no", SSH_STRICT_HOSTKEY_OFF },
760 { "ask", SSH_STRICT_HOSTKEY_ASK },
761 { "off", SSH_STRICT_HOSTKEY_OFF },
762 { "accept-new", SSH_STRICT_HOSTKEY_NEW },
763 { NULL, -1 }
764};
jcs@openbsd.orgf361df42015-11-15 22:26:49 +0000765static const struct multistate multistate_yesnoaskconfirm[] = {
766 { "true", 1 },
767 { "false", 0 },
768 { "yes", 1 },
769 { "no", 0 },
770 { "ask", 2 },
771 { "confirm", 3 },
772 { NULL, -1 }
773};
Damien Millere9fc72e2013-10-15 12:14:12 +1100774static const struct multistate multistate_addressfamily[] = {
775 { "inet", AF_INET },
776 { "inet6", AF_INET6 },
777 { "any", AF_UNSPEC },
778 { NULL, -1 }
779};
780static const struct multistate multistate_controlmaster[] = {
781 { "true", SSHCTL_MASTER_YES },
782 { "yes", SSHCTL_MASTER_YES },
783 { "false", SSHCTL_MASTER_NO },
784 { "no", SSHCTL_MASTER_NO },
785 { "auto", SSHCTL_MASTER_AUTO },
786 { "ask", SSHCTL_MASTER_ASK },
787 { "autoask", SSHCTL_MASTER_AUTO_ASK },
788 { NULL, -1 }
789};
790static const struct multistate multistate_tunnel[] = {
791 { "ethernet", SSH_TUNMODE_ETHERNET },
792 { "point-to-point", SSH_TUNMODE_POINTOPOINT },
793 { "true", SSH_TUNMODE_DEFAULT },
794 { "yes", SSH_TUNMODE_DEFAULT },
795 { "false", SSH_TUNMODE_NO },
796 { "no", SSH_TUNMODE_NO },
797 { NULL, -1 }
798};
799static const struct multistate multistate_requesttty[] = {
800 { "true", REQUEST_TTY_YES },
801 { "yes", REQUEST_TTY_YES },
802 { "false", REQUEST_TTY_NO },
803 { "no", REQUEST_TTY_NO },
804 { "force", REQUEST_TTY_FORCE },
805 { "auto", REQUEST_TTY_AUTO },
806 { NULL, -1 }
807};
Damien Miller38505592013-10-17 11:48:13 +1100808static const struct multistate multistate_canonicalizehostname[] = {
Damien Miller0faf7472013-10-17 11:47:23 +1100809 { "true", SSH_CANONICALISE_YES },
810 { "false", SSH_CANONICALISE_NO },
811 { "yes", SSH_CANONICALISE_YES },
812 { "no", SSH_CANONICALISE_NO },
813 { "always", SSH_CANONICALISE_ALWAYS },
814 { NULL, -1 }
815};
Damien Millere9fc72e2013-10-15 12:14:12 +1100816
Damien Miller5428f641999-11-25 11:54:57 +1100817/*
818 * Processes a single option line as used in the configuration files. This
819 * only sets those values that have not already been set.
820 */
Damien Miller2ccf6611999-11-15 15:25:10 +1100821int
Damien Miller194fd902013-10-15 12:13:05 +1100822process_config_line(Options *options, struct passwd *pw, const char *host,
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000823 const char *original_host, char *line, const char *filename,
824 int linenum, int *activep, int flags)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000825{
djm@openbsd.orgdc7990b2016-04-15 00:30:19 +0000826 return process_config_line_depth(options, pw, host, original_host,
827 line, filename, linenum, activep, flags, 0);
828}
829
830#define WHITESPACE " \t\r\n"
831static int
832process_config_line_depth(Options *options, struct passwd *pw, const char *host,
833 const char *original_host, char *line, const char *filename,
834 int linenum, int *activep, int flags, int depth)
835{
Damien Miller295ee632011-05-29 21:42:31 +1000836 char *s, **charptr, *endofnumber, *keyword, *arg, *arg2;
837 char **cpptr, fwdarg[256];
Darren Tucker07636982013-05-16 20:30:03 +1000838 u_int i, *uintptr, max_entries = 0;
djm@openbsd.orgdc7990b2016-04-15 00:30:19 +0000839 int r, oactive, negated, opcode, *intptr, value, value2, cmdline = 0;
markus@openbsd.org609d7a62017-09-21 19:16:53 +0000840 int remotefwd, dynamicfwd;
Darren Tucker1e44c5d2008-01-01 20:32:26 +1100841 LogLevel *log_level_ptr;
dtucker@openbsd.org68d3a2a2017-04-28 03:20:27 +0000842 SyslogFacility *log_facility_ptr;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000843 long long val64;
Damien Miller61f08ac2003-02-24 11:56:27 +1100844 size_t len;
Damien Miller7acefbb2014-07-18 14:11:24 +1000845 struct Forward fwd;
Damien Millere9fc72e2013-10-15 12:14:12 +1100846 const struct multistate *multistate_ptr;
Damien Miller0faf7472013-10-17 11:47:23 +1100847 struct allowed_cname *cname;
djm@openbsd.orgdc7990b2016-04-15 00:30:19 +0000848 glob_t gl;
dtucker@openbsd.org609d96b2017-12-05 23:59:47 +0000849 const char *errstr;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000850
Damien Miller194fd902013-10-15 12:13:05 +1100851 if (activep == NULL) { /* We are processing a command line directive */
852 cmdline = 1;
853 activep = &cmdline;
854 }
855
djm@openbsd.orgc924b2e2017-02-03 05:05:56 +0000856 /* Strip trailing whitespace. Allow \f (form feed) at EOL only */
djm@openbsd.org26e0bcf2015-03-30 00:00:29 +0000857 if ((len = strlen(line)) == 0)
858 return 0;
859 for (len--; len > 0; len--) {
djm@openbsd.orgc924b2e2017-02-03 05:05:56 +0000860 if (strchr(WHITESPACE "\f", line[len]) == NULL)
Damien Millerc652cac2003-05-14 13:40:54 +1000861 break;
862 line[len] = '\0';
863 }
864
Damien Millerbe484b52000-07-15 14:14:16 +1000865 s = line;
866 /* Get the keyword. (Each line is supposed to begin with a keyword). */
Damien Miller928b2362006-03-26 13:53:32 +1100867 if ((keyword = strdelim(&s)) == NULL)
868 return 0;
Damien Millerbe484b52000-07-15 14:14:16 +1000869 /* Ignore leading whitespace. */
870 if (*keyword == '\0')
871 keyword = strdelim(&s);
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000872 if (keyword == NULL || !*keyword || *keyword == '\n' || *keyword == '#')
Damien Miller95def091999-11-25 00:26:21 +1100873 return 0;
Darren Tucker07636982013-05-16 20:30:03 +1000874 /* Match lowercase keyword */
Damien Millere9fc72e2013-10-15 12:14:12 +1100875 lowercase(keyword);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000876
Darren Tucker07636982013-05-16 20:30:03 +1000877 opcode = parse_token(keyword, filename, linenum,
878 options->ignored_unknown);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000879
Damien Miller95def091999-11-25 00:26:21 +1100880 switch (opcode) {
881 case oBadOption:
Damien Miller5428f641999-11-25 11:54:57 +1100882 /* don't panic, but count bad options */
883 return -1;
djm@openbsd.org99f95ba2017-04-30 23:11:45 +0000884 case oIgnore:
885 return 0;
Darren Tucker07636982013-05-16 20:30:03 +1000886 case oIgnoredUnknownOption:
887 debug("%s line %d: Ignored unknown option \"%s\"",
888 filename, linenum, keyword);
889 return 0;
Damien Millerb78d5eb2003-05-16 11:39:04 +1000890 case oConnectTimeout:
891 intptr = &options->connection_timeout;
Damien Miller509b0102003-12-17 16:33:10 +1100892parse_time:
Damien Millerb78d5eb2003-05-16 11:39:04 +1000893 arg = strdelim(&s);
894 if (!arg || *arg == '\0')
895 fatal("%s line %d: missing time value.",
896 filename, linenum);
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000897 if (strcmp(arg, "none") == 0)
898 value = -1;
899 else if ((value = convtime(arg)) == -1)
Damien Millerb78d5eb2003-05-16 11:39:04 +1000900 fatal("%s line %d: invalid time value.",
901 filename, linenum);
Darren Tuckera52c5b62007-02-19 22:09:45 +1100902 if (*activep && *intptr == -1)
Damien Millerb78d5eb2003-05-16 11:39:04 +1000903 *intptr = value;
904 break;
905
Damien Miller95def091999-11-25 00:26:21 +1100906 case oForwardAgent:
907 intptr = &options->forward_agent;
Damien Millere9fc72e2013-10-15 12:14:12 +1100908 parse_flag:
909 multistate_ptr = multistate_flag;
910 parse_multistate:
Damien Millerbe484b52000-07-15 14:14:16 +1000911 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000912 if (!arg || *arg == '\0')
Damien Millere9fc72e2013-10-15 12:14:12 +1100913 fatal("%s line %d: missing argument.",
914 filename, linenum);
915 value = -1;
916 for (i = 0; multistate_ptr[i].key != NULL; i++) {
917 if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
918 value = multistate_ptr[i].value;
919 break;
920 }
921 }
922 if (value == -1)
923 fatal("%s line %d: unsupported option \"%s\".",
924 filename, linenum, arg);
Damien Miller95def091999-11-25 00:26:21 +1100925 if (*activep && *intptr == -1)
926 *intptr = value;
927 break;
928
929 case oForwardX11:
930 intptr = &options->forward_x11;
931 goto parse_flag;
932
Darren Tucker0a118da2003-10-15 15:54:32 +1000933 case oForwardX11Trusted:
934 intptr = &options->forward_x11_trusted;
935 goto parse_flag;
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000936
Damien Miller1ab6a512010-06-26 10:02:24 +1000937 case oForwardX11Timeout:
938 intptr = &options->forward_x11_timeout;
939 goto parse_time;
Darren Tucker0a118da2003-10-15 15:54:32 +1000940
Damien Miller95def091999-11-25 00:26:21 +1100941 case oGatewayPorts:
Damien Miller7acefbb2014-07-18 14:11:24 +1000942 intptr = &options->fwd_opts.gateway_ports;
Damien Miller95def091999-11-25 00:26:21 +1100943 goto parse_flag;
944
Darren Tuckere7d4b192006-07-12 22:17:10 +1000945 case oExitOnForwardFailure:
946 intptr = &options->exit_on_forward_failure;
947 goto parse_flag;
948
Damien Miller95def091999-11-25 00:26:21 +1100949 case oPasswordAuthentication:
950 intptr = &options->password_authentication;
951 goto parse_flag;
952
Damien Miller874d77b2000-10-14 16:23:11 +1100953 case oKbdInteractiveAuthentication:
954 intptr = &options->kbd_interactive_authentication;
955 goto parse_flag;
956
957 case oKbdInteractiveDevices:
958 charptr = &options->kbd_interactive_devices;
959 goto parse_string;
960
Damien Miller0bc1bd82000-11-13 22:57:25 +1100961 case oPubkeyAuthentication:
962 intptr = &options->pubkey_authentication;
Damien Millere247cc42000-05-07 12:03:14 +1000963 goto parse_flag;
964
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000965 case oHostbasedAuthentication:
966 intptr = &options->hostbased_authentication;
967 goto parse_flag;
968
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000969 case oChallengeResponseAuthentication:
Ben Lindstrom551ea372001-06-05 18:56:16 +0000970 intptr = &options->challenge_response_authentication;
Damien Miller95def091999-11-25 00:26:21 +1100971 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000972
Darren Tucker0efd1552003-08-26 11:49:55 +1000973 case oGssAuthentication:
974 intptr = &options->gss_authentication;
975 goto parse_flag;
976
977 case oGssDelegateCreds:
978 intptr = &options->gss_deleg_creds;
979 goto parse_flag;
980
Damien Miller95def091999-11-25 00:26:21 +1100981 case oBatchMode:
982 intptr = &options->batch_mode;
983 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000984
Damien Miller95def091999-11-25 00:26:21 +1100985 case oCheckHostIP:
986 intptr = &options->check_host_ip;
Damien Miller10288242008-06-30 00:04:03 +1000987 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000988
Damien Miller37876e92003-05-15 10:19:46 +1000989 case oVerifyHostKeyDNS:
990 intptr = &options->verify_host_key_dns;
Damien Millere9fc72e2013-10-15 12:14:12 +1100991 multistate_ptr = multistate_yesnoask;
992 goto parse_multistate;
Damien Miller37876e92003-05-15 10:19:46 +1000993
Damien Miller95def091999-11-25 00:26:21 +1100994 case oStrictHostKeyChecking:
995 intptr = &options->strict_host_key_checking;
djm@openbsd.org22376d22017-09-03 23:33:13 +0000996 multistate_ptr = multistate_strict_hostkey;
Damien Millere9fc72e2013-10-15 12:14:12 +1100997 goto parse_multistate;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000998
Damien Miller95def091999-11-25 00:26:21 +1100999 case oCompression:
1000 intptr = &options->compression;
1001 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001002
Damien Miller12c150e2003-12-17 16:31:10 +11001003 case oTCPKeepAlive:
1004 intptr = &options->tcp_keep_alive;
Damien Miller95def091999-11-25 00:26:21 +11001005 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001006
Ben Lindstrom3cecc9a2001-10-03 17:39:38 +00001007 case oNoHostAuthenticationForLocalhost:
1008 intptr = &options->no_host_authentication_for_localhost;
1009 goto parse_flag;
1010
Damien Miller95def091999-11-25 00:26:21 +11001011 case oNumberOfPasswordPrompts:
1012 intptr = &options->number_of_password_prompts;
1013 goto parse_int;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001014
Damien Millera5539d22003-04-09 20:50:06 +10001015 case oRekeyLimit:
Damien Millera5539d22003-04-09 20:50:06 +10001016 arg = strdelim(&s);
1017 if (!arg || *arg == '\0')
Darren Tuckerc53c2af2013-05-16 20:28:16 +10001018 fatal("%.200s line %d: Missing argument.", filename,
1019 linenum);
1020 if (strcmp(arg, "default") == 0) {
1021 val64 = 0;
1022 } else {
Darren Tuckerb7ee8522013-05-16 20:33:10 +10001023 if (scan_scaled(arg, &val64) == -1)
1024 fatal("%.200s line %d: Bad number '%s': %s",
1025 filename, linenum, arg, strerror(errno));
Darren Tuckerc53c2af2013-05-16 20:28:16 +10001026 if (val64 != 0 && val64 < 16)
1027 fatal("%.200s line %d: RekeyLimit too small",
1028 filename, linenum);
Damien Millera5539d22003-04-09 20:50:06 +10001029 }
Damien Miller3dff1762008-02-10 22:25:52 +11001030 if (*activep && options->rekey_limit == -1)
dtucker@openbsd.org921ff002016-01-29 02:54:45 +00001031 options->rekey_limit = val64;
Darren Tuckerc53c2af2013-05-16 20:28:16 +10001032 if (s != NULL) { /* optional rekey interval present */
1033 if (strcmp(s, "none") == 0) {
1034 (void)strdelim(&s); /* discard */
1035 break;
1036 }
1037 intptr = &options->rekey_interval;
1038 goto parse_time;
1039 }
Damien Millera5539d22003-04-09 20:50:06 +10001040 break;
1041
Damien Miller95def091999-11-25 00:26:21 +11001042 case oIdentityFile:
Damien Millerbe484b52000-07-15 14:14:16 +10001043 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +10001044 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +11001045 fatal("%.200s line %d: Missing argument.", filename, linenum);
1046 if (*activep) {
Damien Miller0bc1bd82000-11-13 22:57:25 +11001047 intptr = &options->num_identity_files;
Damien Millereba71ba2000-04-29 23:57:08 +10001048 if (*intptr >= SSH_MAX_IDENTITY_FILES)
Damien Miller95def091999-11-25 00:26:21 +11001049 fatal("%.200s line %d: Too many identity files specified (max %d).",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001050 filename, linenum, SSH_MAX_IDENTITY_FILES);
djm@openbsd.org957fbce2014-10-08 22:20:25 +00001051 add_identity_file(options, NULL,
1052 arg, flags & SSHCONF_USERCONF);
Damien Miller95def091999-11-25 00:26:21 +11001053 }
1054 break;
1055
djm@openbsd.org4e44a792015-09-24 06:15:11 +00001056 case oCertificateFile:
1057 arg = strdelim(&s);
1058 if (!arg || *arg == '\0')
1059 fatal("%.200s line %d: Missing argument.",
1060 filename, linenum);
1061 if (*activep) {
1062 intptr = &options->num_certificate_files;
1063 if (*intptr >= SSH_MAX_CERTIFICATE_FILES) {
1064 fatal("%.200s line %d: Too many certificate "
1065 "files specified (max %d).",
1066 filename, linenum,
1067 SSH_MAX_CERTIFICATE_FILES);
1068 }
1069 add_certificate_file(options, arg,
1070 flags & SSHCONF_USERCONF);
1071 }
1072 break;
1073
Damien Millerd3a18572000-06-07 19:55:44 +10001074 case oXAuthLocation:
1075 charptr=&options->xauth_location;
1076 goto parse_string;
1077
Damien Miller95def091999-11-25 00:26:21 +11001078 case oUser:
1079 charptr = &options->user;
1080parse_string:
Damien Millerbe484b52000-07-15 14:14:16 +10001081 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +10001082 if (!arg || *arg == '\0')
Damien Miller295ee632011-05-29 21:42:31 +10001083 fatal("%.200s line %d: Missing argument.",
1084 filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +11001085 if (*activep && *charptr == NULL)
Damien Miller37023962000-07-11 17:31:38 +10001086 *charptr = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +11001087 break;
1088
1089 case oGlobalKnownHostsFile:
Damien Miller295ee632011-05-29 21:42:31 +10001090 cpptr = (char **)&options->system_hostfiles;
1091 uintptr = &options->num_system_hostfiles;
1092 max_entries = SSH_MAX_HOSTS_FILES;
1093parse_char_array:
1094 if (*activep && *uintptr == 0) {
1095 while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1096 if ((*uintptr) >= max_entries)
1097 fatal("%s line %d: "
1098 "too many authorized keys files.",
1099 filename, linenum);
1100 cpptr[(*uintptr)++] = xstrdup(arg);
1101 }
1102 }
1103 return 0;
Damien Miller95def091999-11-25 00:26:21 +11001104
1105 case oUserKnownHostsFile:
Damien Miller295ee632011-05-29 21:42:31 +10001106 cpptr = (char **)&options->user_hostfiles;
1107 uintptr = &options->num_user_hostfiles;
1108 max_entries = SSH_MAX_HOSTS_FILES;
1109 goto parse_char_array;
Damien Millereba71ba2000-04-29 23:57:08 +10001110
Damien Miller95def091999-11-25 00:26:21 +11001111 case oHostName:
1112 charptr = &options->hostname;
1113 goto parse_string;
1114
Ben Lindstrom4dccfa52000-12-28 16:40:05 +00001115 case oHostKeyAlias:
1116 charptr = &options->host_key_alias;
1117 goto parse_string;
1118
Ben Lindstromb9be60a2001-03-11 01:49:19 +00001119 case oPreferredAuthentications:
1120 charptr = &options->preferred_authentications;
1121 goto parse_string;
1122
Ben Lindstrome0f88042001-04-30 13:06:24 +00001123 case oBindAddress:
1124 charptr = &options->bind_address;
1125 goto parse_string;
1126
djm@openbsd.orgac2e3022018-02-23 02:34:33 +00001127 case oBindInterface:
1128 charptr = &options->bind_interface;
1129 goto parse_string;
1130
Damien Miller7ea845e2010-02-12 09:21:02 +11001131 case oPKCS11Provider:
1132 charptr = &options->pkcs11_provider;
Ben Lindstromf7db3bb2001-08-06 21:35:51 +00001133 goto parse_string;
Ben Lindstromae996bf2001-08-06 21:27:53 +00001134
Damien Miller95def091999-11-25 00:26:21 +11001135 case oProxyCommand:
Damien Millerd27b9472005-12-13 19:29:02 +11001136 charptr = &options->proxy_command;
djm@openbsd.orged877ef2016-07-15 00:24:30 +00001137 /* Ignore ProxyCommand if ProxyJump already specified */
1138 if (options->jump_host != NULL)
1139 charptr = &options->jump_host; /* Skip below */
Damien Millerd27b9472005-12-13 19:29:02 +11001140parse_command:
Darren Tuckera99c1b72003-06-28 12:40:12 +10001141 if (s == NULL)
1142 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller61f08ac2003-02-24 11:56:27 +11001143 len = strspn(s, WHITESPACE "=");
Damien Miller95def091999-11-25 00:26:21 +11001144 if (*activep && *charptr == NULL)
Damien Miller61f08ac2003-02-24 11:56:27 +11001145 *charptr = xstrdup(s + len);
Damien Miller95def091999-11-25 00:26:21 +11001146 return 0;
1147
djm@openbsd.orged877ef2016-07-15 00:24:30 +00001148 case oProxyJump:
1149 if (s == NULL) {
1150 fatal("%.200s line %d: Missing argument.",
1151 filename, linenum);
1152 }
1153 len = strspn(s, WHITESPACE "=");
1154 if (parse_jump(s + len, options, *activep) == -1) {
1155 fatal("%.200s line %d: Invalid ProxyJump \"%s\"",
1156 filename, linenum, s + len);
1157 }
1158 return 0;
1159
Damien Miller95def091999-11-25 00:26:21 +11001160 case oPort:
naddy@openbsd.org25813332018-10-05 14:26:09 +00001161 arg = strdelim(&s);
1162 if (!arg || *arg == '\0')
1163 fatal("%.200s line %d: Missing argument.",
1164 filename, linenum);
1165 value = a2port(arg);
1166 if (value <= 0)
1167 fatal("%.200s line %d: Bad port '%s'.",
1168 filename, linenum, arg);
1169 if (*activep && options->port == -1)
1170 options->port = value;
1171 break;
1172
1173 case oConnectionAttempts:
1174 intptr = &options->connection_attempts;
Damien Miller95def091999-11-25 00:26:21 +11001175parse_int:
Damien Millerbe484b52000-07-15 14:14:16 +10001176 arg = strdelim(&s);
dtucker@openbsd.org609d96b2017-12-05 23:59:47 +00001177 if ((errstr = atoi_err(arg, &value)) != NULL)
1178 fatal("%s line %d: integer value %s.",
1179 filename, linenum, errstr);
Damien Miller95def091999-11-25 00:26:21 +11001180 if (*activep && *intptr == -1)
1181 *intptr = value;
1182 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001183
Damien Miller78928792000-04-12 20:17:38 +10001184 case oCiphers:
Damien Millerbe484b52000-07-15 14:14:16 +10001185 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +10001186 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +10001187 fatal("%.200s line %d: Missing argument.", filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001188 if (*arg != '-' && !ciphers_valid(*arg == '+' ? arg + 1 : arg))
Damien Miller30c3d422000-05-09 11:02:59 +10001189 fatal("%.200s line %d: Bad SSH2 cipher spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001190 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +10001191 if (*activep && options->ciphers == NULL)
Damien Miller37023962000-07-11 17:31:38 +10001192 options->ciphers = xstrdup(arg);
Damien Miller78928792000-04-12 20:17:38 +10001193 break;
1194
Ben Lindstrom06b33aa2001-02-15 03:01:59 +00001195 case oMacs:
1196 arg = strdelim(&s);
1197 if (!arg || *arg == '\0')
1198 fatal("%.200s line %d: Missing argument.", filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001199 if (*arg != '-' && !mac_valid(*arg == '+' ? arg + 1 : arg))
Ben Lindstrom06b33aa2001-02-15 03:01:59 +00001200 fatal("%.200s line %d: Bad SSH2 Mac spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001201 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstrom06b33aa2001-02-15 03:01:59 +00001202 if (*activep && options->macs == NULL)
1203 options->macs = xstrdup(arg);
1204 break;
1205
Damien Millerd5f62bf2010-09-24 22:11:14 +10001206 case oKexAlgorithms:
1207 arg = strdelim(&s);
1208 if (!arg || *arg == '\0')
1209 fatal("%.200s line %d: Missing argument.",
1210 filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001211 if (*arg != '-' &&
1212 !kex_names_valid(*arg == '+' ? arg + 1 : arg))
Damien Millerd5f62bf2010-09-24 22:11:14 +10001213 fatal("%.200s line %d: Bad SSH2 KexAlgorithms '%s'.",
1214 filename, linenum, arg ? arg : "<NONE>");
1215 if (*activep && options->kex_algorithms == NULL)
1216 options->kex_algorithms = xstrdup(arg);
1217 break;
1218
Ben Lindstrom982dbbc2001-04-17 18:11:36 +00001219 case oHostKeyAlgorithms:
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00001220 charptr = &options->hostkeyalgorithms;
1221parse_keytypes:
Ben Lindstrom982dbbc2001-04-17 18:11:36 +00001222 arg = strdelim(&s);
1223 if (!arg || *arg == '\0')
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00001224 fatal("%.200s line %d: Missing argument.",
1225 filename, linenum);
djm@openbsd.org68bc8cf2017-02-03 23:01:19 +00001226 if (*arg != '-' &&
1227 !sshkey_names_valid2(*arg == '+' ? arg + 1 : arg, 1))
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00001228 fatal("%s line %d: Bad key types '%s'.",
1229 filename, linenum, arg ? arg : "<NONE>");
1230 if (*activep && *charptr == NULL)
1231 *charptr = xstrdup(arg);
Ben Lindstrom982dbbc2001-04-17 18:11:36 +00001232 break;
1233
djm@openbsd.orgecac7e12018-09-20 03:30:44 +00001234 case oCASignatureAlgorithms:
1235 charptr = &options->ca_sign_algorithms;
1236 goto parse_keytypes;
1237
Damien Miller95def091999-11-25 00:26:21 +11001238 case oLogLevel:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001239 log_level_ptr = &options->log_level;
Damien Millerbe484b52000-07-15 14:14:16 +10001240 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +10001241 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001242 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +00001243 fatal("%.200s line %d: unsupported log level '%s'",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001244 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001245 if (*activep && *log_level_ptr == SYSLOG_LEVEL_NOT_SET)
1246 *log_level_ptr = (LogLevel) value;
Damien Miller95def091999-11-25 00:26:21 +11001247 break;
1248
dtucker@openbsd.org68d3a2a2017-04-28 03:20:27 +00001249 case oLogFacility:
1250 log_facility_ptr = &options->log_facility;
1251 arg = strdelim(&s);
1252 value = log_facility_number(arg);
1253 if (value == SYSLOG_FACILITY_NOT_SET)
1254 fatal("%.200s line %d: unsupported log facility '%s'",
1255 filename, linenum, arg ? arg : "<NONE>");
1256 if (*log_facility_ptr == -1)
1257 *log_facility_ptr = (SyslogFacility) value;
1258 break;
1259
Ben Lindstrom62c25a42001-09-12 18:01:59 +00001260 case oLocalForward:
Damien Miller95def091999-11-25 00:26:21 +11001261 case oRemoteForward:
Damien Millera699d952008-11-03 19:27:34 +11001262 case oDynamicForward:
Damien Millerbe484b52000-07-15 14:14:16 +10001263 arg = strdelim(&s);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001264 if (arg == NULL || *arg == '\0')
Ben Lindstrom62c25a42001-09-12 18:01:59 +00001265 fatal("%.200s line %d: Missing port argument.",
1266 filename, linenum);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001267
markus@openbsd.org609d7a62017-09-21 19:16:53 +00001268 remotefwd = (opcode == oRemoteForward);
1269 dynamicfwd = (opcode == oDynamicForward);
1270
1271 if (!dynamicfwd) {
Damien Millera699d952008-11-03 19:27:34 +11001272 arg2 = strdelim(&s);
markus@openbsd.org609d7a62017-09-21 19:16:53 +00001273 if (arg2 == NULL || *arg2 == '\0') {
1274 if (remotefwd)
1275 dynamicfwd = 1;
1276 else
1277 fatal("%.200s line %d: Missing target "
1278 "argument.", filename, linenum);
1279 } else {
1280 /* construct a string for parse_forward */
1281 snprintf(fwdarg, sizeof(fwdarg), "%s:%s", arg,
1282 arg2);
1283 }
Damien Millera699d952008-11-03 19:27:34 +11001284 }
markus@openbsd.org609d7a62017-09-21 19:16:53 +00001285 if (dynamicfwd)
1286 strlcpy(fwdarg, arg, sizeof(fwdarg));
Damien Millera699d952008-11-03 19:27:34 +11001287
markus@openbsd.org609d7a62017-09-21 19:16:53 +00001288 if (parse_forward(&fwd, fwdarg, dynamicfwd, remotefwd) == 0)
Ben Lindstrom62c25a42001-09-12 18:01:59 +00001289 fatal("%.200s line %d: Bad forwarding specification.",
1290 filename, linenum);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001291
Ben Lindstrom62c25a42001-09-12 18:01:59 +00001292 if (*activep) {
markus@openbsd.org609d7a62017-09-21 19:16:53 +00001293 if (remotefwd) {
Damien Millerf91ee4c2005-03-01 21:24:33 +11001294 add_remote_forward(options, &fwd);
markus@openbsd.org609d7a62017-09-21 19:16:53 +00001295 } else {
1296 add_local_forward(options, &fwd);
1297 }
Ben Lindstrom62c25a42001-09-12 18:01:59 +00001298 }
Damien Miller95def091999-11-25 00:26:21 +11001299 break;
1300
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +00001301 case oClearAllForwardings:
1302 intptr = &options->clear_forwardings;
1303 goto parse_flag;
1304
Damien Miller95def091999-11-25 00:26:21 +11001305 case oHost:
Damien Miller194fd902013-10-15 12:13:05 +11001306 if (cmdline)
1307 fatal("Host directive not supported as a command-line "
1308 "option");
Damien Miller95def091999-11-25 00:26:21 +11001309 *activep = 0;
Damien Millerfe924212011-05-15 08:44:45 +10001310 arg2 = NULL;
1311 while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
djm@openbsd.orgdc7990b2016-04-15 00:30:19 +00001312 if ((flags & SSHCONF_NEVERMATCH) != 0)
1313 break;
Damien Millerfe924212011-05-15 08:44:45 +10001314 negated = *arg == '!';
1315 if (negated)
1316 arg++;
Damien Miller37023962000-07-11 17:31:38 +10001317 if (match_pattern(host, arg)) {
Damien Millerfe924212011-05-15 08:44:45 +10001318 if (negated) {
1319 debug("%.200s line %d: Skipping Host "
1320 "block because of negated match "
1321 "for %.100s", filename, linenum,
1322 arg);
1323 *activep = 0;
1324 break;
1325 }
1326 if (!*activep)
1327 arg2 = arg; /* logged below */
Damien Miller95def091999-11-25 00:26:21 +11001328 *activep = 1;
Damien Miller95def091999-11-25 00:26:21 +11001329 }
Damien Millerfe924212011-05-15 08:44:45 +10001330 }
1331 if (*activep)
1332 debug("%.200s line %d: Applying options for %.100s",
1333 filename, linenum, arg2);
Damien Millerbe484b52000-07-15 14:14:16 +10001334 /* Avoid garbage check below, as strdelim is done. */
Damien Miller95def091999-11-25 00:26:21 +11001335 return 0;
1336
Damien Miller194fd902013-10-15 12:13:05 +11001337 case oMatch:
1338 if (cmdline)
1339 fatal("Host directive not supported as a command-line "
1340 "option");
djm@openbsd.org957fbce2014-10-08 22:20:25 +00001341 value = match_cfg_line(options, &s, pw, host, original_host,
1342 flags & SSHCONF_POSTCANON, filename, linenum);
Damien Miller194fd902013-10-15 12:13:05 +11001343 if (value < 0)
1344 fatal("%.200s line %d: Bad Match condition", filename,
1345 linenum);
djm@openbsd.orgdc7990b2016-04-15 00:30:19 +00001346 *activep = (flags & SSHCONF_NEVERMATCH) ? 0 : value;
Damien Miller194fd902013-10-15 12:13:05 +11001347 break;
1348
Damien Miller95def091999-11-25 00:26:21 +11001349 case oEscapeChar:
1350 intptr = &options->escape_char;
Damien Millerbe484b52000-07-15 14:14:16 +10001351 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +10001352 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +11001353 fatal("%.200s line %d: Missing argument.", filename, linenum);
djm@openbsd.org08823322015-05-22 04:45:52 +00001354 if (strcmp(arg, "none") == 0)
1355 value = SSH_ESCAPECHAR_NONE;
1356 else if (arg[1] == '\0')
1357 value = (u_char) arg[0];
1358 else if (arg[0] == '^' && arg[2] == 0 &&
Ben Lindstrom46c16222000-12-22 01:43:59 +00001359 (u_char) arg[1] >= 64 && (u_char) arg[1] < 128)
1360 value = (u_char) arg[1] & 31;
Damien Miller95def091999-11-25 00:26:21 +11001361 else {
1362 fatal("%.200s line %d: Bad escape character.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001363 filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +11001364 /* NOTREACHED */
1365 value = 0; /* Avoid compiler warning. */
1366 }
1367 if (*activep && *intptr == -1)
1368 *intptr = value;
1369 break;
1370
Damien Miller20a8f972003-05-18 20:50:30 +10001371 case oAddressFamily:
Darren Tucker0a4f04b2003-07-03 20:37:47 +10001372 intptr = &options->address_family;
Damien Millere9fc72e2013-10-15 12:14:12 +11001373 multistate_ptr = multistate_addressfamily;
1374 goto parse_multistate;
Damien Miller20a8f972003-05-18 20:50:30 +10001375
Ben Lindstromb6df73b2002-11-09 15:52:31 +00001376 case oEnableSSHKeysign:
1377 intptr = &options->enable_ssh_keysign;
1378 goto parse_flag;
1379
Damien Millerbd394c32004-03-08 23:12:36 +11001380 case oIdentitiesOnly:
1381 intptr = &options->identities_only;
1382 goto parse_flag;
1383
Damien Miller509b0102003-12-17 16:33:10 +11001384 case oServerAliveInterval:
1385 intptr = &options->server_alive_interval;
1386 goto parse_time;
1387
1388 case oServerAliveCountMax:
1389 intptr = &options->server_alive_count_max;
1390 goto parse_int;
1391
Darren Tucker46bc0752004-05-02 22:11:30 +10001392 case oSendEnv:
1393 while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1394 if (strchr(arg, '=') != NULL)
1395 fatal("%s line %d: Invalid environment name.",
1396 filename, linenum);
Damien Millerf8e7acc2005-03-05 11:22:50 +11001397 if (!*activep)
1398 continue;
djm@openbsd.org555294a2018-04-06 13:02:39 +00001399 if (*arg == '-') {
1400 /* Removing an env var */
1401 rm_env(options, arg, filename, linenum);
1402 continue;
1403 } else {
1404 /* Adding an env var */
djm@openbsd.org7082bb52018-06-09 03:01:12 +00001405 if (options->num_send_env >= INT_MAX)
djm@openbsd.org555294a2018-04-06 13:02:39 +00001406 fatal("%s line %d: too many send env.",
1407 filename, linenum);
djm@openbsd.org7082bb52018-06-09 03:01:12 +00001408 options->send_env = xrecallocarray(
1409 options->send_env, options->num_send_env,
djm@openbsd.org89a85d72018-06-10 23:45:41 +00001410 options->num_send_env + 1,
djm@openbsd.org7082bb52018-06-09 03:01:12 +00001411 sizeof(*options->send_env));
djm@openbsd.org555294a2018-04-06 13:02:39 +00001412 options->send_env[options->num_send_env++] =
1413 xstrdup(arg);
1414 }
Darren Tucker46bc0752004-05-02 22:11:30 +10001415 }
1416 break;
1417
djm@openbsd.org7082bb52018-06-09 03:01:12 +00001418 case oSetEnv:
1419 value = options->num_setenv;
1420 while ((arg = strdelimw(&s)) != NULL && *arg != '\0') {
1421 if (strchr(arg, '=') == NULL)
1422 fatal("%s line %d: Invalid SetEnv.",
1423 filename, linenum);
1424 if (!*activep || value != 0)
1425 continue;
1426 /* Adding a setenv var */
1427 if (options->num_setenv >= INT_MAX)
1428 fatal("%s line %d: too many SetEnv.",
1429 filename, linenum);
1430 options->setenv = xrecallocarray(
1431 options->setenv, options->num_setenv,
1432 options->num_setenv + 1, sizeof(*options->setenv));
1433 options->setenv[options->num_setenv++] = xstrdup(arg);
1434 }
1435 break;
1436
Damien Miller0e220db2004-06-15 10:34:08 +10001437 case oControlPath:
1438 charptr = &options->control_path;
1439 goto parse_string;
1440
1441 case oControlMaster:
1442 intptr = &options->control_master;
Damien Millere9fc72e2013-10-15 12:14:12 +11001443 multistate_ptr = multistate_controlmaster;
1444 goto parse_multistate;
Damien Miller0e220db2004-06-15 10:34:08 +10001445
Damien Millere11e1ea2010-08-03 16:04:46 +10001446 case oControlPersist:
1447 /* no/false/yes/true, or a time spec */
1448 intptr = &options->control_persist;
1449 arg = strdelim(&s);
1450 if (!arg || *arg == '\0')
1451 fatal("%.200s line %d: Missing ControlPersist"
1452 " argument.", filename, linenum);
1453 value = 0;
1454 value2 = 0; /* timeout */
1455 if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
1456 value = 0;
1457 else if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
1458 value = 1;
1459 else if ((value2 = convtime(arg)) >= 0)
1460 value = 1;
1461 else
1462 fatal("%.200s line %d: Bad ControlPersist argument.",
1463 filename, linenum);
1464 if (*activep && *intptr == -1) {
1465 *intptr = value;
1466 options->control_persist_timeout = value2;
1467 }
1468 break;
1469
Damien Millere1776152005-03-01 21:47:37 +11001470 case oHashKnownHosts:
1471 intptr = &options->hash_known_hosts;
1472 goto parse_flag;
1473
Damien Millerd27b9472005-12-13 19:29:02 +11001474 case oTunnel:
1475 intptr = &options->tun_open;
Damien Millere9fc72e2013-10-15 12:14:12 +11001476 multistate_ptr = multistate_tunnel;
1477 goto parse_multistate;
Damien Millerd27b9472005-12-13 19:29:02 +11001478
1479 case oTunnelDevice:
1480 arg = strdelim(&s);
1481 if (!arg || *arg == '\0')
1482 fatal("%.200s line %d: Missing argument.", filename, linenum);
1483 value = a2tun(arg, &value2);
Damien Miller7b58e802005-12-13 19:33:19 +11001484 if (value == SSH_TUNID_ERR)
Damien Millerd27b9472005-12-13 19:29:02 +11001485 fatal("%.200s line %d: Bad tun device.", filename, linenum);
1486 if (*activep) {
1487 options->tun_local = value;
1488 options->tun_remote = value2;
1489 }
1490 break;
1491
1492 case oLocalCommand:
1493 charptr = &options->local_command;
1494 goto parse_command;
1495
1496 case oPermitLocalCommand:
1497 intptr = &options->permit_local_command;
1498 goto parse_flag;
1499
bluhm@openbsd.org1112b532017-05-30 18:58:37 +00001500 case oRemoteCommand:
1501 charptr = &options->remote_command;
1502 goto parse_command;
1503
Damien Miller10288242008-06-30 00:04:03 +10001504 case oVisualHostKey:
1505 intptr = &options->visual_host_key;
1506 goto parse_flag;
1507
djm@openbsd.orgdc7990b2016-04-15 00:30:19 +00001508 case oInclude:
1509 if (cmdline)
1510 fatal("Include directive not supported as a "
1511 "command-line option");
1512 value = 0;
1513 while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1514 /*
1515 * Ensure all paths are anchored. User configuration
1516 * files may begin with '~/' but system configurations
1517 * must not. If the path is relative, then treat it
1518 * as living in ~/.ssh for user configurations or
1519 * /etc/ssh for system ones.
1520 */
1521 if (*arg == '~' && (flags & SSHCONF_USERCONF) == 0)
1522 fatal("%.200s line %d: bad include path %s.",
1523 filename, linenum, arg);
1524 if (*arg != '/' && *arg != '~') {
1525 xasprintf(&arg2, "%s/%s",
1526 (flags & SSHCONF_USERCONF) ?
1527 "~/" _PATH_SSH_USER_DIR : SSHDIR, arg);
1528 } else
1529 arg2 = xstrdup(arg);
1530 memset(&gl, 0, sizeof(gl));
1531 r = glob(arg2, GLOB_TILDE, NULL, &gl);
1532 if (r == GLOB_NOMATCH) {
1533 debug("%.200s line %d: include %s matched no "
1534 "files",filename, linenum, arg2);
dtucker@openbsd.orgf6edbe92017-03-10 03:24:48 +00001535 free(arg2);
djm@openbsd.orgdc7990b2016-04-15 00:30:19 +00001536 continue;
1537 } else if (r != 0 || gl.gl_pathc < 0)
1538 fatal("%.200s line %d: glob failed for %s.",
1539 filename, linenum, arg2);
1540 free(arg2);
1541 oactive = *activep;
1542 for (i = 0; i < (u_int)gl.gl_pathc; i++) {
1543 debug3("%.200s line %d: Including file %s "
1544 "depth %d%s", filename, linenum,
1545 gl.gl_pathv[i], depth,
1546 oactive ? "" : " (parse only)");
1547 r = read_config_file_depth(gl.gl_pathv[i],
1548 pw, host, original_host, options,
1549 flags | SSHCONF_CHECKPERM |
1550 (oactive ? 0 : SSHCONF_NEVERMATCH),
1551 activep, depth + 1);
djm@openbsd.orgb64077f2017-01-06 09:27:52 +00001552 if (r != 1 && errno != ENOENT) {
djm@openbsd.org5e820e92017-01-06 03:53:58 +00001553 fatal("Can't open user config file "
1554 "%.100s: %.100s", gl.gl_pathv[i],
1555 strerror(errno));
1556 }
djm@openbsd.orgdc7990b2016-04-15 00:30:19 +00001557 /*
1558 * don't let Match in includes clobber the
1559 * containing file's Match state.
1560 */
1561 *activep = oactive;
1562 if (r != 1)
1563 value = -1;
1564 }
1565 globfree(&gl);
1566 }
1567 if (value != 0)
1568 return value;
1569 break;
1570
Damien Miller0dac6fb2010-11-20 15:19:38 +11001571 case oIPQoS:
1572 arg = strdelim(&s);
1573 if ((value = parse_ipqos(arg)) == -1)
1574 fatal("%s line %d: Bad IPQoS value: %s",
1575 filename, linenum, arg);
1576 arg = strdelim(&s);
1577 if (arg == NULL)
1578 value2 = value;
1579 else if ((value2 = parse_ipqos(arg)) == -1)
1580 fatal("%s line %d: Bad IPQoS value: %s",
1581 filename, linenum, arg);
1582 if (*activep) {
1583 options->ip_qos_interactive = value;
1584 options->ip_qos_bulk = value2;
1585 }
1586 break;
1587
Damien Miller21771e22011-05-15 08:45:50 +10001588 case oRequestTTY:
Damien Miller21771e22011-05-15 08:45:50 +10001589 intptr = &options->request_tty;
Damien Millere9fc72e2013-10-15 12:14:12 +11001590 multistate_ptr = multistate_requesttty;
1591 goto parse_multistate;
Damien Miller21771e22011-05-15 08:45:50 +10001592
Darren Tucker07636982013-05-16 20:30:03 +10001593 case oIgnoreUnknown:
1594 charptr = &options->ignored_unknown;
1595 goto parse_string;
1596
Damien Miller1262b662013-08-21 02:44:24 +10001597 case oProxyUseFdpass:
1598 intptr = &options->proxy_use_fdpass;
1599 goto parse_flag;
1600
Damien Miller0faf7472013-10-17 11:47:23 +11001601 case oCanonicalDomains:
1602 value = options->num_canonical_domains != 0;
1603 while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
millert@openbsd.org887669e2017-10-21 23:06:24 +00001604 if (!valid_domain(arg, 1, &errstr)) {
1605 fatal("%s line %d: %s", filename, linenum,
1606 errstr);
1607 }
Damien Miller0faf7472013-10-17 11:47:23 +11001608 if (!*activep || value)
1609 continue;
1610 if (options->num_canonical_domains >= MAX_CANON_DOMAINS)
1611 fatal("%s line %d: too many hostname suffixes.",
1612 filename, linenum);
1613 options->canonical_domains[
1614 options->num_canonical_domains++] = xstrdup(arg);
1615 }
1616 break;
1617
Damien Miller38505592013-10-17 11:48:13 +11001618 case oCanonicalizePermittedCNAMEs:
Damien Miller0faf7472013-10-17 11:47:23 +11001619 value = options->num_permitted_cnames != 0;
1620 while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1621 /* Either '*' for everything or 'list:list' */
1622 if (strcmp(arg, "*") == 0)
1623 arg2 = arg;
1624 else {
1625 lowercase(arg);
1626 if ((arg2 = strchr(arg, ':')) == NULL ||
1627 arg2[1] == '\0') {
1628 fatal("%s line %d: "
1629 "Invalid permitted CNAME \"%s\"",
1630 filename, linenum, arg);
1631 }
1632 *arg2 = '\0';
1633 arg2++;
1634 }
1635 if (!*activep || value)
1636 continue;
1637 if (options->num_permitted_cnames >= MAX_CANON_DOMAINS)
1638 fatal("%s line %d: too many permitted CNAMEs.",
1639 filename, linenum);
1640 cname = options->permitted_cnames +
1641 options->num_permitted_cnames++;
1642 cname->source_list = xstrdup(arg);
1643 cname->target_list = xstrdup(arg2);
1644 }
1645 break;
1646
Damien Miller38505592013-10-17 11:48:13 +11001647 case oCanonicalizeHostname:
1648 intptr = &options->canonicalize_hostname;
1649 multistate_ptr = multistate_canonicalizehostname;
Damien Miller0faf7472013-10-17 11:47:23 +11001650 goto parse_multistate;
1651
Damien Miller38505592013-10-17 11:48:13 +11001652 case oCanonicalizeMaxDots:
1653 intptr = &options->canonicalize_max_dots;
Damien Miller0faf7472013-10-17 11:47:23 +11001654 goto parse_int;
1655
Damien Miller38505592013-10-17 11:48:13 +11001656 case oCanonicalizeFallbackLocal:
1657 intptr = &options->canonicalize_fallback_local;
Damien Miller0faf7472013-10-17 11:47:23 +11001658 goto parse_flag;
1659
Damien Miller7acefbb2014-07-18 14:11:24 +10001660 case oStreamLocalBindMask:
1661 arg = strdelim(&s);
1662 if (!arg || *arg == '\0')
1663 fatal("%.200s line %d: Missing StreamLocalBindMask argument.", filename, linenum);
1664 /* Parse mode in octal format */
1665 value = strtol(arg, &endofnumber, 8);
1666 if (arg == endofnumber || value < 0 || value > 0777)
1667 fatal("%.200s line %d: Bad mask.", filename, linenum);
1668 options->fwd_opts.streamlocal_bind_mask = (mode_t)value;
1669 break;
1670
1671 case oStreamLocalBindUnlink:
1672 intptr = &options->fwd_opts.streamlocal_bind_unlink;
1673 goto parse_flag;
1674
djm@openbsd.org5e39a492014-12-04 02:24:32 +00001675 case oRevokedHostKeys:
1676 charptr = &options->revoked_host_keys;
1677 goto parse_string;
1678
djm@openbsd.org56d1c832014-12-21 22:27:55 +00001679 case oFingerprintHash:
djm@openbsd.orge752c6d2015-01-08 13:44:36 +00001680 intptr = &options->fingerprint_hash;
djm@openbsd.org56d1c832014-12-21 22:27:55 +00001681 arg = strdelim(&s);
1682 if (!arg || *arg == '\0')
1683 fatal("%.200s line %d: Missing argument.",
1684 filename, linenum);
1685 if ((value = ssh_digest_alg_by_name(arg)) == -1)
1686 fatal("%.200s line %d: Invalid hash algorithm \"%s\".",
1687 filename, linenum, arg);
djm@openbsd.orge752c6d2015-01-08 13:44:36 +00001688 if (*activep && *intptr == -1)
1689 *intptr = value;
djm@openbsd.org56d1c832014-12-21 22:27:55 +00001690 break;
1691
djm@openbsd.org8d4f8722015-01-26 03:04:45 +00001692 case oUpdateHostkeys:
1693 intptr = &options->update_hostkeys;
djm@openbsd.org523463a2015-02-16 22:13:32 +00001694 multistate_ptr = multistate_yesnoask;
1695 goto parse_multistate;
djm@openbsd.org8d4f8722015-01-26 03:04:45 +00001696
djm@openbsd.org46347ed2015-01-30 11:43:14 +00001697 case oHostbasedKeyTypes:
1698 charptr = &options->hostbased_key_types;
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00001699 goto parse_keytypes;
1700
1701 case oPubkeyAcceptedKeyTypes:
1702 charptr = &options->pubkey_key_types;
1703 goto parse_keytypes;
djm@openbsd.org46347ed2015-01-30 11:43:14 +00001704
jcs@openbsd.orgf361df42015-11-15 22:26:49 +00001705 case oAddKeysToAgent:
1706 intptr = &options->add_keys_to_agent;
1707 multistate_ptr = multistate_yesnoaskconfirm;
1708 goto parse_multistate;
1709
markus@openbsd.orgb02ad1c2016-05-04 12:21:53 +00001710 case oIdentityAgent:
1711 charptr = &options->identity_agent;
djm@openbsd.org5eff5b82018-10-03 06:38:35 +00001712 arg = strdelim(&s);
1713 if (!arg || *arg == '\0')
1714 fatal("%.200s line %d: Missing argument.",
1715 filename, linenum);
1716 /* Extra validation if the string represents an env var. */
1717 if (arg[0] == '$' && !valid_env_name(arg + 1)) {
1718 fatal("%.200s line %d: Invalid environment name %s.",
1719 filename, linenum, arg);
1720 }
1721 if (*activep && *charptr == NULL)
1722 *charptr = xstrdup(arg);
1723 break;
markus@openbsd.orgb02ad1c2016-05-04 12:21:53 +00001724
Ben Lindstrom4daea862002-06-09 20:04:02 +00001725 case oDeprecated:
Ben Lindstrom2e17b082002-06-09 20:13:27 +00001726 debug("%s line %d: Deprecated option \"%s\"",
Ben Lindstrom4daea862002-06-09 20:04:02 +00001727 filename, linenum, keyword);
Ben Lindstrom2e17b082002-06-09 20:13:27 +00001728 return 0;
Ben Lindstrom4daea862002-06-09 20:04:02 +00001729
Damien Millerf9b3feb2003-05-16 11:38:32 +10001730 case oUnsupported:
1731 error("%s line %d: Unsupported option \"%s\"",
1732 filename, linenum, keyword);
1733 return 0;
1734
Damien Miller95def091999-11-25 00:26:21 +11001735 default:
djm@openbsd.org957fbce2014-10-08 22:20:25 +00001736 fatal("%s: Unimplemented opcode %d", __func__, opcode);
Damien Miller95def091999-11-25 00:26:21 +11001737 }
1738
1739 /* Check that there is no garbage at end of line. */
Ben Lindstrom226cfa02001-01-22 05:34:40 +00001740 if ((arg = strdelim(&s)) != NULL && *arg != '\0') {
Damien Miller37023962000-07-11 17:31:38 +10001741 fatal("%.200s line %d: garbage at end of line; \"%.200s\".",
Damien Miller0dc1bef2005-07-17 17:22:45 +10001742 filename, linenum, arg);
Damien Miller37023962000-07-11 17:31:38 +10001743 }
Damien Miller95def091999-11-25 00:26:21 +11001744 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001745}
1746
Damien Miller5428f641999-11-25 11:54:57 +11001747/*
1748 * Reads the config file and modifies the options accordingly. Options
1749 * should already be initialized before this call. This never returns if
Ben Lindstromedc0cf22001-09-12 18:32:20 +00001750 * there is an error. If the file does not exist, this returns 0.
Damien Miller5428f641999-11-25 11:54:57 +11001751 */
Ben Lindstromedc0cf22001-09-12 18:32:20 +00001752int
Damien Miller194fd902013-10-15 12:13:05 +11001753read_config_file(const char *filename, struct passwd *pw, const char *host,
djm@openbsd.org957fbce2014-10-08 22:20:25 +00001754 const char *original_host, Options *options, int flags)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001755{
djm@openbsd.orgdc7990b2016-04-15 00:30:19 +00001756 int active = 1;
1757
1758 return read_config_file_depth(filename, pw, host, original_host,
1759 options, flags, &active, 0);
1760}
1761
1762#define READCONF_MAX_DEPTH 16
1763static int
1764read_config_file_depth(const char *filename, struct passwd *pw,
1765 const char *host, const char *original_host, Options *options,
1766 int flags, int *activep, int depth)
1767{
Damien Miller95def091999-11-25 00:26:21 +11001768 FILE *f;
markus@openbsd.org7f906352018-06-06 18:29:18 +00001769 char *line = NULL;
1770 size_t linesize = 0;
djm@openbsd.orgdc7990b2016-04-15 00:30:19 +00001771 int linenum;
Damien Miller95def091999-11-25 00:26:21 +11001772 int bad_options = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001773
djm@openbsd.orgdc7990b2016-04-15 00:30:19 +00001774 if (depth < 0 || depth > READCONF_MAX_DEPTH)
1775 fatal("Too many recursive configuration includes");
1776
Damien Miller57a44762004-04-20 20:11:57 +10001777 if ((f = fopen(filename, "r")) == NULL)
Ben Lindstromedc0cf22001-09-12 18:32:20 +00001778 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001779
Darren Tuckeraefa3682013-04-05 11:18:35 +11001780 if (flags & SSHCONF_CHECKPERM) {
Damien Miller57a44762004-04-20 20:11:57 +10001781 struct stat sb;
Darren Tuckerfc959702004-07-17 16:12:08 +10001782
Damien Miller33793852004-06-15 10:27:55 +10001783 if (fstat(fileno(f), &sb) == -1)
Damien Miller57a44762004-04-20 20:11:57 +10001784 fatal("fstat %s: %s", filename, strerror(errno));
Damien Miller57a44762004-04-20 20:11:57 +10001785 if (((sb.st_uid != 0 && sb.st_uid != getuid()) ||
Damien Miller33793852004-06-15 10:27:55 +10001786 (sb.st_mode & 022) != 0))
Damien Miller57a44762004-04-20 20:11:57 +10001787 fatal("Bad owner or permissions on %s", filename);
Damien Miller57a44762004-04-20 20:11:57 +10001788 }
1789
Damien Miller95def091999-11-25 00:26:21 +11001790 debug("Reading configuration data %.200s", filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001791
Damien Miller5428f641999-11-25 11:54:57 +11001792 /*
1793 * Mark that we are now processing the options. This flag is turned
1794 * on/off by Host specifications.
1795 */
Damien Miller95def091999-11-25 00:26:21 +11001796 linenum = 0;
markus@openbsd.org7f906352018-06-06 18:29:18 +00001797 while (getline(&line, &linesize, f) != -1) {
Damien Miller95def091999-11-25 00:26:21 +11001798 /* Update line number counter. */
1799 linenum++;
djm@openbsd.orgdc7990b2016-04-15 00:30:19 +00001800 if (process_config_line_depth(options, pw, host, original_host,
1801 line, filename, linenum, activep, flags, depth) != 0)
Damien Miller95def091999-11-25 00:26:21 +11001802 bad_options++;
1803 }
markus@openbsd.org7f906352018-06-06 18:29:18 +00001804 free(line);
Damien Miller95def091999-11-25 00:26:21 +11001805 fclose(f);
1806 if (bad_options > 0)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +00001807 fatal("%s: terminating, %d bad configuration options",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001808 filename, bad_options);
Ben Lindstromedc0cf22001-09-12 18:32:20 +00001809 return 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001810}
1811
Damien Miller13f97b22014-02-24 15:57:55 +11001812/* Returns 1 if a string option is unset or set to "none" or 0 otherwise. */
1813int
1814option_clear_or_none(const char *o)
1815{
1816 return o == NULL || strcasecmp(o, "none") == 0;
1817}
1818
Damien Miller5428f641999-11-25 11:54:57 +11001819/*
1820 * Initializes options to special values that indicate that they have not yet
1821 * been set. Read_config_file will only set options with this value. Options
1822 * are processed in the following order: command line, user config file,
1823 * system config file. Last, fill_default_options is called.
1824 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001825
Damien Miller4af51302000-04-16 11:18:38 +10001826void
Damien Miller95def091999-11-25 00:26:21 +11001827initialize_options(Options * options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001828{
Damien Miller95def091999-11-25 00:26:21 +11001829 memset(options, 'X', sizeof(*options));
1830 options->forward_agent = -1;
1831 options->forward_x11 = -1;
Darren Tucker0a118da2003-10-15 15:54:32 +10001832 options->forward_x11_trusted = -1;
Damien Miller1ab6a512010-06-26 10:02:24 +10001833 options->forward_x11_timeout = -1;
dtucker@openbsd.org8543ff32016-06-03 03:14:41 +00001834 options->stdio_forward_host = NULL;
1835 options->stdio_forward_port = 0;
dtucker@openbsd.org0cb2f4c2016-06-03 04:09:38 +00001836 options->clear_forwardings = -1;
Darren Tuckere7d4b192006-07-12 22:17:10 +10001837 options->exit_on_forward_failure = -1;
Damien Millerd3a18572000-06-07 19:55:44 +10001838 options->xauth_location = NULL;
Damien Miller7acefbb2014-07-18 14:11:24 +10001839 options->fwd_opts.gateway_ports = -1;
1840 options->fwd_opts.streamlocal_bind_mask = (mode_t)-1;
1841 options->fwd_opts.streamlocal_bind_unlink = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +11001842 options->pubkey_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +00001843 options->challenge_response_authentication = -1;
Darren Tucker0efd1552003-08-26 11:49:55 +10001844 options->gss_authentication = -1;
1845 options->gss_deleg_creds = -1;
Damien Miller95def091999-11-25 00:26:21 +11001846 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +11001847 options->kbd_interactive_authentication = -1;
1848 options->kbd_interactive_devices = NULL;
Ben Lindstrom5eabda32001-04-12 23:34:34 +00001849 options->hostbased_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +11001850 options->batch_mode = -1;
1851 options->check_host_ip = -1;
1852 options->strict_host_key_checking = -1;
1853 options->compression = -1;
Damien Miller12c150e2003-12-17 16:31:10 +11001854 options->tcp_keep_alive = -1;
Damien Miller95def091999-11-25 00:26:21 +11001855 options->port = -1;
Darren Tucker0a4f04b2003-07-03 20:37:47 +10001856 options->address_family = -1;
Damien Miller95def091999-11-25 00:26:21 +11001857 options->connection_attempts = -1;
Damien Millerb78d5eb2003-05-16 11:39:04 +10001858 options->connection_timeout = -1;
Damien Miller95def091999-11-25 00:26:21 +11001859 options->number_of_password_prompts = -1;
Damien Miller78928792000-04-12 20:17:38 +10001860 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +00001861 options->macs = NULL;
Damien Millerd5f62bf2010-09-24 22:11:14 +10001862 options->kex_algorithms = NULL;
Ben Lindstrom982dbbc2001-04-17 18:11:36 +00001863 options->hostkeyalgorithms = NULL;
djm@openbsd.orgecac7e12018-09-20 03:30:44 +00001864 options->ca_sign_algorithms = NULL;
Damien Miller95def091999-11-25 00:26:21 +11001865 options->num_identity_files = 0;
djm@openbsd.org4e44a792015-09-24 06:15:11 +00001866 options->num_certificate_files = 0;
Damien Miller95def091999-11-25 00:26:21 +11001867 options->hostname = NULL;
Ben Lindstrom4dccfa52000-12-28 16:40:05 +00001868 options->host_key_alias = NULL;
Damien Miller95def091999-11-25 00:26:21 +11001869 options->proxy_command = NULL;
djm@openbsd.orged877ef2016-07-15 00:24:30 +00001870 options->jump_user = NULL;
1871 options->jump_host = NULL;
1872 options->jump_port = -1;
1873 options->jump_extra = NULL;
Damien Miller95def091999-11-25 00:26:21 +11001874 options->user = NULL;
1875 options->escape_char = -1;
Damien Miller295ee632011-05-29 21:42:31 +10001876 options->num_system_hostfiles = 0;
1877 options->num_user_hostfiles = 0;
Damien Miller232cfb12010-06-26 09:50:30 +10001878 options->local_forwards = NULL;
Damien Miller95def091999-11-25 00:26:21 +11001879 options->num_local_forwards = 0;
Damien Miller232cfb12010-06-26 09:50:30 +10001880 options->remote_forwards = NULL;
Damien Miller95def091999-11-25 00:26:21 +11001881 options->num_remote_forwards = 0;
dtucker@openbsd.org68d3a2a2017-04-28 03:20:27 +00001882 options->log_facility = SYSLOG_FACILITY_NOT_SET;
Damien Millerfcd93202002-02-05 12:26:34 +11001883 options->log_level = SYSLOG_LEVEL_NOT_SET;
Ben Lindstromb9be60a2001-03-11 01:49:19 +00001884 options->preferred_authentications = NULL;
Ben Lindstrome0f88042001-04-30 13:06:24 +00001885 options->bind_address = NULL;
djm@openbsd.orgac2e3022018-02-23 02:34:33 +00001886 options->bind_interface = NULL;
Damien Miller7ea845e2010-02-12 09:21:02 +11001887 options->pkcs11_provider = NULL;
Ben Lindstromb6df73b2002-11-09 15:52:31 +00001888 options->enable_ssh_keysign = - 1;
Ben Lindstrom3cecc9a2001-10-03 17:39:38 +00001889 options->no_host_authentication_for_localhost = - 1;
Damien Millerbd394c32004-03-08 23:12:36 +11001890 options->identities_only = - 1;
Damien Millera5539d22003-04-09 20:50:06 +10001891 options->rekey_limit = - 1;
Darren Tuckerc53c2af2013-05-16 20:28:16 +10001892 options->rekey_interval = -1;
Damien Miller37876e92003-05-15 10:19:46 +10001893 options->verify_host_key_dns = -1;
Damien Miller509b0102003-12-17 16:33:10 +11001894 options->server_alive_interval = -1;
1895 options->server_alive_count_max = -1;
djm@openbsd.org7082bb52018-06-09 03:01:12 +00001896 options->send_env = NULL;
Darren Tucker46bc0752004-05-02 22:11:30 +10001897 options->num_send_env = 0;
djm@openbsd.org7082bb52018-06-09 03:01:12 +00001898 options->setenv = NULL;
1899 options->num_setenv = 0;
Damien Miller0e220db2004-06-15 10:34:08 +10001900 options->control_path = NULL;
1901 options->control_master = -1;
Damien Millere11e1ea2010-08-03 16:04:46 +10001902 options->control_persist = -1;
1903 options->control_persist_timeout = 0;
Damien Millere1776152005-03-01 21:47:37 +11001904 options->hash_known_hosts = -1;
Damien Millerd27b9472005-12-13 19:29:02 +11001905 options->tun_open = -1;
1906 options->tun_local = -1;
1907 options->tun_remote = -1;
1908 options->local_command = NULL;
1909 options->permit_local_command = -1;
bluhm@openbsd.org1112b532017-05-30 18:58:37 +00001910 options->remote_command = NULL;
jcs@openbsd.orgf361df42015-11-15 22:26:49 +00001911 options->add_keys_to_agent = -1;
markus@openbsd.orgb02ad1c2016-05-04 12:21:53 +00001912 options->identity_agent = NULL;
Damien Miller10288242008-06-30 00:04:03 +10001913 options->visual_host_key = -1;
Damien Miller0dac6fb2010-11-20 15:19:38 +11001914 options->ip_qos_interactive = -1;
1915 options->ip_qos_bulk = -1;
Damien Miller21771e22011-05-15 08:45:50 +10001916 options->request_tty = -1;
Damien Miller1262b662013-08-21 02:44:24 +10001917 options->proxy_use_fdpass = -1;
Darren Tucker07636982013-05-16 20:30:03 +10001918 options->ignored_unknown = NULL;
Damien Miller0faf7472013-10-17 11:47:23 +11001919 options->num_canonical_domains = 0;
1920 options->num_permitted_cnames = 0;
Damien Miller38505592013-10-17 11:48:13 +11001921 options->canonicalize_max_dots = -1;
1922 options->canonicalize_fallback_local = -1;
1923 options->canonicalize_hostname = -1;
djm@openbsd.org5e39a492014-12-04 02:24:32 +00001924 options->revoked_host_keys = NULL;
djm@openbsd.org56d1c832014-12-21 22:27:55 +00001925 options->fingerprint_hash = -1;
djm@openbsd.org8d4f8722015-01-26 03:04:45 +00001926 options->update_hostkeys = -1;
djm@openbsd.org46347ed2015-01-30 11:43:14 +00001927 options->hostbased_key_types = NULL;
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00001928 options->pubkey_key_types = NULL;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001929}
1930
Damien Miller5428f641999-11-25 11:54:57 +11001931/*
Damien Miller13f97b22014-02-24 15:57:55 +11001932 * A petite version of fill_default_options() that just fills the options
1933 * needed for hostname canonicalization to proceed.
1934 */
1935void
1936fill_default_options_for_canonicalization(Options *options)
1937{
1938 if (options->canonicalize_max_dots == -1)
1939 options->canonicalize_max_dots = 1;
1940 if (options->canonicalize_fallback_local == -1)
1941 options->canonicalize_fallback_local = 1;
1942 if (options->canonicalize_hostname == -1)
1943 options->canonicalize_hostname = SSH_CANONICALISE_NO;
1944}
1945
1946/*
Damien Miller5428f641999-11-25 11:54:57 +11001947 * Called after processing other sources of option data, this fills those
1948 * options for which no value has been specified with their default values.
1949 */
Damien Miller4af51302000-04-16 11:18:38 +10001950void
Damien Miller95def091999-11-25 00:26:21 +11001951fill_default_options(Options * options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001952{
djm@openbsd.orgecac7e12018-09-20 03:30:44 +00001953 char *all_cipher, *all_mac, *all_kex, *all_key, *all_sig;
djm@openbsd.org1b9dd4a2018-08-12 20:19:13 +00001954 int r;
djm@openbsd.org312d2f22018-07-04 13:49:31 +00001955
Damien Miller95def091999-11-25 00:26:21 +11001956 if (options->forward_agent == -1)
Damien Millerb1715dc2000-05-30 13:44:51 +10001957 options->forward_agent = 0;
Damien Miller95def091999-11-25 00:26:21 +11001958 if (options->forward_x11 == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +11001959 options->forward_x11 = 0;
Darren Tucker0a118da2003-10-15 15:54:32 +10001960 if (options->forward_x11_trusted == -1)
1961 options->forward_x11_trusted = 0;
Damien Miller1ab6a512010-06-26 10:02:24 +10001962 if (options->forward_x11_timeout == -1)
1963 options->forward_x11_timeout = 1200;
dtucker@openbsd.org0cb2f4c2016-06-03 04:09:38 +00001964 /*
1965 * stdio forwarding (-W) changes the default for these but we defer
1966 * setting the values so they can be overridden.
1967 */
Darren Tuckere7d4b192006-07-12 22:17:10 +10001968 if (options->exit_on_forward_failure == -1)
dtucker@openbsd.org0cb2f4c2016-06-03 04:09:38 +00001969 options->exit_on_forward_failure =
1970 options->stdio_forward_host != NULL ? 1 : 0;
1971 if (options->clear_forwardings == -1)
1972 options->clear_forwardings =
1973 options->stdio_forward_host != NULL ? 1 : 0;
1974 if (options->clear_forwardings == 1)
1975 clear_forwardings(options);
1976
Damien Millerd3a18572000-06-07 19:55:44 +10001977 if (options->xauth_location == NULL)
Ben Lindstrom1bf11f62001-06-09 01:48:01 +00001978 options->xauth_location = _PATH_XAUTH;
Damien Miller7acefbb2014-07-18 14:11:24 +10001979 if (options->fwd_opts.gateway_ports == -1)
1980 options->fwd_opts.gateway_ports = 0;
1981 if (options->fwd_opts.streamlocal_bind_mask == (mode_t)-1)
1982 options->fwd_opts.streamlocal_bind_mask = 0177;
1983 if (options->fwd_opts.streamlocal_bind_unlink == -1)
1984 options->fwd_opts.streamlocal_bind_unlink = 0;
Damien Miller0bc1bd82000-11-13 22:57:25 +11001985 if (options->pubkey_authentication == -1)
1986 options->pubkey_authentication = 1;
Ben Lindstrom551ea372001-06-05 18:56:16 +00001987 if (options->challenge_response_authentication == -1)
Ben Lindstrom0076d752001-08-06 20:53:26 +00001988 options->challenge_response_authentication = 1;
Darren Tucker0efd1552003-08-26 11:49:55 +10001989 if (options->gss_authentication == -1)
Darren Tuckera044f472003-10-15 15:52:03 +10001990 options->gss_authentication = 0;
Darren Tucker0efd1552003-08-26 11:49:55 +10001991 if (options->gss_deleg_creds == -1)
1992 options->gss_deleg_creds = 0;
Damien Miller95def091999-11-25 00:26:21 +11001993 if (options->password_authentication == -1)
1994 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +11001995 if (options->kbd_interactive_authentication == -1)
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +00001996 options->kbd_interactive_authentication = 1;
Ben Lindstrom5eabda32001-04-12 23:34:34 +00001997 if (options->hostbased_authentication == -1)
1998 options->hostbased_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +11001999 if (options->batch_mode == -1)
2000 options->batch_mode = 0;
2001 if (options->check_host_ip == -1)
2002 options->check_host_ip = 1;
2003 if (options->strict_host_key_checking == -1)
djm@openbsd.org22376d22017-09-03 23:33:13 +00002004 options->strict_host_key_checking = SSH_STRICT_HOSTKEY_ASK;
Damien Miller95def091999-11-25 00:26:21 +11002005 if (options->compression == -1)
2006 options->compression = 0;
Damien Miller12c150e2003-12-17 16:31:10 +11002007 if (options->tcp_keep_alive == -1)
2008 options->tcp_keep_alive = 1;
Damien Miller95def091999-11-25 00:26:21 +11002009 if (options->port == -1)
2010 options->port = 0; /* Filled in ssh_connect. */
Darren Tucker0a4f04b2003-07-03 20:37:47 +10002011 if (options->address_family == -1)
2012 options->address_family = AF_UNSPEC;
Damien Miller95def091999-11-25 00:26:21 +11002013 if (options->connection_attempts == -1)
Ben Lindstromf9cedb92001-08-06 21:07:11 +00002014 options->connection_attempts = 1;
Damien Miller95def091999-11-25 00:26:21 +11002015 if (options->number_of_password_prompts == -1)
2016 options->number_of_password_prompts = 3;
Ben Lindstrom982dbbc2001-04-17 18:11:36 +00002017 /* options->hostkeyalgorithms, default set in myproposals.h */
jcs@openbsd.orgf361df42015-11-15 22:26:49 +00002018 if (options->add_keys_to_agent == -1)
2019 options->add_keys_to_agent = 0;
Damien Miller95def091999-11-25 00:26:21 +11002020 if (options->num_identity_files == 0) {
djm@openbsd.org99f95ba2017-04-30 23:11:45 +00002021 add_identity_file(options, "~/", _PATH_SSH_CLIENT_ID_RSA, 0);
2022 add_identity_file(options, "~/", _PATH_SSH_CLIENT_ID_DSA, 0);
Damien Miller6af914a2010-09-10 11:39:26 +10002023#ifdef OPENSSL_HAS_ECC
djm@openbsd.org99f95ba2017-04-30 23:11:45 +00002024 add_identity_file(options, "~/", _PATH_SSH_CLIENT_ID_ECDSA, 0);
Damien Miller6af914a2010-09-10 11:39:26 +10002025#endif
djm@openbsd.org99f95ba2017-04-30 23:11:45 +00002026 add_identity_file(options, "~/",
2027 _PATH_SSH_CLIENT_ID_ED25519, 0);
markus@openbsd.org1b11ea72018-02-23 15:58:37 +00002028 add_identity_file(options, "~/", _PATH_SSH_CLIENT_ID_XMSS, 0);
Damien Millereba71ba2000-04-29 23:57:08 +10002029 }
Damien Miller95def091999-11-25 00:26:21 +11002030 if (options->escape_char == -1)
2031 options->escape_char = '~';
Damien Miller295ee632011-05-29 21:42:31 +10002032 if (options->num_system_hostfiles == 0) {
2033 options->system_hostfiles[options->num_system_hostfiles++] =
2034 xstrdup(_PATH_SSH_SYSTEM_HOSTFILE);
2035 options->system_hostfiles[options->num_system_hostfiles++] =
2036 xstrdup(_PATH_SSH_SYSTEM_HOSTFILE2);
2037 }
2038 if (options->num_user_hostfiles == 0) {
2039 options->user_hostfiles[options->num_user_hostfiles++] =
2040 xstrdup(_PATH_SSH_USER_HOSTFILE);
2041 options->user_hostfiles[options->num_user_hostfiles++] =
2042 xstrdup(_PATH_SSH_USER_HOSTFILE2);
2043 }
Damien Millerfcd93202002-02-05 12:26:34 +11002044 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +00002045 options->log_level = SYSLOG_LEVEL_INFO;
dtucker@openbsd.org68d3a2a2017-04-28 03:20:27 +00002046 if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
2047 options->log_facility = SYSLOG_FACILITY_USER;
Ben Lindstrom3cecc9a2001-10-03 17:39:38 +00002048 if (options->no_host_authentication_for_localhost == - 1)
2049 options->no_host_authentication_for_localhost = 0;
Damien Millerbd394c32004-03-08 23:12:36 +11002050 if (options->identities_only == -1)
2051 options->identities_only = 0;
Ben Lindstromb6df73b2002-11-09 15:52:31 +00002052 if (options->enable_ssh_keysign == -1)
2053 options->enable_ssh_keysign = 0;
Damien Millera5539d22003-04-09 20:50:06 +10002054 if (options->rekey_limit == -1)
2055 options->rekey_limit = 0;
Darren Tuckerc53c2af2013-05-16 20:28:16 +10002056 if (options->rekey_interval == -1)
2057 options->rekey_interval = 0;
Damien Miller37876e92003-05-15 10:19:46 +10002058 if (options->verify_host_key_dns == -1)
2059 options->verify_host_key_dns = 0;
Damien Miller509b0102003-12-17 16:33:10 +11002060 if (options->server_alive_interval == -1)
2061 options->server_alive_interval = 0;
2062 if (options->server_alive_count_max == -1)
2063 options->server_alive_count_max = 3;
Damien Miller0e220db2004-06-15 10:34:08 +10002064 if (options->control_master == -1)
2065 options->control_master = 0;
Damien Millere11e1ea2010-08-03 16:04:46 +10002066 if (options->control_persist == -1) {
2067 options->control_persist = 0;
2068 options->control_persist_timeout = 0;
2069 }
Damien Millere1776152005-03-01 21:47:37 +11002070 if (options->hash_known_hosts == -1)
2071 options->hash_known_hosts = 0;
Damien Millerd27b9472005-12-13 19:29:02 +11002072 if (options->tun_open == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11002073 options->tun_open = SSH_TUNMODE_NO;
2074 if (options->tun_local == -1)
2075 options->tun_local = SSH_TUNID_ANY;
2076 if (options->tun_remote == -1)
2077 options->tun_remote = SSH_TUNID_ANY;
Damien Millerd27b9472005-12-13 19:29:02 +11002078 if (options->permit_local_command == -1)
2079 options->permit_local_command = 0;
Damien Miller10288242008-06-30 00:04:03 +10002080 if (options->visual_host_key == -1)
2081 options->visual_host_key = 0;
Damien Miller0dac6fb2010-11-20 15:19:38 +11002082 if (options->ip_qos_interactive == -1)
job@openbsd.org5ee84482018-04-04 15:12:17 +00002083 options->ip_qos_interactive = IPTOS_DSCP_AF21;
Damien Miller0dac6fb2010-11-20 15:19:38 +11002084 if (options->ip_qos_bulk == -1)
job@openbsd.org5ee84482018-04-04 15:12:17 +00002085 options->ip_qos_bulk = IPTOS_DSCP_CS1;
Damien Miller21771e22011-05-15 08:45:50 +10002086 if (options->request_tty == -1)
2087 options->request_tty = REQUEST_TTY_AUTO;
Damien Miller1262b662013-08-21 02:44:24 +10002088 if (options->proxy_use_fdpass == -1)
2089 options->proxy_use_fdpass = 0;
Damien Miller38505592013-10-17 11:48:13 +11002090 if (options->canonicalize_max_dots == -1)
2091 options->canonicalize_max_dots = 1;
2092 if (options->canonicalize_fallback_local == -1)
2093 options->canonicalize_fallback_local = 1;
2094 if (options->canonicalize_hostname == -1)
2095 options->canonicalize_hostname = SSH_CANONICALISE_NO;
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002096 if (options->fingerprint_hash == -1)
2097 options->fingerprint_hash = SSH_FP_HASH_DEFAULT;
djm@openbsd.org8d4f8722015-01-26 03:04:45 +00002098 if (options->update_hostkeys == -1)
djm@openbsd.org15ad7502015-02-02 07:41:40 +00002099 options->update_hostkeys = 0;
djm@openbsd.org312d2f22018-07-04 13:49:31 +00002100
2101 /* Expand KEX name lists */
2102 all_cipher = cipher_alg_list(',', 0);
2103 all_mac = mac_alg_list(',');
2104 all_kex = kex_alg_list(',');
2105 all_key = sshkey_alg_list(0, 0, 1, ',');
djm@openbsd.orgecac7e12018-09-20 03:30:44 +00002106 all_sig = sshkey_alg_list(0, 1, 1, ',');
djm@openbsd.org1b9dd4a2018-08-12 20:19:13 +00002107#define ASSEMBLE(what, defaults, all) \
2108 do { \
2109 if ((r = kex_assemble_names(&options->what, \
2110 defaults, all)) != 0) \
2111 fatal("%s: %s: %s", __func__, #what, ssh_err(r)); \
2112 } while (0)
2113 ASSEMBLE(ciphers, KEX_SERVER_ENCRYPT, all_cipher);
2114 ASSEMBLE(macs, KEX_SERVER_MAC, all_mac);
2115 ASSEMBLE(kex_algorithms, KEX_SERVER_KEX, all_kex);
2116 ASSEMBLE(hostbased_key_types, KEX_DEFAULT_PK_ALG, all_key);
2117 ASSEMBLE(pubkey_key_types, KEX_DEFAULT_PK_ALG, all_key);
djm@openbsd.orgecac7e12018-09-20 03:30:44 +00002118 ASSEMBLE(ca_sign_algorithms, SSH_ALLOWED_CA_SIGALGS, all_sig);
djm@openbsd.org1b9dd4a2018-08-12 20:19:13 +00002119#undef ASSEMBLE
djm@openbsd.org312d2f22018-07-04 13:49:31 +00002120 free(all_cipher);
2121 free(all_mac);
2122 free(all_kex);
2123 free(all_key);
djm@openbsd.orgecac7e12018-09-20 03:30:44 +00002124 free(all_sig);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002125
Damien Millere9fc72e2013-10-15 12:14:12 +11002126#define CLEAR_ON_NONE(v) \
2127 do { \
Damien Miller13f97b22014-02-24 15:57:55 +11002128 if (option_clear_or_none(v)) { \
Damien Millere9fc72e2013-10-15 12:14:12 +11002129 free(v); \
2130 v = NULL; \
2131 } \
2132 } while(0)
2133 CLEAR_ON_NONE(options->local_command);
bluhm@openbsd.org1112b532017-05-30 18:58:37 +00002134 CLEAR_ON_NONE(options->remote_command);
Damien Millere9fc72e2013-10-15 12:14:12 +11002135 CLEAR_ON_NONE(options->proxy_command);
2136 CLEAR_ON_NONE(options->control_path);
djm@openbsd.org5e39a492014-12-04 02:24:32 +00002137 CLEAR_ON_NONE(options->revoked_host_keys);
djm@openbsd.org4b22fd82018-05-22 00:13:26 +00002138 if (options->jump_host != NULL &&
2139 strcmp(options->jump_host, "none") == 0 &&
2140 options->jump_port == 0 && options->jump_user == NULL) {
2141 free(options->jump_host);
2142 options->jump_host = NULL;
2143 }
markus@openbsd.org1a75d142016-05-04 14:29:58 +00002144 /* options->identity_agent distinguishes NULL from 'none' */
Damien Miller95def091999-11-25 00:26:21 +11002145 /* options->user will be set in the main program if appropriate */
2146 /* options->hostname will be set in the main program if appropriate */
Ben Lindstrom4dccfa52000-12-28 16:40:05 +00002147 /* options->host_key_alias should not be set by default */
Ben Lindstromb9be60a2001-03-11 01:49:19 +00002148 /* options->preferred_authentications will be set in ssh */
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002149}
Damien Millerf91ee4c2005-03-01 21:24:33 +11002150
Damien Miller7acefbb2014-07-18 14:11:24 +10002151struct fwdarg {
2152 char *arg;
2153 int ispath;
2154};
2155
2156/*
2157 * parse_fwd_field
2158 * parses the next field in a port forwarding specification.
2159 * sets fwd to the parsed field and advances p past the colon
2160 * or sets it to NULL at end of string.
2161 * returns 0 on success, else non-zero.
2162 */
2163static int
2164parse_fwd_field(char **p, struct fwdarg *fwd)
2165{
2166 char *ep, *cp = *p;
2167 int ispath = 0;
2168
2169 if (*cp == '\0') {
2170 *p = NULL;
2171 return -1; /* end of string */
2172 }
2173
2174 /*
2175 * A field escaped with square brackets is used literally.
2176 * XXX - allow ']' to be escaped via backslash?
2177 */
2178 if (*cp == '[') {
2179 /* find matching ']' */
2180 for (ep = cp + 1; *ep != ']' && *ep != '\0'; ep++) {
2181 if (*ep == '/')
2182 ispath = 1;
2183 }
2184 /* no matching ']' or not at end of field. */
2185 if (ep[0] != ']' || (ep[1] != ':' && ep[1] != '\0'))
2186 return -1;
2187 /* NUL terminate the field and advance p past the colon */
2188 *ep++ = '\0';
2189 if (*ep != '\0')
2190 *ep++ = '\0';
2191 fwd->arg = cp + 1;
2192 fwd->ispath = ispath;
2193 *p = ep;
2194 return 0;
2195 }
2196
2197 for (cp = *p; *cp != '\0'; cp++) {
2198 switch (*cp) {
2199 case '\\':
2200 memmove(cp, cp + 1, strlen(cp + 1) + 1);
djm@openbsd.org78c2a4f2015-06-26 05:13:20 +00002201 if (*cp == '\0')
2202 return -1;
Damien Miller7acefbb2014-07-18 14:11:24 +10002203 break;
2204 case '/':
2205 ispath = 1;
2206 break;
2207 case ':':
2208 *cp++ = '\0';
2209 goto done;
2210 }
2211 }
2212done:
2213 fwd->arg = *p;
2214 fwd->ispath = ispath;
2215 *p = cp;
2216 return 0;
2217}
2218
Damien Millerf91ee4c2005-03-01 21:24:33 +11002219/*
2220 * parse_forward
2221 * parses a string containing a port forwarding specification of the form:
Damien Millera699d952008-11-03 19:27:34 +11002222 * dynamicfwd == 0
Damien Miller7acefbb2014-07-18 14:11:24 +10002223 * [listenhost:]listenport|listenpath:connecthost:connectport|connectpath
2224 * listenpath:connectpath
Damien Millera699d952008-11-03 19:27:34 +11002225 * dynamicfwd == 1
2226 * [listenhost:]listenport
Damien Millerf91ee4c2005-03-01 21:24:33 +11002227 * returns number of arguments parsed or zero on error
2228 */
2229int
Damien Miller7acefbb2014-07-18 14:11:24 +10002230parse_forward(struct Forward *fwd, const char *fwdspec, int dynamicfwd, int remotefwd)
Damien Millerf91ee4c2005-03-01 21:24:33 +11002231{
Damien Miller7acefbb2014-07-18 14:11:24 +10002232 struct fwdarg fwdargs[4];
2233 char *p, *cp;
Damien Millerf91ee4c2005-03-01 21:24:33 +11002234 int i;
Damien Millerf91ee4c2005-03-01 21:24:33 +11002235
Damien Miller7acefbb2014-07-18 14:11:24 +10002236 memset(fwd, 0, sizeof(*fwd));
2237 memset(fwdargs, 0, sizeof(fwdargs));
Damien Millerf91ee4c2005-03-01 21:24:33 +11002238
2239 cp = p = xstrdup(fwdspec);
2240
2241 /* skip leading spaces */
Damien Millerfdb23062013-11-21 13:57:15 +11002242 while (isspace((u_char)*cp))
Damien Millerf91ee4c2005-03-01 21:24:33 +11002243 cp++;
2244
Damien Miller7acefbb2014-07-18 14:11:24 +10002245 for (i = 0; i < 4; ++i) {
2246 if (parse_fwd_field(&cp, &fwdargs[i]) != 0)
Damien Millerf91ee4c2005-03-01 21:24:33 +11002247 break;
Damien Miller7acefbb2014-07-18 14:11:24 +10002248 }
Damien Millerf91ee4c2005-03-01 21:24:33 +11002249
Damien Millerf4b39532008-11-03 19:28:21 +11002250 /* Check for trailing garbage */
Damien Miller7acefbb2014-07-18 14:11:24 +10002251 if (cp != NULL && *cp != '\0') {
Damien Millerf91ee4c2005-03-01 21:24:33 +11002252 i = 0; /* failure */
Damien Miller7acefbb2014-07-18 14:11:24 +10002253 }
Damien Millerf91ee4c2005-03-01 21:24:33 +11002254
2255 switch (i) {
Damien Millera699d952008-11-03 19:27:34 +11002256 case 1:
Damien Miller7acefbb2014-07-18 14:11:24 +10002257 if (fwdargs[0].ispath) {
2258 fwd->listen_path = xstrdup(fwdargs[0].arg);
2259 fwd->listen_port = PORT_STREAMLOCAL;
2260 } else {
2261 fwd->listen_host = NULL;
2262 fwd->listen_port = a2port(fwdargs[0].arg);
2263 }
Damien Millera699d952008-11-03 19:27:34 +11002264 fwd->connect_host = xstrdup("socks");
2265 break;
2266
2267 case 2:
Damien Miller7acefbb2014-07-18 14:11:24 +10002268 if (fwdargs[0].ispath && fwdargs[1].ispath) {
2269 fwd->listen_path = xstrdup(fwdargs[0].arg);
2270 fwd->listen_port = PORT_STREAMLOCAL;
2271 fwd->connect_path = xstrdup(fwdargs[1].arg);
2272 fwd->connect_port = PORT_STREAMLOCAL;
2273 } else if (fwdargs[1].ispath) {
2274 fwd->listen_host = NULL;
2275 fwd->listen_port = a2port(fwdargs[0].arg);
2276 fwd->connect_path = xstrdup(fwdargs[1].arg);
2277 fwd->connect_port = PORT_STREAMLOCAL;
2278 } else {
2279 fwd->listen_host = xstrdup(fwdargs[0].arg);
2280 fwd->listen_port = a2port(fwdargs[1].arg);
2281 fwd->connect_host = xstrdup("socks");
2282 }
Damien Millera699d952008-11-03 19:27:34 +11002283 break;
2284
Damien Millerf91ee4c2005-03-01 21:24:33 +11002285 case 3:
Damien Miller7acefbb2014-07-18 14:11:24 +10002286 if (fwdargs[0].ispath) {
2287 fwd->listen_path = xstrdup(fwdargs[0].arg);
2288 fwd->listen_port = PORT_STREAMLOCAL;
2289 fwd->connect_host = xstrdup(fwdargs[1].arg);
2290 fwd->connect_port = a2port(fwdargs[2].arg);
2291 } else if (fwdargs[2].ispath) {
2292 fwd->listen_host = xstrdup(fwdargs[0].arg);
2293 fwd->listen_port = a2port(fwdargs[1].arg);
2294 fwd->connect_path = xstrdup(fwdargs[2].arg);
2295 fwd->connect_port = PORT_STREAMLOCAL;
2296 } else {
2297 fwd->listen_host = NULL;
2298 fwd->listen_port = a2port(fwdargs[0].arg);
2299 fwd->connect_host = xstrdup(fwdargs[1].arg);
2300 fwd->connect_port = a2port(fwdargs[2].arg);
2301 }
Damien Millerf91ee4c2005-03-01 21:24:33 +11002302 break;
2303
2304 case 4:
Damien Miller7acefbb2014-07-18 14:11:24 +10002305 fwd->listen_host = xstrdup(fwdargs[0].arg);
2306 fwd->listen_port = a2port(fwdargs[1].arg);
2307 fwd->connect_host = xstrdup(fwdargs[2].arg);
2308 fwd->connect_port = a2port(fwdargs[3].arg);
Damien Millerf91ee4c2005-03-01 21:24:33 +11002309 break;
2310 default:
2311 i = 0; /* failure */
2312 }
2313
Darren Tuckera627d422013-06-02 07:31:17 +10002314 free(p);
Damien Millerf91ee4c2005-03-01 21:24:33 +11002315
Damien Millera699d952008-11-03 19:27:34 +11002316 if (dynamicfwd) {
2317 if (!(i == 1 || i == 2))
2318 goto fail_free;
2319 } else {
Damien Miller7acefbb2014-07-18 14:11:24 +10002320 if (!(i == 3 || i == 4)) {
2321 if (fwd->connect_path == NULL &&
2322 fwd->listen_path == NULL)
2323 goto fail_free;
2324 }
2325 if (fwd->connect_port <= 0 && fwd->connect_path == NULL)
Damien Millera699d952008-11-03 19:27:34 +11002326 goto fail_free;
2327 }
2328
Damien Miller7acefbb2014-07-18 14:11:24 +10002329 if ((fwd->listen_port < 0 && fwd->listen_path == NULL) ||
2330 (!remotefwd && fwd->listen_port == 0))
Damien Millerf91ee4c2005-03-01 21:24:33 +11002331 goto fail_free;
Damien Millerf91ee4c2005-03-01 21:24:33 +11002332 if (fwd->connect_host != NULL &&
2333 strlen(fwd->connect_host) >= NI_MAXHOST)
2334 goto fail_free;
Damien Miller7acefbb2014-07-18 14:11:24 +10002335 /* XXX - if connecting to a remote socket, max sun len may not match this host */
2336 if (fwd->connect_path != NULL &&
2337 strlen(fwd->connect_path) >= PATH_MAX_SUN)
2338 goto fail_free;
Damien Miller4bf648f2009-02-14 16:28:21 +11002339 if (fwd->listen_host != NULL &&
2340 strlen(fwd->listen_host) >= NI_MAXHOST)
2341 goto fail_free;
Damien Miller7acefbb2014-07-18 14:11:24 +10002342 if (fwd->listen_path != NULL &&
2343 strlen(fwd->listen_path) >= PATH_MAX_SUN)
2344 goto fail_free;
Damien Millerf91ee4c2005-03-01 21:24:33 +11002345
2346 return (i);
2347
2348 fail_free:
Darren Tuckera627d422013-06-02 07:31:17 +10002349 free(fwd->connect_host);
2350 fwd->connect_host = NULL;
Damien Miller7acefbb2014-07-18 14:11:24 +10002351 free(fwd->connect_path);
2352 fwd->connect_path = NULL;
Darren Tuckera627d422013-06-02 07:31:17 +10002353 free(fwd->listen_host);
2354 fwd->listen_host = NULL;
Damien Miller7acefbb2014-07-18 14:11:24 +10002355 free(fwd->listen_path);
2356 fwd->listen_path = NULL;
Damien Millerf91ee4c2005-03-01 21:24:33 +11002357 return (0);
2358}
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002359
djm@openbsd.orged877ef2016-07-15 00:24:30 +00002360int
2361parse_jump(const char *s, Options *o, int active)
2362{
2363 char *orig, *sdup, *cp;
2364 char *host = NULL, *user = NULL;
naddy@openbsd.org324583e2016-07-20 10:45:27 +00002365 int ret = -1, port = -1, first;
djm@openbsd.orged877ef2016-07-15 00:24:30 +00002366
2367 active &= o->proxy_command == NULL && o->jump_host == NULL;
2368
2369 orig = sdup = xstrdup(s);
naddy@openbsd.org324583e2016-07-20 10:45:27 +00002370 first = active;
djm@openbsd.org286f5a72016-07-22 03:35:11 +00002371 do {
djm@openbsd.org4b22fd82018-05-22 00:13:26 +00002372 if (strcasecmp(s, "none") == 0)
2373 break;
djm@openbsd.org286f5a72016-07-22 03:35:11 +00002374 if ((cp = strrchr(sdup, ',')) == NULL)
2375 cp = sdup; /* last */
2376 else
2377 *cp++ = '\0';
2378
naddy@openbsd.org324583e2016-07-20 10:45:27 +00002379 if (first) {
djm@openbsd.orged877ef2016-07-15 00:24:30 +00002380 /* First argument and configuration is active */
millert@openbsd.org887669e2017-10-21 23:06:24 +00002381 if (parse_ssh_uri(cp, &user, &host, &port) == -1 ||
2382 parse_user_host_port(cp, &user, &host, &port) != 0)
djm@openbsd.orged877ef2016-07-15 00:24:30 +00002383 goto out;
2384 } else {
2385 /* Subsequent argument or inactive configuration */
millert@openbsd.org887669e2017-10-21 23:06:24 +00002386 if (parse_ssh_uri(cp, NULL, NULL, NULL) == -1 ||
2387 parse_user_host_port(cp, NULL, NULL, NULL) != 0)
djm@openbsd.orged877ef2016-07-15 00:24:30 +00002388 goto out;
2389 }
naddy@openbsd.org324583e2016-07-20 10:45:27 +00002390 first = 0; /* only check syntax for subsequent hosts */
djm@openbsd.org286f5a72016-07-22 03:35:11 +00002391 } while (cp != sdup);
djm@openbsd.orged877ef2016-07-15 00:24:30 +00002392 /* success */
naddy@openbsd.org324583e2016-07-20 10:45:27 +00002393 if (active) {
djm@openbsd.org4b22fd82018-05-22 00:13:26 +00002394 if (strcasecmp(s, "none") == 0) {
2395 o->jump_host = xstrdup("none");
2396 o->jump_port = 0;
2397 } else {
2398 o->jump_user = user;
2399 o->jump_host = host;
2400 o->jump_port = port;
2401 o->proxy_command = xstrdup("none");
2402 user = host = NULL;
2403 if ((cp = strrchr(s, ',')) != NULL && cp != s) {
2404 o->jump_extra = xstrdup(s);
2405 o->jump_extra[cp - s] = '\0';
2406 }
djm@openbsd.org286f5a72016-07-22 03:35:11 +00002407 }
naddy@openbsd.org324583e2016-07-20 10:45:27 +00002408 }
djm@openbsd.orged877ef2016-07-15 00:24:30 +00002409 ret = 0;
2410 out:
naddy@openbsd.org324583e2016-07-20 10:45:27 +00002411 free(orig);
djm@openbsd.orged877ef2016-07-15 00:24:30 +00002412 free(user);
2413 free(host);
2414 return ret;
2415}
2416
millert@openbsd.org887669e2017-10-21 23:06:24 +00002417int
2418parse_ssh_uri(const char *uri, char **userp, char **hostp, int *portp)
2419{
2420 char *path;
2421 int r;
2422
2423 r = parse_uri("ssh", uri, userp, hostp, portp, &path);
2424 if (r == 0 && path != NULL)
2425 r = -1; /* path not allowed */
2426 return r;
2427}
2428
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002429/* XXX the following is a near-vebatim copy from servconf.c; refactor */
2430static const char *
2431fmt_multistate_int(int val, const struct multistate *m)
2432{
2433 u_int i;
2434
2435 for (i = 0; m[i].key != NULL; i++) {
2436 if (m[i].value == val)
2437 return m[i].key;
2438 }
2439 return "UNKNOWN";
2440}
2441
2442static const char *
2443fmt_intarg(OpCodes code, int val)
2444{
2445 if (val == -1)
2446 return "unset";
2447 switch (code) {
2448 case oAddressFamily:
2449 return fmt_multistate_int(val, multistate_addressfamily);
2450 case oVerifyHostKeyDNS:
djm@openbsd.org523463a2015-02-16 22:13:32 +00002451 case oUpdateHostkeys:
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002452 return fmt_multistate_int(val, multistate_yesnoask);
djm@openbsd.org22376d22017-09-03 23:33:13 +00002453 case oStrictHostKeyChecking:
2454 return fmt_multistate_int(val, multistate_strict_hostkey);
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002455 case oControlMaster:
2456 return fmt_multistate_int(val, multistate_controlmaster);
2457 case oTunnel:
2458 return fmt_multistate_int(val, multistate_tunnel);
2459 case oRequestTTY:
2460 return fmt_multistate_int(val, multistate_requesttty);
2461 case oCanonicalizeHostname:
2462 return fmt_multistate_int(val, multistate_canonicalizehostname);
djm@openbsd.org30fd7f92018-04-06 03:51:27 +00002463 case oAddKeysToAgent:
2464 return fmt_multistate_int(val, multistate_yesnoaskconfirm);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002465 case oFingerprintHash:
2466 return ssh_digest_alg_name(val);
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002467 default:
2468 switch (val) {
2469 case 0:
2470 return "no";
2471 case 1:
2472 return "yes";
2473 default:
2474 return "UNKNOWN";
2475 }
2476 }
2477}
2478
2479static const char *
2480lookup_opcode_name(OpCodes code)
2481{
2482 u_int i;
2483
2484 for (i = 0; keywords[i].name != NULL; i++)
2485 if (keywords[i].opcode == code)
2486 return(keywords[i].name);
2487 return "UNKNOWN";
2488}
2489
2490static void
2491dump_cfg_int(OpCodes code, int val)
2492{
2493 printf("%s %d\n", lookup_opcode_name(code), val);
2494}
2495
2496static void
2497dump_cfg_fmtint(OpCodes code, int val)
2498{
2499 printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
2500}
2501
2502static void
2503dump_cfg_string(OpCodes code, const char *val)
2504{
2505 if (val == NULL)
2506 return;
2507 printf("%s %s\n", lookup_opcode_name(code), val);
2508}
2509
2510static void
2511dump_cfg_strarray(OpCodes code, u_int count, char **vals)
2512{
2513 u_int i;
2514
2515 for (i = 0; i < count; i++)
2516 printf("%s %s\n", lookup_opcode_name(code), vals[i]);
2517}
2518
2519static void
2520dump_cfg_strarray_oneline(OpCodes code, u_int count, char **vals)
2521{
2522 u_int i;
2523
2524 printf("%s", lookup_opcode_name(code));
2525 for (i = 0; i < count; i++)
2526 printf(" %s", vals[i]);
2527 printf("\n");
2528}
2529
2530static void
2531dump_cfg_forwards(OpCodes code, u_int count, const struct Forward *fwds)
2532{
2533 const struct Forward *fwd;
2534 u_int i;
2535
2536 /* oDynamicForward */
2537 for (i = 0; i < count; i++) {
2538 fwd = &fwds[i];
djm@openbsd.org4833d012017-01-30 00:34:01 +00002539 if (code == oDynamicForward && fwd->connect_host != NULL &&
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002540 strcmp(fwd->connect_host, "socks") != 0)
2541 continue;
djm@openbsd.org4833d012017-01-30 00:34:01 +00002542 if (code == oLocalForward && fwd->connect_host != NULL &&
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002543 strcmp(fwd->connect_host, "socks") == 0)
2544 continue;
2545 printf("%s", lookup_opcode_name(code));
2546 if (fwd->listen_port == PORT_STREAMLOCAL)
2547 printf(" %s", fwd->listen_path);
2548 else if (fwd->listen_host == NULL)
2549 printf(" %d", fwd->listen_port);
2550 else {
2551 printf(" [%s]:%d",
2552 fwd->listen_host, fwd->listen_port);
2553 }
2554 if (code != oDynamicForward) {
2555 if (fwd->connect_port == PORT_STREAMLOCAL)
2556 printf(" %s", fwd->connect_path);
2557 else if (fwd->connect_host == NULL)
2558 printf(" %d", fwd->connect_port);
2559 else {
2560 printf(" [%s]:%d",
2561 fwd->connect_host, fwd->connect_port);
2562 }
2563 }
2564 printf("\n");
2565 }
2566}
2567
2568void
2569dump_client_config(Options *o, const char *host)
2570{
2571 int i;
djm@openbsd.org312d2f22018-07-04 13:49:31 +00002572 char buf[8], *all_key;
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002573
djm@openbsd.org60a92472015-08-21 23:53:08 +00002574 /* This is normally prepared in ssh_kex2 */
djm@openbsd.org312d2f22018-07-04 13:49:31 +00002575 all_key = sshkey_alg_list(0, 0, 1, ',');
2576 if (kex_assemble_names( &o->hostkeyalgorithms,
2577 KEX_DEFAULT_PK_ALG, all_key) != 0)
djm@openbsd.org60a92472015-08-21 23:53:08 +00002578 fatal("%s: kex_assemble_names failed", __func__);
djm@openbsd.org312d2f22018-07-04 13:49:31 +00002579 free(all_key);
djm@openbsd.org60a92472015-08-21 23:53:08 +00002580
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002581 /* Most interesting options first: user, host, port */
2582 dump_cfg_string(oUser, o->user);
2583 dump_cfg_string(oHostName, host);
2584 dump_cfg_int(oPort, o->port);
2585
2586 /* Flag options */
djm@openbsd.org30fd7f92018-04-06 03:51:27 +00002587 dump_cfg_fmtint(oAddKeysToAgent, o->add_keys_to_agent);
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002588 dump_cfg_fmtint(oAddressFamily, o->address_family);
2589 dump_cfg_fmtint(oBatchMode, o->batch_mode);
2590 dump_cfg_fmtint(oCanonicalizeFallbackLocal, o->canonicalize_fallback_local);
2591 dump_cfg_fmtint(oCanonicalizeHostname, o->canonicalize_hostname);
2592 dump_cfg_fmtint(oChallengeResponseAuthentication, o->challenge_response_authentication);
2593 dump_cfg_fmtint(oCheckHostIP, o->check_host_ip);
2594 dump_cfg_fmtint(oCompression, o->compression);
2595 dump_cfg_fmtint(oControlMaster, o->control_master);
2596 dump_cfg_fmtint(oEnableSSHKeysign, o->enable_ssh_keysign);
dtucker@openbsd.org0cb2f4c2016-06-03 04:09:38 +00002597 dump_cfg_fmtint(oClearAllForwardings, o->clear_forwardings);
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002598 dump_cfg_fmtint(oExitOnForwardFailure, o->exit_on_forward_failure);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002599 dump_cfg_fmtint(oFingerprintHash, o->fingerprint_hash);
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002600 dump_cfg_fmtint(oForwardAgent, o->forward_agent);
2601 dump_cfg_fmtint(oForwardX11, o->forward_x11);
2602 dump_cfg_fmtint(oForwardX11Trusted, o->forward_x11_trusted);
2603 dump_cfg_fmtint(oGatewayPorts, o->fwd_opts.gateway_ports);
2604#ifdef GSSAPI
2605 dump_cfg_fmtint(oGssAuthentication, o->gss_authentication);
2606 dump_cfg_fmtint(oGssDelegateCreds, o->gss_deleg_creds);
2607#endif /* GSSAPI */
2608 dump_cfg_fmtint(oHashKnownHosts, o->hash_known_hosts);
2609 dump_cfg_fmtint(oHostbasedAuthentication, o->hostbased_authentication);
2610 dump_cfg_fmtint(oIdentitiesOnly, o->identities_only);
2611 dump_cfg_fmtint(oKbdInteractiveAuthentication, o->kbd_interactive_authentication);
2612 dump_cfg_fmtint(oNoHostAuthenticationForLocalhost, o->no_host_authentication_for_localhost);
2613 dump_cfg_fmtint(oPasswordAuthentication, o->password_authentication);
2614 dump_cfg_fmtint(oPermitLocalCommand, o->permit_local_command);
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002615 dump_cfg_fmtint(oProxyUseFdpass, o->proxy_use_fdpass);
2616 dump_cfg_fmtint(oPubkeyAuthentication, o->pubkey_authentication);
2617 dump_cfg_fmtint(oRequestTTY, o->request_tty);
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002618 dump_cfg_fmtint(oStreamLocalBindUnlink, o->fwd_opts.streamlocal_bind_unlink);
2619 dump_cfg_fmtint(oStrictHostKeyChecking, o->strict_host_key_checking);
2620 dump_cfg_fmtint(oTCPKeepAlive, o->tcp_keep_alive);
2621 dump_cfg_fmtint(oTunnel, o->tun_open);
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002622 dump_cfg_fmtint(oVerifyHostKeyDNS, o->verify_host_key_dns);
2623 dump_cfg_fmtint(oVisualHostKey, o->visual_host_key);
djm@openbsd.org8d4f8722015-01-26 03:04:45 +00002624 dump_cfg_fmtint(oUpdateHostkeys, o->update_hostkeys);
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002625
2626 /* Integer options */
2627 dump_cfg_int(oCanonicalizeMaxDots, o->canonicalize_max_dots);
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002628 dump_cfg_int(oConnectionAttempts, o->connection_attempts);
2629 dump_cfg_int(oForwardX11Timeout, o->forward_x11_timeout);
2630 dump_cfg_int(oNumberOfPasswordPrompts, o->number_of_password_prompts);
2631 dump_cfg_int(oServerAliveCountMax, o->server_alive_count_max);
2632 dump_cfg_int(oServerAliveInterval, o->server_alive_interval);
2633
2634 /* String options */
2635 dump_cfg_string(oBindAddress, o->bind_address);
djm@openbsd.orgac2e3022018-02-23 02:34:33 +00002636 dump_cfg_string(oBindInterface, o->bind_interface);
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002637 dump_cfg_string(oCiphers, o->ciphers ? o->ciphers : KEX_CLIENT_ENCRYPT);
2638 dump_cfg_string(oControlPath, o->control_path);
djm@openbsd.org60a92472015-08-21 23:53:08 +00002639 dump_cfg_string(oHostKeyAlgorithms, o->hostkeyalgorithms);
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002640 dump_cfg_string(oHostKeyAlias, o->host_key_alias);
djm@openbsd.org46347ed2015-01-30 11:43:14 +00002641 dump_cfg_string(oHostbasedKeyTypes, o->hostbased_key_types);
markus@openbsd.orgb02ad1c2016-05-04 12:21:53 +00002642 dump_cfg_string(oIdentityAgent, o->identity_agent);
djm@openbsd.org30fd7f92018-04-06 03:51:27 +00002643 dump_cfg_string(oIgnoreUnknown, o->ignored_unknown);
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002644 dump_cfg_string(oKbdInteractiveDevices, o->kbd_interactive_devices);
2645 dump_cfg_string(oKexAlgorithms, o->kex_algorithms ? o->kex_algorithms : KEX_CLIENT_KEX);
djm@openbsd.orgecac7e12018-09-20 03:30:44 +00002646 dump_cfg_string(oCASignatureAlgorithms, o->ca_sign_algorithms ? o->ca_sign_algorithms : SSH_ALLOWED_CA_SIGALGS);
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002647 dump_cfg_string(oLocalCommand, o->local_command);
bluhm@openbsd.org1112b532017-05-30 18:58:37 +00002648 dump_cfg_string(oRemoteCommand, o->remote_command);
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002649 dump_cfg_string(oLogLevel, log_level_name(o->log_level));
2650 dump_cfg_string(oMacs, o->macs ? o->macs : KEX_CLIENT_MAC);
djm@openbsd.org381a2612017-01-30 00:38:50 +00002651#ifdef ENABLE_PKCS11
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002652 dump_cfg_string(oPKCS11Provider, o->pkcs11_provider);
djm@openbsd.org381a2612017-01-30 00:38:50 +00002653#endif
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002654 dump_cfg_string(oPreferredAuthentications, o->preferred_authentications);
djm@openbsd.org0c46bbe2015-10-07 15:59:12 +00002655 dump_cfg_string(oPubkeyAcceptedKeyTypes, o->pubkey_key_types);
djm@openbsd.org5e39a492014-12-04 02:24:32 +00002656 dump_cfg_string(oRevokedHostKeys, o->revoked_host_keys);
djm@openbsd.org46347ed2015-01-30 11:43:14 +00002657 dump_cfg_string(oXAuthLocation, o->xauth_location);
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002658
djm@openbsd.org46347ed2015-01-30 11:43:14 +00002659 /* Forwards */
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002660 dump_cfg_forwards(oDynamicForward, o->num_local_forwards, o->local_forwards);
2661 dump_cfg_forwards(oLocalForward, o->num_local_forwards, o->local_forwards);
2662 dump_cfg_forwards(oRemoteForward, o->num_remote_forwards, o->remote_forwards);
2663
2664 /* String array options */
2665 dump_cfg_strarray(oIdentityFile, o->num_identity_files, o->identity_files);
2666 dump_cfg_strarray_oneline(oCanonicalDomains, o->num_canonical_domains, o->canonical_domains);
djm@openbsd.org30fd7f92018-04-06 03:51:27 +00002667 dump_cfg_strarray(oCertificateFile, o->num_certificate_files, o->certificate_files);
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002668 dump_cfg_strarray_oneline(oGlobalKnownHostsFile, o->num_system_hostfiles, o->system_hostfiles);
2669 dump_cfg_strarray_oneline(oUserKnownHostsFile, o->num_user_hostfiles, o->user_hostfiles);
2670 dump_cfg_strarray(oSendEnv, o->num_send_env, o->send_env);
djm@openbsd.org7082bb52018-06-09 03:01:12 +00002671 dump_cfg_strarray(oSetEnv, o->num_setenv, o->setenv);
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002672
2673 /* Special cases */
2674
2675 /* oConnectTimeout */
2676 if (o->connection_timeout == -1)
2677 printf("connecttimeout none\n");
2678 else
2679 dump_cfg_int(oConnectTimeout, o->connection_timeout);
2680
2681 /* oTunnelDevice */
2682 printf("tunneldevice");
2683 if (o->tun_local == SSH_TUNID_ANY)
2684 printf(" any");
2685 else
2686 printf(" %d", o->tun_local);
2687 if (o->tun_remote == SSH_TUNID_ANY)
2688 printf(":any");
2689 else
2690 printf(":%d", o->tun_remote);
2691 printf("\n");
2692
2693 /* oCanonicalizePermittedCNAMEs */
2694 if ( o->num_permitted_cnames > 0) {
2695 printf("canonicalizePermittedcnames");
2696 for (i = 0; i < o->num_permitted_cnames; i++) {
2697 printf(" %s:%s", o->permitted_cnames[i].source_list,
2698 o->permitted_cnames[i].target_list);
2699 }
2700 printf("\n");
2701 }
2702
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002703 /* oControlPersist */
2704 if (o->control_persist == 0 || o->control_persist_timeout == 0)
2705 dump_cfg_fmtint(oControlPersist, o->control_persist);
2706 else
2707 dump_cfg_int(oControlPersist, o->control_persist_timeout);
2708
2709 /* oEscapeChar */
2710 if (o->escape_char == SSH_ESCAPECHAR_NONE)
2711 printf("escapechar none\n");
2712 else {
djm@openbsd.orged877ef2016-07-15 00:24:30 +00002713 vis(buf, o->escape_char, VIS_WHITE, 0);
2714 printf("escapechar %s\n", buf);
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002715 }
2716
2717 /* oIPQoS */
2718 printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
2719 printf("%s\n", iptos2str(o->ip_qos_bulk));
2720
2721 /* oRekeyLimit */
dtucker@openbsd.org921ff002016-01-29 02:54:45 +00002722 printf("rekeylimit %llu %d\n",
2723 (unsigned long long)o->rekey_limit, o->rekey_interval);
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002724
2725 /* oStreamLocalBindMask */
2726 printf("streamlocalbindmask 0%o\n",
2727 o->fwd_opts.streamlocal_bind_mask);
djm@openbsd.orged877ef2016-07-15 00:24:30 +00002728
djm@openbsd.org30fd7f92018-04-06 03:51:27 +00002729 /* oLogFacility */
2730 printf("syslogfacility %s\n", log_facility_name(o->log_facility));
2731
djm@openbsd.orged877ef2016-07-15 00:24:30 +00002732 /* oProxyCommand / oProxyJump */
2733 if (o->jump_host == NULL)
2734 dump_cfg_string(oProxyCommand, o->proxy_command);
2735 else {
2736 /* Check for numeric addresses */
2737 i = strchr(o->jump_host, ':') != NULL ||
2738 strspn(o->jump_host, "1234567890.") == strlen(o->jump_host);
2739 snprintf(buf, sizeof(buf), "%d", o->jump_port);
2740 printf("proxyjump %s%s%s%s%s%s%s%s%s\n",
djm@openbsd.org286f5a72016-07-22 03:35:11 +00002741 /* optional additional jump spec */
2742 o->jump_extra == NULL ? "" : o->jump_extra,
2743 o->jump_extra == NULL ? "" : ",",
djm@openbsd.orged877ef2016-07-15 00:24:30 +00002744 /* optional user */
2745 o->jump_user == NULL ? "" : o->jump_user,
2746 o->jump_user == NULL ? "" : "@",
2747 /* opening [ if hostname is numeric */
2748 i ? "[" : "",
2749 /* mandatory hostname */
2750 o->jump_host,
2751 /* closing ] if hostname is numeric */
2752 i ? "]" : "",
2753 /* optional port number */
2754 o->jump_port <= 0 ? "" : ":",
djm@openbsd.org286f5a72016-07-22 03:35:11 +00002755 o->jump_port <= 0 ? "" : buf);
djm@openbsd.orged877ef2016-07-15 00:24:30 +00002756 }
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002757}