blob: 7948ce1cda719ae949552b338b07b94a892f8865 [file] [log] [blame]
Damien Miller7acefbb2014-07-18 14:11:24 +10001/* $OpenBSD: readconf.c,v 1.220 2014/07/15 15:54:14 millert 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>
Damien Millerb8fe89c2006-07-24 14:51:00 +100031#include <netdb.h>
Darren Tuckera3357662014-01-18 00:03:57 +110032#ifdef HAVE_PATHS_H
33# include <paths.h>
34#endif
Damien Miller194fd902013-10-15 12:13:05 +110035#include <pwd.h>
Damien Millerd7834352006-08-05 12:39:39 +100036#include <signal.h>
Damien Millerded319c2006-09-01 15:38:36 +100037#include <stdarg.h>
Damien Millera7a73ee2006-08-05 11:37:59 +100038#include <stdio.h>
Damien Millere3476ed2006-07-24 14:13:33 +100039#include <string.h>
Damien Millere6b3b612006-07-24 14:01:23 +100040#include <unistd.h>
Darren Tuckere194ba42013-05-16 20:47:31 +100041#ifdef HAVE_UTIL_H
Darren Tuckerb7ee8522013-05-16 20:33:10 +100042#include <util.h>
Darren Tuckere194ba42013-05-16 20:47:31 +100043#endif
Damien Millerc7b06362006-03-15 11:53:45 +110044
Damien Millerd4a8b7e1999-10-27 13:42:43 +100045#include "xmalloc.h"
Damien Millerd7834352006-08-05 12:39:39 +100046#include "ssh.h"
Damien Miller78928792000-04-12 20:17:38 +100047#include "compat.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000048#include "cipher.h"
49#include "pathnames.h"
50#include "log.h"
Damien Millerd7834352006-08-05 12:39:39 +100051#include "key.h"
Damien Miller7acefbb2014-07-18 14:11:24 +100052#include "misc.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000053#include "readconf.h"
54#include "match.h"
Damien Millerd7834352006-08-05 12:39:39 +100055#include "buffer.h"
Ben Lindstrom06b33aa2001-02-15 03:01:59 +000056#include "kex.h"
57#include "mac.h"
Damien Miller194fd902013-10-15 12:13:05 +110058#include "uidswap.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100059
60/* Format of the configuration file:
61
62 # Configuration data is parsed as follows:
63 # 1. command line options
64 # 2. user-specific file
65 # 3. system-wide file
66 # Any configuration value is only changed the first time it is set.
67 # Thus, host-specific definitions should be at the beginning of the
68 # configuration file, and defaults at the end.
69
70 # Host-specific declarations. These may override anything above. A single
71 # host may match multiple declarations; these are processed in the order
72 # that they are given in.
73
74 Host *.ngs.fi ngs.fi
Ben Lindstrom4daea862002-06-09 20:04:02 +000075 User foo
Damien Millerd4a8b7e1999-10-27 13:42:43 +100076
77 Host fake.com
78 HostName another.host.name.real.org
79 User blaah
80 Port 34289
81 ForwardX11 no
82 ForwardAgent no
83
84 Host books.com
85 RemoteForward 9999 shadows.cs.hut.fi:9999
86 Cipher 3des
87
88 Host fascist.blob.com
89 Port 23123
90 User tylonen
Damien Millerd4a8b7e1999-10-27 13:42:43 +100091 PasswordAuthentication no
92
93 Host puukko.hut.fi
94 User t35124p
95 ProxyCommand ssh-proxy %h %p
96
97 Host *.fr
Ben Lindstrom4daea862002-06-09 20:04:02 +000098 PublicKeyAuthentication no
Damien Millerd4a8b7e1999-10-27 13:42:43 +100099
100 Host *.su
101 Cipher none
102 PasswordAuthentication no
103
Damien Millerd27b9472005-12-13 19:29:02 +1100104 Host vpn.fake.com
105 Tunnel yes
106 TunnelDevice 3
107
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000108 # Defaults for various options
109 Host *
110 ForwardAgent no
Damien Miller0bc1bd82000-11-13 22:57:25 +1100111 ForwardX11 no
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000112 PasswordAuthentication yes
113 RSAAuthentication yes
114 RhostsRSAAuthentication yes
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000115 StrictHostKeyChecking yes
Damien Miller12c150e2003-12-17 16:31:10 +1100116 TcpKeepAlive no
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000117 IdentityFile ~/.ssh/identity
118 Port 22
119 EscapeChar ~
120
121*/
122
123/* Keyword tokens. */
124
Damien Miller95def091999-11-25 00:26:21 +1100125typedef enum {
126 oBadOption,
Damien Miller194fd902013-10-15 12:13:05 +1100127 oHost, oMatch,
Damien Miller1ab6a512010-06-26 10:02:24 +1000128 oForwardAgent, oForwardX11, oForwardX11Trusted, oForwardX11Timeout,
129 oGatewayPorts, oExitOnForwardFailure,
Ben Lindstromcb72e4f2002-06-21 00:41:51 +0000130 oPasswordAuthentication, oRSAAuthentication,
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000131 oChallengeResponseAuthentication, oXAuthLocation,
Damien Miller95def091999-11-25 00:26:21 +1100132 oIdentityFile, oHostName, oPort, oCipher, oRemoteForward, oLocalForward,
Damien Miller194fd902013-10-15 12:13:05 +1100133 oUser, oEscapeChar, oRhostsRSAAuthentication, oProxyCommand,
Damien Miller95def091999-11-25 00:26:21 +1100134 oGlobalKnownHostsFile, oUserKnownHostsFile, oConnectionAttempts,
135 oBatchMode, oCheckHostIP, oStrictHostKeyChecking, oCompression,
Damien Miller12c150e2003-12-17 16:31:10 +1100136 oCompressionLevel, oTCPKeepAlive, oNumberOfPasswordPrompts,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000137 oUsePrivilegedPort, oLogLevel, oCiphers, oProtocol, oMacs,
Damien Miller0bc1bd82000-11-13 22:57:25 +1100138 oGlobalKnownHostsFile2, oUserKnownHostsFile2, oPubkeyAuthentication,
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000139 oKbdInteractiveAuthentication, oKbdInteractiveDevices, oHostKeyAlias,
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000140 oDynamicForward, oPreferredAuthentications, oHostbasedAuthentication,
Damien Miller7ea845e2010-02-12 09:21:02 +1100141 oHostKeyAlgorithms, oBindAddress, oPKCS11Provider,
Ben Lindstrom4daea862002-06-09 20:04:02 +0000142 oClearAllForwardings, oNoHostAuthenticationForLocalhost,
Damien Millerb78d5eb2003-05-16 11:39:04 +1000143 oEnableSSHKeysign, oRekeyLimit, oVerifyHostKeyDNS, oConnectTimeout,
Darren Tucker0efd1552003-08-26 11:49:55 +1000144 oAddressFamily, oGssAuthentication, oGssDelegateCreds,
Damien Millerbd394c32004-03-08 23:12:36 +1100145 oServerAliveInterval, oServerAliveCountMax, oIdentitiesOnly,
Damien Millere11e1ea2010-08-03 16:04:46 +1000146 oSendEnv, oControlPath, oControlMaster, oControlPersist,
147 oHashKnownHosts,
Damien Millerd27b9472005-12-13 19:29:02 +1100148 oTunnel, oTunnelDevice, oLocalCommand, oPermitLocalCommand,
Damien Miller7cc194f2014-02-04 11:12:56 +1100149 oVisualHostKey, oUseRoaming,
Damien Miller1262b662013-08-21 02:44:24 +1000150 oKexAlgorithms, oIPQoS, oRequestTTY, oIgnoreUnknown, oProxyUseFdpass,
Damien Miller38505592013-10-17 11:48:13 +1100151 oCanonicalDomains, oCanonicalizeHostname, oCanonicalizeMaxDots,
152 oCanonicalizeFallbackLocal, oCanonicalizePermittedCNAMEs,
Damien Miller7acefbb2014-07-18 14:11:24 +1000153 oStreamLocalBindMask, oStreamLocalBindUnlink,
Darren Tucker07636982013-05-16 20:30:03 +1000154 oIgnoredUnknownOption, oDeprecated, oUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000155} OpCodes;
156
157/* Textual representations of the tokens. */
158
Damien Miller95def091999-11-25 00:26:21 +1100159static struct {
160 const char *name;
161 OpCodes opcode;
162} keywords[] = {
163 { "forwardagent", oForwardAgent },
164 { "forwardx11", oForwardX11 },
Darren Tucker0a118da2003-10-15 15:54:32 +1000165 { "forwardx11trusted", oForwardX11Trusted },
Damien Miller1ab6a512010-06-26 10:02:24 +1000166 { "forwardx11timeout", oForwardX11Timeout },
Darren Tuckere7d4b192006-07-12 22:17:10 +1000167 { "exitonforwardfailure", oExitOnForwardFailure },
Damien Millerd3a18572000-06-07 19:55:44 +1000168 { "xauthlocation", oXAuthLocation },
Damien Miller95def091999-11-25 00:26:21 +1100169 { "gatewayports", oGatewayPorts },
170 { "useprivilegedport", oUsePrivilegedPort },
Darren Tuckerec960f22003-08-13 20:37:05 +1000171 { "rhostsauthentication", oDeprecated },
Damien Miller95def091999-11-25 00:26:21 +1100172 { "passwordauthentication", oPasswordAuthentication },
Damien Miller874d77b2000-10-14 16:23:11 +1100173 { "kbdinteractiveauthentication", oKbdInteractiveAuthentication },
174 { "kbdinteractivedevices", oKbdInteractiveDevices },
Damien Miller95def091999-11-25 00:26:21 +1100175 { "rsaauthentication", oRSAAuthentication },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100176 { "pubkeyauthentication", oPubkeyAuthentication },
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000177 { "dsaauthentication", oPubkeyAuthentication }, /* alias */
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000178 { "rhostsrsaauthentication", oRhostsRSAAuthentication },
Ben Lindstromd69dab32001-04-12 23:36:05 +0000179 { "hostbasedauthentication", oHostbasedAuthentication },
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000180 { "challengeresponseauthentication", oChallengeResponseAuthentication },
181 { "skeyauthentication", oChallengeResponseAuthentication }, /* alias */
182 { "tisauthentication", oChallengeResponseAuthentication }, /* alias */
Damien Millerf9b3feb2003-05-16 11:38:32 +1000183 { "kerberosauthentication", oUnsupported },
184 { "kerberostgtpassing", oUnsupported },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000185 { "afstokenpassing", oUnsupported },
Darren Tucker0efd1552003-08-26 11:49:55 +1000186#if defined(GSSAPI)
187 { "gssapiauthentication", oGssAuthentication },
Darren Tucker0efd1552003-08-26 11:49:55 +1000188 { "gssapidelegatecredentials", oGssDelegateCreds },
189#else
190 { "gssapiauthentication", oUnsupported },
191 { "gssapidelegatecredentials", oUnsupported },
192#endif
Ben Lindstrom4daea862002-06-09 20:04:02 +0000193 { "fallbacktorsh", oDeprecated },
194 { "usersh", oDeprecated },
Damien Miller95def091999-11-25 00:26:21 +1100195 { "identityfile", oIdentityFile },
Damien Miller5bc6aae2009-01-28 16:27:31 +1100196 { "identityfile2", oIdentityFile }, /* obsolete */
Damien Millerbd394c32004-03-08 23:12:36 +1100197 { "identitiesonly", oIdentitiesOnly },
Damien Miller95def091999-11-25 00:26:21 +1100198 { "hostname", oHostName },
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000199 { "hostkeyalias", oHostKeyAlias },
Damien Miller95def091999-11-25 00:26:21 +1100200 { "proxycommand", oProxyCommand },
201 { "port", oPort },
202 { "cipher", oCipher },
Damien Miller78928792000-04-12 20:17:38 +1000203 { "ciphers", oCiphers },
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000204 { "macs", oMacs },
Damien Miller78928792000-04-12 20:17:38 +1000205 { "protocol", oProtocol },
Damien Miller95def091999-11-25 00:26:21 +1100206 { "remoteforward", oRemoteForward },
207 { "localforward", oLocalForward },
208 { "user", oUser },
209 { "host", oHost },
Damien Miller194fd902013-10-15 12:13:05 +1100210 { "match", oMatch },
Damien Miller95def091999-11-25 00:26:21 +1100211 { "escapechar", oEscapeChar },
Damien Miller95def091999-11-25 00:26:21 +1100212 { "globalknownhostsfile", oGlobalKnownHostsFile },
Damien Miller295ee632011-05-29 21:42:31 +1000213 { "globalknownhostsfile2", oDeprecated },
Damien Miller5bc6aae2009-01-28 16:27:31 +1100214 { "userknownhostsfile", oUserKnownHostsFile },
Damien Miller295ee632011-05-29 21:42:31 +1000215 { "userknownhostsfile2", oDeprecated },
Damien Miller95def091999-11-25 00:26:21 +1100216 { "connectionattempts", oConnectionAttempts },
217 { "batchmode", oBatchMode },
218 { "checkhostip", oCheckHostIP },
219 { "stricthostkeychecking", oStrictHostKeyChecking },
220 { "compression", oCompression },
221 { "compressionlevel", oCompressionLevel },
Damien Miller12c150e2003-12-17 16:31:10 +1100222 { "tcpkeepalive", oTCPKeepAlive },
223 { "keepalive", oTCPKeepAlive }, /* obsolete */
Damien Miller95def091999-11-25 00:26:21 +1100224 { "numberofpasswordprompts", oNumberOfPasswordPrompts },
Damien Miller95def091999-11-25 00:26:21 +1100225 { "loglevel", oLogLevel },
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000226 { "dynamicforward", oDynamicForward },
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000227 { "preferredauthentications", oPreferredAuthentications },
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000228 { "hostkeyalgorithms", oHostKeyAlgorithms },
Ben Lindstrome0f88042001-04-30 13:06:24 +0000229 { "bindaddress", oBindAddress },
Damien Miller7ea845e2010-02-12 09:21:02 +1100230#ifdef ENABLE_PKCS11
231 { "smartcarddevice", oPKCS11Provider },
232 { "pkcs11provider", oPKCS11Provider },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000233#else
234 { "smartcarddevice", oUnsupported },
Damien Miller7ea845e2010-02-12 09:21:02 +1100235 { "pkcs11provider", oUnsupported },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000236#endif
Damien Miller9f0f5c62001-12-21 14:45:46 +1100237 { "clearallforwardings", oClearAllForwardings },
Ben Lindstromb6df73b2002-11-09 15:52:31 +0000238 { "enablesshkeysign", oEnableSSHKeysign },
Damien Miller37876e92003-05-15 10:19:46 +1000239 { "verifyhostkeydns", oVerifyHostKeyDNS },
Damien Miller9f0f5c62001-12-21 14:45:46 +1100240 { "nohostauthenticationforlocalhost", oNoHostAuthenticationForLocalhost },
Damien Millera5539d22003-04-09 20:50:06 +1000241 { "rekeylimit", oRekeyLimit },
Damien Millerb78d5eb2003-05-16 11:39:04 +1000242 { "connecttimeout", oConnectTimeout },
Damien Miller20a8f972003-05-18 20:50:30 +1000243 { "addressfamily", oAddressFamily },
Damien Miller509b0102003-12-17 16:33:10 +1100244 { "serveraliveinterval", oServerAliveInterval },
245 { "serveralivecountmax", oServerAliveCountMax },
Darren Tucker46bc0752004-05-02 22:11:30 +1000246 { "sendenv", oSendEnv },
Damien Miller0e220db2004-06-15 10:34:08 +1000247 { "controlpath", oControlPath },
248 { "controlmaster", oControlMaster },
Damien Millere11e1ea2010-08-03 16:04:46 +1000249 { "controlpersist", oControlPersist },
Damien Millere1776152005-03-01 21:47:37 +1100250 { "hashknownhosts", oHashKnownHosts },
Damien Millerd27b9472005-12-13 19:29:02 +1100251 { "tunnel", oTunnel },
252 { "tunneldevice", oTunnelDevice },
253 { "localcommand", oLocalCommand },
254 { "permitlocalcommand", oPermitLocalCommand },
Damien Miller10288242008-06-30 00:04:03 +1000255 { "visualhostkey", oVisualHostKey },
Darren Tucker71e4d542009-07-06 07:12:27 +1000256 { "useroaming", oUseRoaming },
Damien Millerd5f62bf2010-09-24 22:11:14 +1000257 { "kexalgorithms", oKexAlgorithms },
Damien Miller0dac6fb2010-11-20 15:19:38 +1100258 { "ipqos", oIPQoS },
Damien Miller21771e22011-05-15 08:45:50 +1000259 { "requesttty", oRequestTTY },
Damien Miller1262b662013-08-21 02:44:24 +1000260 { "proxyusefdpass", oProxyUseFdpass },
Damien Miller0faf7472013-10-17 11:47:23 +1100261 { "canonicaldomains", oCanonicalDomains },
Damien Miller38505592013-10-17 11:48:13 +1100262 { "canonicalizefallbacklocal", oCanonicalizeFallbackLocal },
263 { "canonicalizehostname", oCanonicalizeHostname },
264 { "canonicalizemaxdots", oCanonicalizeMaxDots },
265 { "canonicalizepermittedcnames", oCanonicalizePermittedCNAMEs },
Damien Miller7acefbb2014-07-18 14:11:24 +1000266 { "streamlocalbindmask", oStreamLocalBindMask },
267 { "streamlocalbindunlink", oStreamLocalBindUnlink },
Darren Tucker07636982013-05-16 20:30:03 +1000268 { "ignoreunknown", oIgnoreUnknown },
Damien Miller01ed2272008-11-05 16:20:46 +1100269
Ben Lindstrom65366a82001-12-06 16:32:47 +0000270 { NULL, oBadOption }
Damien Miller5ce662a1999-11-11 17:57:39 +1100271};
272
Damien Miller5428f641999-11-25 11:54:57 +1100273/*
274 * Adds a local TCP/IP port forward to options. Never returns if there is an
275 * error.
276 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000277
Damien Miller4af51302000-04-16 11:18:38 +1000278void
Damien Miller7acefbb2014-07-18 14:11:24 +1000279add_local_forward(Options *options, const struct Forward *newfwd)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000280{
Damien Miller7acefbb2014-07-18 14:11:24 +1000281 struct Forward *fwd;
Ben Lindstrom99a4e142002-07-09 14:06:40 +0000282#ifndef NO_IPPORT_RESERVED_CONCEPT
Damien Miller95def091999-11-25 00:26:21 +1100283 extern uid_t original_real_uid;
Damien Miller7acefbb2014-07-18 14:11:24 +1000284 if (newfwd->listen_port < IPPORT_RESERVED && original_real_uid != 0 &&
285 newfwd->listen_path == NULL)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000286 fatal("Privileged ports can only be forwarded by root.");
Damien Millerbac2d8a2000-09-05 16:13:06 +1100287#endif
Damien Miller232cfb12010-06-26 09:50:30 +1000288 options->local_forwards = xrealloc(options->local_forwards,
289 options->num_local_forwards + 1,
290 sizeof(*options->local_forwards));
Damien Miller95def091999-11-25 00:26:21 +1100291 fwd = &options->local_forwards[options->num_local_forwards++];
Damien Millerf91ee4c2005-03-01 21:24:33 +1100292
Damien Miller1a0442f2008-11-05 16:30:06 +1100293 fwd->listen_host = newfwd->listen_host;
Damien Millerf91ee4c2005-03-01 21:24:33 +1100294 fwd->listen_port = newfwd->listen_port;
Damien Miller7acefbb2014-07-18 14:11:24 +1000295 fwd->listen_path = newfwd->listen_path;
Damien Miller1a0442f2008-11-05 16:30:06 +1100296 fwd->connect_host = newfwd->connect_host;
Damien Millerf91ee4c2005-03-01 21:24:33 +1100297 fwd->connect_port = newfwd->connect_port;
Damien Miller7acefbb2014-07-18 14:11:24 +1000298 fwd->connect_path = newfwd->connect_path;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000299}
300
Damien Miller5428f641999-11-25 11:54:57 +1100301/*
302 * Adds a remote TCP/IP port forward to options. Never returns if there is
303 * an error.
304 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000305
Damien Miller4af51302000-04-16 11:18:38 +1000306void
Damien Miller7acefbb2014-07-18 14:11:24 +1000307add_remote_forward(Options *options, const struct Forward *newfwd)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000308{
Damien Miller7acefbb2014-07-18 14:11:24 +1000309 struct Forward *fwd;
Damien Miller232cfb12010-06-26 09:50:30 +1000310
311 options->remote_forwards = xrealloc(options->remote_forwards,
312 options->num_remote_forwards + 1,
313 sizeof(*options->remote_forwards));
Damien Miller95def091999-11-25 00:26:21 +1100314 fwd = &options->remote_forwards[options->num_remote_forwards++];
Damien Millerf91ee4c2005-03-01 21:24:33 +1100315
Damien Miller1a0442f2008-11-05 16:30:06 +1100316 fwd->listen_host = newfwd->listen_host;
Damien Millerf91ee4c2005-03-01 21:24:33 +1100317 fwd->listen_port = newfwd->listen_port;
Damien Miller7acefbb2014-07-18 14:11:24 +1000318 fwd->listen_path = newfwd->listen_path;
Damien Miller1a0442f2008-11-05 16:30:06 +1100319 fwd->connect_host = newfwd->connect_host;
Damien Millerf91ee4c2005-03-01 21:24:33 +1100320 fwd->connect_port = newfwd->connect_port;
Damien Miller7acefbb2014-07-18 14:11:24 +1000321 fwd->connect_path = newfwd->connect_path;
Darren Tucker68afb8c2011-10-02 18:59:03 +1100322 fwd->handle = newfwd->handle;
Damien Miller388f6fc2010-05-21 14:57:35 +1000323 fwd->allocated_port = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000324}
325
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000326static void
327clear_forwardings(Options *options)
328{
329 int i;
330
Damien Millerf91ee4c2005-03-01 21:24:33 +1100331 for (i = 0; i < options->num_local_forwards; i++) {
Darren Tuckera627d422013-06-02 07:31:17 +1000332 free(options->local_forwards[i].listen_host);
Damien Miller7acefbb2014-07-18 14:11:24 +1000333 free(options->local_forwards[i].listen_path);
Darren Tuckera627d422013-06-02 07:31:17 +1000334 free(options->local_forwards[i].connect_host);
Damien Miller7acefbb2014-07-18 14:11:24 +1000335 free(options->local_forwards[i].connect_path);
Damien Millerf91ee4c2005-03-01 21:24:33 +1100336 }
Damien Miller232cfb12010-06-26 09:50:30 +1000337 if (options->num_local_forwards > 0) {
Darren Tuckera627d422013-06-02 07:31:17 +1000338 free(options->local_forwards);
Damien Miller232cfb12010-06-26 09:50:30 +1000339 options->local_forwards = NULL;
340 }
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000341 options->num_local_forwards = 0;
Damien Millerf91ee4c2005-03-01 21:24:33 +1100342 for (i = 0; i < options->num_remote_forwards; i++) {
Darren Tuckera627d422013-06-02 07:31:17 +1000343 free(options->remote_forwards[i].listen_host);
Damien Miller7acefbb2014-07-18 14:11:24 +1000344 free(options->remote_forwards[i].listen_path);
Darren Tuckera627d422013-06-02 07:31:17 +1000345 free(options->remote_forwards[i].connect_host);
Damien Miller7acefbb2014-07-18 14:11:24 +1000346 free(options->remote_forwards[i].connect_path);
Damien Millerf91ee4c2005-03-01 21:24:33 +1100347 }
Damien Miller232cfb12010-06-26 09:50:30 +1000348 if (options->num_remote_forwards > 0) {
Darren Tuckera627d422013-06-02 07:31:17 +1000349 free(options->remote_forwards);
Damien Miller232cfb12010-06-26 09:50:30 +1000350 options->remote_forwards = NULL;
351 }
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000352 options->num_remote_forwards = 0;
Damien Miller7b58e802005-12-13 19:33:19 +1100353 options->tun_open = SSH_TUNMODE_NO;
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000354}
355
Darren Tucker19104782013-04-05 11:13:08 +1100356void
357add_identity_file(Options *options, const char *dir, const char *filename,
358 int userprovided)
359{
360 char *path;
Damien Miller15271902014-05-15 13:47:56 +1000361 int i;
Darren Tucker19104782013-04-05 11:13:08 +1100362
363 if (options->num_identity_files >= SSH_MAX_IDENTITY_FILES)
364 fatal("Too many identity files specified (max %d)",
365 SSH_MAX_IDENTITY_FILES);
366
367 if (dir == NULL) /* no dir, filename is absolute */
368 path = xstrdup(filename);
369 else
370 (void)xasprintf(&path, "%.100s%.100s", dir, filename);
371
Damien Miller15271902014-05-15 13:47:56 +1000372 /* Avoid registering duplicates */
373 for (i = 0; i < options->num_identity_files; i++) {
374 if (options->identity_file_userprovided[i] == userprovided &&
375 strcmp(options->identity_files[i], path) == 0) {
376 debug2("%s: ignoring duplicate key %s", __func__, path);
377 free(path);
378 return;
379 }
380 }
381
Darren Tucker19104782013-04-05 11:13:08 +1100382 options->identity_file_userprovided[options->num_identity_files] =
383 userprovided;
384 options->identity_files[options->num_identity_files++] = path;
385}
386
Damien Miller194fd902013-10-15 12:13:05 +1100387int
388default_ssh_port(void)
389{
390 static int port;
391 struct servent *sp;
392
393 if (port == 0) {
394 sp = getservbyname(SSH_SERVICE_NAME, "tcp");
395 port = sp ? ntohs(sp->s_port) : SSH_DEFAULT_PORT;
396 }
397 return port;
398}
399
400/*
401 * Execute a command in a shell.
402 * Return its exit status or -1 on abnormal exit.
403 */
404static int
405execute_in_shell(const char *cmd)
406{
407 char *shell, *command_string;
408 pid_t pid;
409 int devnull, status;
410 extern uid_t original_real_uid;
411
412 if ((shell = getenv("SHELL")) == NULL)
413 shell = _PATH_BSHELL;
414
415 /*
416 * Use "exec" to avoid "sh -c" processes on some platforms
417 * (e.g. Solaris)
418 */
419 xasprintf(&command_string, "exec %s", cmd);
420
421 /* Need this to redirect subprocess stdin/out */
422 if ((devnull = open(_PATH_DEVNULL, O_RDWR)) == -1)
423 fatal("open(/dev/null): %s", strerror(errno));
424
425 debug("Executing command: '%.500s'", cmd);
426
427 /* Fork and execute the command. */
428 if ((pid = fork()) == 0) {
429 char *argv[4];
430
431 /* Child. Permanently give up superuser privileges. */
432 permanently_drop_suid(original_real_uid);
433
434 /* Redirect child stdin and stdout. Leave stderr */
435 if (dup2(devnull, STDIN_FILENO) == -1)
436 fatal("dup2: %s", strerror(errno));
437 if (dup2(devnull, STDOUT_FILENO) == -1)
438 fatal("dup2: %s", strerror(errno));
439 if (devnull > STDERR_FILENO)
440 close(devnull);
441 closefrom(STDERR_FILENO + 1);
442
443 argv[0] = shell;
444 argv[1] = "-c";
445 argv[2] = command_string;
446 argv[3] = NULL;
447
448 execv(argv[0], argv);
449 error("Unable to execute '%.100s': %s", cmd, strerror(errno));
450 /* Die with signal to make this error apparent to parent. */
451 signal(SIGTERM, SIG_DFL);
452 kill(getpid(), SIGTERM);
453 _exit(1);
454 }
455 /* Parent. */
456 if (pid < 0)
457 fatal("%s: fork: %.100s", __func__, strerror(errno));
458
459 close(devnull);
460 free(command_string);
461
462 while (waitpid(pid, &status, 0) == -1) {
463 if (errno != EINTR && errno != EAGAIN)
464 fatal("%s: waitpid: %s", __func__, strerror(errno));
465 }
466 if (!WIFEXITED(status)) {
467 error("command '%.100s' exited abnormally", cmd);
468 return -1;
469 }
470 debug3("command returned status %d", WEXITSTATUS(status));
471 return WEXITSTATUS(status);
472}
473
474/*
475 * Parse and execute a Match directive.
476 */
477static int
478match_cfg_line(Options *options, char **condition, struct passwd *pw,
479 const char *host_arg, const char *filename, int linenum)
480{
Damien Miller084bcd22013-10-23 16:30:51 +1100481 char *arg, *attrib, *cmd, *cp = *condition, *host;
482 const char *ruser;
Damien Millercf31f382013-10-24 21:02:56 +1100483 int r, port, result = 1, attributes = 0;
Damien Miller194fd902013-10-15 12:13:05 +1100484 size_t len;
485 char thishost[NI_MAXHOST], shorthost[NI_MAXHOST], portstr[NI_MAXSERV];
486
487 /*
488 * Configuration is likely to be incomplete at this point so we
489 * must be prepared to use default values.
490 */
491 port = options->port <= 0 ? default_ssh_port() : options->port;
492 ruser = options->user == NULL ? pw->pw_name : options->user;
Damien Miller084bcd22013-10-23 16:30:51 +1100493 if (options->hostname != NULL) {
Damien Millereff5cad2013-10-23 16:31:10 +1100494 /* NB. Please keep in sync with ssh.c:main() */
Damien Miller084bcd22013-10-23 16:30:51 +1100495 host = percent_expand(options->hostname,
496 "h", host_arg, (char *)NULL);
497 } else
498 host = xstrdup(host_arg);
Damien Miller194fd902013-10-15 12:13:05 +1100499
500 debug3("checking match for '%s' host %s", cp, host);
501 while ((attrib = strdelim(&cp)) && *attrib != '\0') {
Damien Millercf31f382013-10-24 21:02:56 +1100502 attributes++;
503 if (strcasecmp(attrib, "all") == 0) {
504 if (attributes != 1 ||
505 ((arg = strdelim(&cp)) != NULL && *arg != '\0')) {
506 error("'all' cannot be combined with other "
507 "Match attributes");
508 result = -1;
509 goto out;
510 }
511 *condition = cp;
512 result = 1;
513 goto out;
514 }
Damien Miller194fd902013-10-15 12:13:05 +1100515 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
516 error("Missing Match criteria for %s", attrib);
Damien Miller084bcd22013-10-23 16:30:51 +1100517 result = -1;
518 goto out;
Damien Miller194fd902013-10-15 12:13:05 +1100519 }
520 len = strlen(arg);
521 if (strcasecmp(attrib, "host") == 0) {
522 if (match_hostname(host, arg, len) != 1)
523 result = 0;
524 else
525 debug("%.200s line %d: matched 'Host %.100s' ",
526 filename, linenum, host);
527 } else if (strcasecmp(attrib, "originalhost") == 0) {
528 if (match_hostname(host_arg, arg, len) != 1)
529 result = 0;
530 else
531 debug("%.200s line %d: matched "
532 "'OriginalHost %.100s' ",
533 filename, linenum, host_arg);
534 } else if (strcasecmp(attrib, "user") == 0) {
535 if (match_pattern_list(ruser, arg, len, 0) != 1)
536 result = 0;
537 else
538 debug("%.200s line %d: matched 'User %.100s' ",
539 filename, linenum, ruser);
540 } else if (strcasecmp(attrib, "localuser") == 0) {
541 if (match_pattern_list(pw->pw_name, arg, len, 0) != 1)
542 result = 0;
543 else
544 debug("%.200s line %d: matched "
545 "'LocalUser %.100s' ",
546 filename, linenum, pw->pw_name);
Damien Miller8a04be72013-10-23 16:29:40 +1100547 } else if (strcasecmp(attrib, "exec") == 0) {
Damien Miller194fd902013-10-15 12:13:05 +1100548 if (gethostname(thishost, sizeof(thishost)) == -1)
549 fatal("gethostname: %s", strerror(errno));
550 strlcpy(shorthost, thishost, sizeof(shorthost));
551 shorthost[strcspn(thishost, ".")] = '\0';
552 snprintf(portstr, sizeof(portstr), "%d", port);
553
554 cmd = percent_expand(arg,
555 "L", shorthost,
556 "d", pw->pw_dir,
557 "h", host,
558 "l", thishost,
559 "n", host_arg,
560 "p", portstr,
561 "r", ruser,
562 "u", pw->pw_name,
563 (char *)NULL);
Damien Miller06287802014-02-24 15:56:45 +1100564 if (result != 1) {
565 /* skip execution if prior predicate failed */
566 debug("%.200s line %d: skipped exec \"%.100s\"",
Damien Miller194fd902013-10-15 12:13:05 +1100567 filename, linenum, cmd);
Damien Miller06287802014-02-24 15:56:45 +1100568 } else {
569 r = execute_in_shell(cmd);
570 if (r == -1) {
571 fatal("%.200s line %d: match exec "
572 "'%.100s' error", filename,
573 linenum, cmd);
574 } else if (r == 0) {
575 debug("%.200s line %d: matched "
576 "'exec \"%.100s\"'", filename,
577 linenum, cmd);
578 } else {
579 debug("%.200s line %d: no match "
580 "'exec \"%.100s\"'", filename,
581 linenum, cmd);
582 result = 0;
583 }
584 }
Damien Miller194fd902013-10-15 12:13:05 +1100585 free(cmd);
586 } else {
587 error("Unsupported Match attribute %s", attrib);
Damien Miller084bcd22013-10-23 16:30:51 +1100588 result = -1;
589 goto out;
Damien Miller194fd902013-10-15 12:13:05 +1100590 }
591 }
Damien Millercf31f382013-10-24 21:02:56 +1100592 if (attributes == 0) {
593 error("One or more attributes required for Match");
594 result = -1;
595 goto out;
596 }
Damien Miller194fd902013-10-15 12:13:05 +1100597 debug3("match %sfound", result ? "" : "not ");
598 *condition = cp;
Damien Miller084bcd22013-10-23 16:30:51 +1100599 out:
600 free(host);
Damien Miller194fd902013-10-15 12:13:05 +1100601 return result;
602}
603
Damien Miller0faf7472013-10-17 11:47:23 +1100604/* Check and prepare a domain name: removes trailing '.' and lowercases */
605static void
606valid_domain(char *name, const char *filename, int linenum)
607{
608 size_t i, l = strlen(name);
609 u_char c, last = '\0';
610
611 if (l == 0)
612 fatal("%s line %d: empty hostname suffix", filename, linenum);
613 if (!isalpha((u_char)name[0]) && !isdigit((u_char)name[0]))
614 fatal("%s line %d: hostname suffix \"%.100s\" "
615 "starts with invalid character", filename, linenum, name);
616 for (i = 0; i < l; i++) {
617 c = tolower((u_char)name[i]);
618 name[i] = (char)c;
619 if (last == '.' && c == '.')
620 fatal("%s line %d: hostname suffix \"%.100s\" contains "
621 "consecutive separators", filename, linenum, name);
622 if (c != '.' && c != '-' && !isalnum(c) &&
623 c != '_') /* technically invalid, but common */
624 fatal("%s line %d: hostname suffix \"%.100s\" contains "
625 "invalid characters", filename, linenum, name);
626 last = c;
627 }
628 if (name[l - 1] == '.')
629 name[l - 1] = '\0';
630}
631
Damien Miller5428f641999-11-25 11:54:57 +1100632/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000633 * Returns the number of the token pointed to by cp or oBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100634 */
Damien Miller4af51302000-04-16 11:18:38 +1000635static OpCodes
Darren Tucker07636982013-05-16 20:30:03 +1000636parse_token(const char *cp, const char *filename, int linenum,
637 const char *ignored_unknown)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000638{
Darren Tucker07636982013-05-16 20:30:03 +1000639 int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000640
Damien Miller95def091999-11-25 00:26:21 +1100641 for (i = 0; keywords[i].name; i++)
Darren Tucker07636982013-05-16 20:30:03 +1000642 if (strcmp(cp, keywords[i].name) == 0)
Damien Miller95def091999-11-25 00:26:21 +1100643 return keywords[i].opcode;
Darren Tucker07636982013-05-16 20:30:03 +1000644 if (ignored_unknown != NULL && match_pattern_list(cp, ignored_unknown,
645 strlen(ignored_unknown), 1) == 1)
646 return oIgnoredUnknownOption;
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000647 error("%s: line %d: Bad configuration option: %s",
648 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100649 return oBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000650}
651
Damien Millere9fc72e2013-10-15 12:14:12 +1100652/* Multistate option parsing */
653struct multistate {
654 char *key;
655 int value;
656};
657static const struct multistate multistate_flag[] = {
658 { "true", 1 },
659 { "false", 0 },
660 { "yes", 1 },
661 { "no", 0 },
662 { NULL, -1 }
663};
664static const struct multistate multistate_yesnoask[] = {
665 { "true", 1 },
666 { "false", 0 },
667 { "yes", 1 },
668 { "no", 0 },
669 { "ask", 2 },
670 { NULL, -1 }
671};
672static const struct multistate multistate_addressfamily[] = {
673 { "inet", AF_INET },
674 { "inet6", AF_INET6 },
675 { "any", AF_UNSPEC },
676 { NULL, -1 }
677};
678static const struct multistate multistate_controlmaster[] = {
679 { "true", SSHCTL_MASTER_YES },
680 { "yes", SSHCTL_MASTER_YES },
681 { "false", SSHCTL_MASTER_NO },
682 { "no", SSHCTL_MASTER_NO },
683 { "auto", SSHCTL_MASTER_AUTO },
684 { "ask", SSHCTL_MASTER_ASK },
685 { "autoask", SSHCTL_MASTER_AUTO_ASK },
686 { NULL, -1 }
687};
688static const struct multistate multistate_tunnel[] = {
689 { "ethernet", SSH_TUNMODE_ETHERNET },
690 { "point-to-point", SSH_TUNMODE_POINTOPOINT },
691 { "true", SSH_TUNMODE_DEFAULT },
692 { "yes", SSH_TUNMODE_DEFAULT },
693 { "false", SSH_TUNMODE_NO },
694 { "no", SSH_TUNMODE_NO },
695 { NULL, -1 }
696};
697static const struct multistate multistate_requesttty[] = {
698 { "true", REQUEST_TTY_YES },
699 { "yes", REQUEST_TTY_YES },
700 { "false", REQUEST_TTY_NO },
701 { "no", REQUEST_TTY_NO },
702 { "force", REQUEST_TTY_FORCE },
703 { "auto", REQUEST_TTY_AUTO },
704 { NULL, -1 }
705};
Damien Miller38505592013-10-17 11:48:13 +1100706static const struct multistate multistate_canonicalizehostname[] = {
Damien Miller0faf7472013-10-17 11:47:23 +1100707 { "true", SSH_CANONICALISE_YES },
708 { "false", SSH_CANONICALISE_NO },
709 { "yes", SSH_CANONICALISE_YES },
710 { "no", SSH_CANONICALISE_NO },
711 { "always", SSH_CANONICALISE_ALWAYS },
712 { NULL, -1 }
713};
Damien Millere9fc72e2013-10-15 12:14:12 +1100714
Damien Miller5428f641999-11-25 11:54:57 +1100715/*
716 * Processes a single option line as used in the configuration files. This
717 * only sets those values that have not already been set.
718 */
Damien Miller61f08ac2003-02-24 11:56:27 +1100719#define WHITESPACE " \t\r\n"
Damien Miller2ccf6611999-11-15 15:25:10 +1100720int
Damien Miller194fd902013-10-15 12:13:05 +1100721process_config_line(Options *options, struct passwd *pw, const char *host,
722 char *line, const char *filename, int linenum, int *activep, int userconfig)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000723{
Damien Miller295ee632011-05-29 21:42:31 +1000724 char *s, **charptr, *endofnumber, *keyword, *arg, *arg2;
725 char **cpptr, fwdarg[256];
Darren Tucker07636982013-05-16 20:30:03 +1000726 u_int i, *uintptr, max_entries = 0;
Damien Miller194fd902013-10-15 12:13:05 +1100727 int negated, opcode, *intptr, value, value2, cmdline = 0;
Darren Tucker1e44c5d2008-01-01 20:32:26 +1100728 LogLevel *log_level_ptr;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000729 long long val64;
Damien Miller61f08ac2003-02-24 11:56:27 +1100730 size_t len;
Damien Miller7acefbb2014-07-18 14:11:24 +1000731 struct Forward fwd;
Damien Millere9fc72e2013-10-15 12:14:12 +1100732 const struct multistate *multistate_ptr;
Damien Miller0faf7472013-10-17 11:47:23 +1100733 struct allowed_cname *cname;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000734
Damien Miller194fd902013-10-15 12:13:05 +1100735 if (activep == NULL) { /* We are processing a command line directive */
736 cmdline = 1;
737 activep = &cmdline;
738 }
739
Damien Millerc652cac2003-05-14 13:40:54 +1000740 /* Strip trailing whitespace */
Darren Tucker47eede72005-03-14 23:08:12 +1100741 for (len = strlen(line) - 1; len > 0; len--) {
Damien Millerc652cac2003-05-14 13:40:54 +1000742 if (strchr(WHITESPACE, line[len]) == NULL)
743 break;
744 line[len] = '\0';
745 }
746
Damien Millerbe484b52000-07-15 14:14:16 +1000747 s = line;
748 /* Get the keyword. (Each line is supposed to begin with a keyword). */
Damien Miller928b2362006-03-26 13:53:32 +1100749 if ((keyword = strdelim(&s)) == NULL)
750 return 0;
Damien Millerbe484b52000-07-15 14:14:16 +1000751 /* Ignore leading whitespace. */
752 if (*keyword == '\0')
753 keyword = strdelim(&s);
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000754 if (keyword == NULL || !*keyword || *keyword == '\n' || *keyword == '#')
Damien Miller95def091999-11-25 00:26:21 +1100755 return 0;
Darren Tucker07636982013-05-16 20:30:03 +1000756 /* Match lowercase keyword */
Damien Millere9fc72e2013-10-15 12:14:12 +1100757 lowercase(keyword);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000758
Darren Tucker07636982013-05-16 20:30:03 +1000759 opcode = parse_token(keyword, filename, linenum,
760 options->ignored_unknown);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000761
Damien Miller95def091999-11-25 00:26:21 +1100762 switch (opcode) {
763 case oBadOption:
Damien Miller5428f641999-11-25 11:54:57 +1100764 /* don't panic, but count bad options */
765 return -1;
Damien Miller95def091999-11-25 00:26:21 +1100766 /* NOTREACHED */
Darren Tucker07636982013-05-16 20:30:03 +1000767 case oIgnoredUnknownOption:
768 debug("%s line %d: Ignored unknown option \"%s\"",
769 filename, linenum, keyword);
770 return 0;
Damien Millerb78d5eb2003-05-16 11:39:04 +1000771 case oConnectTimeout:
772 intptr = &options->connection_timeout;
Damien Miller509b0102003-12-17 16:33:10 +1100773parse_time:
Damien Millerb78d5eb2003-05-16 11:39:04 +1000774 arg = strdelim(&s);
775 if (!arg || *arg == '\0')
776 fatal("%s line %d: missing time value.",
777 filename, linenum);
778 if ((value = convtime(arg)) == -1)
779 fatal("%s line %d: invalid time value.",
780 filename, linenum);
Darren Tuckera52c5b62007-02-19 22:09:45 +1100781 if (*activep && *intptr == -1)
Damien Millerb78d5eb2003-05-16 11:39:04 +1000782 *intptr = value;
783 break;
784
Damien Miller95def091999-11-25 00:26:21 +1100785 case oForwardAgent:
786 intptr = &options->forward_agent;
Damien Millere9fc72e2013-10-15 12:14:12 +1100787 parse_flag:
788 multistate_ptr = multistate_flag;
789 parse_multistate:
Damien Millerbe484b52000-07-15 14:14:16 +1000790 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000791 if (!arg || *arg == '\0')
Damien Millere9fc72e2013-10-15 12:14:12 +1100792 fatal("%s line %d: missing argument.",
793 filename, linenum);
794 value = -1;
795 for (i = 0; multistate_ptr[i].key != NULL; i++) {
796 if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
797 value = multistate_ptr[i].value;
798 break;
799 }
800 }
801 if (value == -1)
802 fatal("%s line %d: unsupported option \"%s\".",
803 filename, linenum, arg);
Damien Miller95def091999-11-25 00:26:21 +1100804 if (*activep && *intptr == -1)
805 *intptr = value;
806 break;
807
808 case oForwardX11:
809 intptr = &options->forward_x11;
810 goto parse_flag;
811
Darren Tucker0a118da2003-10-15 15:54:32 +1000812 case oForwardX11Trusted:
813 intptr = &options->forward_x11_trusted;
814 goto parse_flag;
Damien Miller1ab6a512010-06-26 10:02:24 +1000815
816 case oForwardX11Timeout:
817 intptr = &options->forward_x11_timeout;
818 goto parse_time;
Darren Tucker0a118da2003-10-15 15:54:32 +1000819
Damien Miller95def091999-11-25 00:26:21 +1100820 case oGatewayPorts:
Damien Miller7acefbb2014-07-18 14:11:24 +1000821 intptr = &options->fwd_opts.gateway_ports;
Damien Miller95def091999-11-25 00:26:21 +1100822 goto parse_flag;
823
Darren Tuckere7d4b192006-07-12 22:17:10 +1000824 case oExitOnForwardFailure:
825 intptr = &options->exit_on_forward_failure;
826 goto parse_flag;
827
Damien Miller95def091999-11-25 00:26:21 +1100828 case oUsePrivilegedPort:
829 intptr = &options->use_privileged_port;
830 goto parse_flag;
831
Damien Miller95def091999-11-25 00:26:21 +1100832 case oPasswordAuthentication:
833 intptr = &options->password_authentication;
834 goto parse_flag;
835
Damien Miller874d77b2000-10-14 16:23:11 +1100836 case oKbdInteractiveAuthentication:
837 intptr = &options->kbd_interactive_authentication;
838 goto parse_flag;
839
840 case oKbdInteractiveDevices:
841 charptr = &options->kbd_interactive_devices;
842 goto parse_string;
843
Damien Miller0bc1bd82000-11-13 22:57:25 +1100844 case oPubkeyAuthentication:
845 intptr = &options->pubkey_authentication;
Damien Millere247cc42000-05-07 12:03:14 +1000846 goto parse_flag;
847
Damien Miller95def091999-11-25 00:26:21 +1100848 case oRSAAuthentication:
849 intptr = &options->rsa_authentication;
850 goto parse_flag;
851
852 case oRhostsRSAAuthentication:
853 intptr = &options->rhosts_rsa_authentication;
854 goto parse_flag;
855
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000856 case oHostbasedAuthentication:
857 intptr = &options->hostbased_authentication;
858 goto parse_flag;
859
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000860 case oChallengeResponseAuthentication:
Ben Lindstrom551ea372001-06-05 18:56:16 +0000861 intptr = &options->challenge_response_authentication;
Damien Miller95def091999-11-25 00:26:21 +1100862 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000863
Darren Tucker0efd1552003-08-26 11:49:55 +1000864 case oGssAuthentication:
865 intptr = &options->gss_authentication;
866 goto parse_flag;
867
868 case oGssDelegateCreds:
869 intptr = &options->gss_deleg_creds;
870 goto parse_flag;
871
Damien Miller95def091999-11-25 00:26:21 +1100872 case oBatchMode:
873 intptr = &options->batch_mode;
874 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000875
Damien Miller95def091999-11-25 00:26:21 +1100876 case oCheckHostIP:
877 intptr = &options->check_host_ip;
Damien Miller10288242008-06-30 00:04:03 +1000878 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000879
Damien Miller37876e92003-05-15 10:19:46 +1000880 case oVerifyHostKeyDNS:
881 intptr = &options->verify_host_key_dns;
Damien Millere9fc72e2013-10-15 12:14:12 +1100882 multistate_ptr = multistate_yesnoask;
883 goto parse_multistate;
Damien Miller37876e92003-05-15 10:19:46 +1000884
Damien Miller95def091999-11-25 00:26:21 +1100885 case oStrictHostKeyChecking:
886 intptr = &options->strict_host_key_checking;
Damien Millere9fc72e2013-10-15 12:14:12 +1100887 multistate_ptr = multistate_yesnoask;
888 goto parse_multistate;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000889
Damien Miller95def091999-11-25 00:26:21 +1100890 case oCompression:
891 intptr = &options->compression;
892 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000893
Damien Miller12c150e2003-12-17 16:31:10 +1100894 case oTCPKeepAlive:
895 intptr = &options->tcp_keep_alive;
Damien Miller95def091999-11-25 00:26:21 +1100896 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000897
Ben Lindstrom3cecc9a2001-10-03 17:39:38 +0000898 case oNoHostAuthenticationForLocalhost:
899 intptr = &options->no_host_authentication_for_localhost;
900 goto parse_flag;
901
Damien Miller95def091999-11-25 00:26:21 +1100902 case oNumberOfPasswordPrompts:
903 intptr = &options->number_of_password_prompts;
904 goto parse_int;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000905
Damien Miller95def091999-11-25 00:26:21 +1100906 case oCompressionLevel:
907 intptr = &options->compression_level;
908 goto parse_int;
909
Damien Millera5539d22003-04-09 20:50:06 +1000910 case oRekeyLimit:
Damien Millera5539d22003-04-09 20:50:06 +1000911 arg = strdelim(&s);
912 if (!arg || *arg == '\0')
Darren Tuckerc53c2af2013-05-16 20:28:16 +1000913 fatal("%.200s line %d: Missing argument.", filename,
914 linenum);
915 if (strcmp(arg, "default") == 0) {
916 val64 = 0;
917 } else {
Darren Tuckerb7ee8522013-05-16 20:33:10 +1000918 if (scan_scaled(arg, &val64) == -1)
919 fatal("%.200s line %d: Bad number '%s': %s",
920 filename, linenum, arg, strerror(errno));
921 /* check for too-large or too-small limits */
922 if (val64 > UINT_MAX)
Darren Tuckerc53c2af2013-05-16 20:28:16 +1000923 fatal("%.200s line %d: RekeyLimit too large",
924 filename, linenum);
925 if (val64 != 0 && val64 < 16)
926 fatal("%.200s line %d: RekeyLimit too small",
927 filename, linenum);
Damien Millera5539d22003-04-09 20:50:06 +1000928 }
Damien Miller3dff1762008-02-10 22:25:52 +1100929 if (*activep && options->rekey_limit == -1)
930 options->rekey_limit = (u_int32_t)val64;
Darren Tuckerc53c2af2013-05-16 20:28:16 +1000931 if (s != NULL) { /* optional rekey interval present */
932 if (strcmp(s, "none") == 0) {
933 (void)strdelim(&s); /* discard */
934 break;
935 }
936 intptr = &options->rekey_interval;
937 goto parse_time;
938 }
Damien Millera5539d22003-04-09 20:50:06 +1000939 break;
940
Damien Miller95def091999-11-25 00:26:21 +1100941 case oIdentityFile:
Damien Millerbe484b52000-07-15 14:14:16 +1000942 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000943 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +1100944 fatal("%.200s line %d: Missing argument.", filename, linenum);
945 if (*activep) {
Damien Miller0bc1bd82000-11-13 22:57:25 +1100946 intptr = &options->num_identity_files;
Damien Millereba71ba2000-04-29 23:57:08 +1000947 if (*intptr >= SSH_MAX_IDENTITY_FILES)
Damien Miller95def091999-11-25 00:26:21 +1100948 fatal("%.200s line %d: Too many identity files specified (max %d).",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100949 filename, linenum, SSH_MAX_IDENTITY_FILES);
Darren Tuckeraefa3682013-04-05 11:18:35 +1100950 add_identity_file(options, NULL, arg, userconfig);
Damien Miller95def091999-11-25 00:26:21 +1100951 }
952 break;
953
Damien Millerd3a18572000-06-07 19:55:44 +1000954 case oXAuthLocation:
955 charptr=&options->xauth_location;
956 goto parse_string;
957
Damien Miller95def091999-11-25 00:26:21 +1100958 case oUser:
959 charptr = &options->user;
960parse_string:
Damien Millerbe484b52000-07-15 14:14:16 +1000961 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000962 if (!arg || *arg == '\0')
Damien Miller295ee632011-05-29 21:42:31 +1000963 fatal("%.200s line %d: Missing argument.",
964 filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +1100965 if (*activep && *charptr == NULL)
Damien Miller37023962000-07-11 17:31:38 +1000966 *charptr = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +1100967 break;
968
969 case oGlobalKnownHostsFile:
Damien Miller295ee632011-05-29 21:42:31 +1000970 cpptr = (char **)&options->system_hostfiles;
971 uintptr = &options->num_system_hostfiles;
972 max_entries = SSH_MAX_HOSTS_FILES;
973parse_char_array:
974 if (*activep && *uintptr == 0) {
975 while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
976 if ((*uintptr) >= max_entries)
977 fatal("%s line %d: "
978 "too many authorized keys files.",
979 filename, linenum);
980 cpptr[(*uintptr)++] = xstrdup(arg);
981 }
982 }
983 return 0;
Damien Miller95def091999-11-25 00:26:21 +1100984
985 case oUserKnownHostsFile:
Damien Miller295ee632011-05-29 21:42:31 +1000986 cpptr = (char **)&options->user_hostfiles;
987 uintptr = &options->num_user_hostfiles;
988 max_entries = SSH_MAX_HOSTS_FILES;
989 goto parse_char_array;
Damien Millereba71ba2000-04-29 23:57:08 +1000990
Damien Miller95def091999-11-25 00:26:21 +1100991 case oHostName:
992 charptr = &options->hostname;
993 goto parse_string;
994
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000995 case oHostKeyAlias:
996 charptr = &options->host_key_alias;
997 goto parse_string;
998
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000999 case oPreferredAuthentications:
1000 charptr = &options->preferred_authentications;
1001 goto parse_string;
1002
Ben Lindstrome0f88042001-04-30 13:06:24 +00001003 case oBindAddress:
1004 charptr = &options->bind_address;
1005 goto parse_string;
1006
Damien Miller7ea845e2010-02-12 09:21:02 +11001007 case oPKCS11Provider:
1008 charptr = &options->pkcs11_provider;
Ben Lindstromf7db3bb2001-08-06 21:35:51 +00001009 goto parse_string;
Ben Lindstromae996bf2001-08-06 21:27:53 +00001010
Damien Miller95def091999-11-25 00:26:21 +11001011 case oProxyCommand:
Damien Millerd27b9472005-12-13 19:29:02 +11001012 charptr = &options->proxy_command;
1013parse_command:
Darren Tuckera99c1b72003-06-28 12:40:12 +10001014 if (s == NULL)
1015 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller61f08ac2003-02-24 11:56:27 +11001016 len = strspn(s, WHITESPACE "=");
Damien Miller95def091999-11-25 00:26:21 +11001017 if (*activep && *charptr == NULL)
Damien Miller61f08ac2003-02-24 11:56:27 +11001018 *charptr = xstrdup(s + len);
Damien Miller95def091999-11-25 00:26:21 +11001019 return 0;
1020
1021 case oPort:
1022 intptr = &options->port;
1023parse_int:
Damien Millerbe484b52000-07-15 14:14:16 +10001024 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +10001025 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +11001026 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +10001027 if (arg[0] < '0' || arg[0] > '9')
Damien Miller95def091999-11-25 00:26:21 +11001028 fatal("%.200s line %d: Bad number.", filename, linenum);
Damien Miller5428f641999-11-25 11:54:57 +11001029
1030 /* Octal, decimal, or hex format? */
Damien Miller37023962000-07-11 17:31:38 +10001031 value = strtol(arg, &endofnumber, 0);
1032 if (arg == endofnumber)
Damien Miller5428f641999-11-25 11:54:57 +11001033 fatal("%.200s line %d: Bad number.", filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +11001034 if (*activep && *intptr == -1)
1035 *intptr = value;
1036 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001037
Damien Miller95def091999-11-25 00:26:21 +11001038 case oConnectionAttempts:
1039 intptr = &options->connection_attempts;
1040 goto parse_int;
Damien Miller5ce662a1999-11-11 17:57:39 +11001041
Damien Miller95def091999-11-25 00:26:21 +11001042 case oCipher:
1043 intptr = &options->cipher;
Damien Millerbe484b52000-07-15 14:14:16 +10001044 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +10001045 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +10001046 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +10001047 value = cipher_number(arg);
Damien Miller95def091999-11-25 00:26:21 +11001048 if (value == -1)
1049 fatal("%.200s line %d: Bad cipher '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001050 filename, linenum, arg ? arg : "<NONE>");
Damien Miller95def091999-11-25 00:26:21 +11001051 if (*activep && *intptr == -1)
1052 *intptr = value;
1053 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001054
Damien Miller78928792000-04-12 20:17:38 +10001055 case oCiphers:
Damien Millerbe484b52000-07-15 14:14:16 +10001056 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +10001057 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +10001058 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +10001059 if (!ciphers_valid(arg))
Damien Miller30c3d422000-05-09 11:02:59 +10001060 fatal("%.200s line %d: Bad SSH2 cipher spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001061 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +10001062 if (*activep && options->ciphers == NULL)
Damien Miller37023962000-07-11 17:31:38 +10001063 options->ciphers = xstrdup(arg);
Damien Miller78928792000-04-12 20:17:38 +10001064 break;
1065
Ben Lindstrom06b33aa2001-02-15 03:01:59 +00001066 case oMacs:
1067 arg = strdelim(&s);
1068 if (!arg || *arg == '\0')
1069 fatal("%.200s line %d: Missing argument.", filename, linenum);
1070 if (!mac_valid(arg))
1071 fatal("%.200s line %d: Bad SSH2 Mac spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001072 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstrom06b33aa2001-02-15 03:01:59 +00001073 if (*activep && options->macs == NULL)
1074 options->macs = xstrdup(arg);
1075 break;
1076
Damien Millerd5f62bf2010-09-24 22:11:14 +10001077 case oKexAlgorithms:
1078 arg = strdelim(&s);
1079 if (!arg || *arg == '\0')
1080 fatal("%.200s line %d: Missing argument.",
1081 filename, linenum);
1082 if (!kex_names_valid(arg))
1083 fatal("%.200s line %d: Bad SSH2 KexAlgorithms '%s'.",
1084 filename, linenum, arg ? arg : "<NONE>");
1085 if (*activep && options->kex_algorithms == NULL)
1086 options->kex_algorithms = xstrdup(arg);
1087 break;
1088
Ben Lindstrom982dbbc2001-04-17 18:11:36 +00001089 case oHostKeyAlgorithms:
1090 arg = strdelim(&s);
1091 if (!arg || *arg == '\0')
1092 fatal("%.200s line %d: Missing argument.", filename, linenum);
1093 if (!key_names_valid2(arg))
1094 fatal("%.200s line %d: Bad protocol 2 host key algorithms '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001095 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstrom982dbbc2001-04-17 18:11:36 +00001096 if (*activep && options->hostkeyalgorithms == NULL)
1097 options->hostkeyalgorithms = xstrdup(arg);
1098 break;
1099
Damien Miller78928792000-04-12 20:17:38 +10001100 case oProtocol:
1101 intptr = &options->protocol;
Damien Millerbe484b52000-07-15 14:14:16 +10001102 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +10001103 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +10001104 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +10001105 value = proto_spec(arg);
Damien Miller78928792000-04-12 20:17:38 +10001106 if (value == SSH_PROTO_UNKNOWN)
1107 fatal("%.200s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001108 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +10001109 if (*activep && *intptr == SSH_PROTO_UNKNOWN)
1110 *intptr = value;
1111 break;
1112
Damien Miller95def091999-11-25 00:26:21 +11001113 case oLogLevel:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001114 log_level_ptr = &options->log_level;
Damien Millerbe484b52000-07-15 14:14:16 +10001115 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +10001116 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001117 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +00001118 fatal("%.200s line %d: unsupported log level '%s'",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001119 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001120 if (*activep && *log_level_ptr == SYSLOG_LEVEL_NOT_SET)
1121 *log_level_ptr = (LogLevel) value;
Damien Miller95def091999-11-25 00:26:21 +11001122 break;
1123
Ben Lindstrom62c25a42001-09-12 18:01:59 +00001124 case oLocalForward:
Damien Miller95def091999-11-25 00:26:21 +11001125 case oRemoteForward:
Damien Millera699d952008-11-03 19:27:34 +11001126 case oDynamicForward:
Damien Millerbe484b52000-07-15 14:14:16 +10001127 arg = strdelim(&s);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001128 if (arg == NULL || *arg == '\0')
Ben Lindstrom62c25a42001-09-12 18:01:59 +00001129 fatal("%.200s line %d: Missing port argument.",
1130 filename, linenum);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001131
Damien Millera699d952008-11-03 19:27:34 +11001132 if (opcode == oLocalForward ||
1133 opcode == oRemoteForward) {
1134 arg2 = strdelim(&s);
1135 if (arg2 == NULL || *arg2 == '\0')
1136 fatal("%.200s line %d: Missing target argument.",
1137 filename, linenum);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001138
Damien Millera699d952008-11-03 19:27:34 +11001139 /* construct a string for parse_forward */
1140 snprintf(fwdarg, sizeof(fwdarg), "%s:%s", arg, arg2);
1141 } else if (opcode == oDynamicForward) {
1142 strlcpy(fwdarg, arg, sizeof(fwdarg));
1143 }
1144
1145 if (parse_forward(&fwd, fwdarg,
Damien Miller4bf648f2009-02-14 16:28:21 +11001146 opcode == oDynamicForward ? 1 : 0,
1147 opcode == oRemoteForward ? 1 : 0) == 0)
Ben Lindstrom62c25a42001-09-12 18:01:59 +00001148 fatal("%.200s line %d: Bad forwarding specification.",
1149 filename, linenum);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001150
Ben Lindstrom62c25a42001-09-12 18:01:59 +00001151 if (*activep) {
Damien Millera699d952008-11-03 19:27:34 +11001152 if (opcode == oLocalForward ||
1153 opcode == oDynamicForward)
Damien Millerf91ee4c2005-03-01 21:24:33 +11001154 add_local_forward(options, &fwd);
Ben Lindstrom62c25a42001-09-12 18:01:59 +00001155 else if (opcode == oRemoteForward)
Damien Millerf91ee4c2005-03-01 21:24:33 +11001156 add_remote_forward(options, &fwd);
Ben Lindstrom62c25a42001-09-12 18:01:59 +00001157 }
Damien Miller95def091999-11-25 00:26:21 +11001158 break;
1159
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +00001160 case oClearAllForwardings:
1161 intptr = &options->clear_forwardings;
1162 goto parse_flag;
1163
Damien Miller95def091999-11-25 00:26:21 +11001164 case oHost:
Damien Miller194fd902013-10-15 12:13:05 +11001165 if (cmdline)
1166 fatal("Host directive not supported as a command-line "
1167 "option");
Damien Miller95def091999-11-25 00:26:21 +11001168 *activep = 0;
Damien Millerfe924212011-05-15 08:44:45 +10001169 arg2 = NULL;
1170 while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1171 negated = *arg == '!';
1172 if (negated)
1173 arg++;
Damien Miller37023962000-07-11 17:31:38 +10001174 if (match_pattern(host, arg)) {
Damien Millerfe924212011-05-15 08:44:45 +10001175 if (negated) {
1176 debug("%.200s line %d: Skipping Host "
1177 "block because of negated match "
1178 "for %.100s", filename, linenum,
1179 arg);
1180 *activep = 0;
1181 break;
1182 }
1183 if (!*activep)
1184 arg2 = arg; /* logged below */
Damien Miller95def091999-11-25 00:26:21 +11001185 *activep = 1;
Damien Miller95def091999-11-25 00:26:21 +11001186 }
Damien Millerfe924212011-05-15 08:44:45 +10001187 }
1188 if (*activep)
1189 debug("%.200s line %d: Applying options for %.100s",
1190 filename, linenum, arg2);
Damien Millerbe484b52000-07-15 14:14:16 +10001191 /* Avoid garbage check below, as strdelim is done. */
Damien Miller95def091999-11-25 00:26:21 +11001192 return 0;
1193
Damien Miller194fd902013-10-15 12:13:05 +11001194 case oMatch:
1195 if (cmdline)
1196 fatal("Host directive not supported as a command-line "
1197 "option");
1198 value = match_cfg_line(options, &s, pw, host,
1199 filename, linenum);
1200 if (value < 0)
1201 fatal("%.200s line %d: Bad Match condition", filename,
1202 linenum);
1203 *activep = value;
1204 break;
1205
Damien Miller95def091999-11-25 00:26:21 +11001206 case oEscapeChar:
1207 intptr = &options->escape_char;
Damien Millerbe484b52000-07-15 14:14:16 +10001208 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +10001209 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +11001210 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +10001211 if (arg[0] == '^' && arg[2] == 0 &&
Ben Lindstrom46c16222000-12-22 01:43:59 +00001212 (u_char) arg[1] >= 64 && (u_char) arg[1] < 128)
1213 value = (u_char) arg[1] & 31;
Damien Miller37023962000-07-11 17:31:38 +10001214 else if (strlen(arg) == 1)
Ben Lindstrom46c16222000-12-22 01:43:59 +00001215 value = (u_char) arg[0];
Damien Miller37023962000-07-11 17:31:38 +10001216 else if (strcmp(arg, "none") == 0)
Ben Lindstrom2b1f71b2001-06-05 20:32:21 +00001217 value = SSH_ESCAPECHAR_NONE;
Damien Miller95def091999-11-25 00:26:21 +11001218 else {
1219 fatal("%.200s line %d: Bad escape character.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001220 filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +11001221 /* NOTREACHED */
1222 value = 0; /* Avoid compiler warning. */
1223 }
1224 if (*activep && *intptr == -1)
1225 *intptr = value;
1226 break;
1227
Damien Miller20a8f972003-05-18 20:50:30 +10001228 case oAddressFamily:
Darren Tucker0a4f04b2003-07-03 20:37:47 +10001229 intptr = &options->address_family;
Damien Millere9fc72e2013-10-15 12:14:12 +11001230 multistate_ptr = multistate_addressfamily;
1231 goto parse_multistate;
Damien Miller20a8f972003-05-18 20:50:30 +10001232
Ben Lindstromb6df73b2002-11-09 15:52:31 +00001233 case oEnableSSHKeysign:
1234 intptr = &options->enable_ssh_keysign;
1235 goto parse_flag;
1236
Damien Millerbd394c32004-03-08 23:12:36 +11001237 case oIdentitiesOnly:
1238 intptr = &options->identities_only;
1239 goto parse_flag;
1240
Damien Miller509b0102003-12-17 16:33:10 +11001241 case oServerAliveInterval:
1242 intptr = &options->server_alive_interval;
1243 goto parse_time;
1244
1245 case oServerAliveCountMax:
1246 intptr = &options->server_alive_count_max;
1247 goto parse_int;
1248
Darren Tucker46bc0752004-05-02 22:11:30 +10001249 case oSendEnv:
1250 while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1251 if (strchr(arg, '=') != NULL)
1252 fatal("%s line %d: Invalid environment name.",
1253 filename, linenum);
Damien Millerf8e7acc2005-03-05 11:22:50 +11001254 if (!*activep)
1255 continue;
Darren Tucker46bc0752004-05-02 22:11:30 +10001256 if (options->num_send_env >= MAX_SEND_ENV)
1257 fatal("%s line %d: too many send env.",
1258 filename, linenum);
1259 options->send_env[options->num_send_env++] =
1260 xstrdup(arg);
1261 }
1262 break;
1263
Damien Miller0e220db2004-06-15 10:34:08 +10001264 case oControlPath:
1265 charptr = &options->control_path;
1266 goto parse_string;
1267
1268 case oControlMaster:
1269 intptr = &options->control_master;
Damien Millere9fc72e2013-10-15 12:14:12 +11001270 multistate_ptr = multistate_controlmaster;
1271 goto parse_multistate;
Damien Miller0e220db2004-06-15 10:34:08 +10001272
Damien Millere11e1ea2010-08-03 16:04:46 +10001273 case oControlPersist:
1274 /* no/false/yes/true, or a time spec */
1275 intptr = &options->control_persist;
1276 arg = strdelim(&s);
1277 if (!arg || *arg == '\0')
1278 fatal("%.200s line %d: Missing ControlPersist"
1279 " argument.", filename, linenum);
1280 value = 0;
1281 value2 = 0; /* timeout */
1282 if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
1283 value = 0;
1284 else if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
1285 value = 1;
1286 else if ((value2 = convtime(arg)) >= 0)
1287 value = 1;
1288 else
1289 fatal("%.200s line %d: Bad ControlPersist argument.",
1290 filename, linenum);
1291 if (*activep && *intptr == -1) {
1292 *intptr = value;
1293 options->control_persist_timeout = value2;
1294 }
1295 break;
1296
Damien Millere1776152005-03-01 21:47:37 +11001297 case oHashKnownHosts:
1298 intptr = &options->hash_known_hosts;
1299 goto parse_flag;
1300
Damien Millerd27b9472005-12-13 19:29:02 +11001301 case oTunnel:
1302 intptr = &options->tun_open;
Damien Millere9fc72e2013-10-15 12:14:12 +11001303 multistate_ptr = multistate_tunnel;
1304 goto parse_multistate;
Damien Millerd27b9472005-12-13 19:29:02 +11001305
1306 case oTunnelDevice:
1307 arg = strdelim(&s);
1308 if (!arg || *arg == '\0')
1309 fatal("%.200s line %d: Missing argument.", filename, linenum);
1310 value = a2tun(arg, &value2);
Damien Miller7b58e802005-12-13 19:33:19 +11001311 if (value == SSH_TUNID_ERR)
Damien Millerd27b9472005-12-13 19:29:02 +11001312 fatal("%.200s line %d: Bad tun device.", filename, linenum);
1313 if (*activep) {
1314 options->tun_local = value;
1315 options->tun_remote = value2;
1316 }
1317 break;
1318
1319 case oLocalCommand:
1320 charptr = &options->local_command;
1321 goto parse_command;
1322
1323 case oPermitLocalCommand:
1324 intptr = &options->permit_local_command;
1325 goto parse_flag;
1326
Damien Miller10288242008-06-30 00:04:03 +10001327 case oVisualHostKey:
1328 intptr = &options->visual_host_key;
1329 goto parse_flag;
1330
Damien Miller0dac6fb2010-11-20 15:19:38 +11001331 case oIPQoS:
1332 arg = strdelim(&s);
1333 if ((value = parse_ipqos(arg)) == -1)
1334 fatal("%s line %d: Bad IPQoS value: %s",
1335 filename, linenum, arg);
1336 arg = strdelim(&s);
1337 if (arg == NULL)
1338 value2 = value;
1339 else if ((value2 = parse_ipqos(arg)) == -1)
1340 fatal("%s line %d: Bad IPQoS value: %s",
1341 filename, linenum, arg);
1342 if (*activep) {
1343 options->ip_qos_interactive = value;
1344 options->ip_qos_bulk = value2;
1345 }
1346 break;
1347
Darren Tucker71e4d542009-07-06 07:12:27 +10001348 case oUseRoaming:
1349 intptr = &options->use_roaming;
1350 goto parse_flag;
1351
Damien Miller21771e22011-05-15 08:45:50 +10001352 case oRequestTTY:
Damien Miller21771e22011-05-15 08:45:50 +10001353 intptr = &options->request_tty;
Damien Millere9fc72e2013-10-15 12:14:12 +11001354 multistate_ptr = multistate_requesttty;
1355 goto parse_multistate;
Damien Miller21771e22011-05-15 08:45:50 +10001356
Darren Tucker07636982013-05-16 20:30:03 +10001357 case oIgnoreUnknown:
1358 charptr = &options->ignored_unknown;
1359 goto parse_string;
1360
Damien Miller1262b662013-08-21 02:44:24 +10001361 case oProxyUseFdpass:
1362 intptr = &options->proxy_use_fdpass;
1363 goto parse_flag;
1364
Damien Miller0faf7472013-10-17 11:47:23 +11001365 case oCanonicalDomains:
1366 value = options->num_canonical_domains != 0;
1367 while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1368 valid_domain(arg, filename, linenum);
1369 if (!*activep || value)
1370 continue;
1371 if (options->num_canonical_domains >= MAX_CANON_DOMAINS)
1372 fatal("%s line %d: too many hostname suffixes.",
1373 filename, linenum);
1374 options->canonical_domains[
1375 options->num_canonical_domains++] = xstrdup(arg);
1376 }
1377 break;
1378
Damien Miller38505592013-10-17 11:48:13 +11001379 case oCanonicalizePermittedCNAMEs:
Damien Miller0faf7472013-10-17 11:47:23 +11001380 value = options->num_permitted_cnames != 0;
1381 while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1382 /* Either '*' for everything or 'list:list' */
1383 if (strcmp(arg, "*") == 0)
1384 arg2 = arg;
1385 else {
1386 lowercase(arg);
1387 if ((arg2 = strchr(arg, ':')) == NULL ||
1388 arg2[1] == '\0') {
1389 fatal("%s line %d: "
1390 "Invalid permitted CNAME \"%s\"",
1391 filename, linenum, arg);
1392 }
1393 *arg2 = '\0';
1394 arg2++;
1395 }
1396 if (!*activep || value)
1397 continue;
1398 if (options->num_permitted_cnames >= MAX_CANON_DOMAINS)
1399 fatal("%s line %d: too many permitted CNAMEs.",
1400 filename, linenum);
1401 cname = options->permitted_cnames +
1402 options->num_permitted_cnames++;
1403 cname->source_list = xstrdup(arg);
1404 cname->target_list = xstrdup(arg2);
1405 }
1406 break;
1407
Damien Miller38505592013-10-17 11:48:13 +11001408 case oCanonicalizeHostname:
1409 intptr = &options->canonicalize_hostname;
1410 multistate_ptr = multistate_canonicalizehostname;
Damien Miller0faf7472013-10-17 11:47:23 +11001411 goto parse_multistate;
1412
Damien Miller38505592013-10-17 11:48:13 +11001413 case oCanonicalizeMaxDots:
1414 intptr = &options->canonicalize_max_dots;
Damien Miller0faf7472013-10-17 11:47:23 +11001415 goto parse_int;
1416
Damien Miller38505592013-10-17 11:48:13 +11001417 case oCanonicalizeFallbackLocal:
1418 intptr = &options->canonicalize_fallback_local;
Damien Miller0faf7472013-10-17 11:47:23 +11001419 goto parse_flag;
1420
Damien Miller7acefbb2014-07-18 14:11:24 +10001421 case oStreamLocalBindMask:
1422 arg = strdelim(&s);
1423 if (!arg || *arg == '\0')
1424 fatal("%.200s line %d: Missing StreamLocalBindMask argument.", filename, linenum);
1425 /* Parse mode in octal format */
1426 value = strtol(arg, &endofnumber, 8);
1427 if (arg == endofnumber || value < 0 || value > 0777)
1428 fatal("%.200s line %d: Bad mask.", filename, linenum);
1429 options->fwd_opts.streamlocal_bind_mask = (mode_t)value;
1430 break;
1431
1432 case oStreamLocalBindUnlink:
1433 intptr = &options->fwd_opts.streamlocal_bind_unlink;
1434 goto parse_flag;
1435
Ben Lindstrom4daea862002-06-09 20:04:02 +00001436 case oDeprecated:
Ben Lindstrom2e17b082002-06-09 20:13:27 +00001437 debug("%s line %d: Deprecated option \"%s\"",
Ben Lindstrom4daea862002-06-09 20:04:02 +00001438 filename, linenum, keyword);
Ben Lindstrom2e17b082002-06-09 20:13:27 +00001439 return 0;
Ben Lindstrom4daea862002-06-09 20:04:02 +00001440
Damien Millerf9b3feb2003-05-16 11:38:32 +10001441 case oUnsupported:
1442 error("%s line %d: Unsupported option \"%s\"",
1443 filename, linenum, keyword);
1444 return 0;
1445
Damien Miller95def091999-11-25 00:26:21 +11001446 default:
1447 fatal("process_config_line: Unimplemented opcode %d", opcode);
1448 }
1449
1450 /* Check that there is no garbage at end of line. */
Ben Lindstrom226cfa02001-01-22 05:34:40 +00001451 if ((arg = strdelim(&s)) != NULL && *arg != '\0') {
Damien Miller37023962000-07-11 17:31:38 +10001452 fatal("%.200s line %d: garbage at end of line; \"%.200s\".",
Damien Miller0dc1bef2005-07-17 17:22:45 +10001453 filename, linenum, arg);
Damien Miller37023962000-07-11 17:31:38 +10001454 }
Damien Miller95def091999-11-25 00:26:21 +11001455 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001456}
1457
1458
Damien Miller5428f641999-11-25 11:54:57 +11001459/*
1460 * Reads the config file and modifies the options accordingly. Options
1461 * should already be initialized before this call. This never returns if
Ben Lindstromedc0cf22001-09-12 18:32:20 +00001462 * there is an error. If the file does not exist, this returns 0.
Damien Miller5428f641999-11-25 11:54:57 +11001463 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001464
Ben Lindstromedc0cf22001-09-12 18:32:20 +00001465int
Damien Miller194fd902013-10-15 12:13:05 +11001466read_config_file(const char *filename, struct passwd *pw, const char *host,
1467 Options *options, int flags)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001468{
Damien Miller95def091999-11-25 00:26:21 +11001469 FILE *f;
1470 char line[1024];
1471 int active, linenum;
1472 int bad_options = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001473
Damien Miller57a44762004-04-20 20:11:57 +10001474 if ((f = fopen(filename, "r")) == NULL)
Ben Lindstromedc0cf22001-09-12 18:32:20 +00001475 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001476
Darren Tuckeraefa3682013-04-05 11:18:35 +11001477 if (flags & SSHCONF_CHECKPERM) {
Damien Miller57a44762004-04-20 20:11:57 +10001478 struct stat sb;
Darren Tuckerfc959702004-07-17 16:12:08 +10001479
Damien Miller33793852004-06-15 10:27:55 +10001480 if (fstat(fileno(f), &sb) == -1)
Damien Miller57a44762004-04-20 20:11:57 +10001481 fatal("fstat %s: %s", filename, strerror(errno));
Damien Miller57a44762004-04-20 20:11:57 +10001482 if (((sb.st_uid != 0 && sb.st_uid != getuid()) ||
Damien Miller33793852004-06-15 10:27:55 +10001483 (sb.st_mode & 022) != 0))
Damien Miller57a44762004-04-20 20:11:57 +10001484 fatal("Bad owner or permissions on %s", filename);
Damien Miller57a44762004-04-20 20:11:57 +10001485 }
1486
Damien Miller95def091999-11-25 00:26:21 +11001487 debug("Reading configuration data %.200s", filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001488
Damien Miller5428f641999-11-25 11:54:57 +11001489 /*
1490 * Mark that we are now processing the options. This flag is turned
1491 * on/off by Host specifications.
1492 */
Damien Miller95def091999-11-25 00:26:21 +11001493 active = 1;
1494 linenum = 0;
1495 while (fgets(line, sizeof(line), f)) {
1496 /* Update line number counter. */
1497 linenum++;
Damien Miller194fd902013-10-15 12:13:05 +11001498 if (process_config_line(options, pw, host, line, filename,
1499 linenum, &active, flags & SSHCONF_USERCONF) != 0)
Damien Miller95def091999-11-25 00:26:21 +11001500 bad_options++;
1501 }
1502 fclose(f);
1503 if (bad_options > 0)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +00001504 fatal("%s: terminating, %d bad configuration options",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001505 filename, bad_options);
Ben Lindstromedc0cf22001-09-12 18:32:20 +00001506 return 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001507}
1508
Damien Miller13f97b22014-02-24 15:57:55 +11001509/* Returns 1 if a string option is unset or set to "none" or 0 otherwise. */
1510int
1511option_clear_or_none(const char *o)
1512{
1513 return o == NULL || strcasecmp(o, "none") == 0;
1514}
1515
Damien Miller5428f641999-11-25 11:54:57 +11001516/*
1517 * Initializes options to special values that indicate that they have not yet
1518 * been set. Read_config_file will only set options with this value. Options
1519 * are processed in the following order: command line, user config file,
1520 * system config file. Last, fill_default_options is called.
1521 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001522
Damien Miller4af51302000-04-16 11:18:38 +10001523void
Damien Miller95def091999-11-25 00:26:21 +11001524initialize_options(Options * options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001525{
Damien Miller95def091999-11-25 00:26:21 +11001526 memset(options, 'X', sizeof(*options));
1527 options->forward_agent = -1;
1528 options->forward_x11 = -1;
Darren Tucker0a118da2003-10-15 15:54:32 +10001529 options->forward_x11_trusted = -1;
Damien Miller1ab6a512010-06-26 10:02:24 +10001530 options->forward_x11_timeout = -1;
Darren Tuckere7d4b192006-07-12 22:17:10 +10001531 options->exit_on_forward_failure = -1;
Damien Millerd3a18572000-06-07 19:55:44 +10001532 options->xauth_location = NULL;
Damien Miller7acefbb2014-07-18 14:11:24 +10001533 options->fwd_opts.gateway_ports = -1;
1534 options->fwd_opts.streamlocal_bind_mask = (mode_t)-1;
1535 options->fwd_opts.streamlocal_bind_unlink = -1;
Damien Miller95def091999-11-25 00:26:21 +11001536 options->use_privileged_port = -1;
Damien Miller95def091999-11-25 00:26:21 +11001537 options->rsa_authentication = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +11001538 options->pubkey_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +00001539 options->challenge_response_authentication = -1;
Darren Tucker0efd1552003-08-26 11:49:55 +10001540 options->gss_authentication = -1;
1541 options->gss_deleg_creds = -1;
Damien Miller95def091999-11-25 00:26:21 +11001542 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +11001543 options->kbd_interactive_authentication = -1;
1544 options->kbd_interactive_devices = NULL;
Damien Miller95def091999-11-25 00:26:21 +11001545 options->rhosts_rsa_authentication = -1;
Ben Lindstrom5eabda32001-04-12 23:34:34 +00001546 options->hostbased_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +11001547 options->batch_mode = -1;
1548 options->check_host_ip = -1;
1549 options->strict_host_key_checking = -1;
1550 options->compression = -1;
Damien Miller12c150e2003-12-17 16:31:10 +11001551 options->tcp_keep_alive = -1;
Damien Miller95def091999-11-25 00:26:21 +11001552 options->compression_level = -1;
1553 options->port = -1;
Darren Tucker0a4f04b2003-07-03 20:37:47 +10001554 options->address_family = -1;
Damien Miller95def091999-11-25 00:26:21 +11001555 options->connection_attempts = -1;
Damien Millerb78d5eb2003-05-16 11:39:04 +10001556 options->connection_timeout = -1;
Damien Miller95def091999-11-25 00:26:21 +11001557 options->number_of_password_prompts = -1;
1558 options->cipher = -1;
Damien Miller78928792000-04-12 20:17:38 +10001559 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +00001560 options->macs = NULL;
Damien Millerd5f62bf2010-09-24 22:11:14 +10001561 options->kex_algorithms = NULL;
Ben Lindstrom982dbbc2001-04-17 18:11:36 +00001562 options->hostkeyalgorithms = NULL;
Damien Miller78928792000-04-12 20:17:38 +10001563 options->protocol = SSH_PROTO_UNKNOWN;
Damien Miller95def091999-11-25 00:26:21 +11001564 options->num_identity_files = 0;
1565 options->hostname = NULL;
Ben Lindstrom4dccfa52000-12-28 16:40:05 +00001566 options->host_key_alias = NULL;
Damien Miller95def091999-11-25 00:26:21 +11001567 options->proxy_command = NULL;
1568 options->user = NULL;
1569 options->escape_char = -1;
Damien Miller295ee632011-05-29 21:42:31 +10001570 options->num_system_hostfiles = 0;
1571 options->num_user_hostfiles = 0;
Damien Miller232cfb12010-06-26 09:50:30 +10001572 options->local_forwards = NULL;
Damien Miller95def091999-11-25 00:26:21 +11001573 options->num_local_forwards = 0;
Damien Miller232cfb12010-06-26 09:50:30 +10001574 options->remote_forwards = NULL;
Damien Miller95def091999-11-25 00:26:21 +11001575 options->num_remote_forwards = 0;
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +00001576 options->clear_forwardings = -1;
Damien Millerfcd93202002-02-05 12:26:34 +11001577 options->log_level = SYSLOG_LEVEL_NOT_SET;
Ben Lindstromb9be60a2001-03-11 01:49:19 +00001578 options->preferred_authentications = NULL;
Ben Lindstrome0f88042001-04-30 13:06:24 +00001579 options->bind_address = NULL;
Damien Miller7ea845e2010-02-12 09:21:02 +11001580 options->pkcs11_provider = NULL;
Ben Lindstromb6df73b2002-11-09 15:52:31 +00001581 options->enable_ssh_keysign = - 1;
Ben Lindstrom3cecc9a2001-10-03 17:39:38 +00001582 options->no_host_authentication_for_localhost = - 1;
Damien Millerbd394c32004-03-08 23:12:36 +11001583 options->identities_only = - 1;
Damien Millera5539d22003-04-09 20:50:06 +10001584 options->rekey_limit = - 1;
Darren Tuckerc53c2af2013-05-16 20:28:16 +10001585 options->rekey_interval = -1;
Damien Miller37876e92003-05-15 10:19:46 +10001586 options->verify_host_key_dns = -1;
Damien Miller509b0102003-12-17 16:33:10 +11001587 options->server_alive_interval = -1;
1588 options->server_alive_count_max = -1;
Darren Tucker46bc0752004-05-02 22:11:30 +10001589 options->num_send_env = 0;
Damien Miller0e220db2004-06-15 10:34:08 +10001590 options->control_path = NULL;
1591 options->control_master = -1;
Damien Millere11e1ea2010-08-03 16:04:46 +10001592 options->control_persist = -1;
1593 options->control_persist_timeout = 0;
Damien Millere1776152005-03-01 21:47:37 +11001594 options->hash_known_hosts = -1;
Damien Millerd27b9472005-12-13 19:29:02 +11001595 options->tun_open = -1;
1596 options->tun_local = -1;
1597 options->tun_remote = -1;
1598 options->local_command = NULL;
1599 options->permit_local_command = -1;
Darren Tucker71e4d542009-07-06 07:12:27 +10001600 options->use_roaming = -1;
Damien Miller10288242008-06-30 00:04:03 +10001601 options->visual_host_key = -1;
Damien Miller0dac6fb2010-11-20 15:19:38 +11001602 options->ip_qos_interactive = -1;
1603 options->ip_qos_bulk = -1;
Damien Miller21771e22011-05-15 08:45:50 +10001604 options->request_tty = -1;
Damien Miller1262b662013-08-21 02:44:24 +10001605 options->proxy_use_fdpass = -1;
Darren Tucker07636982013-05-16 20:30:03 +10001606 options->ignored_unknown = NULL;
Damien Miller0faf7472013-10-17 11:47:23 +11001607 options->num_canonical_domains = 0;
1608 options->num_permitted_cnames = 0;
Damien Miller38505592013-10-17 11:48:13 +11001609 options->canonicalize_max_dots = -1;
1610 options->canonicalize_fallback_local = -1;
1611 options->canonicalize_hostname = -1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001612}
1613
Damien Miller5428f641999-11-25 11:54:57 +11001614/*
Damien Miller13f97b22014-02-24 15:57:55 +11001615 * A petite version of fill_default_options() that just fills the options
1616 * needed for hostname canonicalization to proceed.
1617 */
1618void
1619fill_default_options_for_canonicalization(Options *options)
1620{
1621 if (options->canonicalize_max_dots == -1)
1622 options->canonicalize_max_dots = 1;
1623 if (options->canonicalize_fallback_local == -1)
1624 options->canonicalize_fallback_local = 1;
1625 if (options->canonicalize_hostname == -1)
1626 options->canonicalize_hostname = SSH_CANONICALISE_NO;
1627}
1628
1629/*
Damien Miller5428f641999-11-25 11:54:57 +11001630 * Called after processing other sources of option data, this fills those
1631 * options for which no value has been specified with their default values.
1632 */
Damien Miller4af51302000-04-16 11:18:38 +10001633void
Damien Miller95def091999-11-25 00:26:21 +11001634fill_default_options(Options * options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001635{
Damien Miller95def091999-11-25 00:26:21 +11001636 if (options->forward_agent == -1)
Damien Millerb1715dc2000-05-30 13:44:51 +10001637 options->forward_agent = 0;
Damien Miller95def091999-11-25 00:26:21 +11001638 if (options->forward_x11 == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +11001639 options->forward_x11 = 0;
Darren Tucker0a118da2003-10-15 15:54:32 +10001640 if (options->forward_x11_trusted == -1)
1641 options->forward_x11_trusted = 0;
Damien Miller1ab6a512010-06-26 10:02:24 +10001642 if (options->forward_x11_timeout == -1)
1643 options->forward_x11_timeout = 1200;
Darren Tuckere7d4b192006-07-12 22:17:10 +10001644 if (options->exit_on_forward_failure == -1)
1645 options->exit_on_forward_failure = 0;
Damien Millerd3a18572000-06-07 19:55:44 +10001646 if (options->xauth_location == NULL)
Ben Lindstrom1bf11f62001-06-09 01:48:01 +00001647 options->xauth_location = _PATH_XAUTH;
Damien Miller7acefbb2014-07-18 14:11:24 +10001648 if (options->fwd_opts.gateway_ports == -1)
1649 options->fwd_opts.gateway_ports = 0;
1650 if (options->fwd_opts.streamlocal_bind_mask == (mode_t)-1)
1651 options->fwd_opts.streamlocal_bind_mask = 0177;
1652 if (options->fwd_opts.streamlocal_bind_unlink == -1)
1653 options->fwd_opts.streamlocal_bind_unlink = 0;
Damien Miller95def091999-11-25 00:26:21 +11001654 if (options->use_privileged_port == -1)
Ben Lindstromcebc8582001-03-08 03:39:10 +00001655 options->use_privileged_port = 0;
Damien Miller95def091999-11-25 00:26:21 +11001656 if (options->rsa_authentication == -1)
1657 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +11001658 if (options->pubkey_authentication == -1)
1659 options->pubkey_authentication = 1;
Ben Lindstrom551ea372001-06-05 18:56:16 +00001660 if (options->challenge_response_authentication == -1)
Ben Lindstrom0076d752001-08-06 20:53:26 +00001661 options->challenge_response_authentication = 1;
Darren Tucker0efd1552003-08-26 11:49:55 +10001662 if (options->gss_authentication == -1)
Darren Tuckera044f472003-10-15 15:52:03 +10001663 options->gss_authentication = 0;
Darren Tucker0efd1552003-08-26 11:49:55 +10001664 if (options->gss_deleg_creds == -1)
1665 options->gss_deleg_creds = 0;
Damien Miller95def091999-11-25 00:26:21 +11001666 if (options->password_authentication == -1)
1667 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +11001668 if (options->kbd_interactive_authentication == -1)
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +00001669 options->kbd_interactive_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +11001670 if (options->rhosts_rsa_authentication == -1)
Ben Lindstrom2bf82762002-06-11 15:53:05 +00001671 options->rhosts_rsa_authentication = 0;
Ben Lindstrom5eabda32001-04-12 23:34:34 +00001672 if (options->hostbased_authentication == -1)
1673 options->hostbased_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +11001674 if (options->batch_mode == -1)
1675 options->batch_mode = 0;
1676 if (options->check_host_ip == -1)
1677 options->check_host_ip = 1;
1678 if (options->strict_host_key_checking == -1)
1679 options->strict_host_key_checking = 2; /* 2 is default */
1680 if (options->compression == -1)
1681 options->compression = 0;
Damien Miller12c150e2003-12-17 16:31:10 +11001682 if (options->tcp_keep_alive == -1)
1683 options->tcp_keep_alive = 1;
Damien Miller95def091999-11-25 00:26:21 +11001684 if (options->compression_level == -1)
1685 options->compression_level = 6;
1686 if (options->port == -1)
1687 options->port = 0; /* Filled in ssh_connect. */
Darren Tucker0a4f04b2003-07-03 20:37:47 +10001688 if (options->address_family == -1)
1689 options->address_family = AF_UNSPEC;
Damien Miller95def091999-11-25 00:26:21 +11001690 if (options->connection_attempts == -1)
Ben Lindstromf9cedb92001-08-06 21:07:11 +00001691 options->connection_attempts = 1;
Damien Miller95def091999-11-25 00:26:21 +11001692 if (options->number_of_password_prompts == -1)
1693 options->number_of_password_prompts = 3;
1694 /* Selected in ssh_login(). */
1695 if (options->cipher == -1)
1696 options->cipher = SSH_CIPHER_NOT_SET;
Damien Miller30c3d422000-05-09 11:02:59 +10001697 /* options->ciphers, default set in myproposals.h */
Ben Lindstrom06b33aa2001-02-15 03:01:59 +00001698 /* options->macs, default set in myproposals.h */
Damien Millerd5f62bf2010-09-24 22:11:14 +10001699 /* options->kex_algorithms, default set in myproposals.h */
Ben Lindstrom982dbbc2001-04-17 18:11:36 +00001700 /* options->hostkeyalgorithms, default set in myproposals.h */
Damien Miller78928792000-04-12 20:17:38 +10001701 if (options->protocol == SSH_PROTO_UNKNOWN)
Darren Tuckerbad50762009-10-11 21:51:08 +11001702 options->protocol = SSH_PROTO_2;
Damien Miller95def091999-11-25 00:26:21 +11001703 if (options->num_identity_files == 0) {
Damien Miller0bc1bd82000-11-13 22:57:25 +11001704 if (options->protocol & SSH_PROTO_1) {
Darren Tucker19104782013-04-05 11:13:08 +11001705 add_identity_file(options, "~/",
1706 _PATH_SSH_CLIENT_IDENTITY, 0);
Damien Miller0bc1bd82000-11-13 22:57:25 +11001707 }
1708 if (options->protocol & SSH_PROTO_2) {
Darren Tucker19104782013-04-05 11:13:08 +11001709 add_identity_file(options, "~/",
1710 _PATH_SSH_CLIENT_ID_RSA, 0);
1711 add_identity_file(options, "~/",
1712 _PATH_SSH_CLIENT_ID_DSA, 0);
Damien Miller6af914a2010-09-10 11:39:26 +10001713#ifdef OPENSSL_HAS_ECC
Darren Tucker19104782013-04-05 11:13:08 +11001714 add_identity_file(options, "~/",
1715 _PATH_SSH_CLIENT_ID_ECDSA, 0);
Damien Miller6af914a2010-09-10 11:39:26 +10001716#endif
Damien Miller5be9d9e2013-12-07 11:24:01 +11001717 add_identity_file(options, "~/",
1718 _PATH_SSH_CLIENT_ID_ED25519, 0);
Damien Miller0bc1bd82000-11-13 22:57:25 +11001719 }
Damien Millereba71ba2000-04-29 23:57:08 +10001720 }
Damien Miller95def091999-11-25 00:26:21 +11001721 if (options->escape_char == -1)
1722 options->escape_char = '~';
Damien Miller295ee632011-05-29 21:42:31 +10001723 if (options->num_system_hostfiles == 0) {
1724 options->system_hostfiles[options->num_system_hostfiles++] =
1725 xstrdup(_PATH_SSH_SYSTEM_HOSTFILE);
1726 options->system_hostfiles[options->num_system_hostfiles++] =
1727 xstrdup(_PATH_SSH_SYSTEM_HOSTFILE2);
1728 }
1729 if (options->num_user_hostfiles == 0) {
1730 options->user_hostfiles[options->num_user_hostfiles++] =
1731 xstrdup(_PATH_SSH_USER_HOSTFILE);
1732 options->user_hostfiles[options->num_user_hostfiles++] =
1733 xstrdup(_PATH_SSH_USER_HOSTFILE2);
1734 }
Damien Millerfcd93202002-02-05 12:26:34 +11001735 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +00001736 options->log_level = SYSLOG_LEVEL_INFO;
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +00001737 if (options->clear_forwardings == 1)
1738 clear_forwardings(options);
Ben Lindstrom3cecc9a2001-10-03 17:39:38 +00001739 if (options->no_host_authentication_for_localhost == - 1)
1740 options->no_host_authentication_for_localhost = 0;
Damien Millerbd394c32004-03-08 23:12:36 +11001741 if (options->identities_only == -1)
1742 options->identities_only = 0;
Ben Lindstromb6df73b2002-11-09 15:52:31 +00001743 if (options->enable_ssh_keysign == -1)
1744 options->enable_ssh_keysign = 0;
Damien Millera5539d22003-04-09 20:50:06 +10001745 if (options->rekey_limit == -1)
1746 options->rekey_limit = 0;
Darren Tuckerc53c2af2013-05-16 20:28:16 +10001747 if (options->rekey_interval == -1)
1748 options->rekey_interval = 0;
Damien Miller37876e92003-05-15 10:19:46 +10001749 if (options->verify_host_key_dns == -1)
1750 options->verify_host_key_dns = 0;
Damien Miller509b0102003-12-17 16:33:10 +11001751 if (options->server_alive_interval == -1)
1752 options->server_alive_interval = 0;
1753 if (options->server_alive_count_max == -1)
1754 options->server_alive_count_max = 3;
Damien Miller0e220db2004-06-15 10:34:08 +10001755 if (options->control_master == -1)
1756 options->control_master = 0;
Damien Millere11e1ea2010-08-03 16:04:46 +10001757 if (options->control_persist == -1) {
1758 options->control_persist = 0;
1759 options->control_persist_timeout = 0;
1760 }
Damien Millere1776152005-03-01 21:47:37 +11001761 if (options->hash_known_hosts == -1)
1762 options->hash_known_hosts = 0;
Damien Millerd27b9472005-12-13 19:29:02 +11001763 if (options->tun_open == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001764 options->tun_open = SSH_TUNMODE_NO;
1765 if (options->tun_local == -1)
1766 options->tun_local = SSH_TUNID_ANY;
1767 if (options->tun_remote == -1)
1768 options->tun_remote = SSH_TUNID_ANY;
Damien Millerd27b9472005-12-13 19:29:02 +11001769 if (options->permit_local_command == -1)
1770 options->permit_local_command = 0;
Darren Tucker71e4d542009-07-06 07:12:27 +10001771 if (options->use_roaming == -1)
1772 options->use_roaming = 1;
Damien Miller10288242008-06-30 00:04:03 +10001773 if (options->visual_host_key == -1)
1774 options->visual_host_key = 0;
Damien Miller0dac6fb2010-11-20 15:19:38 +11001775 if (options->ip_qos_interactive == -1)
1776 options->ip_qos_interactive = IPTOS_LOWDELAY;
1777 if (options->ip_qos_bulk == -1)
1778 options->ip_qos_bulk = IPTOS_THROUGHPUT;
Damien Miller21771e22011-05-15 08:45:50 +10001779 if (options->request_tty == -1)
1780 options->request_tty = REQUEST_TTY_AUTO;
Damien Miller1262b662013-08-21 02:44:24 +10001781 if (options->proxy_use_fdpass == -1)
1782 options->proxy_use_fdpass = 0;
Damien Miller38505592013-10-17 11:48:13 +11001783 if (options->canonicalize_max_dots == -1)
1784 options->canonicalize_max_dots = 1;
1785 if (options->canonicalize_fallback_local == -1)
1786 options->canonicalize_fallback_local = 1;
1787 if (options->canonicalize_hostname == -1)
1788 options->canonicalize_hostname = SSH_CANONICALISE_NO;
Damien Millere9fc72e2013-10-15 12:14:12 +11001789#define CLEAR_ON_NONE(v) \
1790 do { \
Damien Miller13f97b22014-02-24 15:57:55 +11001791 if (option_clear_or_none(v)) { \
Damien Millere9fc72e2013-10-15 12:14:12 +11001792 free(v); \
1793 v = NULL; \
1794 } \
1795 } while(0)
1796 CLEAR_ON_NONE(options->local_command);
1797 CLEAR_ON_NONE(options->proxy_command);
1798 CLEAR_ON_NONE(options->control_path);
Damien Miller95def091999-11-25 00:26:21 +11001799 /* options->user will be set in the main program if appropriate */
1800 /* options->hostname will be set in the main program if appropriate */
Ben Lindstrom4dccfa52000-12-28 16:40:05 +00001801 /* options->host_key_alias should not be set by default */
Ben Lindstromb9be60a2001-03-11 01:49:19 +00001802 /* options->preferred_authentications will be set in ssh */
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001803}
Damien Millerf91ee4c2005-03-01 21:24:33 +11001804
Damien Miller7acefbb2014-07-18 14:11:24 +10001805struct fwdarg {
1806 char *arg;
1807 int ispath;
1808};
1809
1810/*
1811 * parse_fwd_field
1812 * parses the next field in a port forwarding specification.
1813 * sets fwd to the parsed field and advances p past the colon
1814 * or sets it to NULL at end of string.
1815 * returns 0 on success, else non-zero.
1816 */
1817static int
1818parse_fwd_field(char **p, struct fwdarg *fwd)
1819{
1820 char *ep, *cp = *p;
1821 int ispath = 0;
1822
1823 if (*cp == '\0') {
1824 *p = NULL;
1825 return -1; /* end of string */
1826 }
1827
1828 /*
1829 * A field escaped with square brackets is used literally.
1830 * XXX - allow ']' to be escaped via backslash?
1831 */
1832 if (*cp == '[') {
1833 /* find matching ']' */
1834 for (ep = cp + 1; *ep != ']' && *ep != '\0'; ep++) {
1835 if (*ep == '/')
1836 ispath = 1;
1837 }
1838 /* no matching ']' or not at end of field. */
1839 if (ep[0] != ']' || (ep[1] != ':' && ep[1] != '\0'))
1840 return -1;
1841 /* NUL terminate the field and advance p past the colon */
1842 *ep++ = '\0';
1843 if (*ep != '\0')
1844 *ep++ = '\0';
1845 fwd->arg = cp + 1;
1846 fwd->ispath = ispath;
1847 *p = ep;
1848 return 0;
1849 }
1850
1851 for (cp = *p; *cp != '\0'; cp++) {
1852 switch (*cp) {
1853 case '\\':
1854 memmove(cp, cp + 1, strlen(cp + 1) + 1);
1855 cp++;
1856 break;
1857 case '/':
1858 ispath = 1;
1859 break;
1860 case ':':
1861 *cp++ = '\0';
1862 goto done;
1863 }
1864 }
1865done:
1866 fwd->arg = *p;
1867 fwd->ispath = ispath;
1868 *p = cp;
1869 return 0;
1870}
1871
Damien Millerf91ee4c2005-03-01 21:24:33 +11001872/*
1873 * parse_forward
1874 * parses a string containing a port forwarding specification of the form:
Damien Millera699d952008-11-03 19:27:34 +11001875 * dynamicfwd == 0
Damien Miller7acefbb2014-07-18 14:11:24 +10001876 * [listenhost:]listenport|listenpath:connecthost:connectport|connectpath
1877 * listenpath:connectpath
Damien Millera699d952008-11-03 19:27:34 +11001878 * dynamicfwd == 1
1879 * [listenhost:]listenport
Damien Millerf91ee4c2005-03-01 21:24:33 +11001880 * returns number of arguments parsed or zero on error
1881 */
1882int
Damien Miller7acefbb2014-07-18 14:11:24 +10001883parse_forward(struct Forward *fwd, const char *fwdspec, int dynamicfwd, int remotefwd)
Damien Millerf91ee4c2005-03-01 21:24:33 +11001884{
Damien Miller7acefbb2014-07-18 14:11:24 +10001885 struct fwdarg fwdargs[4];
1886 char *p, *cp;
Damien Millerf91ee4c2005-03-01 21:24:33 +11001887 int i;
Damien Millerf91ee4c2005-03-01 21:24:33 +11001888
Damien Miller7acefbb2014-07-18 14:11:24 +10001889 memset(fwd, 0, sizeof(*fwd));
1890 memset(fwdargs, 0, sizeof(fwdargs));
Damien Millerf91ee4c2005-03-01 21:24:33 +11001891
1892 cp = p = xstrdup(fwdspec);
1893
1894 /* skip leading spaces */
Damien Millerfdb23062013-11-21 13:57:15 +11001895 while (isspace((u_char)*cp))
Damien Millerf91ee4c2005-03-01 21:24:33 +11001896 cp++;
1897
Damien Miller7acefbb2014-07-18 14:11:24 +10001898 for (i = 0; i < 4; ++i) {
1899 if (parse_fwd_field(&cp, &fwdargs[i]) != 0)
Damien Millerf91ee4c2005-03-01 21:24:33 +11001900 break;
Damien Miller7acefbb2014-07-18 14:11:24 +10001901 }
Damien Millerf91ee4c2005-03-01 21:24:33 +11001902
Damien Millerf4b39532008-11-03 19:28:21 +11001903 /* Check for trailing garbage */
Damien Miller7acefbb2014-07-18 14:11:24 +10001904 if (cp != NULL && *cp != '\0') {
Damien Millerf91ee4c2005-03-01 21:24:33 +11001905 i = 0; /* failure */
Damien Miller7acefbb2014-07-18 14:11:24 +10001906 }
Damien Millerf91ee4c2005-03-01 21:24:33 +11001907
1908 switch (i) {
Damien Millera699d952008-11-03 19:27:34 +11001909 case 1:
Damien Miller7acefbb2014-07-18 14:11:24 +10001910 if (fwdargs[0].ispath) {
1911 fwd->listen_path = xstrdup(fwdargs[0].arg);
1912 fwd->listen_port = PORT_STREAMLOCAL;
1913 } else {
1914 fwd->listen_host = NULL;
1915 fwd->listen_port = a2port(fwdargs[0].arg);
1916 }
Damien Millera699d952008-11-03 19:27:34 +11001917 fwd->connect_host = xstrdup("socks");
1918 break;
1919
1920 case 2:
Damien Miller7acefbb2014-07-18 14:11:24 +10001921 if (fwdargs[0].ispath && fwdargs[1].ispath) {
1922 fwd->listen_path = xstrdup(fwdargs[0].arg);
1923 fwd->listen_port = PORT_STREAMLOCAL;
1924 fwd->connect_path = xstrdup(fwdargs[1].arg);
1925 fwd->connect_port = PORT_STREAMLOCAL;
1926 } else if (fwdargs[1].ispath) {
1927 fwd->listen_host = NULL;
1928 fwd->listen_port = a2port(fwdargs[0].arg);
1929 fwd->connect_path = xstrdup(fwdargs[1].arg);
1930 fwd->connect_port = PORT_STREAMLOCAL;
1931 } else {
1932 fwd->listen_host = xstrdup(fwdargs[0].arg);
1933 fwd->listen_port = a2port(fwdargs[1].arg);
1934 fwd->connect_host = xstrdup("socks");
1935 }
Damien Millera699d952008-11-03 19:27:34 +11001936 break;
1937
Damien Millerf91ee4c2005-03-01 21:24:33 +11001938 case 3:
Damien Miller7acefbb2014-07-18 14:11:24 +10001939 if (fwdargs[0].ispath) {
1940 fwd->listen_path = xstrdup(fwdargs[0].arg);
1941 fwd->listen_port = PORT_STREAMLOCAL;
1942 fwd->connect_host = xstrdup(fwdargs[1].arg);
1943 fwd->connect_port = a2port(fwdargs[2].arg);
1944 } else if (fwdargs[2].ispath) {
1945 fwd->listen_host = xstrdup(fwdargs[0].arg);
1946 fwd->listen_port = a2port(fwdargs[1].arg);
1947 fwd->connect_path = xstrdup(fwdargs[2].arg);
1948 fwd->connect_port = PORT_STREAMLOCAL;
1949 } else {
1950 fwd->listen_host = NULL;
1951 fwd->listen_port = a2port(fwdargs[0].arg);
1952 fwd->connect_host = xstrdup(fwdargs[1].arg);
1953 fwd->connect_port = a2port(fwdargs[2].arg);
1954 }
Damien Millerf91ee4c2005-03-01 21:24:33 +11001955 break;
1956
1957 case 4:
Damien Miller7acefbb2014-07-18 14:11:24 +10001958 fwd->listen_host = xstrdup(fwdargs[0].arg);
1959 fwd->listen_port = a2port(fwdargs[1].arg);
1960 fwd->connect_host = xstrdup(fwdargs[2].arg);
1961 fwd->connect_port = a2port(fwdargs[3].arg);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001962 break;
1963 default:
1964 i = 0; /* failure */
1965 }
1966
Darren Tuckera627d422013-06-02 07:31:17 +10001967 free(p);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001968
Damien Millera699d952008-11-03 19:27:34 +11001969 if (dynamicfwd) {
1970 if (!(i == 1 || i == 2))
1971 goto fail_free;
1972 } else {
Damien Miller7acefbb2014-07-18 14:11:24 +10001973 if (!(i == 3 || i == 4)) {
1974 if (fwd->connect_path == NULL &&
1975 fwd->listen_path == NULL)
1976 goto fail_free;
1977 }
1978 if (fwd->connect_port <= 0 && fwd->connect_path == NULL)
Damien Millera699d952008-11-03 19:27:34 +11001979 goto fail_free;
1980 }
1981
Damien Miller7acefbb2014-07-18 14:11:24 +10001982 if ((fwd->listen_port < 0 && fwd->listen_path == NULL) ||
1983 (!remotefwd && fwd->listen_port == 0))
Damien Millerf91ee4c2005-03-01 21:24:33 +11001984 goto fail_free;
Damien Millerf91ee4c2005-03-01 21:24:33 +11001985 if (fwd->connect_host != NULL &&
1986 strlen(fwd->connect_host) >= NI_MAXHOST)
1987 goto fail_free;
Damien Miller7acefbb2014-07-18 14:11:24 +10001988 /* XXX - if connecting to a remote socket, max sun len may not match this host */
1989 if (fwd->connect_path != NULL &&
1990 strlen(fwd->connect_path) >= PATH_MAX_SUN)
1991 goto fail_free;
Damien Miller4bf648f2009-02-14 16:28:21 +11001992 if (fwd->listen_host != NULL &&
1993 strlen(fwd->listen_host) >= NI_MAXHOST)
1994 goto fail_free;
Damien Miller7acefbb2014-07-18 14:11:24 +10001995 if (fwd->listen_path != NULL &&
1996 strlen(fwd->listen_path) >= PATH_MAX_SUN)
1997 goto fail_free;
Damien Millerf91ee4c2005-03-01 21:24:33 +11001998
1999 return (i);
2000
2001 fail_free:
Darren Tuckera627d422013-06-02 07:31:17 +10002002 free(fwd->connect_host);
2003 fwd->connect_host = NULL;
Damien Miller7acefbb2014-07-18 14:11:24 +10002004 free(fwd->connect_path);
2005 fwd->connect_path = NULL;
Darren Tuckera627d422013-06-02 07:31:17 +10002006 free(fwd->listen_host);
2007 fwd->listen_host = NULL;
Damien Miller7acefbb2014-07-18 14:11:24 +10002008 free(fwd->listen_path);
2009 fwd->listen_path = NULL;
Damien Millerf91ee4c2005-03-01 21:24:33 +11002010 return (0);
2011}