blob: f1c860b9cf6116db773d466e6ddc970fb3c28305 [file] [log] [blame]
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00001/* $OpenBSD: readconf.c,v 1.238 2015/07/10 06:21:53 markus 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>
Darren Tuckere194ba42013-05-16 20:47:31 +100042#ifdef HAVE_UTIL_H
Darren Tuckerb7ee8522013-05-16 20:33:10 +100043#include <util.h>
Darren Tuckere194ba42013-05-16 20:47:31 +100044#endif
djm@openbsd.org957fbce2014-10-08 22:20:25 +000045#if defined(HAVE_STRNVIS) && defined(HAVE_VIS_H) && !defined(BROKEN_STRNVIS)
46# include <vis.h>
47#endif
Damien Millerc7b06362006-03-15 11:53:45 +110048
Damien Millerd4a8b7e1999-10-27 13:42:43 +100049#include "xmalloc.h"
Damien Millerd7834352006-08-05 12:39:39 +100050#include "ssh.h"
Damien Miller78928792000-04-12 20:17:38 +100051#include "compat.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000052#include "cipher.h"
53#include "pathnames.h"
54#include "log.h"
djm@openbsd.org1129dcf2015-01-15 09:40:00 +000055#include "sshkey.h"
Damien Miller7acefbb2014-07-18 14:11:24 +100056#include "misc.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000057#include "readconf.h"
58#include "match.h"
Ben Lindstrom06b33aa2001-02-15 03:01:59 +000059#include "kex.h"
60#include "mac.h"
Damien Miller194fd902013-10-15 12:13:05 +110061#include "uidswap.h"
djm@openbsd.org957fbce2014-10-08 22:20:25 +000062#include "myproposal.h"
djm@openbsd.org56d1c832014-12-21 22:27:55 +000063#include "digest.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100064
65/* Format of the configuration file:
66
67 # Configuration data is parsed as follows:
68 # 1. command line options
69 # 2. user-specific file
70 # 3. system-wide file
71 # Any configuration value is only changed the first time it is set.
72 # Thus, host-specific definitions should be at the beginning of the
73 # configuration file, and defaults at the end.
74
75 # Host-specific declarations. These may override anything above. A single
76 # host may match multiple declarations; these are processed in the order
77 # that they are given in.
78
79 Host *.ngs.fi ngs.fi
Ben Lindstrom4daea862002-06-09 20:04:02 +000080 User foo
Damien Millerd4a8b7e1999-10-27 13:42:43 +100081
82 Host fake.com
83 HostName another.host.name.real.org
84 User blaah
85 Port 34289
86 ForwardX11 no
87 ForwardAgent no
88
89 Host books.com
90 RemoteForward 9999 shadows.cs.hut.fi:9999
91 Cipher 3des
92
93 Host fascist.blob.com
94 Port 23123
95 User tylonen
Damien Millerd4a8b7e1999-10-27 13:42:43 +100096 PasswordAuthentication no
97
98 Host puukko.hut.fi
99 User t35124p
100 ProxyCommand ssh-proxy %h %p
101
102 Host *.fr
Ben Lindstrom4daea862002-06-09 20:04:02 +0000103 PublicKeyAuthentication no
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000104
105 Host *.su
106 Cipher none
107 PasswordAuthentication no
108
Damien Millerd27b9472005-12-13 19:29:02 +1100109 Host vpn.fake.com
110 Tunnel yes
111 TunnelDevice 3
112
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000113 # Defaults for various options
114 Host *
115 ForwardAgent no
Damien Miller0bc1bd82000-11-13 22:57:25 +1100116 ForwardX11 no
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000117 PasswordAuthentication yes
118 RSAAuthentication yes
119 RhostsRSAAuthentication yes
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000120 StrictHostKeyChecking yes
Damien Miller12c150e2003-12-17 16:31:10 +1100121 TcpKeepAlive no
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000122 IdentityFile ~/.ssh/identity
123 Port 22
124 EscapeChar ~
125
126*/
127
128/* Keyword tokens. */
129
Damien Miller95def091999-11-25 00:26:21 +1100130typedef enum {
131 oBadOption,
Damien Miller194fd902013-10-15 12:13:05 +1100132 oHost, oMatch,
Damien Miller1ab6a512010-06-26 10:02:24 +1000133 oForwardAgent, oForwardX11, oForwardX11Trusted, oForwardX11Timeout,
134 oGatewayPorts, oExitOnForwardFailure,
Ben Lindstromcb72e4f2002-06-21 00:41:51 +0000135 oPasswordAuthentication, oRSAAuthentication,
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000136 oChallengeResponseAuthentication, oXAuthLocation,
Damien Miller95def091999-11-25 00:26:21 +1100137 oIdentityFile, oHostName, oPort, oCipher, oRemoteForward, oLocalForward,
Damien Miller194fd902013-10-15 12:13:05 +1100138 oUser, oEscapeChar, oRhostsRSAAuthentication, oProxyCommand,
Damien Miller95def091999-11-25 00:26:21 +1100139 oGlobalKnownHostsFile, oUserKnownHostsFile, oConnectionAttempts,
140 oBatchMode, oCheckHostIP, oStrictHostKeyChecking, oCompression,
Damien Miller12c150e2003-12-17 16:31:10 +1100141 oCompressionLevel, oTCPKeepAlive, oNumberOfPasswordPrompts,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000142 oUsePrivilegedPort, oLogLevel, oCiphers, oProtocol, oMacs,
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000143 oPubkeyAuthentication,
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000144 oKbdInteractiveAuthentication, oKbdInteractiveDevices, oHostKeyAlias,
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000145 oDynamicForward, oPreferredAuthentications, oHostbasedAuthentication,
Damien Miller7ea845e2010-02-12 09:21:02 +1100146 oHostKeyAlgorithms, oBindAddress, oPKCS11Provider,
Ben Lindstrom4daea862002-06-09 20:04:02 +0000147 oClearAllForwardings, oNoHostAuthenticationForLocalhost,
Damien Millerb78d5eb2003-05-16 11:39:04 +1000148 oEnableSSHKeysign, oRekeyLimit, oVerifyHostKeyDNS, oConnectTimeout,
Darren Tucker0efd1552003-08-26 11:49:55 +1000149 oAddressFamily, oGssAuthentication, oGssDelegateCreds,
Damien Millerbd394c32004-03-08 23:12:36 +1100150 oServerAliveInterval, oServerAliveCountMax, oIdentitiesOnly,
Damien Millere11e1ea2010-08-03 16:04:46 +1000151 oSendEnv, oControlPath, oControlMaster, oControlPersist,
152 oHashKnownHosts,
Damien Millerd27b9472005-12-13 19:29:02 +1100153 oTunnel, oTunnelDevice, oLocalCommand, oPermitLocalCommand,
Damien Miller7cc194f2014-02-04 11:12:56 +1100154 oVisualHostKey, oUseRoaming,
Damien Miller1262b662013-08-21 02:44:24 +1000155 oKexAlgorithms, oIPQoS, oRequestTTY, oIgnoreUnknown, oProxyUseFdpass,
Damien Miller38505592013-10-17 11:48:13 +1100156 oCanonicalDomains, oCanonicalizeHostname, oCanonicalizeMaxDots,
157 oCanonicalizeFallbackLocal, oCanonicalizePermittedCNAMEs,
djm@openbsd.org5e39a492014-12-04 02:24:32 +0000158 oStreamLocalBindMask, oStreamLocalBindUnlink, oRevokedHostKeys,
djm@openbsd.org46347ed2015-01-30 11:43:14 +0000159 oFingerprintHash, oUpdateHostkeys, oHostbasedKeyTypes,
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000160 oPubkeyAcceptedKeyTypes,
Darren Tucker07636982013-05-16 20:30:03 +1000161 oIgnoredUnknownOption, oDeprecated, oUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000162} OpCodes;
163
164/* Textual representations of the tokens. */
165
Damien Miller95def091999-11-25 00:26:21 +1100166static struct {
167 const char *name;
168 OpCodes opcode;
169} keywords[] = {
170 { "forwardagent", oForwardAgent },
171 { "forwardx11", oForwardX11 },
Darren Tucker0a118da2003-10-15 15:54:32 +1000172 { "forwardx11trusted", oForwardX11Trusted },
Damien Miller1ab6a512010-06-26 10:02:24 +1000173 { "forwardx11timeout", oForwardX11Timeout },
Darren Tuckere7d4b192006-07-12 22:17:10 +1000174 { "exitonforwardfailure", oExitOnForwardFailure },
Damien Millerd3a18572000-06-07 19:55:44 +1000175 { "xauthlocation", oXAuthLocation },
Damien Miller95def091999-11-25 00:26:21 +1100176 { "gatewayports", oGatewayPorts },
177 { "useprivilegedport", oUsePrivilegedPort },
Darren Tuckerec960f22003-08-13 20:37:05 +1000178 { "rhostsauthentication", oDeprecated },
Damien Miller95def091999-11-25 00:26:21 +1100179 { "passwordauthentication", oPasswordAuthentication },
Damien Miller874d77b2000-10-14 16:23:11 +1100180 { "kbdinteractiveauthentication", oKbdInteractiveAuthentication },
181 { "kbdinteractivedevices", oKbdInteractiveDevices },
Damien Miller95def091999-11-25 00:26:21 +1100182 { "rsaauthentication", oRSAAuthentication },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100183 { "pubkeyauthentication", oPubkeyAuthentication },
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000184 { "dsaauthentication", oPubkeyAuthentication }, /* alias */
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000185 { "rhostsrsaauthentication", oRhostsRSAAuthentication },
Ben Lindstromd69dab32001-04-12 23:36:05 +0000186 { "hostbasedauthentication", oHostbasedAuthentication },
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000187 { "challengeresponseauthentication", oChallengeResponseAuthentication },
188 { "skeyauthentication", oChallengeResponseAuthentication }, /* alias */
189 { "tisauthentication", oChallengeResponseAuthentication }, /* alias */
Damien Millerf9b3feb2003-05-16 11:38:32 +1000190 { "kerberosauthentication", oUnsupported },
191 { "kerberostgtpassing", oUnsupported },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000192 { "afstokenpassing", oUnsupported },
Darren Tucker0efd1552003-08-26 11:49:55 +1000193#if defined(GSSAPI)
194 { "gssapiauthentication", oGssAuthentication },
Darren Tucker0efd1552003-08-26 11:49:55 +1000195 { "gssapidelegatecredentials", oGssDelegateCreds },
196#else
197 { "gssapiauthentication", oUnsupported },
198 { "gssapidelegatecredentials", oUnsupported },
199#endif
Ben Lindstrom4daea862002-06-09 20:04:02 +0000200 { "fallbacktorsh", oDeprecated },
201 { "usersh", oDeprecated },
Damien Miller95def091999-11-25 00:26:21 +1100202 { "identityfile", oIdentityFile },
Damien Miller5bc6aae2009-01-28 16:27:31 +1100203 { "identityfile2", oIdentityFile }, /* obsolete */
Damien Millerbd394c32004-03-08 23:12:36 +1100204 { "identitiesonly", oIdentitiesOnly },
Damien Miller95def091999-11-25 00:26:21 +1100205 { "hostname", oHostName },
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000206 { "hostkeyalias", oHostKeyAlias },
Damien Miller95def091999-11-25 00:26:21 +1100207 { "proxycommand", oProxyCommand },
208 { "port", oPort },
209 { "cipher", oCipher },
Damien Miller78928792000-04-12 20:17:38 +1000210 { "ciphers", oCiphers },
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000211 { "macs", oMacs },
Damien Miller78928792000-04-12 20:17:38 +1000212 { "protocol", oProtocol },
Damien Miller95def091999-11-25 00:26:21 +1100213 { "remoteforward", oRemoteForward },
214 { "localforward", oLocalForward },
215 { "user", oUser },
216 { "host", oHost },
Damien Miller194fd902013-10-15 12:13:05 +1100217 { "match", oMatch },
Damien Miller95def091999-11-25 00:26:21 +1100218 { "escapechar", oEscapeChar },
Damien Miller95def091999-11-25 00:26:21 +1100219 { "globalknownhostsfile", oGlobalKnownHostsFile },
Damien Miller295ee632011-05-29 21:42:31 +1000220 { "globalknownhostsfile2", oDeprecated },
Damien Miller5bc6aae2009-01-28 16:27:31 +1100221 { "userknownhostsfile", oUserKnownHostsFile },
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000222 { "userknownhostsfile2", oDeprecated },
Damien Miller95def091999-11-25 00:26:21 +1100223 { "connectionattempts", oConnectionAttempts },
224 { "batchmode", oBatchMode },
225 { "checkhostip", oCheckHostIP },
226 { "stricthostkeychecking", oStrictHostKeyChecking },
227 { "compression", oCompression },
228 { "compressionlevel", oCompressionLevel },
Damien Miller12c150e2003-12-17 16:31:10 +1100229 { "tcpkeepalive", oTCPKeepAlive },
230 { "keepalive", oTCPKeepAlive }, /* obsolete */
Damien Miller95def091999-11-25 00:26:21 +1100231 { "numberofpasswordprompts", oNumberOfPasswordPrompts },
Damien Miller95def091999-11-25 00:26:21 +1100232 { "loglevel", oLogLevel },
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000233 { "dynamicforward", oDynamicForward },
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000234 { "preferredauthentications", oPreferredAuthentications },
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000235 { "hostkeyalgorithms", oHostKeyAlgorithms },
Ben Lindstrome0f88042001-04-30 13:06:24 +0000236 { "bindaddress", oBindAddress },
Damien Miller7ea845e2010-02-12 09:21:02 +1100237#ifdef ENABLE_PKCS11
238 { "smartcarddevice", oPKCS11Provider },
239 { "pkcs11provider", oPKCS11Provider },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000240#else
241 { "smartcarddevice", oUnsupported },
Damien Miller7ea845e2010-02-12 09:21:02 +1100242 { "pkcs11provider", oUnsupported },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000243#endif
Damien Miller9f0f5c62001-12-21 14:45:46 +1100244 { "clearallforwardings", oClearAllForwardings },
Ben Lindstromb6df73b2002-11-09 15:52:31 +0000245 { "enablesshkeysign", oEnableSSHKeysign },
Damien Miller37876e92003-05-15 10:19:46 +1000246 { "verifyhostkeydns", oVerifyHostKeyDNS },
Damien Miller9f0f5c62001-12-21 14:45:46 +1100247 { "nohostauthenticationforlocalhost", oNoHostAuthenticationForLocalhost },
Damien Millera5539d22003-04-09 20:50:06 +1000248 { "rekeylimit", oRekeyLimit },
Damien Millerb78d5eb2003-05-16 11:39:04 +1000249 { "connecttimeout", oConnectTimeout },
Damien Miller20a8f972003-05-18 20:50:30 +1000250 { "addressfamily", oAddressFamily },
Damien Miller509b0102003-12-17 16:33:10 +1100251 { "serveraliveinterval", oServerAliveInterval },
252 { "serveralivecountmax", oServerAliveCountMax },
Darren Tucker46bc0752004-05-02 22:11:30 +1000253 { "sendenv", oSendEnv },
Damien Miller0e220db2004-06-15 10:34:08 +1000254 { "controlpath", oControlPath },
255 { "controlmaster", oControlMaster },
Damien Millere11e1ea2010-08-03 16:04:46 +1000256 { "controlpersist", oControlPersist },
Damien Millere1776152005-03-01 21:47:37 +1100257 { "hashknownhosts", oHashKnownHosts },
Damien Millerd27b9472005-12-13 19:29:02 +1100258 { "tunnel", oTunnel },
259 { "tunneldevice", oTunnelDevice },
260 { "localcommand", oLocalCommand },
261 { "permitlocalcommand", oPermitLocalCommand },
Damien Miller10288242008-06-30 00:04:03 +1000262 { "visualhostkey", oVisualHostKey },
Darren Tucker71e4d542009-07-06 07:12:27 +1000263 { "useroaming", oUseRoaming },
Damien Millerd5f62bf2010-09-24 22:11:14 +1000264 { "kexalgorithms", oKexAlgorithms },
Damien Miller0dac6fb2010-11-20 15:19:38 +1100265 { "ipqos", oIPQoS },
Damien Miller21771e22011-05-15 08:45:50 +1000266 { "requesttty", oRequestTTY },
Damien Miller1262b662013-08-21 02:44:24 +1000267 { "proxyusefdpass", oProxyUseFdpass },
Damien Miller0faf7472013-10-17 11:47:23 +1100268 { "canonicaldomains", oCanonicalDomains },
Damien Miller38505592013-10-17 11:48:13 +1100269 { "canonicalizefallbacklocal", oCanonicalizeFallbackLocal },
270 { "canonicalizehostname", oCanonicalizeHostname },
271 { "canonicalizemaxdots", oCanonicalizeMaxDots },
272 { "canonicalizepermittedcnames", oCanonicalizePermittedCNAMEs },
Damien Miller7acefbb2014-07-18 14:11:24 +1000273 { "streamlocalbindmask", oStreamLocalBindMask },
274 { "streamlocalbindunlink", oStreamLocalBindUnlink },
djm@openbsd.org5e39a492014-12-04 02:24:32 +0000275 { "revokedhostkeys", oRevokedHostKeys },
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000276 { "fingerprinthash", oFingerprintHash },
djm@openbsd.org8d4f8722015-01-26 03:04:45 +0000277 { "updatehostkeys", oUpdateHostkeys },
djm@openbsd.org46347ed2015-01-30 11:43:14 +0000278 { "hostbasedkeytypes", oHostbasedKeyTypes },
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000279 { "pubkeyacceptedkeytypes", oPubkeyAcceptedKeyTypes },
Darren Tucker07636982013-05-16 20:30:03 +1000280 { "ignoreunknown", oIgnoreUnknown },
Damien Miller01ed2272008-11-05 16:20:46 +1100281
Ben Lindstrom65366a82001-12-06 16:32:47 +0000282 { NULL, oBadOption }
Damien Miller5ce662a1999-11-11 17:57:39 +1100283};
284
Damien Miller5428f641999-11-25 11:54:57 +1100285/*
286 * Adds a local TCP/IP port forward to options. Never returns if there is an
287 * error.
288 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000289
Damien Miller4af51302000-04-16 11:18:38 +1000290void
Damien Miller7acefbb2014-07-18 14:11:24 +1000291add_local_forward(Options *options, const struct Forward *newfwd)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000292{
Damien Miller7acefbb2014-07-18 14:11:24 +1000293 struct Forward *fwd;
Ben Lindstrom99a4e142002-07-09 14:06:40 +0000294#ifndef NO_IPPORT_RESERVED_CONCEPT
Damien Miller95def091999-11-25 00:26:21 +1100295 extern uid_t original_real_uid;
Damien Miller7acefbb2014-07-18 14:11:24 +1000296 if (newfwd->listen_port < IPPORT_RESERVED && original_real_uid != 0 &&
297 newfwd->listen_path == NULL)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000298 fatal("Privileged ports can only be forwarded by root.");
Damien Millerbac2d8a2000-09-05 16:13:06 +1100299#endif
deraadt@openbsd.org657a5fb2015-04-24 01:36:00 +0000300 options->local_forwards = xreallocarray(options->local_forwards,
Damien Miller232cfb12010-06-26 09:50:30 +1000301 options->num_local_forwards + 1,
302 sizeof(*options->local_forwards));
Damien Miller95def091999-11-25 00:26:21 +1100303 fwd = &options->local_forwards[options->num_local_forwards++];
Damien Millerf91ee4c2005-03-01 21:24:33 +1100304
Damien Miller1a0442f2008-11-05 16:30:06 +1100305 fwd->listen_host = newfwd->listen_host;
Damien Millerf91ee4c2005-03-01 21:24:33 +1100306 fwd->listen_port = newfwd->listen_port;
Damien Miller7acefbb2014-07-18 14:11:24 +1000307 fwd->listen_path = newfwd->listen_path;
Damien Miller1a0442f2008-11-05 16:30:06 +1100308 fwd->connect_host = newfwd->connect_host;
Damien Millerf91ee4c2005-03-01 21:24:33 +1100309 fwd->connect_port = newfwd->connect_port;
Damien Miller7acefbb2014-07-18 14:11:24 +1000310 fwd->connect_path = newfwd->connect_path;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000311}
312
Damien Miller5428f641999-11-25 11:54:57 +1100313/*
314 * Adds a remote TCP/IP port forward to options. Never returns if there is
315 * an error.
316 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000317
Damien Miller4af51302000-04-16 11:18:38 +1000318void
Damien Miller7acefbb2014-07-18 14:11:24 +1000319add_remote_forward(Options *options, const struct Forward *newfwd)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000320{
Damien Miller7acefbb2014-07-18 14:11:24 +1000321 struct Forward *fwd;
Damien Miller232cfb12010-06-26 09:50:30 +1000322
deraadt@openbsd.org657a5fb2015-04-24 01:36:00 +0000323 options->remote_forwards = xreallocarray(options->remote_forwards,
Damien Miller232cfb12010-06-26 09:50:30 +1000324 options->num_remote_forwards + 1,
325 sizeof(*options->remote_forwards));
Damien Miller95def091999-11-25 00:26:21 +1100326 fwd = &options->remote_forwards[options->num_remote_forwards++];
Damien Millerf91ee4c2005-03-01 21:24:33 +1100327
Damien Miller1a0442f2008-11-05 16:30:06 +1100328 fwd->listen_host = newfwd->listen_host;
Damien Millerf91ee4c2005-03-01 21:24:33 +1100329 fwd->listen_port = newfwd->listen_port;
Damien Miller7acefbb2014-07-18 14:11:24 +1000330 fwd->listen_path = newfwd->listen_path;
Damien Miller1a0442f2008-11-05 16:30:06 +1100331 fwd->connect_host = newfwd->connect_host;
Damien Millerf91ee4c2005-03-01 21:24:33 +1100332 fwd->connect_port = newfwd->connect_port;
Damien Miller7acefbb2014-07-18 14:11:24 +1000333 fwd->connect_path = newfwd->connect_path;
Darren Tucker68afb8c2011-10-02 18:59:03 +1100334 fwd->handle = newfwd->handle;
Damien Miller388f6fc2010-05-21 14:57:35 +1000335 fwd->allocated_port = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000336}
337
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000338static void
339clear_forwardings(Options *options)
340{
341 int i;
342
Damien Millerf91ee4c2005-03-01 21:24:33 +1100343 for (i = 0; i < options->num_local_forwards; i++) {
Darren Tuckera627d422013-06-02 07:31:17 +1000344 free(options->local_forwards[i].listen_host);
Damien Miller7acefbb2014-07-18 14:11:24 +1000345 free(options->local_forwards[i].listen_path);
Darren Tuckera627d422013-06-02 07:31:17 +1000346 free(options->local_forwards[i].connect_host);
Damien Miller7acefbb2014-07-18 14:11:24 +1000347 free(options->local_forwards[i].connect_path);
Damien Millerf91ee4c2005-03-01 21:24:33 +1100348 }
Damien Miller232cfb12010-06-26 09:50:30 +1000349 if (options->num_local_forwards > 0) {
Darren Tuckera627d422013-06-02 07:31:17 +1000350 free(options->local_forwards);
Damien Miller232cfb12010-06-26 09:50:30 +1000351 options->local_forwards = NULL;
352 }
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000353 options->num_local_forwards = 0;
Damien Millerf91ee4c2005-03-01 21:24:33 +1100354 for (i = 0; i < options->num_remote_forwards; i++) {
Darren Tuckera627d422013-06-02 07:31:17 +1000355 free(options->remote_forwards[i].listen_host);
Damien Miller7acefbb2014-07-18 14:11:24 +1000356 free(options->remote_forwards[i].listen_path);
Darren Tuckera627d422013-06-02 07:31:17 +1000357 free(options->remote_forwards[i].connect_host);
Damien Miller7acefbb2014-07-18 14:11:24 +1000358 free(options->remote_forwards[i].connect_path);
Damien Millerf91ee4c2005-03-01 21:24:33 +1100359 }
Damien Miller232cfb12010-06-26 09:50:30 +1000360 if (options->num_remote_forwards > 0) {
Darren Tuckera627d422013-06-02 07:31:17 +1000361 free(options->remote_forwards);
Damien Miller232cfb12010-06-26 09:50:30 +1000362 options->remote_forwards = NULL;
363 }
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000364 options->num_remote_forwards = 0;
Damien Miller7b58e802005-12-13 19:33:19 +1100365 options->tun_open = SSH_TUNMODE_NO;
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000366}
367
Darren Tucker19104782013-04-05 11:13:08 +1100368void
369add_identity_file(Options *options, const char *dir, const char *filename,
370 int userprovided)
371{
372 char *path;
Damien Miller15271902014-05-15 13:47:56 +1000373 int i;
Darren Tucker19104782013-04-05 11:13:08 +1100374
375 if (options->num_identity_files >= SSH_MAX_IDENTITY_FILES)
376 fatal("Too many identity files specified (max %d)",
377 SSH_MAX_IDENTITY_FILES);
378
379 if (dir == NULL) /* no dir, filename is absolute */
380 path = xstrdup(filename);
381 else
382 (void)xasprintf(&path, "%.100s%.100s", dir, filename);
383
Damien Miller15271902014-05-15 13:47:56 +1000384 /* Avoid registering duplicates */
385 for (i = 0; i < options->num_identity_files; i++) {
386 if (options->identity_file_userprovided[i] == userprovided &&
387 strcmp(options->identity_files[i], path) == 0) {
388 debug2("%s: ignoring duplicate key %s", __func__, path);
389 free(path);
390 return;
391 }
392 }
393
Darren Tucker19104782013-04-05 11:13:08 +1100394 options->identity_file_userprovided[options->num_identity_files] =
395 userprovided;
396 options->identity_files[options->num_identity_files++] = path;
397}
398
Damien Miller194fd902013-10-15 12:13:05 +1100399int
400default_ssh_port(void)
401{
402 static int port;
403 struct servent *sp;
404
405 if (port == 0) {
406 sp = getservbyname(SSH_SERVICE_NAME, "tcp");
407 port = sp ? ntohs(sp->s_port) : SSH_DEFAULT_PORT;
408 }
409 return port;
410}
411
412/*
413 * Execute a command in a shell.
414 * Return its exit status or -1 on abnormal exit.
415 */
416static int
417execute_in_shell(const char *cmd)
418{
419 char *shell, *command_string;
420 pid_t pid;
421 int devnull, status;
422 extern uid_t original_real_uid;
423
424 if ((shell = getenv("SHELL")) == NULL)
425 shell = _PATH_BSHELL;
426
427 /*
428 * Use "exec" to avoid "sh -c" processes on some platforms
429 * (e.g. Solaris)
430 */
431 xasprintf(&command_string, "exec %s", cmd);
432
433 /* Need this to redirect subprocess stdin/out */
434 if ((devnull = open(_PATH_DEVNULL, O_RDWR)) == -1)
435 fatal("open(/dev/null): %s", strerror(errno));
436
437 debug("Executing command: '%.500s'", cmd);
438
439 /* Fork and execute the command. */
440 if ((pid = fork()) == 0) {
441 char *argv[4];
442
443 /* Child. Permanently give up superuser privileges. */
444 permanently_drop_suid(original_real_uid);
445
446 /* Redirect child stdin and stdout. Leave stderr */
447 if (dup2(devnull, STDIN_FILENO) == -1)
448 fatal("dup2: %s", strerror(errno));
449 if (dup2(devnull, STDOUT_FILENO) == -1)
450 fatal("dup2: %s", strerror(errno));
451 if (devnull > STDERR_FILENO)
452 close(devnull);
453 closefrom(STDERR_FILENO + 1);
454
455 argv[0] = shell;
456 argv[1] = "-c";
457 argv[2] = command_string;
458 argv[3] = NULL;
459
460 execv(argv[0], argv);
461 error("Unable to execute '%.100s': %s", cmd, strerror(errno));
462 /* Die with signal to make this error apparent to parent. */
463 signal(SIGTERM, SIG_DFL);
464 kill(getpid(), SIGTERM);
465 _exit(1);
466 }
467 /* Parent. */
468 if (pid < 0)
469 fatal("%s: fork: %.100s", __func__, strerror(errno));
470
471 close(devnull);
472 free(command_string);
473
474 while (waitpid(pid, &status, 0) == -1) {
475 if (errno != EINTR && errno != EAGAIN)
476 fatal("%s: waitpid: %s", __func__, strerror(errno));
477 }
478 if (!WIFEXITED(status)) {
479 error("command '%.100s' exited abnormally", cmd);
480 return -1;
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000481 }
Damien Miller194fd902013-10-15 12:13:05 +1100482 debug3("command returned status %d", WEXITSTATUS(status));
483 return WEXITSTATUS(status);
484}
485
486/*
487 * Parse and execute a Match directive.
488 */
489static int
490match_cfg_line(Options *options, char **condition, struct passwd *pw,
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000491 const char *host_arg, const char *original_host, int post_canon,
492 const char *filename, int linenum)
Damien Miller194fd902013-10-15 12:13:05 +1100493{
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000494 char *arg, *oattrib, *attrib, *cmd, *cp = *condition, *host, *criteria;
Damien Miller084bcd22013-10-23 16:30:51 +1100495 const char *ruser;
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000496 int r, port, this_result, result = 1, attributes = 0, negate;
Damien Miller194fd902013-10-15 12:13:05 +1100497 char thishost[NI_MAXHOST], shorthost[NI_MAXHOST], portstr[NI_MAXSERV];
498
499 /*
500 * Configuration is likely to be incomplete at this point so we
501 * must be prepared to use default values.
502 */
503 port = options->port <= 0 ? default_ssh_port() : options->port;
504 ruser = options->user == NULL ? pw->pw_name : options->user;
Damien Miller084bcd22013-10-23 16:30:51 +1100505 if (options->hostname != NULL) {
Damien Millereff5cad2013-10-23 16:31:10 +1100506 /* NB. Please keep in sync with ssh.c:main() */
Damien Miller084bcd22013-10-23 16:30:51 +1100507 host = percent_expand(options->hostname,
508 "h", host_arg, (char *)NULL);
509 } else
510 host = xstrdup(host_arg);
Damien Miller194fd902013-10-15 12:13:05 +1100511
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000512 debug2("checking match for '%s' host %s originally %s",
513 cp, host, original_host);
514 while ((oattrib = attrib = strdelim(&cp)) && *attrib != '\0') {
515 criteria = NULL;
516 this_result = 1;
517 if ((negate = attrib[0] == '!'))
518 attrib++;
519 /* criteria "all" and "canonical" have no argument */
Damien Millercf31f382013-10-24 21:02:56 +1100520 if (strcasecmp(attrib, "all") == 0) {
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000521 if (attributes > 1 ||
Damien Millercf31f382013-10-24 21:02:56 +1100522 ((arg = strdelim(&cp)) != NULL && *arg != '\0')) {
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000523 error("%.200s line %d: '%s' cannot be combined "
524 "with other Match attributes",
525 filename, linenum, oattrib);
Damien Millercf31f382013-10-24 21:02:56 +1100526 result = -1;
527 goto out;
528 }
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000529 if (result)
530 result = negate ? 0 : 1;
Damien Millercf31f382013-10-24 21:02:56 +1100531 goto out;
532 }
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000533 attributes++;
534 if (strcasecmp(attrib, "canonical") == 0) {
535 r = !!post_canon; /* force bitmask member to boolean */
536 if (r == (negate ? 1 : 0))
537 this_result = result = 0;
538 debug3("%.200s line %d: %smatched '%s'",
539 filename, linenum,
540 this_result ? "" : "not ", oattrib);
541 continue;
542 }
543 /* All other criteria require an argument */
Damien Miller194fd902013-10-15 12:13:05 +1100544 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
545 error("Missing Match criteria for %s", attrib);
Damien Miller084bcd22013-10-23 16:30:51 +1100546 result = -1;
547 goto out;
Damien Miller194fd902013-10-15 12:13:05 +1100548 }
Damien Miller194fd902013-10-15 12:13:05 +1100549 if (strcasecmp(attrib, "host") == 0) {
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000550 criteria = xstrdup(host);
djm@openbsd.orge661a862015-05-04 06:10:48 +0000551 r = match_hostname(host, arg) == 1;
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000552 if (r == (negate ? 1 : 0))
553 this_result = result = 0;
Damien Miller194fd902013-10-15 12:13:05 +1100554 } else if (strcasecmp(attrib, "originalhost") == 0) {
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000555 criteria = xstrdup(original_host);
djm@openbsd.orge661a862015-05-04 06:10:48 +0000556 r = match_hostname(original_host, arg) == 1;
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000557 if (r == (negate ? 1 : 0))
558 this_result = result = 0;
Damien Miller194fd902013-10-15 12:13:05 +1100559 } else if (strcasecmp(attrib, "user") == 0) {
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000560 criteria = xstrdup(ruser);
djm@openbsd.orge661a862015-05-04 06:10:48 +0000561 r = match_pattern_list(ruser, arg, 0) == 1;
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000562 if (r == (negate ? 1 : 0))
563 this_result = result = 0;
Damien Miller194fd902013-10-15 12:13:05 +1100564 } else if (strcasecmp(attrib, "localuser") == 0) {
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000565 criteria = xstrdup(pw->pw_name);
djm@openbsd.orge661a862015-05-04 06:10:48 +0000566 r = match_pattern_list(pw->pw_name, arg, 0) == 1;
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000567 if (r == (negate ? 1 : 0))
568 this_result = result = 0;
Damien Miller8a04be72013-10-23 16:29:40 +1100569 } else if (strcasecmp(attrib, "exec") == 0) {
Damien Miller194fd902013-10-15 12:13:05 +1100570 if (gethostname(thishost, sizeof(thishost)) == -1)
571 fatal("gethostname: %s", strerror(errno));
572 strlcpy(shorthost, thishost, sizeof(shorthost));
573 shorthost[strcspn(thishost, ".")] = '\0';
574 snprintf(portstr, sizeof(portstr), "%d", port);
575
576 cmd = percent_expand(arg,
577 "L", shorthost,
578 "d", pw->pw_dir,
579 "h", host,
580 "l", thishost,
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000581 "n", original_host,
Damien Miller194fd902013-10-15 12:13:05 +1100582 "p", portstr,
583 "r", ruser,
584 "u", pw->pw_name,
585 (char *)NULL);
Damien Miller06287802014-02-24 15:56:45 +1100586 if (result != 1) {
587 /* skip execution if prior predicate failed */
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000588 debug3("%.200s line %d: skipped exec "
589 "\"%.100s\"", filename, linenum, cmd);
590 free(cmd);
591 continue;
Damien Miller06287802014-02-24 15:56:45 +1100592 }
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000593 r = execute_in_shell(cmd);
594 if (r == -1) {
595 fatal("%.200s line %d: match exec "
596 "'%.100s' error", filename,
597 linenum, cmd);
598 }
599 criteria = xstrdup(cmd);
Damien Miller194fd902013-10-15 12:13:05 +1100600 free(cmd);
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000601 /* Force exit status to boolean */
602 r = r == 0;
603 if (r == (negate ? 1 : 0))
604 this_result = result = 0;
Damien Miller194fd902013-10-15 12:13:05 +1100605 } else {
606 error("Unsupported Match attribute %s", attrib);
Damien Miller084bcd22013-10-23 16:30:51 +1100607 result = -1;
608 goto out;
Damien Miller194fd902013-10-15 12:13:05 +1100609 }
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000610 debug3("%.200s line %d: %smatched '%s \"%.100s\"' ",
611 filename, linenum, this_result ? "": "not ",
612 oattrib, criteria);
613 free(criteria);
Damien Miller194fd902013-10-15 12:13:05 +1100614 }
Damien Millercf31f382013-10-24 21:02:56 +1100615 if (attributes == 0) {
616 error("One or more attributes required for Match");
617 result = -1;
618 goto out;
619 }
Damien Miller084bcd22013-10-23 16:30:51 +1100620 out:
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000621 if (result != -1)
622 debug2("match %sfound", result ? "" : "not ");
623 *condition = cp;
Damien Miller084bcd22013-10-23 16:30:51 +1100624 free(host);
Damien Miller194fd902013-10-15 12:13:05 +1100625 return result;
626}
627
Damien Miller0faf7472013-10-17 11:47:23 +1100628/* Check and prepare a domain name: removes trailing '.' and lowercases */
629static void
630valid_domain(char *name, const char *filename, int linenum)
631{
632 size_t i, l = strlen(name);
633 u_char c, last = '\0';
634
635 if (l == 0)
636 fatal("%s line %d: empty hostname suffix", filename, linenum);
637 if (!isalpha((u_char)name[0]) && !isdigit((u_char)name[0]))
638 fatal("%s line %d: hostname suffix \"%.100s\" "
639 "starts with invalid character", filename, linenum, name);
640 for (i = 0; i < l; i++) {
641 c = tolower((u_char)name[i]);
642 name[i] = (char)c;
643 if (last == '.' && c == '.')
644 fatal("%s line %d: hostname suffix \"%.100s\" contains "
645 "consecutive separators", filename, linenum, name);
646 if (c != '.' && c != '-' && !isalnum(c) &&
647 c != '_') /* technically invalid, but common */
648 fatal("%s line %d: hostname suffix \"%.100s\" contains "
649 "invalid characters", filename, linenum, name);
650 last = c;
651 }
652 if (name[l - 1] == '.')
653 name[l - 1] = '\0';
654}
655
Damien Miller5428f641999-11-25 11:54:57 +1100656/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000657 * Returns the number of the token pointed to by cp or oBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100658 */
Damien Miller4af51302000-04-16 11:18:38 +1000659static OpCodes
Darren Tucker07636982013-05-16 20:30:03 +1000660parse_token(const char *cp, const char *filename, int linenum,
661 const char *ignored_unknown)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000662{
Darren Tucker07636982013-05-16 20:30:03 +1000663 int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000664
Damien Miller95def091999-11-25 00:26:21 +1100665 for (i = 0; keywords[i].name; i++)
Darren Tucker07636982013-05-16 20:30:03 +1000666 if (strcmp(cp, keywords[i].name) == 0)
Damien Miller95def091999-11-25 00:26:21 +1100667 return keywords[i].opcode;
djm@openbsd.orge661a862015-05-04 06:10:48 +0000668 if (ignored_unknown != NULL &&
669 match_pattern_list(cp, ignored_unknown, 1) == 1)
Darren Tucker07636982013-05-16 20:30:03 +1000670 return oIgnoredUnknownOption;
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000671 error("%s: line %d: Bad configuration option: %s",
672 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100673 return oBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000674}
675
Damien Millere9fc72e2013-10-15 12:14:12 +1100676/* Multistate option parsing */
677struct multistate {
678 char *key;
679 int value;
680};
681static const struct multistate multistate_flag[] = {
682 { "true", 1 },
683 { "false", 0 },
684 { "yes", 1 },
685 { "no", 0 },
686 { NULL, -1 }
687};
688static const struct multistate multistate_yesnoask[] = {
689 { "true", 1 },
690 { "false", 0 },
691 { "yes", 1 },
692 { "no", 0 },
693 { "ask", 2 },
694 { NULL, -1 }
695};
696static const struct multistate multistate_addressfamily[] = {
697 { "inet", AF_INET },
698 { "inet6", AF_INET6 },
699 { "any", AF_UNSPEC },
700 { NULL, -1 }
701};
702static const struct multistate multistate_controlmaster[] = {
703 { "true", SSHCTL_MASTER_YES },
704 { "yes", SSHCTL_MASTER_YES },
705 { "false", SSHCTL_MASTER_NO },
706 { "no", SSHCTL_MASTER_NO },
707 { "auto", SSHCTL_MASTER_AUTO },
708 { "ask", SSHCTL_MASTER_ASK },
709 { "autoask", SSHCTL_MASTER_AUTO_ASK },
710 { NULL, -1 }
711};
712static const struct multistate multistate_tunnel[] = {
713 { "ethernet", SSH_TUNMODE_ETHERNET },
714 { "point-to-point", SSH_TUNMODE_POINTOPOINT },
715 { "true", SSH_TUNMODE_DEFAULT },
716 { "yes", SSH_TUNMODE_DEFAULT },
717 { "false", SSH_TUNMODE_NO },
718 { "no", SSH_TUNMODE_NO },
719 { NULL, -1 }
720};
721static const struct multistate multistate_requesttty[] = {
722 { "true", REQUEST_TTY_YES },
723 { "yes", REQUEST_TTY_YES },
724 { "false", REQUEST_TTY_NO },
725 { "no", REQUEST_TTY_NO },
726 { "force", REQUEST_TTY_FORCE },
727 { "auto", REQUEST_TTY_AUTO },
728 { NULL, -1 }
729};
Damien Miller38505592013-10-17 11:48:13 +1100730static const struct multistate multistate_canonicalizehostname[] = {
Damien Miller0faf7472013-10-17 11:47:23 +1100731 { "true", SSH_CANONICALISE_YES },
732 { "false", SSH_CANONICALISE_NO },
733 { "yes", SSH_CANONICALISE_YES },
734 { "no", SSH_CANONICALISE_NO },
735 { "always", SSH_CANONICALISE_ALWAYS },
736 { NULL, -1 }
737};
Damien Millere9fc72e2013-10-15 12:14:12 +1100738
Damien Miller5428f641999-11-25 11:54:57 +1100739/*
740 * Processes a single option line as used in the configuration files. This
741 * only sets those values that have not already been set.
742 */
Damien Miller61f08ac2003-02-24 11:56:27 +1100743#define WHITESPACE " \t\r\n"
Damien Miller2ccf6611999-11-15 15:25:10 +1100744int
Damien Miller194fd902013-10-15 12:13:05 +1100745process_config_line(Options *options, struct passwd *pw, const char *host,
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000746 const char *original_host, char *line, const char *filename,
747 int linenum, int *activep, int flags)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000748{
Damien Miller295ee632011-05-29 21:42:31 +1000749 char *s, **charptr, *endofnumber, *keyword, *arg, *arg2;
750 char **cpptr, fwdarg[256];
Darren Tucker07636982013-05-16 20:30:03 +1000751 u_int i, *uintptr, max_entries = 0;
Damien Miller194fd902013-10-15 12:13:05 +1100752 int negated, opcode, *intptr, value, value2, cmdline = 0;
Darren Tucker1e44c5d2008-01-01 20:32:26 +1100753 LogLevel *log_level_ptr;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000754 long long val64;
Damien Miller61f08ac2003-02-24 11:56:27 +1100755 size_t len;
Damien Miller7acefbb2014-07-18 14:11:24 +1000756 struct Forward fwd;
Damien Millere9fc72e2013-10-15 12:14:12 +1100757 const struct multistate *multistate_ptr;
Damien Miller0faf7472013-10-17 11:47:23 +1100758 struct allowed_cname *cname;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000759
Damien Miller194fd902013-10-15 12:13:05 +1100760 if (activep == NULL) { /* We are processing a command line directive */
761 cmdline = 1;
762 activep = &cmdline;
763 }
764
Damien Millerc652cac2003-05-14 13:40:54 +1000765 /* Strip trailing whitespace */
djm@openbsd.org26e0bcf2015-03-30 00:00:29 +0000766 if ((len = strlen(line)) == 0)
767 return 0;
768 for (len--; len > 0; len--) {
Damien Millerc652cac2003-05-14 13:40:54 +1000769 if (strchr(WHITESPACE, line[len]) == NULL)
770 break;
771 line[len] = '\0';
772 }
773
Damien Millerbe484b52000-07-15 14:14:16 +1000774 s = line;
775 /* Get the keyword. (Each line is supposed to begin with a keyword). */
Damien Miller928b2362006-03-26 13:53:32 +1100776 if ((keyword = strdelim(&s)) == NULL)
777 return 0;
Damien Millerbe484b52000-07-15 14:14:16 +1000778 /* Ignore leading whitespace. */
779 if (*keyword == '\0')
780 keyword = strdelim(&s);
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000781 if (keyword == NULL || !*keyword || *keyword == '\n' || *keyword == '#')
Damien Miller95def091999-11-25 00:26:21 +1100782 return 0;
Darren Tucker07636982013-05-16 20:30:03 +1000783 /* Match lowercase keyword */
Damien Millere9fc72e2013-10-15 12:14:12 +1100784 lowercase(keyword);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000785
Darren Tucker07636982013-05-16 20:30:03 +1000786 opcode = parse_token(keyword, filename, linenum,
787 options->ignored_unknown);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000788
Damien Miller95def091999-11-25 00:26:21 +1100789 switch (opcode) {
790 case oBadOption:
Damien Miller5428f641999-11-25 11:54:57 +1100791 /* don't panic, but count bad options */
792 return -1;
Damien Miller95def091999-11-25 00:26:21 +1100793 /* NOTREACHED */
Darren Tucker07636982013-05-16 20:30:03 +1000794 case oIgnoredUnknownOption:
795 debug("%s line %d: Ignored unknown option \"%s\"",
796 filename, linenum, keyword);
797 return 0;
Damien Millerb78d5eb2003-05-16 11:39:04 +1000798 case oConnectTimeout:
799 intptr = &options->connection_timeout;
Damien Miller509b0102003-12-17 16:33:10 +1100800parse_time:
Damien Millerb78d5eb2003-05-16 11:39:04 +1000801 arg = strdelim(&s);
802 if (!arg || *arg == '\0')
803 fatal("%s line %d: missing time value.",
804 filename, linenum);
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000805 if (strcmp(arg, "none") == 0)
806 value = -1;
807 else if ((value = convtime(arg)) == -1)
Damien Millerb78d5eb2003-05-16 11:39:04 +1000808 fatal("%s line %d: invalid time value.",
809 filename, linenum);
Darren Tuckera52c5b62007-02-19 22:09:45 +1100810 if (*activep && *intptr == -1)
Damien Millerb78d5eb2003-05-16 11:39:04 +1000811 *intptr = value;
812 break;
813
Damien Miller95def091999-11-25 00:26:21 +1100814 case oForwardAgent:
815 intptr = &options->forward_agent;
Damien Millere9fc72e2013-10-15 12:14:12 +1100816 parse_flag:
817 multistate_ptr = multistate_flag;
818 parse_multistate:
Damien Millerbe484b52000-07-15 14:14:16 +1000819 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000820 if (!arg || *arg == '\0')
Damien Millere9fc72e2013-10-15 12:14:12 +1100821 fatal("%s line %d: missing argument.",
822 filename, linenum);
823 value = -1;
824 for (i = 0; multistate_ptr[i].key != NULL; i++) {
825 if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
826 value = multistate_ptr[i].value;
827 break;
828 }
829 }
830 if (value == -1)
831 fatal("%s line %d: unsupported option \"%s\".",
832 filename, linenum, arg);
Damien Miller95def091999-11-25 00:26:21 +1100833 if (*activep && *intptr == -1)
834 *intptr = value;
835 break;
836
837 case oForwardX11:
838 intptr = &options->forward_x11;
839 goto parse_flag;
840
Darren Tucker0a118da2003-10-15 15:54:32 +1000841 case oForwardX11Trusted:
842 intptr = &options->forward_x11_trusted;
843 goto parse_flag;
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000844
Damien Miller1ab6a512010-06-26 10:02:24 +1000845 case oForwardX11Timeout:
846 intptr = &options->forward_x11_timeout;
847 goto parse_time;
Darren Tucker0a118da2003-10-15 15:54:32 +1000848
Damien Miller95def091999-11-25 00:26:21 +1100849 case oGatewayPorts:
Damien Miller7acefbb2014-07-18 14:11:24 +1000850 intptr = &options->fwd_opts.gateway_ports;
Damien Miller95def091999-11-25 00:26:21 +1100851 goto parse_flag;
852
Darren Tuckere7d4b192006-07-12 22:17:10 +1000853 case oExitOnForwardFailure:
854 intptr = &options->exit_on_forward_failure;
855 goto parse_flag;
856
Damien Miller95def091999-11-25 00:26:21 +1100857 case oUsePrivilegedPort:
858 intptr = &options->use_privileged_port;
859 goto parse_flag;
860
Damien Miller95def091999-11-25 00:26:21 +1100861 case oPasswordAuthentication:
862 intptr = &options->password_authentication;
863 goto parse_flag;
864
Damien Miller874d77b2000-10-14 16:23:11 +1100865 case oKbdInteractiveAuthentication:
866 intptr = &options->kbd_interactive_authentication;
867 goto parse_flag;
868
869 case oKbdInteractiveDevices:
870 charptr = &options->kbd_interactive_devices;
871 goto parse_string;
872
Damien Miller0bc1bd82000-11-13 22:57:25 +1100873 case oPubkeyAuthentication:
874 intptr = &options->pubkey_authentication;
Damien Millere247cc42000-05-07 12:03:14 +1000875 goto parse_flag;
876
Damien Miller95def091999-11-25 00:26:21 +1100877 case oRSAAuthentication:
878 intptr = &options->rsa_authentication;
879 goto parse_flag;
880
881 case oRhostsRSAAuthentication:
882 intptr = &options->rhosts_rsa_authentication;
883 goto parse_flag;
884
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000885 case oHostbasedAuthentication:
886 intptr = &options->hostbased_authentication;
887 goto parse_flag;
888
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000889 case oChallengeResponseAuthentication:
Ben Lindstrom551ea372001-06-05 18:56:16 +0000890 intptr = &options->challenge_response_authentication;
Damien Miller95def091999-11-25 00:26:21 +1100891 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000892
Darren Tucker0efd1552003-08-26 11:49:55 +1000893 case oGssAuthentication:
894 intptr = &options->gss_authentication;
895 goto parse_flag;
896
897 case oGssDelegateCreds:
898 intptr = &options->gss_deleg_creds;
899 goto parse_flag;
900
Damien Miller95def091999-11-25 00:26:21 +1100901 case oBatchMode:
902 intptr = &options->batch_mode;
903 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000904
Damien Miller95def091999-11-25 00:26:21 +1100905 case oCheckHostIP:
906 intptr = &options->check_host_ip;
Damien Miller10288242008-06-30 00:04:03 +1000907 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000908
Damien Miller37876e92003-05-15 10:19:46 +1000909 case oVerifyHostKeyDNS:
910 intptr = &options->verify_host_key_dns;
Damien Millere9fc72e2013-10-15 12:14:12 +1100911 multistate_ptr = multistate_yesnoask;
912 goto parse_multistate;
Damien Miller37876e92003-05-15 10:19:46 +1000913
Damien Miller95def091999-11-25 00:26:21 +1100914 case oStrictHostKeyChecking:
915 intptr = &options->strict_host_key_checking;
Damien Millere9fc72e2013-10-15 12:14:12 +1100916 multistate_ptr = multistate_yesnoask;
917 goto parse_multistate;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000918
Damien Miller95def091999-11-25 00:26:21 +1100919 case oCompression:
920 intptr = &options->compression;
921 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000922
Damien Miller12c150e2003-12-17 16:31:10 +1100923 case oTCPKeepAlive:
924 intptr = &options->tcp_keep_alive;
Damien Miller95def091999-11-25 00:26:21 +1100925 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000926
Ben Lindstrom3cecc9a2001-10-03 17:39:38 +0000927 case oNoHostAuthenticationForLocalhost:
928 intptr = &options->no_host_authentication_for_localhost;
929 goto parse_flag;
930
Damien Miller95def091999-11-25 00:26:21 +1100931 case oNumberOfPasswordPrompts:
932 intptr = &options->number_of_password_prompts;
933 goto parse_int;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000934
Damien Miller95def091999-11-25 00:26:21 +1100935 case oCompressionLevel:
936 intptr = &options->compression_level;
937 goto parse_int;
938
Damien Millera5539d22003-04-09 20:50:06 +1000939 case oRekeyLimit:
Damien Millera5539d22003-04-09 20:50:06 +1000940 arg = strdelim(&s);
941 if (!arg || *arg == '\0')
Darren Tuckerc53c2af2013-05-16 20:28:16 +1000942 fatal("%.200s line %d: Missing argument.", filename,
943 linenum);
944 if (strcmp(arg, "default") == 0) {
945 val64 = 0;
946 } else {
Darren Tuckerb7ee8522013-05-16 20:33:10 +1000947 if (scan_scaled(arg, &val64) == -1)
948 fatal("%.200s line %d: Bad number '%s': %s",
949 filename, linenum, arg, strerror(errno));
950 /* check for too-large or too-small limits */
951 if (val64 > UINT_MAX)
Darren Tuckerc53c2af2013-05-16 20:28:16 +1000952 fatal("%.200s line %d: RekeyLimit too large",
953 filename, linenum);
954 if (val64 != 0 && val64 < 16)
955 fatal("%.200s line %d: RekeyLimit too small",
956 filename, linenum);
Damien Millera5539d22003-04-09 20:50:06 +1000957 }
Damien Miller3dff1762008-02-10 22:25:52 +1100958 if (*activep && options->rekey_limit == -1)
959 options->rekey_limit = (u_int32_t)val64;
Darren Tuckerc53c2af2013-05-16 20:28:16 +1000960 if (s != NULL) { /* optional rekey interval present */
961 if (strcmp(s, "none") == 0) {
962 (void)strdelim(&s); /* discard */
963 break;
964 }
965 intptr = &options->rekey_interval;
966 goto parse_time;
967 }
Damien Millera5539d22003-04-09 20:50:06 +1000968 break;
969
Damien Miller95def091999-11-25 00:26:21 +1100970 case oIdentityFile:
Damien Millerbe484b52000-07-15 14:14:16 +1000971 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000972 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100973 fatal("%.200s line %d: Missing argument.", filename, linenum);
974 if (*activep) {
Damien Miller0bc1bd82000-11-13 22:57:25 +1100975 intptr = &options->num_identity_files;
Damien Millereba71ba2000-04-29 23:57:08 +1000976 if (*intptr >= SSH_MAX_IDENTITY_FILES)
Damien Miller95def091999-11-25 00:26:21 +1100977 fatal("%.200s line %d: Too many identity files specified (max %d).",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100978 filename, linenum, SSH_MAX_IDENTITY_FILES);
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000979 add_identity_file(options, NULL,
980 arg, flags & SSHCONF_USERCONF);
Damien Miller95def091999-11-25 00:26:21 +1100981 }
982 break;
983
Damien Millerd3a18572000-06-07 19:55:44 +1000984 case oXAuthLocation:
985 charptr=&options->xauth_location;
986 goto parse_string;
987
Damien Miller95def091999-11-25 00:26:21 +1100988 case oUser:
989 charptr = &options->user;
990parse_string:
Damien Millerbe484b52000-07-15 14:14:16 +1000991 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000992 if (!arg || *arg == '\0')
Damien Miller295ee632011-05-29 21:42:31 +1000993 fatal("%.200s line %d: Missing argument.",
994 filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100995 if (*activep && *charptr == NULL)
Damien Miller37023962000-07-11 17:31:38 +1000996 *charptr = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100997 break;
998
999 case oGlobalKnownHostsFile:
Damien Miller295ee632011-05-29 21:42:31 +10001000 cpptr = (char **)&options->system_hostfiles;
1001 uintptr = &options->num_system_hostfiles;
1002 max_entries = SSH_MAX_HOSTS_FILES;
1003parse_char_array:
1004 if (*activep && *uintptr == 0) {
1005 while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1006 if ((*uintptr) >= max_entries)
1007 fatal("%s line %d: "
1008 "too many authorized keys files.",
1009 filename, linenum);
1010 cpptr[(*uintptr)++] = xstrdup(arg);
1011 }
1012 }
1013 return 0;
Damien Miller95def091999-11-25 00:26:21 +11001014
1015 case oUserKnownHostsFile:
Damien Miller295ee632011-05-29 21:42:31 +10001016 cpptr = (char **)&options->user_hostfiles;
1017 uintptr = &options->num_user_hostfiles;
1018 max_entries = SSH_MAX_HOSTS_FILES;
1019 goto parse_char_array;
Damien Millereba71ba2000-04-29 23:57:08 +10001020
Damien Miller95def091999-11-25 00:26:21 +11001021 case oHostName:
1022 charptr = &options->hostname;
1023 goto parse_string;
1024
Ben Lindstrom4dccfa52000-12-28 16:40:05 +00001025 case oHostKeyAlias:
1026 charptr = &options->host_key_alias;
1027 goto parse_string;
1028
Ben Lindstromb9be60a2001-03-11 01:49:19 +00001029 case oPreferredAuthentications:
1030 charptr = &options->preferred_authentications;
1031 goto parse_string;
1032
Ben Lindstrome0f88042001-04-30 13:06:24 +00001033 case oBindAddress:
1034 charptr = &options->bind_address;
1035 goto parse_string;
1036
Damien Miller7ea845e2010-02-12 09:21:02 +11001037 case oPKCS11Provider:
1038 charptr = &options->pkcs11_provider;
Ben Lindstromf7db3bb2001-08-06 21:35:51 +00001039 goto parse_string;
Ben Lindstromae996bf2001-08-06 21:27:53 +00001040
Damien Miller95def091999-11-25 00:26:21 +11001041 case oProxyCommand:
Damien Millerd27b9472005-12-13 19:29:02 +11001042 charptr = &options->proxy_command;
1043parse_command:
Darren Tuckera99c1b72003-06-28 12:40:12 +10001044 if (s == NULL)
1045 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller61f08ac2003-02-24 11:56:27 +11001046 len = strspn(s, WHITESPACE "=");
Damien Miller95def091999-11-25 00:26:21 +11001047 if (*activep && *charptr == NULL)
Damien Miller61f08ac2003-02-24 11:56:27 +11001048 *charptr = xstrdup(s + len);
Damien Miller95def091999-11-25 00:26:21 +11001049 return 0;
1050
1051 case oPort:
1052 intptr = &options->port;
1053parse_int:
Damien Millerbe484b52000-07-15 14:14:16 +10001054 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +10001055 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +11001056 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +10001057 if (arg[0] < '0' || arg[0] > '9')
Damien Miller95def091999-11-25 00:26:21 +11001058 fatal("%.200s line %d: Bad number.", filename, linenum);
Damien Miller5428f641999-11-25 11:54:57 +11001059
1060 /* Octal, decimal, or hex format? */
Damien Miller37023962000-07-11 17:31:38 +10001061 value = strtol(arg, &endofnumber, 0);
1062 if (arg == endofnumber)
Damien Miller5428f641999-11-25 11:54:57 +11001063 fatal("%.200s line %d: Bad number.", filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +11001064 if (*activep && *intptr == -1)
1065 *intptr = value;
1066 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001067
Damien Miller95def091999-11-25 00:26:21 +11001068 case oConnectionAttempts:
1069 intptr = &options->connection_attempts;
1070 goto parse_int;
Damien Miller5ce662a1999-11-11 17:57:39 +11001071
Damien Miller95def091999-11-25 00:26:21 +11001072 case oCipher:
1073 intptr = &options->cipher;
Damien Millerbe484b52000-07-15 14:14:16 +10001074 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +10001075 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +10001076 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +10001077 value = cipher_number(arg);
Damien Miller95def091999-11-25 00:26:21 +11001078 if (value == -1)
1079 fatal("%.200s line %d: Bad cipher '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001080 filename, linenum, arg ? arg : "<NONE>");
Damien Miller95def091999-11-25 00:26:21 +11001081 if (*activep && *intptr == -1)
1082 *intptr = value;
1083 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001084
Damien Miller78928792000-04-12 20:17:38 +10001085 case oCiphers:
Damien Millerbe484b52000-07-15 14:14:16 +10001086 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +10001087 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +10001088 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +10001089 if (!ciphers_valid(arg))
Damien Miller30c3d422000-05-09 11:02:59 +10001090 fatal("%.200s line %d: Bad SSH2 cipher spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001091 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +10001092 if (*activep && options->ciphers == NULL)
Damien Miller37023962000-07-11 17:31:38 +10001093 options->ciphers = xstrdup(arg);
Damien Miller78928792000-04-12 20:17:38 +10001094 break;
1095
Ben Lindstrom06b33aa2001-02-15 03:01:59 +00001096 case oMacs:
1097 arg = strdelim(&s);
1098 if (!arg || *arg == '\0')
1099 fatal("%.200s line %d: Missing argument.", filename, linenum);
1100 if (!mac_valid(arg))
1101 fatal("%.200s line %d: Bad SSH2 Mac spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001102 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstrom06b33aa2001-02-15 03:01:59 +00001103 if (*activep && options->macs == NULL)
1104 options->macs = xstrdup(arg);
1105 break;
1106
Damien Millerd5f62bf2010-09-24 22:11:14 +10001107 case oKexAlgorithms:
1108 arg = strdelim(&s);
1109 if (!arg || *arg == '\0')
1110 fatal("%.200s line %d: Missing argument.",
1111 filename, linenum);
1112 if (!kex_names_valid(arg))
1113 fatal("%.200s line %d: Bad SSH2 KexAlgorithms '%s'.",
1114 filename, linenum, arg ? arg : "<NONE>");
1115 if (*activep && options->kex_algorithms == NULL)
1116 options->kex_algorithms = xstrdup(arg);
1117 break;
1118
Ben Lindstrom982dbbc2001-04-17 18:11:36 +00001119 case oHostKeyAlgorithms:
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00001120 charptr = &options->hostkeyalgorithms;
1121parse_keytypes:
Ben Lindstrom982dbbc2001-04-17 18:11:36 +00001122 arg = strdelim(&s);
1123 if (!arg || *arg == '\0')
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00001124 fatal("%.200s line %d: Missing argument.",
1125 filename, linenum);
djm@openbsd.org1f729f02015-01-13 07:39:19 +00001126 if (!sshkey_names_valid2(arg, 1))
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00001127 fatal("%s line %d: Bad key types '%s'.",
1128 filename, linenum, arg ? arg : "<NONE>");
1129 if (*activep && *charptr == NULL)
1130 *charptr = xstrdup(arg);
Ben Lindstrom982dbbc2001-04-17 18:11:36 +00001131 break;
1132
Damien Miller78928792000-04-12 20:17:38 +10001133 case oProtocol:
1134 intptr = &options->protocol;
Damien Millerbe484b52000-07-15 14:14:16 +10001135 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +10001136 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +10001137 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +10001138 value = proto_spec(arg);
Damien Miller78928792000-04-12 20:17:38 +10001139 if (value == SSH_PROTO_UNKNOWN)
1140 fatal("%.200s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001141 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +10001142 if (*activep && *intptr == SSH_PROTO_UNKNOWN)
1143 *intptr = value;
1144 break;
1145
Damien Miller95def091999-11-25 00:26:21 +11001146 case oLogLevel:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001147 log_level_ptr = &options->log_level;
Damien Millerbe484b52000-07-15 14:14:16 +10001148 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +10001149 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001150 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +00001151 fatal("%.200s line %d: unsupported log level '%s'",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001152 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001153 if (*activep && *log_level_ptr == SYSLOG_LEVEL_NOT_SET)
1154 *log_level_ptr = (LogLevel) value;
Damien Miller95def091999-11-25 00:26:21 +11001155 break;
1156
Ben Lindstrom62c25a42001-09-12 18:01:59 +00001157 case oLocalForward:
Damien Miller95def091999-11-25 00:26:21 +11001158 case oRemoteForward:
Damien Millera699d952008-11-03 19:27:34 +11001159 case oDynamicForward:
Damien Millerbe484b52000-07-15 14:14:16 +10001160 arg = strdelim(&s);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001161 if (arg == NULL || *arg == '\0')
Ben Lindstrom62c25a42001-09-12 18:01:59 +00001162 fatal("%.200s line %d: Missing port argument.",
1163 filename, linenum);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001164
Damien Millera699d952008-11-03 19:27:34 +11001165 if (opcode == oLocalForward ||
1166 opcode == oRemoteForward) {
1167 arg2 = strdelim(&s);
1168 if (arg2 == NULL || *arg2 == '\0')
1169 fatal("%.200s line %d: Missing target argument.",
1170 filename, linenum);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001171
Damien Millera699d952008-11-03 19:27:34 +11001172 /* construct a string for parse_forward */
1173 snprintf(fwdarg, sizeof(fwdarg), "%s:%s", arg, arg2);
1174 } else if (opcode == oDynamicForward) {
1175 strlcpy(fwdarg, arg, sizeof(fwdarg));
1176 }
1177
1178 if (parse_forward(&fwd, fwdarg,
Damien Miller4bf648f2009-02-14 16:28:21 +11001179 opcode == oDynamicForward ? 1 : 0,
1180 opcode == oRemoteForward ? 1 : 0) == 0)
Ben Lindstrom62c25a42001-09-12 18:01:59 +00001181 fatal("%.200s line %d: Bad forwarding specification.",
1182 filename, linenum);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001183
Ben Lindstrom62c25a42001-09-12 18:01:59 +00001184 if (*activep) {
Damien Millera699d952008-11-03 19:27:34 +11001185 if (opcode == oLocalForward ||
1186 opcode == oDynamicForward)
Damien Millerf91ee4c2005-03-01 21:24:33 +11001187 add_local_forward(options, &fwd);
Ben Lindstrom62c25a42001-09-12 18:01:59 +00001188 else if (opcode == oRemoteForward)
Damien Millerf91ee4c2005-03-01 21:24:33 +11001189 add_remote_forward(options, &fwd);
Ben Lindstrom62c25a42001-09-12 18:01:59 +00001190 }
Damien Miller95def091999-11-25 00:26:21 +11001191 break;
1192
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +00001193 case oClearAllForwardings:
1194 intptr = &options->clear_forwardings;
1195 goto parse_flag;
1196
Damien Miller95def091999-11-25 00:26:21 +11001197 case oHost:
Damien Miller194fd902013-10-15 12:13:05 +11001198 if (cmdline)
1199 fatal("Host directive not supported as a command-line "
1200 "option");
Damien Miller95def091999-11-25 00:26:21 +11001201 *activep = 0;
Damien Millerfe924212011-05-15 08:44:45 +10001202 arg2 = NULL;
1203 while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1204 negated = *arg == '!';
1205 if (negated)
1206 arg++;
Damien Miller37023962000-07-11 17:31:38 +10001207 if (match_pattern(host, arg)) {
Damien Millerfe924212011-05-15 08:44:45 +10001208 if (negated) {
1209 debug("%.200s line %d: Skipping Host "
1210 "block because of negated match "
1211 "for %.100s", filename, linenum,
1212 arg);
1213 *activep = 0;
1214 break;
1215 }
1216 if (!*activep)
1217 arg2 = arg; /* logged below */
Damien Miller95def091999-11-25 00:26:21 +11001218 *activep = 1;
Damien Miller95def091999-11-25 00:26:21 +11001219 }
Damien Millerfe924212011-05-15 08:44:45 +10001220 }
1221 if (*activep)
1222 debug("%.200s line %d: Applying options for %.100s",
1223 filename, linenum, arg2);
Damien Millerbe484b52000-07-15 14:14:16 +10001224 /* Avoid garbage check below, as strdelim is done. */
Damien Miller95def091999-11-25 00:26:21 +11001225 return 0;
1226
Damien Miller194fd902013-10-15 12:13:05 +11001227 case oMatch:
1228 if (cmdline)
1229 fatal("Host directive not supported as a command-line "
1230 "option");
djm@openbsd.org957fbce2014-10-08 22:20:25 +00001231 value = match_cfg_line(options, &s, pw, host, original_host,
1232 flags & SSHCONF_POSTCANON, filename, linenum);
Damien Miller194fd902013-10-15 12:13:05 +11001233 if (value < 0)
1234 fatal("%.200s line %d: Bad Match condition", filename,
1235 linenum);
1236 *activep = value;
1237 break;
1238
Damien Miller95def091999-11-25 00:26:21 +11001239 case oEscapeChar:
1240 intptr = &options->escape_char;
Damien Millerbe484b52000-07-15 14:14:16 +10001241 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +10001242 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +11001243 fatal("%.200s line %d: Missing argument.", filename, linenum);
djm@openbsd.org08823322015-05-22 04:45:52 +00001244 if (strcmp(arg, "none") == 0)
1245 value = SSH_ESCAPECHAR_NONE;
1246 else if (arg[1] == '\0')
1247 value = (u_char) arg[0];
1248 else if (arg[0] == '^' && arg[2] == 0 &&
Ben Lindstrom46c16222000-12-22 01:43:59 +00001249 (u_char) arg[1] >= 64 && (u_char) arg[1] < 128)
1250 value = (u_char) arg[1] & 31;
Damien Miller95def091999-11-25 00:26:21 +11001251 else {
1252 fatal("%.200s line %d: Bad escape character.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001253 filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +11001254 /* NOTREACHED */
1255 value = 0; /* Avoid compiler warning. */
1256 }
1257 if (*activep && *intptr == -1)
1258 *intptr = value;
1259 break;
1260
Damien Miller20a8f972003-05-18 20:50:30 +10001261 case oAddressFamily:
Darren Tucker0a4f04b2003-07-03 20:37:47 +10001262 intptr = &options->address_family;
Damien Millere9fc72e2013-10-15 12:14:12 +11001263 multistate_ptr = multistate_addressfamily;
1264 goto parse_multistate;
Damien Miller20a8f972003-05-18 20:50:30 +10001265
Ben Lindstromb6df73b2002-11-09 15:52:31 +00001266 case oEnableSSHKeysign:
1267 intptr = &options->enable_ssh_keysign;
1268 goto parse_flag;
1269
Damien Millerbd394c32004-03-08 23:12:36 +11001270 case oIdentitiesOnly:
1271 intptr = &options->identities_only;
1272 goto parse_flag;
1273
Damien Miller509b0102003-12-17 16:33:10 +11001274 case oServerAliveInterval:
1275 intptr = &options->server_alive_interval;
1276 goto parse_time;
1277
1278 case oServerAliveCountMax:
1279 intptr = &options->server_alive_count_max;
1280 goto parse_int;
1281
Darren Tucker46bc0752004-05-02 22:11:30 +10001282 case oSendEnv:
1283 while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1284 if (strchr(arg, '=') != NULL)
1285 fatal("%s line %d: Invalid environment name.",
1286 filename, linenum);
Damien Millerf8e7acc2005-03-05 11:22:50 +11001287 if (!*activep)
1288 continue;
Darren Tucker46bc0752004-05-02 22:11:30 +10001289 if (options->num_send_env >= MAX_SEND_ENV)
1290 fatal("%s line %d: too many send env.",
1291 filename, linenum);
1292 options->send_env[options->num_send_env++] =
1293 xstrdup(arg);
1294 }
1295 break;
1296
Damien Miller0e220db2004-06-15 10:34:08 +10001297 case oControlPath:
1298 charptr = &options->control_path;
1299 goto parse_string;
1300
1301 case oControlMaster:
1302 intptr = &options->control_master;
Damien Millere9fc72e2013-10-15 12:14:12 +11001303 multistate_ptr = multistate_controlmaster;
1304 goto parse_multistate;
Damien Miller0e220db2004-06-15 10:34:08 +10001305
Damien Millere11e1ea2010-08-03 16:04:46 +10001306 case oControlPersist:
1307 /* no/false/yes/true, or a time spec */
1308 intptr = &options->control_persist;
1309 arg = strdelim(&s);
1310 if (!arg || *arg == '\0')
1311 fatal("%.200s line %d: Missing ControlPersist"
1312 " argument.", filename, linenum);
1313 value = 0;
1314 value2 = 0; /* timeout */
1315 if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
1316 value = 0;
1317 else if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
1318 value = 1;
1319 else if ((value2 = convtime(arg)) >= 0)
1320 value = 1;
1321 else
1322 fatal("%.200s line %d: Bad ControlPersist argument.",
1323 filename, linenum);
1324 if (*activep && *intptr == -1) {
1325 *intptr = value;
1326 options->control_persist_timeout = value2;
1327 }
1328 break;
1329
Damien Millere1776152005-03-01 21:47:37 +11001330 case oHashKnownHosts:
1331 intptr = &options->hash_known_hosts;
1332 goto parse_flag;
1333
Damien Millerd27b9472005-12-13 19:29:02 +11001334 case oTunnel:
1335 intptr = &options->tun_open;
Damien Millere9fc72e2013-10-15 12:14:12 +11001336 multistate_ptr = multistate_tunnel;
1337 goto parse_multistate;
Damien Millerd27b9472005-12-13 19:29:02 +11001338
1339 case oTunnelDevice:
1340 arg = strdelim(&s);
1341 if (!arg || *arg == '\0')
1342 fatal("%.200s line %d: Missing argument.", filename, linenum);
1343 value = a2tun(arg, &value2);
Damien Miller7b58e802005-12-13 19:33:19 +11001344 if (value == SSH_TUNID_ERR)
Damien Millerd27b9472005-12-13 19:29:02 +11001345 fatal("%.200s line %d: Bad tun device.", filename, linenum);
1346 if (*activep) {
1347 options->tun_local = value;
1348 options->tun_remote = value2;
1349 }
1350 break;
1351
1352 case oLocalCommand:
1353 charptr = &options->local_command;
1354 goto parse_command;
1355
1356 case oPermitLocalCommand:
1357 intptr = &options->permit_local_command;
1358 goto parse_flag;
1359
Damien Miller10288242008-06-30 00:04:03 +10001360 case oVisualHostKey:
1361 intptr = &options->visual_host_key;
1362 goto parse_flag;
1363
Damien Miller0dac6fb2010-11-20 15:19:38 +11001364 case oIPQoS:
1365 arg = strdelim(&s);
1366 if ((value = parse_ipqos(arg)) == -1)
1367 fatal("%s line %d: Bad IPQoS value: %s",
1368 filename, linenum, arg);
1369 arg = strdelim(&s);
1370 if (arg == NULL)
1371 value2 = value;
1372 else if ((value2 = parse_ipqos(arg)) == -1)
1373 fatal("%s line %d: Bad IPQoS value: %s",
1374 filename, linenum, arg);
1375 if (*activep) {
1376 options->ip_qos_interactive = value;
1377 options->ip_qos_bulk = value2;
1378 }
1379 break;
1380
Darren Tucker71e4d542009-07-06 07:12:27 +10001381 case oUseRoaming:
1382 intptr = &options->use_roaming;
1383 goto parse_flag;
1384
Damien Miller21771e22011-05-15 08:45:50 +10001385 case oRequestTTY:
Damien Miller21771e22011-05-15 08:45:50 +10001386 intptr = &options->request_tty;
Damien Millere9fc72e2013-10-15 12:14:12 +11001387 multistate_ptr = multistate_requesttty;
1388 goto parse_multistate;
Damien Miller21771e22011-05-15 08:45:50 +10001389
Darren Tucker07636982013-05-16 20:30:03 +10001390 case oIgnoreUnknown:
1391 charptr = &options->ignored_unknown;
1392 goto parse_string;
1393
Damien Miller1262b662013-08-21 02:44:24 +10001394 case oProxyUseFdpass:
1395 intptr = &options->proxy_use_fdpass;
1396 goto parse_flag;
1397
Damien Miller0faf7472013-10-17 11:47:23 +11001398 case oCanonicalDomains:
1399 value = options->num_canonical_domains != 0;
1400 while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1401 valid_domain(arg, filename, linenum);
1402 if (!*activep || value)
1403 continue;
1404 if (options->num_canonical_domains >= MAX_CANON_DOMAINS)
1405 fatal("%s line %d: too many hostname suffixes.",
1406 filename, linenum);
1407 options->canonical_domains[
1408 options->num_canonical_domains++] = xstrdup(arg);
1409 }
1410 break;
1411
Damien Miller38505592013-10-17 11:48:13 +11001412 case oCanonicalizePermittedCNAMEs:
Damien Miller0faf7472013-10-17 11:47:23 +11001413 value = options->num_permitted_cnames != 0;
1414 while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1415 /* Either '*' for everything or 'list:list' */
1416 if (strcmp(arg, "*") == 0)
1417 arg2 = arg;
1418 else {
1419 lowercase(arg);
1420 if ((arg2 = strchr(arg, ':')) == NULL ||
1421 arg2[1] == '\0') {
1422 fatal("%s line %d: "
1423 "Invalid permitted CNAME \"%s\"",
1424 filename, linenum, arg);
1425 }
1426 *arg2 = '\0';
1427 arg2++;
1428 }
1429 if (!*activep || value)
1430 continue;
1431 if (options->num_permitted_cnames >= MAX_CANON_DOMAINS)
1432 fatal("%s line %d: too many permitted CNAMEs.",
1433 filename, linenum);
1434 cname = options->permitted_cnames +
1435 options->num_permitted_cnames++;
1436 cname->source_list = xstrdup(arg);
1437 cname->target_list = xstrdup(arg2);
1438 }
1439 break;
1440
Damien Miller38505592013-10-17 11:48:13 +11001441 case oCanonicalizeHostname:
1442 intptr = &options->canonicalize_hostname;
1443 multistate_ptr = multistate_canonicalizehostname;
Damien Miller0faf7472013-10-17 11:47:23 +11001444 goto parse_multistate;
1445
Damien Miller38505592013-10-17 11:48:13 +11001446 case oCanonicalizeMaxDots:
1447 intptr = &options->canonicalize_max_dots;
Damien Miller0faf7472013-10-17 11:47:23 +11001448 goto parse_int;
1449
Damien Miller38505592013-10-17 11:48:13 +11001450 case oCanonicalizeFallbackLocal:
1451 intptr = &options->canonicalize_fallback_local;
Damien Miller0faf7472013-10-17 11:47:23 +11001452 goto parse_flag;
1453
Damien Miller7acefbb2014-07-18 14:11:24 +10001454 case oStreamLocalBindMask:
1455 arg = strdelim(&s);
1456 if (!arg || *arg == '\0')
1457 fatal("%.200s line %d: Missing StreamLocalBindMask argument.", filename, linenum);
1458 /* Parse mode in octal format */
1459 value = strtol(arg, &endofnumber, 8);
1460 if (arg == endofnumber || value < 0 || value > 0777)
1461 fatal("%.200s line %d: Bad mask.", filename, linenum);
1462 options->fwd_opts.streamlocal_bind_mask = (mode_t)value;
1463 break;
1464
1465 case oStreamLocalBindUnlink:
1466 intptr = &options->fwd_opts.streamlocal_bind_unlink;
1467 goto parse_flag;
1468
djm@openbsd.org5e39a492014-12-04 02:24:32 +00001469 case oRevokedHostKeys:
1470 charptr = &options->revoked_host_keys;
1471 goto parse_string;
1472
djm@openbsd.org56d1c832014-12-21 22:27:55 +00001473 case oFingerprintHash:
djm@openbsd.orge752c6d2015-01-08 13:44:36 +00001474 intptr = &options->fingerprint_hash;
djm@openbsd.org56d1c832014-12-21 22:27:55 +00001475 arg = strdelim(&s);
1476 if (!arg || *arg == '\0')
1477 fatal("%.200s line %d: Missing argument.",
1478 filename, linenum);
1479 if ((value = ssh_digest_alg_by_name(arg)) == -1)
1480 fatal("%.200s line %d: Invalid hash algorithm \"%s\".",
1481 filename, linenum, arg);
djm@openbsd.orge752c6d2015-01-08 13:44:36 +00001482 if (*activep && *intptr == -1)
1483 *intptr = value;
djm@openbsd.org56d1c832014-12-21 22:27:55 +00001484 break;
1485
djm@openbsd.org8d4f8722015-01-26 03:04:45 +00001486 case oUpdateHostkeys:
1487 intptr = &options->update_hostkeys;
djm@openbsd.org523463a2015-02-16 22:13:32 +00001488 multistate_ptr = multistate_yesnoask;
1489 goto parse_multistate;
djm@openbsd.org8d4f8722015-01-26 03:04:45 +00001490
djm@openbsd.org46347ed2015-01-30 11:43:14 +00001491 case oHostbasedKeyTypes:
1492 charptr = &options->hostbased_key_types;
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00001493 goto parse_keytypes;
1494
1495 case oPubkeyAcceptedKeyTypes:
1496 charptr = &options->pubkey_key_types;
1497 goto parse_keytypes;
djm@openbsd.org46347ed2015-01-30 11:43:14 +00001498
Ben Lindstrom4daea862002-06-09 20:04:02 +00001499 case oDeprecated:
Ben Lindstrom2e17b082002-06-09 20:13:27 +00001500 debug("%s line %d: Deprecated option \"%s\"",
Ben Lindstrom4daea862002-06-09 20:04:02 +00001501 filename, linenum, keyword);
Ben Lindstrom2e17b082002-06-09 20:13:27 +00001502 return 0;
Ben Lindstrom4daea862002-06-09 20:04:02 +00001503
Damien Millerf9b3feb2003-05-16 11:38:32 +10001504 case oUnsupported:
1505 error("%s line %d: Unsupported option \"%s\"",
1506 filename, linenum, keyword);
1507 return 0;
1508
Damien Miller95def091999-11-25 00:26:21 +11001509 default:
djm@openbsd.org957fbce2014-10-08 22:20:25 +00001510 fatal("%s: Unimplemented opcode %d", __func__, opcode);
Damien Miller95def091999-11-25 00:26:21 +11001511 }
1512
1513 /* Check that there is no garbage at end of line. */
Ben Lindstrom226cfa02001-01-22 05:34:40 +00001514 if ((arg = strdelim(&s)) != NULL && *arg != '\0') {
Damien Miller37023962000-07-11 17:31:38 +10001515 fatal("%.200s line %d: garbage at end of line; \"%.200s\".",
Damien Miller0dc1bef2005-07-17 17:22:45 +10001516 filename, linenum, arg);
Damien Miller37023962000-07-11 17:31:38 +10001517 }
Damien Miller95def091999-11-25 00:26:21 +11001518 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001519}
1520
1521
Damien Miller5428f641999-11-25 11:54:57 +11001522/*
1523 * Reads the config file and modifies the options accordingly. Options
1524 * should already be initialized before this call. This never returns if
Ben Lindstromedc0cf22001-09-12 18:32:20 +00001525 * there is an error. If the file does not exist, this returns 0.
Damien Miller5428f641999-11-25 11:54:57 +11001526 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001527
Ben Lindstromedc0cf22001-09-12 18:32:20 +00001528int
Damien Miller194fd902013-10-15 12:13:05 +11001529read_config_file(const char *filename, struct passwd *pw, const char *host,
djm@openbsd.org957fbce2014-10-08 22:20:25 +00001530 const char *original_host, Options *options, int flags)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001531{
Damien Miller95def091999-11-25 00:26:21 +11001532 FILE *f;
1533 char line[1024];
1534 int active, linenum;
1535 int bad_options = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001536
Damien Miller57a44762004-04-20 20:11:57 +10001537 if ((f = fopen(filename, "r")) == NULL)
Ben Lindstromedc0cf22001-09-12 18:32:20 +00001538 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001539
Darren Tuckeraefa3682013-04-05 11:18:35 +11001540 if (flags & SSHCONF_CHECKPERM) {
Damien Miller57a44762004-04-20 20:11:57 +10001541 struct stat sb;
Darren Tuckerfc959702004-07-17 16:12:08 +10001542
Damien Miller33793852004-06-15 10:27:55 +10001543 if (fstat(fileno(f), &sb) == -1)
Damien Miller57a44762004-04-20 20:11:57 +10001544 fatal("fstat %s: %s", filename, strerror(errno));
Damien Miller57a44762004-04-20 20:11:57 +10001545 if (((sb.st_uid != 0 && sb.st_uid != getuid()) ||
Damien Miller33793852004-06-15 10:27:55 +10001546 (sb.st_mode & 022) != 0))
Damien Miller57a44762004-04-20 20:11:57 +10001547 fatal("Bad owner or permissions on %s", filename);
Damien Miller57a44762004-04-20 20:11:57 +10001548 }
1549
Damien Miller95def091999-11-25 00:26:21 +11001550 debug("Reading configuration data %.200s", filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001551
Damien Miller5428f641999-11-25 11:54:57 +11001552 /*
1553 * Mark that we are now processing the options. This flag is turned
1554 * on/off by Host specifications.
1555 */
Damien Miller95def091999-11-25 00:26:21 +11001556 active = 1;
1557 linenum = 0;
1558 while (fgets(line, sizeof(line), f)) {
1559 /* Update line number counter. */
1560 linenum++;
djm@openbsd.org957fbce2014-10-08 22:20:25 +00001561 if (process_config_line(options, pw, host, original_host,
1562 line, filename, linenum, &active, flags) != 0)
Damien Miller95def091999-11-25 00:26:21 +11001563 bad_options++;
1564 }
1565 fclose(f);
1566 if (bad_options > 0)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +00001567 fatal("%s: terminating, %d bad configuration options",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001568 filename, bad_options);
Ben Lindstromedc0cf22001-09-12 18:32:20 +00001569 return 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001570}
1571
Damien Miller13f97b22014-02-24 15:57:55 +11001572/* Returns 1 if a string option is unset or set to "none" or 0 otherwise. */
1573int
1574option_clear_or_none(const char *o)
1575{
1576 return o == NULL || strcasecmp(o, "none") == 0;
1577}
1578
Damien Miller5428f641999-11-25 11:54:57 +11001579/*
1580 * Initializes options to special values that indicate that they have not yet
1581 * been set. Read_config_file will only set options with this value. Options
1582 * are processed in the following order: command line, user config file,
1583 * system config file. Last, fill_default_options is called.
1584 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001585
Damien Miller4af51302000-04-16 11:18:38 +10001586void
Damien Miller95def091999-11-25 00:26:21 +11001587initialize_options(Options * options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001588{
Damien Miller95def091999-11-25 00:26:21 +11001589 memset(options, 'X', sizeof(*options));
1590 options->forward_agent = -1;
1591 options->forward_x11 = -1;
Darren Tucker0a118da2003-10-15 15:54:32 +10001592 options->forward_x11_trusted = -1;
Damien Miller1ab6a512010-06-26 10:02:24 +10001593 options->forward_x11_timeout = -1;
Darren Tuckere7d4b192006-07-12 22:17:10 +10001594 options->exit_on_forward_failure = -1;
Damien Millerd3a18572000-06-07 19:55:44 +10001595 options->xauth_location = NULL;
Damien Miller7acefbb2014-07-18 14:11:24 +10001596 options->fwd_opts.gateway_ports = -1;
1597 options->fwd_opts.streamlocal_bind_mask = (mode_t)-1;
1598 options->fwd_opts.streamlocal_bind_unlink = -1;
Damien Miller95def091999-11-25 00:26:21 +11001599 options->use_privileged_port = -1;
Damien Miller95def091999-11-25 00:26:21 +11001600 options->rsa_authentication = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +11001601 options->pubkey_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +00001602 options->challenge_response_authentication = -1;
Darren Tucker0efd1552003-08-26 11:49:55 +10001603 options->gss_authentication = -1;
1604 options->gss_deleg_creds = -1;
Damien Miller95def091999-11-25 00:26:21 +11001605 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +11001606 options->kbd_interactive_authentication = -1;
1607 options->kbd_interactive_devices = NULL;
Damien Miller95def091999-11-25 00:26:21 +11001608 options->rhosts_rsa_authentication = -1;
Ben Lindstrom5eabda32001-04-12 23:34:34 +00001609 options->hostbased_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +11001610 options->batch_mode = -1;
1611 options->check_host_ip = -1;
1612 options->strict_host_key_checking = -1;
1613 options->compression = -1;
Damien Miller12c150e2003-12-17 16:31:10 +11001614 options->tcp_keep_alive = -1;
Damien Miller95def091999-11-25 00:26:21 +11001615 options->compression_level = -1;
1616 options->port = -1;
Darren Tucker0a4f04b2003-07-03 20:37:47 +10001617 options->address_family = -1;
Damien Miller95def091999-11-25 00:26:21 +11001618 options->connection_attempts = -1;
Damien Millerb78d5eb2003-05-16 11:39:04 +10001619 options->connection_timeout = -1;
Damien Miller95def091999-11-25 00:26:21 +11001620 options->number_of_password_prompts = -1;
1621 options->cipher = -1;
Damien Miller78928792000-04-12 20:17:38 +10001622 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +00001623 options->macs = NULL;
Damien Millerd5f62bf2010-09-24 22:11:14 +10001624 options->kex_algorithms = NULL;
Ben Lindstrom982dbbc2001-04-17 18:11:36 +00001625 options->hostkeyalgorithms = NULL;
Damien Miller78928792000-04-12 20:17:38 +10001626 options->protocol = SSH_PROTO_UNKNOWN;
Damien Miller95def091999-11-25 00:26:21 +11001627 options->num_identity_files = 0;
1628 options->hostname = NULL;
Ben Lindstrom4dccfa52000-12-28 16:40:05 +00001629 options->host_key_alias = NULL;
Damien Miller95def091999-11-25 00:26:21 +11001630 options->proxy_command = NULL;
1631 options->user = NULL;
1632 options->escape_char = -1;
Damien Miller295ee632011-05-29 21:42:31 +10001633 options->num_system_hostfiles = 0;
1634 options->num_user_hostfiles = 0;
Damien Miller232cfb12010-06-26 09:50:30 +10001635 options->local_forwards = NULL;
Damien Miller95def091999-11-25 00:26:21 +11001636 options->num_local_forwards = 0;
Damien Miller232cfb12010-06-26 09:50:30 +10001637 options->remote_forwards = NULL;
Damien Miller95def091999-11-25 00:26:21 +11001638 options->num_remote_forwards = 0;
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +00001639 options->clear_forwardings = -1;
Damien Millerfcd93202002-02-05 12:26:34 +11001640 options->log_level = SYSLOG_LEVEL_NOT_SET;
Ben Lindstromb9be60a2001-03-11 01:49:19 +00001641 options->preferred_authentications = NULL;
Ben Lindstrome0f88042001-04-30 13:06:24 +00001642 options->bind_address = NULL;
Damien Miller7ea845e2010-02-12 09:21:02 +11001643 options->pkcs11_provider = NULL;
Ben Lindstromb6df73b2002-11-09 15:52:31 +00001644 options->enable_ssh_keysign = - 1;
Ben Lindstrom3cecc9a2001-10-03 17:39:38 +00001645 options->no_host_authentication_for_localhost = - 1;
Damien Millerbd394c32004-03-08 23:12:36 +11001646 options->identities_only = - 1;
Damien Millera5539d22003-04-09 20:50:06 +10001647 options->rekey_limit = - 1;
Darren Tuckerc53c2af2013-05-16 20:28:16 +10001648 options->rekey_interval = -1;
Damien Miller37876e92003-05-15 10:19:46 +10001649 options->verify_host_key_dns = -1;
Damien Miller509b0102003-12-17 16:33:10 +11001650 options->server_alive_interval = -1;
1651 options->server_alive_count_max = -1;
Darren Tucker46bc0752004-05-02 22:11:30 +10001652 options->num_send_env = 0;
Damien Miller0e220db2004-06-15 10:34:08 +10001653 options->control_path = NULL;
1654 options->control_master = -1;
Damien Millere11e1ea2010-08-03 16:04:46 +10001655 options->control_persist = -1;
1656 options->control_persist_timeout = 0;
Damien Millere1776152005-03-01 21:47:37 +11001657 options->hash_known_hosts = -1;
Damien Millerd27b9472005-12-13 19:29:02 +11001658 options->tun_open = -1;
1659 options->tun_local = -1;
1660 options->tun_remote = -1;
1661 options->local_command = NULL;
1662 options->permit_local_command = -1;
Darren Tucker71e4d542009-07-06 07:12:27 +10001663 options->use_roaming = -1;
Damien Miller10288242008-06-30 00:04:03 +10001664 options->visual_host_key = -1;
Damien Miller0dac6fb2010-11-20 15:19:38 +11001665 options->ip_qos_interactive = -1;
1666 options->ip_qos_bulk = -1;
Damien Miller21771e22011-05-15 08:45:50 +10001667 options->request_tty = -1;
Damien Miller1262b662013-08-21 02:44:24 +10001668 options->proxy_use_fdpass = -1;
Darren Tucker07636982013-05-16 20:30:03 +10001669 options->ignored_unknown = NULL;
Damien Miller0faf7472013-10-17 11:47:23 +11001670 options->num_canonical_domains = 0;
1671 options->num_permitted_cnames = 0;
Damien Miller38505592013-10-17 11:48:13 +11001672 options->canonicalize_max_dots = -1;
1673 options->canonicalize_fallback_local = -1;
1674 options->canonicalize_hostname = -1;
djm@openbsd.org5e39a492014-12-04 02:24:32 +00001675 options->revoked_host_keys = NULL;
djm@openbsd.org56d1c832014-12-21 22:27:55 +00001676 options->fingerprint_hash = -1;
djm@openbsd.org8d4f8722015-01-26 03:04:45 +00001677 options->update_hostkeys = -1;
djm@openbsd.org46347ed2015-01-30 11:43:14 +00001678 options->hostbased_key_types = NULL;
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00001679 options->pubkey_key_types = NULL;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001680}
1681
Damien Miller5428f641999-11-25 11:54:57 +11001682/*
Damien Miller13f97b22014-02-24 15:57:55 +11001683 * A petite version of fill_default_options() that just fills the options
1684 * needed for hostname canonicalization to proceed.
1685 */
1686void
1687fill_default_options_for_canonicalization(Options *options)
1688{
1689 if (options->canonicalize_max_dots == -1)
1690 options->canonicalize_max_dots = 1;
1691 if (options->canonicalize_fallback_local == -1)
1692 options->canonicalize_fallback_local = 1;
1693 if (options->canonicalize_hostname == -1)
1694 options->canonicalize_hostname = SSH_CANONICALISE_NO;
1695}
1696
1697/*
Damien Miller5428f641999-11-25 11:54:57 +11001698 * Called after processing other sources of option data, this fills those
1699 * options for which no value has been specified with their default values.
1700 */
Damien Miller4af51302000-04-16 11:18:38 +10001701void
Damien Miller95def091999-11-25 00:26:21 +11001702fill_default_options(Options * options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001703{
Damien Miller95def091999-11-25 00:26:21 +11001704 if (options->forward_agent == -1)
Damien Millerb1715dc2000-05-30 13:44:51 +10001705 options->forward_agent = 0;
Damien Miller95def091999-11-25 00:26:21 +11001706 if (options->forward_x11 == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +11001707 options->forward_x11 = 0;
Darren Tucker0a118da2003-10-15 15:54:32 +10001708 if (options->forward_x11_trusted == -1)
1709 options->forward_x11_trusted = 0;
Damien Miller1ab6a512010-06-26 10:02:24 +10001710 if (options->forward_x11_timeout == -1)
1711 options->forward_x11_timeout = 1200;
Darren Tuckere7d4b192006-07-12 22:17:10 +10001712 if (options->exit_on_forward_failure == -1)
1713 options->exit_on_forward_failure = 0;
Damien Millerd3a18572000-06-07 19:55:44 +10001714 if (options->xauth_location == NULL)
Ben Lindstrom1bf11f62001-06-09 01:48:01 +00001715 options->xauth_location = _PATH_XAUTH;
Damien Miller7acefbb2014-07-18 14:11:24 +10001716 if (options->fwd_opts.gateway_ports == -1)
1717 options->fwd_opts.gateway_ports = 0;
1718 if (options->fwd_opts.streamlocal_bind_mask == (mode_t)-1)
1719 options->fwd_opts.streamlocal_bind_mask = 0177;
1720 if (options->fwd_opts.streamlocal_bind_unlink == -1)
1721 options->fwd_opts.streamlocal_bind_unlink = 0;
Damien Miller95def091999-11-25 00:26:21 +11001722 if (options->use_privileged_port == -1)
Ben Lindstromcebc8582001-03-08 03:39:10 +00001723 options->use_privileged_port = 0;
Damien Miller95def091999-11-25 00:26:21 +11001724 if (options->rsa_authentication == -1)
1725 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +11001726 if (options->pubkey_authentication == -1)
1727 options->pubkey_authentication = 1;
Ben Lindstrom551ea372001-06-05 18:56:16 +00001728 if (options->challenge_response_authentication == -1)
Ben Lindstrom0076d752001-08-06 20:53:26 +00001729 options->challenge_response_authentication = 1;
Darren Tucker0efd1552003-08-26 11:49:55 +10001730 if (options->gss_authentication == -1)
Darren Tuckera044f472003-10-15 15:52:03 +10001731 options->gss_authentication = 0;
Darren Tucker0efd1552003-08-26 11:49:55 +10001732 if (options->gss_deleg_creds == -1)
1733 options->gss_deleg_creds = 0;
Damien Miller95def091999-11-25 00:26:21 +11001734 if (options->password_authentication == -1)
1735 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +11001736 if (options->kbd_interactive_authentication == -1)
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +00001737 options->kbd_interactive_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +11001738 if (options->rhosts_rsa_authentication == -1)
Ben Lindstrom2bf82762002-06-11 15:53:05 +00001739 options->rhosts_rsa_authentication = 0;
Ben Lindstrom5eabda32001-04-12 23:34:34 +00001740 if (options->hostbased_authentication == -1)
1741 options->hostbased_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +11001742 if (options->batch_mode == -1)
1743 options->batch_mode = 0;
1744 if (options->check_host_ip == -1)
1745 options->check_host_ip = 1;
1746 if (options->strict_host_key_checking == -1)
1747 options->strict_host_key_checking = 2; /* 2 is default */
1748 if (options->compression == -1)
1749 options->compression = 0;
Damien Miller12c150e2003-12-17 16:31:10 +11001750 if (options->tcp_keep_alive == -1)
1751 options->tcp_keep_alive = 1;
Damien Miller95def091999-11-25 00:26:21 +11001752 if (options->compression_level == -1)
1753 options->compression_level = 6;
1754 if (options->port == -1)
1755 options->port = 0; /* Filled in ssh_connect. */
Darren Tucker0a4f04b2003-07-03 20:37:47 +10001756 if (options->address_family == -1)
1757 options->address_family = AF_UNSPEC;
Damien Miller95def091999-11-25 00:26:21 +11001758 if (options->connection_attempts == -1)
Ben Lindstromf9cedb92001-08-06 21:07:11 +00001759 options->connection_attempts = 1;
Damien Miller95def091999-11-25 00:26:21 +11001760 if (options->number_of_password_prompts == -1)
1761 options->number_of_password_prompts = 3;
1762 /* Selected in ssh_login(). */
1763 if (options->cipher == -1)
1764 options->cipher = SSH_CIPHER_NOT_SET;
Damien Miller30c3d422000-05-09 11:02:59 +10001765 /* options->ciphers, default set in myproposals.h */
Ben Lindstrom06b33aa2001-02-15 03:01:59 +00001766 /* options->macs, default set in myproposals.h */
Damien Millerd5f62bf2010-09-24 22:11:14 +10001767 /* options->kex_algorithms, default set in myproposals.h */
Ben Lindstrom982dbbc2001-04-17 18:11:36 +00001768 /* options->hostkeyalgorithms, default set in myproposals.h */
Damien Miller78928792000-04-12 20:17:38 +10001769 if (options->protocol == SSH_PROTO_UNKNOWN)
Darren Tuckerbad50762009-10-11 21:51:08 +11001770 options->protocol = SSH_PROTO_2;
Damien Miller95def091999-11-25 00:26:21 +11001771 if (options->num_identity_files == 0) {
Damien Miller0bc1bd82000-11-13 22:57:25 +11001772 if (options->protocol & SSH_PROTO_1) {
Darren Tucker19104782013-04-05 11:13:08 +11001773 add_identity_file(options, "~/",
1774 _PATH_SSH_CLIENT_IDENTITY, 0);
Damien Miller0bc1bd82000-11-13 22:57:25 +11001775 }
1776 if (options->protocol & SSH_PROTO_2) {
Darren Tucker19104782013-04-05 11:13:08 +11001777 add_identity_file(options, "~/",
1778 _PATH_SSH_CLIENT_ID_RSA, 0);
1779 add_identity_file(options, "~/",
1780 _PATH_SSH_CLIENT_ID_DSA, 0);
Damien Miller6af914a2010-09-10 11:39:26 +10001781#ifdef OPENSSL_HAS_ECC
Darren Tucker19104782013-04-05 11:13:08 +11001782 add_identity_file(options, "~/",
1783 _PATH_SSH_CLIENT_ID_ECDSA, 0);
Damien Miller6af914a2010-09-10 11:39:26 +10001784#endif
Damien Miller5be9d9e2013-12-07 11:24:01 +11001785 add_identity_file(options, "~/",
1786 _PATH_SSH_CLIENT_ID_ED25519, 0);
Damien Miller0bc1bd82000-11-13 22:57:25 +11001787 }
Damien Millereba71ba2000-04-29 23:57:08 +10001788 }
Damien Miller95def091999-11-25 00:26:21 +11001789 if (options->escape_char == -1)
1790 options->escape_char = '~';
Damien Miller295ee632011-05-29 21:42:31 +10001791 if (options->num_system_hostfiles == 0) {
1792 options->system_hostfiles[options->num_system_hostfiles++] =
1793 xstrdup(_PATH_SSH_SYSTEM_HOSTFILE);
1794 options->system_hostfiles[options->num_system_hostfiles++] =
1795 xstrdup(_PATH_SSH_SYSTEM_HOSTFILE2);
1796 }
1797 if (options->num_user_hostfiles == 0) {
1798 options->user_hostfiles[options->num_user_hostfiles++] =
1799 xstrdup(_PATH_SSH_USER_HOSTFILE);
1800 options->user_hostfiles[options->num_user_hostfiles++] =
1801 xstrdup(_PATH_SSH_USER_HOSTFILE2);
1802 }
Damien Millerfcd93202002-02-05 12:26:34 +11001803 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +00001804 options->log_level = SYSLOG_LEVEL_INFO;
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +00001805 if (options->clear_forwardings == 1)
1806 clear_forwardings(options);
Ben Lindstrom3cecc9a2001-10-03 17:39:38 +00001807 if (options->no_host_authentication_for_localhost == - 1)
1808 options->no_host_authentication_for_localhost = 0;
Damien Millerbd394c32004-03-08 23:12:36 +11001809 if (options->identities_only == -1)
1810 options->identities_only = 0;
Ben Lindstromb6df73b2002-11-09 15:52:31 +00001811 if (options->enable_ssh_keysign == -1)
1812 options->enable_ssh_keysign = 0;
Damien Millera5539d22003-04-09 20:50:06 +10001813 if (options->rekey_limit == -1)
1814 options->rekey_limit = 0;
Darren Tuckerc53c2af2013-05-16 20:28:16 +10001815 if (options->rekey_interval == -1)
1816 options->rekey_interval = 0;
Damien Miller37876e92003-05-15 10:19:46 +10001817 if (options->verify_host_key_dns == -1)
1818 options->verify_host_key_dns = 0;
Damien Miller509b0102003-12-17 16:33:10 +11001819 if (options->server_alive_interval == -1)
1820 options->server_alive_interval = 0;
1821 if (options->server_alive_count_max == -1)
1822 options->server_alive_count_max = 3;
Damien Miller0e220db2004-06-15 10:34:08 +10001823 if (options->control_master == -1)
1824 options->control_master = 0;
Damien Millere11e1ea2010-08-03 16:04:46 +10001825 if (options->control_persist == -1) {
1826 options->control_persist = 0;
1827 options->control_persist_timeout = 0;
1828 }
Damien Millere1776152005-03-01 21:47:37 +11001829 if (options->hash_known_hosts == -1)
1830 options->hash_known_hosts = 0;
Damien Millerd27b9472005-12-13 19:29:02 +11001831 if (options->tun_open == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001832 options->tun_open = SSH_TUNMODE_NO;
1833 if (options->tun_local == -1)
1834 options->tun_local = SSH_TUNID_ANY;
1835 if (options->tun_remote == -1)
1836 options->tun_remote = SSH_TUNID_ANY;
Damien Millerd27b9472005-12-13 19:29:02 +11001837 if (options->permit_local_command == -1)
1838 options->permit_local_command = 0;
Darren Tucker71e4d542009-07-06 07:12:27 +10001839 if (options->use_roaming == -1)
1840 options->use_roaming = 1;
Damien Miller10288242008-06-30 00:04:03 +10001841 if (options->visual_host_key == -1)
1842 options->visual_host_key = 0;
Damien Miller0dac6fb2010-11-20 15:19:38 +11001843 if (options->ip_qos_interactive == -1)
1844 options->ip_qos_interactive = IPTOS_LOWDELAY;
1845 if (options->ip_qos_bulk == -1)
1846 options->ip_qos_bulk = IPTOS_THROUGHPUT;
Damien Miller21771e22011-05-15 08:45:50 +10001847 if (options->request_tty == -1)
1848 options->request_tty = REQUEST_TTY_AUTO;
Damien Miller1262b662013-08-21 02:44:24 +10001849 if (options->proxy_use_fdpass == -1)
1850 options->proxy_use_fdpass = 0;
Damien Miller38505592013-10-17 11:48:13 +11001851 if (options->canonicalize_max_dots == -1)
1852 options->canonicalize_max_dots = 1;
1853 if (options->canonicalize_fallback_local == -1)
1854 options->canonicalize_fallback_local = 1;
1855 if (options->canonicalize_hostname == -1)
1856 options->canonicalize_hostname = SSH_CANONICALISE_NO;
djm@openbsd.org56d1c832014-12-21 22:27:55 +00001857 if (options->fingerprint_hash == -1)
1858 options->fingerprint_hash = SSH_FP_HASH_DEFAULT;
djm@openbsd.org8d4f8722015-01-26 03:04:45 +00001859 if (options->update_hostkeys == -1)
djm@openbsd.org15ad7502015-02-02 07:41:40 +00001860 options->update_hostkeys = 0;
djm@openbsd.org46347ed2015-01-30 11:43:14 +00001861 if (options->hostbased_key_types == NULL)
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00001862 options->hostbased_key_types = xstrdup(KEX_DEFAULT_PK_ALG);
1863 if (options->pubkey_key_types == NULL)
1864 options->pubkey_key_types = xstrdup(KEX_DEFAULT_PK_ALG);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00001865
Damien Millere9fc72e2013-10-15 12:14:12 +11001866#define CLEAR_ON_NONE(v) \
1867 do { \
Damien Miller13f97b22014-02-24 15:57:55 +11001868 if (option_clear_or_none(v)) { \
Damien Millere9fc72e2013-10-15 12:14:12 +11001869 free(v); \
1870 v = NULL; \
1871 } \
1872 } while(0)
1873 CLEAR_ON_NONE(options->local_command);
1874 CLEAR_ON_NONE(options->proxy_command);
1875 CLEAR_ON_NONE(options->control_path);
djm@openbsd.org5e39a492014-12-04 02:24:32 +00001876 CLEAR_ON_NONE(options->revoked_host_keys);
Damien Miller95def091999-11-25 00:26:21 +11001877 /* options->user will be set in the main program if appropriate */
1878 /* options->hostname will be set in the main program if appropriate */
Ben Lindstrom4dccfa52000-12-28 16:40:05 +00001879 /* options->host_key_alias should not be set by default */
Ben Lindstromb9be60a2001-03-11 01:49:19 +00001880 /* options->preferred_authentications will be set in ssh */
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001881}
Damien Millerf91ee4c2005-03-01 21:24:33 +11001882
Damien Miller7acefbb2014-07-18 14:11:24 +10001883struct fwdarg {
1884 char *arg;
1885 int ispath;
1886};
1887
1888/*
1889 * parse_fwd_field
1890 * parses the next field in a port forwarding specification.
1891 * sets fwd to the parsed field and advances p past the colon
1892 * or sets it to NULL at end of string.
1893 * returns 0 on success, else non-zero.
1894 */
1895static int
1896parse_fwd_field(char **p, struct fwdarg *fwd)
1897{
1898 char *ep, *cp = *p;
1899 int ispath = 0;
1900
1901 if (*cp == '\0') {
1902 *p = NULL;
1903 return -1; /* end of string */
1904 }
1905
1906 /*
1907 * A field escaped with square brackets is used literally.
1908 * XXX - allow ']' to be escaped via backslash?
1909 */
1910 if (*cp == '[') {
1911 /* find matching ']' */
1912 for (ep = cp + 1; *ep != ']' && *ep != '\0'; ep++) {
1913 if (*ep == '/')
1914 ispath = 1;
1915 }
1916 /* no matching ']' or not at end of field. */
1917 if (ep[0] != ']' || (ep[1] != ':' && ep[1] != '\0'))
1918 return -1;
1919 /* NUL terminate the field and advance p past the colon */
1920 *ep++ = '\0';
1921 if (*ep != '\0')
1922 *ep++ = '\0';
1923 fwd->arg = cp + 1;
1924 fwd->ispath = ispath;
1925 *p = ep;
1926 return 0;
1927 }
1928
1929 for (cp = *p; *cp != '\0'; cp++) {
1930 switch (*cp) {
1931 case '\\':
1932 memmove(cp, cp + 1, strlen(cp + 1) + 1);
djm@openbsd.org78c2a4f2015-06-26 05:13:20 +00001933 if (*cp == '\0')
1934 return -1;
Damien Miller7acefbb2014-07-18 14:11:24 +10001935 break;
1936 case '/':
1937 ispath = 1;
1938 break;
1939 case ':':
1940 *cp++ = '\0';
1941 goto done;
1942 }
1943 }
1944done:
1945 fwd->arg = *p;
1946 fwd->ispath = ispath;
1947 *p = cp;
1948 return 0;
1949}
1950
Damien Millerf91ee4c2005-03-01 21:24:33 +11001951/*
1952 * parse_forward
1953 * parses a string containing a port forwarding specification of the form:
Damien Millera699d952008-11-03 19:27:34 +11001954 * dynamicfwd == 0
Damien Miller7acefbb2014-07-18 14:11:24 +10001955 * [listenhost:]listenport|listenpath:connecthost:connectport|connectpath
1956 * listenpath:connectpath
Damien Millera699d952008-11-03 19:27:34 +11001957 * dynamicfwd == 1
1958 * [listenhost:]listenport
Damien Millerf91ee4c2005-03-01 21:24:33 +11001959 * returns number of arguments parsed or zero on error
1960 */
1961int
Damien Miller7acefbb2014-07-18 14:11:24 +10001962parse_forward(struct Forward *fwd, const char *fwdspec, int dynamicfwd, int remotefwd)
Damien Millerf91ee4c2005-03-01 21:24:33 +11001963{
Damien Miller7acefbb2014-07-18 14:11:24 +10001964 struct fwdarg fwdargs[4];
1965 char *p, *cp;
Damien Millerf91ee4c2005-03-01 21:24:33 +11001966 int i;
Damien Millerf91ee4c2005-03-01 21:24:33 +11001967
Damien Miller7acefbb2014-07-18 14:11:24 +10001968 memset(fwd, 0, sizeof(*fwd));
1969 memset(fwdargs, 0, sizeof(fwdargs));
Damien Millerf91ee4c2005-03-01 21:24:33 +11001970
1971 cp = p = xstrdup(fwdspec);
1972
1973 /* skip leading spaces */
Damien Millerfdb23062013-11-21 13:57:15 +11001974 while (isspace((u_char)*cp))
Damien Millerf91ee4c2005-03-01 21:24:33 +11001975 cp++;
1976
Damien Miller7acefbb2014-07-18 14:11:24 +10001977 for (i = 0; i < 4; ++i) {
1978 if (parse_fwd_field(&cp, &fwdargs[i]) != 0)
Damien Millerf91ee4c2005-03-01 21:24:33 +11001979 break;
Damien Miller7acefbb2014-07-18 14:11:24 +10001980 }
Damien Millerf91ee4c2005-03-01 21:24:33 +11001981
Damien Millerf4b39532008-11-03 19:28:21 +11001982 /* Check for trailing garbage */
Damien Miller7acefbb2014-07-18 14:11:24 +10001983 if (cp != NULL && *cp != '\0') {
Damien Millerf91ee4c2005-03-01 21:24:33 +11001984 i = 0; /* failure */
Damien Miller7acefbb2014-07-18 14:11:24 +10001985 }
Damien Millerf91ee4c2005-03-01 21:24:33 +11001986
1987 switch (i) {
Damien Millera699d952008-11-03 19:27:34 +11001988 case 1:
Damien Miller7acefbb2014-07-18 14:11:24 +10001989 if (fwdargs[0].ispath) {
1990 fwd->listen_path = xstrdup(fwdargs[0].arg);
1991 fwd->listen_port = PORT_STREAMLOCAL;
1992 } else {
1993 fwd->listen_host = NULL;
1994 fwd->listen_port = a2port(fwdargs[0].arg);
1995 }
Damien Millera699d952008-11-03 19:27:34 +11001996 fwd->connect_host = xstrdup("socks");
1997 break;
1998
1999 case 2:
Damien Miller7acefbb2014-07-18 14:11:24 +10002000 if (fwdargs[0].ispath && fwdargs[1].ispath) {
2001 fwd->listen_path = xstrdup(fwdargs[0].arg);
2002 fwd->listen_port = PORT_STREAMLOCAL;
2003 fwd->connect_path = xstrdup(fwdargs[1].arg);
2004 fwd->connect_port = PORT_STREAMLOCAL;
2005 } else if (fwdargs[1].ispath) {
2006 fwd->listen_host = NULL;
2007 fwd->listen_port = a2port(fwdargs[0].arg);
2008 fwd->connect_path = xstrdup(fwdargs[1].arg);
2009 fwd->connect_port = PORT_STREAMLOCAL;
2010 } else {
2011 fwd->listen_host = xstrdup(fwdargs[0].arg);
2012 fwd->listen_port = a2port(fwdargs[1].arg);
2013 fwd->connect_host = xstrdup("socks");
2014 }
Damien Millera699d952008-11-03 19:27:34 +11002015 break;
2016
Damien Millerf91ee4c2005-03-01 21:24:33 +11002017 case 3:
Damien Miller7acefbb2014-07-18 14:11:24 +10002018 if (fwdargs[0].ispath) {
2019 fwd->listen_path = xstrdup(fwdargs[0].arg);
2020 fwd->listen_port = PORT_STREAMLOCAL;
2021 fwd->connect_host = xstrdup(fwdargs[1].arg);
2022 fwd->connect_port = a2port(fwdargs[2].arg);
2023 } else if (fwdargs[2].ispath) {
2024 fwd->listen_host = xstrdup(fwdargs[0].arg);
2025 fwd->listen_port = a2port(fwdargs[1].arg);
2026 fwd->connect_path = xstrdup(fwdargs[2].arg);
2027 fwd->connect_port = PORT_STREAMLOCAL;
2028 } else {
2029 fwd->listen_host = NULL;
2030 fwd->listen_port = a2port(fwdargs[0].arg);
2031 fwd->connect_host = xstrdup(fwdargs[1].arg);
2032 fwd->connect_port = a2port(fwdargs[2].arg);
2033 }
Damien Millerf91ee4c2005-03-01 21:24:33 +11002034 break;
2035
2036 case 4:
Damien Miller7acefbb2014-07-18 14:11:24 +10002037 fwd->listen_host = xstrdup(fwdargs[0].arg);
2038 fwd->listen_port = a2port(fwdargs[1].arg);
2039 fwd->connect_host = xstrdup(fwdargs[2].arg);
2040 fwd->connect_port = a2port(fwdargs[3].arg);
Damien Millerf91ee4c2005-03-01 21:24:33 +11002041 break;
2042 default:
2043 i = 0; /* failure */
2044 }
2045
Darren Tuckera627d422013-06-02 07:31:17 +10002046 free(p);
Damien Millerf91ee4c2005-03-01 21:24:33 +11002047
Damien Millera699d952008-11-03 19:27:34 +11002048 if (dynamicfwd) {
2049 if (!(i == 1 || i == 2))
2050 goto fail_free;
2051 } else {
Damien Miller7acefbb2014-07-18 14:11:24 +10002052 if (!(i == 3 || i == 4)) {
2053 if (fwd->connect_path == NULL &&
2054 fwd->listen_path == NULL)
2055 goto fail_free;
2056 }
2057 if (fwd->connect_port <= 0 && fwd->connect_path == NULL)
Damien Millera699d952008-11-03 19:27:34 +11002058 goto fail_free;
2059 }
2060
Damien Miller7acefbb2014-07-18 14:11:24 +10002061 if ((fwd->listen_port < 0 && fwd->listen_path == NULL) ||
2062 (!remotefwd && fwd->listen_port == 0))
Damien Millerf91ee4c2005-03-01 21:24:33 +11002063 goto fail_free;
Damien Millerf91ee4c2005-03-01 21:24:33 +11002064 if (fwd->connect_host != NULL &&
2065 strlen(fwd->connect_host) >= NI_MAXHOST)
2066 goto fail_free;
Damien Miller7acefbb2014-07-18 14:11:24 +10002067 /* XXX - if connecting to a remote socket, max sun len may not match this host */
2068 if (fwd->connect_path != NULL &&
2069 strlen(fwd->connect_path) >= PATH_MAX_SUN)
2070 goto fail_free;
Damien Miller4bf648f2009-02-14 16:28:21 +11002071 if (fwd->listen_host != NULL &&
2072 strlen(fwd->listen_host) >= NI_MAXHOST)
2073 goto fail_free;
Damien Miller7acefbb2014-07-18 14:11:24 +10002074 if (fwd->listen_path != NULL &&
2075 strlen(fwd->listen_path) >= PATH_MAX_SUN)
2076 goto fail_free;
Damien Millerf91ee4c2005-03-01 21:24:33 +11002077
2078 return (i);
2079
2080 fail_free:
Darren Tuckera627d422013-06-02 07:31:17 +10002081 free(fwd->connect_host);
2082 fwd->connect_host = NULL;
Damien Miller7acefbb2014-07-18 14:11:24 +10002083 free(fwd->connect_path);
2084 fwd->connect_path = NULL;
Darren Tuckera627d422013-06-02 07:31:17 +10002085 free(fwd->listen_host);
2086 fwd->listen_host = NULL;
Damien Miller7acefbb2014-07-18 14:11:24 +10002087 free(fwd->listen_path);
2088 fwd->listen_path = NULL;
Damien Millerf91ee4c2005-03-01 21:24:33 +11002089 return (0);
2090}
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002091
2092/* XXX the following is a near-vebatim copy from servconf.c; refactor */
2093static const char *
2094fmt_multistate_int(int val, const struct multistate *m)
2095{
2096 u_int i;
2097
2098 for (i = 0; m[i].key != NULL; i++) {
2099 if (m[i].value == val)
2100 return m[i].key;
2101 }
2102 return "UNKNOWN";
2103}
2104
2105static const char *
2106fmt_intarg(OpCodes code, int val)
2107{
2108 if (val == -1)
2109 return "unset";
2110 switch (code) {
2111 case oAddressFamily:
2112 return fmt_multistate_int(val, multistate_addressfamily);
2113 case oVerifyHostKeyDNS:
2114 case oStrictHostKeyChecking:
djm@openbsd.org523463a2015-02-16 22:13:32 +00002115 case oUpdateHostkeys:
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002116 return fmt_multistate_int(val, multistate_yesnoask);
2117 case oControlMaster:
2118 return fmt_multistate_int(val, multistate_controlmaster);
2119 case oTunnel:
2120 return fmt_multistate_int(val, multistate_tunnel);
2121 case oRequestTTY:
2122 return fmt_multistate_int(val, multistate_requesttty);
2123 case oCanonicalizeHostname:
2124 return fmt_multistate_int(val, multistate_canonicalizehostname);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002125 case oFingerprintHash:
2126 return ssh_digest_alg_name(val);
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002127 case oProtocol:
2128 switch (val) {
2129 case SSH_PROTO_1:
2130 return "1";
2131 case SSH_PROTO_2:
2132 return "2";
2133 case (SSH_PROTO_1|SSH_PROTO_2):
2134 return "2,1";
2135 default:
2136 return "UNKNOWN";
2137 }
2138 default:
2139 switch (val) {
2140 case 0:
2141 return "no";
2142 case 1:
2143 return "yes";
2144 default:
2145 return "UNKNOWN";
2146 }
2147 }
2148}
2149
2150static const char *
2151lookup_opcode_name(OpCodes code)
2152{
2153 u_int i;
2154
2155 for (i = 0; keywords[i].name != NULL; i++)
2156 if (keywords[i].opcode == code)
2157 return(keywords[i].name);
2158 return "UNKNOWN";
2159}
2160
2161static void
2162dump_cfg_int(OpCodes code, int val)
2163{
2164 printf("%s %d\n", lookup_opcode_name(code), val);
2165}
2166
2167static void
2168dump_cfg_fmtint(OpCodes code, int val)
2169{
2170 printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
2171}
2172
2173static void
2174dump_cfg_string(OpCodes code, const char *val)
2175{
2176 if (val == NULL)
2177 return;
2178 printf("%s %s\n", lookup_opcode_name(code), val);
2179}
2180
2181static void
2182dump_cfg_strarray(OpCodes code, u_int count, char **vals)
2183{
2184 u_int i;
2185
2186 for (i = 0; i < count; i++)
2187 printf("%s %s\n", lookup_opcode_name(code), vals[i]);
2188}
2189
2190static void
2191dump_cfg_strarray_oneline(OpCodes code, u_int count, char **vals)
2192{
2193 u_int i;
2194
2195 printf("%s", lookup_opcode_name(code));
2196 for (i = 0; i < count; i++)
2197 printf(" %s", vals[i]);
2198 printf("\n");
2199}
2200
2201static void
2202dump_cfg_forwards(OpCodes code, u_int count, const struct Forward *fwds)
2203{
2204 const struct Forward *fwd;
2205 u_int i;
2206
2207 /* oDynamicForward */
2208 for (i = 0; i < count; i++) {
2209 fwd = &fwds[i];
2210 if (code == oDynamicForward &&
2211 strcmp(fwd->connect_host, "socks") != 0)
2212 continue;
2213 if (code == oLocalForward &&
2214 strcmp(fwd->connect_host, "socks") == 0)
2215 continue;
2216 printf("%s", lookup_opcode_name(code));
2217 if (fwd->listen_port == PORT_STREAMLOCAL)
2218 printf(" %s", fwd->listen_path);
2219 else if (fwd->listen_host == NULL)
2220 printf(" %d", fwd->listen_port);
2221 else {
2222 printf(" [%s]:%d",
2223 fwd->listen_host, fwd->listen_port);
2224 }
2225 if (code != oDynamicForward) {
2226 if (fwd->connect_port == PORT_STREAMLOCAL)
2227 printf(" %s", fwd->connect_path);
2228 else if (fwd->connect_host == NULL)
2229 printf(" %d", fwd->connect_port);
2230 else {
2231 printf(" [%s]:%d",
2232 fwd->connect_host, fwd->connect_port);
2233 }
2234 }
2235 printf("\n");
2236 }
2237}
2238
2239void
2240dump_client_config(Options *o, const char *host)
2241{
2242 int i;
2243 char vbuf[5];
2244
2245 /* Most interesting options first: user, host, port */
2246 dump_cfg_string(oUser, o->user);
2247 dump_cfg_string(oHostName, host);
2248 dump_cfg_int(oPort, o->port);
2249
2250 /* Flag options */
2251 dump_cfg_fmtint(oAddressFamily, o->address_family);
2252 dump_cfg_fmtint(oBatchMode, o->batch_mode);
2253 dump_cfg_fmtint(oCanonicalizeFallbackLocal, o->canonicalize_fallback_local);
2254 dump_cfg_fmtint(oCanonicalizeHostname, o->canonicalize_hostname);
2255 dump_cfg_fmtint(oChallengeResponseAuthentication, o->challenge_response_authentication);
2256 dump_cfg_fmtint(oCheckHostIP, o->check_host_ip);
2257 dump_cfg_fmtint(oCompression, o->compression);
2258 dump_cfg_fmtint(oControlMaster, o->control_master);
2259 dump_cfg_fmtint(oEnableSSHKeysign, o->enable_ssh_keysign);
2260 dump_cfg_fmtint(oExitOnForwardFailure, o->exit_on_forward_failure);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002261 dump_cfg_fmtint(oFingerprintHash, o->fingerprint_hash);
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002262 dump_cfg_fmtint(oForwardAgent, o->forward_agent);
2263 dump_cfg_fmtint(oForwardX11, o->forward_x11);
2264 dump_cfg_fmtint(oForwardX11Trusted, o->forward_x11_trusted);
2265 dump_cfg_fmtint(oGatewayPorts, o->fwd_opts.gateway_ports);
2266#ifdef GSSAPI
2267 dump_cfg_fmtint(oGssAuthentication, o->gss_authentication);
2268 dump_cfg_fmtint(oGssDelegateCreds, o->gss_deleg_creds);
2269#endif /* GSSAPI */
2270 dump_cfg_fmtint(oHashKnownHosts, o->hash_known_hosts);
2271 dump_cfg_fmtint(oHostbasedAuthentication, o->hostbased_authentication);
2272 dump_cfg_fmtint(oIdentitiesOnly, o->identities_only);
2273 dump_cfg_fmtint(oKbdInteractiveAuthentication, o->kbd_interactive_authentication);
2274 dump_cfg_fmtint(oNoHostAuthenticationForLocalhost, o->no_host_authentication_for_localhost);
2275 dump_cfg_fmtint(oPasswordAuthentication, o->password_authentication);
2276 dump_cfg_fmtint(oPermitLocalCommand, o->permit_local_command);
2277 dump_cfg_fmtint(oProtocol, o->protocol);
2278 dump_cfg_fmtint(oProxyUseFdpass, o->proxy_use_fdpass);
2279 dump_cfg_fmtint(oPubkeyAuthentication, o->pubkey_authentication);
2280 dump_cfg_fmtint(oRequestTTY, o->request_tty);
2281 dump_cfg_fmtint(oRhostsRSAAuthentication, o->rhosts_rsa_authentication);
2282 dump_cfg_fmtint(oRSAAuthentication, o->rsa_authentication);
2283 dump_cfg_fmtint(oStreamLocalBindUnlink, o->fwd_opts.streamlocal_bind_unlink);
2284 dump_cfg_fmtint(oStrictHostKeyChecking, o->strict_host_key_checking);
2285 dump_cfg_fmtint(oTCPKeepAlive, o->tcp_keep_alive);
2286 dump_cfg_fmtint(oTunnel, o->tun_open);
2287 dump_cfg_fmtint(oUsePrivilegedPort, o->use_privileged_port);
2288 dump_cfg_fmtint(oVerifyHostKeyDNS, o->verify_host_key_dns);
2289 dump_cfg_fmtint(oVisualHostKey, o->visual_host_key);
djm@openbsd.org8d4f8722015-01-26 03:04:45 +00002290 dump_cfg_fmtint(oUpdateHostkeys, o->update_hostkeys);
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002291
2292 /* Integer options */
2293 dump_cfg_int(oCanonicalizeMaxDots, o->canonicalize_max_dots);
2294 dump_cfg_int(oCompressionLevel, o->compression_level);
2295 dump_cfg_int(oConnectionAttempts, o->connection_attempts);
2296 dump_cfg_int(oForwardX11Timeout, o->forward_x11_timeout);
2297 dump_cfg_int(oNumberOfPasswordPrompts, o->number_of_password_prompts);
2298 dump_cfg_int(oServerAliveCountMax, o->server_alive_count_max);
2299 dump_cfg_int(oServerAliveInterval, o->server_alive_interval);
2300
2301 /* String options */
2302 dump_cfg_string(oBindAddress, o->bind_address);
2303 dump_cfg_string(oCiphers, o->ciphers ? o->ciphers : KEX_CLIENT_ENCRYPT);
2304 dump_cfg_string(oControlPath, o->control_path);
2305 dump_cfg_string(oHostKeyAlgorithms, o->hostkeyalgorithms ? o->hostkeyalgorithms : KEX_DEFAULT_PK_ALG);
2306 dump_cfg_string(oHostKeyAlias, o->host_key_alias);
djm@openbsd.org46347ed2015-01-30 11:43:14 +00002307 dump_cfg_string(oHostbasedKeyTypes, o->hostbased_key_types);
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002308 dump_cfg_string(oKbdInteractiveDevices, o->kbd_interactive_devices);
2309 dump_cfg_string(oKexAlgorithms, o->kex_algorithms ? o->kex_algorithms : KEX_CLIENT_KEX);
2310 dump_cfg_string(oLocalCommand, o->local_command);
2311 dump_cfg_string(oLogLevel, log_level_name(o->log_level));
2312 dump_cfg_string(oMacs, o->macs ? o->macs : KEX_CLIENT_MAC);
2313 dump_cfg_string(oPKCS11Provider, o->pkcs11_provider);
2314 dump_cfg_string(oPreferredAuthentications, o->preferred_authentications);
2315 dump_cfg_string(oProxyCommand, o->proxy_command);
djm@openbsd.org5e39a492014-12-04 02:24:32 +00002316 dump_cfg_string(oRevokedHostKeys, o->revoked_host_keys);
djm@openbsd.org46347ed2015-01-30 11:43:14 +00002317 dump_cfg_string(oXAuthLocation, o->xauth_location);
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002318
djm@openbsd.org46347ed2015-01-30 11:43:14 +00002319 /* Forwards */
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002320 dump_cfg_forwards(oDynamicForward, o->num_local_forwards, o->local_forwards);
2321 dump_cfg_forwards(oLocalForward, o->num_local_forwards, o->local_forwards);
2322 dump_cfg_forwards(oRemoteForward, o->num_remote_forwards, o->remote_forwards);
2323
2324 /* String array options */
2325 dump_cfg_strarray(oIdentityFile, o->num_identity_files, o->identity_files);
2326 dump_cfg_strarray_oneline(oCanonicalDomains, o->num_canonical_domains, o->canonical_domains);
2327 dump_cfg_strarray_oneline(oGlobalKnownHostsFile, o->num_system_hostfiles, o->system_hostfiles);
2328 dump_cfg_strarray_oneline(oUserKnownHostsFile, o->num_user_hostfiles, o->user_hostfiles);
2329 dump_cfg_strarray(oSendEnv, o->num_send_env, o->send_env);
2330
2331 /* Special cases */
2332
2333 /* oConnectTimeout */
2334 if (o->connection_timeout == -1)
2335 printf("connecttimeout none\n");
2336 else
2337 dump_cfg_int(oConnectTimeout, o->connection_timeout);
2338
2339 /* oTunnelDevice */
2340 printf("tunneldevice");
2341 if (o->tun_local == SSH_TUNID_ANY)
2342 printf(" any");
2343 else
2344 printf(" %d", o->tun_local);
2345 if (o->tun_remote == SSH_TUNID_ANY)
2346 printf(":any");
2347 else
2348 printf(":%d", o->tun_remote);
2349 printf("\n");
2350
2351 /* oCanonicalizePermittedCNAMEs */
2352 if ( o->num_permitted_cnames > 0) {
2353 printf("canonicalizePermittedcnames");
2354 for (i = 0; i < o->num_permitted_cnames; i++) {
2355 printf(" %s:%s", o->permitted_cnames[i].source_list,
2356 o->permitted_cnames[i].target_list);
2357 }
2358 printf("\n");
2359 }
2360
2361 /* oCipher */
2362 if (o->cipher != SSH_CIPHER_NOT_SET)
2363 printf("Cipher %s\n", cipher_name(o->cipher));
2364
2365 /* oControlPersist */
2366 if (o->control_persist == 0 || o->control_persist_timeout == 0)
2367 dump_cfg_fmtint(oControlPersist, o->control_persist);
2368 else
2369 dump_cfg_int(oControlPersist, o->control_persist_timeout);
2370
2371 /* oEscapeChar */
2372 if (o->escape_char == SSH_ESCAPECHAR_NONE)
2373 printf("escapechar none\n");
2374 else {
2375 vis(vbuf, o->escape_char, VIS_WHITE, 0);
2376 printf("escapechar %s\n", vbuf);
2377 }
2378
2379 /* oIPQoS */
2380 printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
2381 printf("%s\n", iptos2str(o->ip_qos_bulk));
2382
2383 /* oRekeyLimit */
2384 printf("rekeylimit %lld %d\n",
2385 (long long)o->rekey_limit, o->rekey_interval);
2386
2387 /* oStreamLocalBindMask */
2388 printf("streamlocalbindmask 0%o\n",
2389 o->fwd_opts.streamlocal_bind_mask);
2390}