blob: 8e9a25da76b9b16040ed532da0fe6d125022b319 [file] [log] [blame]
markus@openbsd.orga3068632016-01-14 16:17:39 +00001/* $OpenBSD: readconf.c,v 1.248 2016/01/14 16:17:40 markus Exp $ */
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002/*
Damien Miller95def091999-11-25 00:26:21 +11003 * Author: Tatu Ylonen <ylo@cs.hut.fi>
Damien Miller95def091999-11-25 00:26:21 +11004 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
5 * All rights reserved
Damien Miller95def091999-11-25 00:26:21 +11006 * Functions for reading the configuration files.
Damien Miller4af51302000-04-16 11:18:38 +10007 *
Damien Millere4340be2000-09-16 13:29:08 +11008 * As far as I am concerned, the code I have written for this software
9 * can be used freely for any purpose. Any derived versions of this
10 * software must be clearly marked as such, and if the derived work is
11 * incompatible with the protocol description in the RFC file, it must be
12 * called by a name other than "ssh" or "Secure Shell".
Damien Miller95def091999-11-25 00:26:21 +110013 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100014
15#include "includes.h"
Damien Millerf17883e2006-03-15 11:45:54 +110016
17#include <sys/types.h>
18#include <sys/stat.h>
Damien Miller8ec8c3e2006-07-10 20:35:38 +100019#include <sys/socket.h>
Damien Miller194fd902013-10-15 12:13:05 +110020#include <sys/wait.h>
Damien Miller7acefbb2014-07-18 14:11:24 +100021#include <sys/un.h>
Damien Miller8ec8c3e2006-07-10 20:35:38 +100022
23#include <netinet/in.h>
Damien Miller0dac6fb2010-11-20 15:19:38 +110024#include <netinet/in_systm.h>
25#include <netinet/ip.h>
Darren Tucker0eeafcd2014-01-31 14:18:51 +110026#include <arpa/inet.h>
Damien Millerd4a8b7e1999-10-27 13:42:43 +100027
Damien Millerc7b06362006-03-15 11:53:45 +110028#include <ctype.h>
Darren Tucker39972492006-07-12 22:22:46 +100029#include <errno.h>
Damien Miller194fd902013-10-15 12:13:05 +110030#include <fcntl.h>
deraadt@openbsd.org2ae4f332015-01-16 06:40:12 +000031#include <limits.h>
Damien Millerb8fe89c2006-07-24 14:51:00 +100032#include <netdb.h>
Darren Tuckera3357662014-01-18 00:03:57 +110033#ifdef HAVE_PATHS_H
34# include <paths.h>
35#endif
Damien Miller194fd902013-10-15 12:13:05 +110036#include <pwd.h>
Damien Millerd7834352006-08-05 12:39:39 +100037#include <signal.h>
Damien Millerded319c2006-09-01 15:38:36 +100038#include <stdarg.h>
Damien Millera7a73ee2006-08-05 11:37:59 +100039#include <stdio.h>
Damien Millere3476ed2006-07-24 14:13:33 +100040#include <string.h>
Damien Millere6b3b612006-07-24 14:01:23 +100041#include <unistd.h>
Darren Tuckere194ba42013-05-16 20:47:31 +100042#ifdef HAVE_UTIL_H
Darren Tuckerb7ee8522013-05-16 20:33:10 +100043#include <util.h>
Darren Tuckere194ba42013-05-16 20:47:31 +100044#endif
djm@openbsd.org957fbce2014-10-08 22:20:25 +000045#if defined(HAVE_STRNVIS) && defined(HAVE_VIS_H) && !defined(BROKEN_STRNVIS)
46# include <vis.h>
47#endif
Damien Millerc7b06362006-03-15 11:53:45 +110048
Damien Millerd4a8b7e1999-10-27 13:42:43 +100049#include "xmalloc.h"
Damien Millerd7834352006-08-05 12:39:39 +100050#include "ssh.h"
Damien Miller78928792000-04-12 20:17:38 +100051#include "compat.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000052#include "cipher.h"
53#include "pathnames.h"
54#include "log.h"
djm@openbsd.org1129dcf2015-01-15 09:40:00 +000055#include "sshkey.h"
Damien Miller7acefbb2014-07-18 14:11:24 +100056#include "misc.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000057#include "readconf.h"
58#include "match.h"
Ben Lindstrom06b33aa2001-02-15 03:01:59 +000059#include "kex.h"
60#include "mac.h"
Damien Miller194fd902013-10-15 12:13:05 +110061#include "uidswap.h"
djm@openbsd.org957fbce2014-10-08 22:20:25 +000062#include "myproposal.h"
djm@openbsd.org56d1c832014-12-21 22:27:55 +000063#include "digest.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100064
65/* Format of the configuration file:
66
67 # Configuration data is parsed as follows:
68 # 1. command line options
69 # 2. user-specific file
70 # 3. system-wide file
71 # Any configuration value is only changed the first time it is set.
72 # Thus, host-specific definitions should be at the beginning of the
73 # configuration file, and defaults at the end.
74
75 # Host-specific declarations. These may override anything above. A single
76 # host may match multiple declarations; these are processed in the order
77 # that they are given in.
78
79 Host *.ngs.fi ngs.fi
Ben Lindstrom4daea862002-06-09 20:04:02 +000080 User foo
Damien Millerd4a8b7e1999-10-27 13:42:43 +100081
82 Host fake.com
83 HostName another.host.name.real.org
84 User blaah
85 Port 34289
86 ForwardX11 no
87 ForwardAgent no
88
89 Host books.com
90 RemoteForward 9999 shadows.cs.hut.fi:9999
91 Cipher 3des
92
93 Host fascist.blob.com
94 Port 23123
95 User tylonen
Damien Millerd4a8b7e1999-10-27 13:42:43 +100096 PasswordAuthentication no
97
98 Host puukko.hut.fi
99 User t35124p
100 ProxyCommand ssh-proxy %h %p
101
102 Host *.fr
Ben Lindstrom4daea862002-06-09 20:04:02 +0000103 PublicKeyAuthentication no
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000104
105 Host *.su
106 Cipher none
107 PasswordAuthentication no
108
Damien Millerd27b9472005-12-13 19:29:02 +1100109 Host vpn.fake.com
110 Tunnel yes
111 TunnelDevice 3
112
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000113 # Defaults for various options
114 Host *
115 ForwardAgent no
Damien Miller0bc1bd82000-11-13 22:57:25 +1100116 ForwardX11 no
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000117 PasswordAuthentication yes
118 RSAAuthentication yes
119 RhostsRSAAuthentication yes
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000120 StrictHostKeyChecking yes
Damien Miller12c150e2003-12-17 16:31:10 +1100121 TcpKeepAlive no
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000122 IdentityFile ~/.ssh/identity
123 Port 22
124 EscapeChar ~
125
126*/
127
128/* Keyword tokens. */
129
Damien Miller95def091999-11-25 00:26:21 +1100130typedef enum {
131 oBadOption,
Damien Miller194fd902013-10-15 12:13:05 +1100132 oHost, oMatch,
Damien Miller1ab6a512010-06-26 10:02:24 +1000133 oForwardAgent, oForwardX11, oForwardX11Trusted, oForwardX11Timeout,
134 oGatewayPorts, oExitOnForwardFailure,
Ben Lindstromcb72e4f2002-06-21 00:41:51 +0000135 oPasswordAuthentication, oRSAAuthentication,
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000136 oChallengeResponseAuthentication, oXAuthLocation,
Damien Miller95def091999-11-25 00:26:21 +1100137 oIdentityFile, oHostName, oPort, oCipher, oRemoteForward, oLocalForward,
jcs@openbsd.orgf361df42015-11-15 22:26:49 +0000138 oCertificateFile, oAddKeysToAgent,
Damien Miller194fd902013-10-15 12:13:05 +1100139 oUser, oEscapeChar, oRhostsRSAAuthentication, oProxyCommand,
Damien Miller95def091999-11-25 00:26:21 +1100140 oGlobalKnownHostsFile, oUserKnownHostsFile, oConnectionAttempts,
141 oBatchMode, oCheckHostIP, oStrictHostKeyChecking, oCompression,
Damien Miller12c150e2003-12-17 16:31:10 +1100142 oCompressionLevel, oTCPKeepAlive, oNumberOfPasswordPrompts,
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000143 oUsePrivilegedPort, oLogLevel, oCiphers, oProtocol, oMacs,
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000144 oPubkeyAuthentication,
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000145 oKbdInteractiveAuthentication, oKbdInteractiveDevices, oHostKeyAlias,
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000146 oDynamicForward, oPreferredAuthentications, oHostbasedAuthentication,
Damien Miller7ea845e2010-02-12 09:21:02 +1100147 oHostKeyAlgorithms, oBindAddress, oPKCS11Provider,
Ben Lindstrom4daea862002-06-09 20:04:02 +0000148 oClearAllForwardings, oNoHostAuthenticationForLocalhost,
Damien Millerb78d5eb2003-05-16 11:39:04 +1000149 oEnableSSHKeysign, oRekeyLimit, oVerifyHostKeyDNS, oConnectTimeout,
Darren Tucker0efd1552003-08-26 11:49:55 +1000150 oAddressFamily, oGssAuthentication, oGssDelegateCreds,
Damien Millerbd394c32004-03-08 23:12:36 +1100151 oServerAliveInterval, oServerAliveCountMax, oIdentitiesOnly,
Damien Millere11e1ea2010-08-03 16:04:46 +1000152 oSendEnv, oControlPath, oControlMaster, oControlPersist,
153 oHashKnownHosts,
Damien Millerd27b9472005-12-13 19:29:02 +1100154 oTunnel, oTunnelDevice, oLocalCommand, oPermitLocalCommand,
markus@openbsd.orga3068632016-01-14 16:17:39 +0000155 oVisualHostKey,
Damien Miller1262b662013-08-21 02:44:24 +1000156 oKexAlgorithms, oIPQoS, oRequestTTY, oIgnoreUnknown, oProxyUseFdpass,
Damien Miller38505592013-10-17 11:48:13 +1100157 oCanonicalDomains, oCanonicalizeHostname, oCanonicalizeMaxDots,
158 oCanonicalizeFallbackLocal, oCanonicalizePermittedCNAMEs,
djm@openbsd.org5e39a492014-12-04 02:24:32 +0000159 oStreamLocalBindMask, oStreamLocalBindUnlink, oRevokedHostKeys,
djm@openbsd.org46347ed2015-01-30 11:43:14 +0000160 oFingerprintHash, oUpdateHostkeys, oHostbasedKeyTypes,
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000161 oPubkeyAcceptedKeyTypes,
Darren Tucker07636982013-05-16 20:30:03 +1000162 oIgnoredUnknownOption, oDeprecated, oUnsupported
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000163} OpCodes;
164
165/* Textual representations of the tokens. */
166
Damien Miller95def091999-11-25 00:26:21 +1100167static struct {
168 const char *name;
169 OpCodes opcode;
170} keywords[] = {
171 { "forwardagent", oForwardAgent },
172 { "forwardx11", oForwardX11 },
Darren Tucker0a118da2003-10-15 15:54:32 +1000173 { "forwardx11trusted", oForwardX11Trusted },
Damien Miller1ab6a512010-06-26 10:02:24 +1000174 { "forwardx11timeout", oForwardX11Timeout },
Darren Tuckere7d4b192006-07-12 22:17:10 +1000175 { "exitonforwardfailure", oExitOnForwardFailure },
Damien Millerd3a18572000-06-07 19:55:44 +1000176 { "xauthlocation", oXAuthLocation },
Damien Miller95def091999-11-25 00:26:21 +1100177 { "gatewayports", oGatewayPorts },
178 { "useprivilegedport", oUsePrivilegedPort },
Darren Tuckerec960f22003-08-13 20:37:05 +1000179 { "rhostsauthentication", oDeprecated },
Damien Miller95def091999-11-25 00:26:21 +1100180 { "passwordauthentication", oPasswordAuthentication },
Damien Miller874d77b2000-10-14 16:23:11 +1100181 { "kbdinteractiveauthentication", oKbdInteractiveAuthentication },
182 { "kbdinteractivedevices", oKbdInteractiveDevices },
Damien Miller95def091999-11-25 00:26:21 +1100183 { "rsaauthentication", oRSAAuthentication },
Damien Miller0bc1bd82000-11-13 22:57:25 +1100184 { "pubkeyauthentication", oPubkeyAuthentication },
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000185 { "dsaauthentication", oPubkeyAuthentication }, /* alias */
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000186 { "rhostsrsaauthentication", oRhostsRSAAuthentication },
Ben Lindstromd69dab32001-04-12 23:36:05 +0000187 { "hostbasedauthentication", oHostbasedAuthentication },
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000188 { "challengeresponseauthentication", oChallengeResponseAuthentication },
189 { "skeyauthentication", oChallengeResponseAuthentication }, /* alias */
190 { "tisauthentication", oChallengeResponseAuthentication }, /* alias */
Damien Millerf9b3feb2003-05-16 11:38:32 +1000191 { "kerberosauthentication", oUnsupported },
192 { "kerberostgtpassing", oUnsupported },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000193 { "afstokenpassing", oUnsupported },
Darren Tucker0efd1552003-08-26 11:49:55 +1000194#if defined(GSSAPI)
195 { "gssapiauthentication", oGssAuthentication },
Darren Tucker0efd1552003-08-26 11:49:55 +1000196 { "gssapidelegatecredentials", oGssDelegateCreds },
197#else
198 { "gssapiauthentication", oUnsupported },
199 { "gssapidelegatecredentials", oUnsupported },
200#endif
Ben Lindstrom4daea862002-06-09 20:04:02 +0000201 { "fallbacktorsh", oDeprecated },
202 { "usersh", oDeprecated },
Damien Miller95def091999-11-25 00:26:21 +1100203 { "identityfile", oIdentityFile },
Damien Miller5bc6aae2009-01-28 16:27:31 +1100204 { "identityfile2", oIdentityFile }, /* obsolete */
Damien Millerbd394c32004-03-08 23:12:36 +1100205 { "identitiesonly", oIdentitiesOnly },
djm@openbsd.org4e44a792015-09-24 06:15:11 +0000206 { "certificatefile", oCertificateFile },
jcs@openbsd.orgf361df42015-11-15 22:26:49 +0000207 { "addkeystoagent", oAddKeysToAgent },
Damien Miller95def091999-11-25 00:26:21 +1100208 { "hostname", oHostName },
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000209 { "hostkeyalias", oHostKeyAlias },
Damien Miller95def091999-11-25 00:26:21 +1100210 { "proxycommand", oProxyCommand },
211 { "port", oPort },
212 { "cipher", oCipher },
Damien Miller78928792000-04-12 20:17:38 +1000213 { "ciphers", oCiphers },
Ben Lindstrom06b33aa2001-02-15 03:01:59 +0000214 { "macs", oMacs },
Damien Miller78928792000-04-12 20:17:38 +1000215 { "protocol", oProtocol },
Damien Miller95def091999-11-25 00:26:21 +1100216 { "remoteforward", oRemoteForward },
217 { "localforward", oLocalForward },
218 { "user", oUser },
219 { "host", oHost },
Damien Miller194fd902013-10-15 12:13:05 +1100220 { "match", oMatch },
Damien Miller95def091999-11-25 00:26:21 +1100221 { "escapechar", oEscapeChar },
Damien Miller95def091999-11-25 00:26:21 +1100222 { "globalknownhostsfile", oGlobalKnownHostsFile },
Damien Miller295ee632011-05-29 21:42:31 +1000223 { "globalknownhostsfile2", oDeprecated },
Damien Miller5bc6aae2009-01-28 16:27:31 +1100224 { "userknownhostsfile", oUserKnownHostsFile },
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000225 { "userknownhostsfile2", oDeprecated },
Damien Miller95def091999-11-25 00:26:21 +1100226 { "connectionattempts", oConnectionAttempts },
227 { "batchmode", oBatchMode },
228 { "checkhostip", oCheckHostIP },
229 { "stricthostkeychecking", oStrictHostKeyChecking },
230 { "compression", oCompression },
231 { "compressionlevel", oCompressionLevel },
Damien Miller12c150e2003-12-17 16:31:10 +1100232 { "tcpkeepalive", oTCPKeepAlive },
233 { "keepalive", oTCPKeepAlive }, /* obsolete */
Damien Miller95def091999-11-25 00:26:21 +1100234 { "numberofpasswordprompts", oNumberOfPasswordPrompts },
Damien Miller95def091999-11-25 00:26:21 +1100235 { "loglevel", oLogLevel },
Ben Lindstrom3bb4f9d2001-04-08 18:30:26 +0000236 { "dynamicforward", oDynamicForward },
Ben Lindstromb9be60a2001-03-11 01:49:19 +0000237 { "preferredauthentications", oPreferredAuthentications },
Ben Lindstrom982dbbc2001-04-17 18:11:36 +0000238 { "hostkeyalgorithms", oHostKeyAlgorithms },
Ben Lindstrome0f88042001-04-30 13:06:24 +0000239 { "bindaddress", oBindAddress },
Damien Miller7ea845e2010-02-12 09:21:02 +1100240#ifdef ENABLE_PKCS11
241 { "smartcarddevice", oPKCS11Provider },
242 { "pkcs11provider", oPKCS11Provider },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000243#else
244 { "smartcarddevice", oUnsupported },
Damien Miller7ea845e2010-02-12 09:21:02 +1100245 { "pkcs11provider", oUnsupported },
Damien Millerf9b3feb2003-05-16 11:38:32 +1000246#endif
Damien Miller9f0f5c62001-12-21 14:45:46 +1100247 { "clearallforwardings", oClearAllForwardings },
Ben Lindstromb6df73b2002-11-09 15:52:31 +0000248 { "enablesshkeysign", oEnableSSHKeysign },
Damien Miller37876e92003-05-15 10:19:46 +1000249 { "verifyhostkeydns", oVerifyHostKeyDNS },
Damien Miller9f0f5c62001-12-21 14:45:46 +1100250 { "nohostauthenticationforlocalhost", oNoHostAuthenticationForLocalhost },
Damien Millera5539d22003-04-09 20:50:06 +1000251 { "rekeylimit", oRekeyLimit },
Damien Millerb78d5eb2003-05-16 11:39:04 +1000252 { "connecttimeout", oConnectTimeout },
Damien Miller20a8f972003-05-18 20:50:30 +1000253 { "addressfamily", oAddressFamily },
Damien Miller509b0102003-12-17 16:33:10 +1100254 { "serveraliveinterval", oServerAliveInterval },
255 { "serveralivecountmax", oServerAliveCountMax },
Darren Tucker46bc0752004-05-02 22:11:30 +1000256 { "sendenv", oSendEnv },
Damien Miller0e220db2004-06-15 10:34:08 +1000257 { "controlpath", oControlPath },
258 { "controlmaster", oControlMaster },
Damien Millere11e1ea2010-08-03 16:04:46 +1000259 { "controlpersist", oControlPersist },
Damien Millere1776152005-03-01 21:47:37 +1100260 { "hashknownhosts", oHashKnownHosts },
Damien Millerd27b9472005-12-13 19:29:02 +1100261 { "tunnel", oTunnel },
262 { "tunneldevice", oTunnelDevice },
263 { "localcommand", oLocalCommand },
264 { "permitlocalcommand", oPermitLocalCommand },
Damien Miller10288242008-06-30 00:04:03 +1000265 { "visualhostkey", oVisualHostKey },
markus@openbsd.orga3068632016-01-14 16:17:39 +0000266 { "useroaming", oDeprecated },
Damien Millerd5f62bf2010-09-24 22:11:14 +1000267 { "kexalgorithms", oKexAlgorithms },
Damien Miller0dac6fb2010-11-20 15:19:38 +1100268 { "ipqos", oIPQoS },
Damien Miller21771e22011-05-15 08:45:50 +1000269 { "requesttty", oRequestTTY },
Damien Miller1262b662013-08-21 02:44:24 +1000270 { "proxyusefdpass", oProxyUseFdpass },
Damien Miller0faf7472013-10-17 11:47:23 +1100271 { "canonicaldomains", oCanonicalDomains },
Damien Miller38505592013-10-17 11:48:13 +1100272 { "canonicalizefallbacklocal", oCanonicalizeFallbackLocal },
273 { "canonicalizehostname", oCanonicalizeHostname },
274 { "canonicalizemaxdots", oCanonicalizeMaxDots },
275 { "canonicalizepermittedcnames", oCanonicalizePermittedCNAMEs },
Damien Miller7acefbb2014-07-18 14:11:24 +1000276 { "streamlocalbindmask", oStreamLocalBindMask },
277 { "streamlocalbindunlink", oStreamLocalBindUnlink },
djm@openbsd.org5e39a492014-12-04 02:24:32 +0000278 { "revokedhostkeys", oRevokedHostKeys },
djm@openbsd.org56d1c832014-12-21 22:27:55 +0000279 { "fingerprinthash", oFingerprintHash },
djm@openbsd.org8d4f8722015-01-26 03:04:45 +0000280 { "updatehostkeys", oUpdateHostkeys },
djm@openbsd.org46347ed2015-01-30 11:43:14 +0000281 { "hostbasedkeytypes", oHostbasedKeyTypes },
markus@openbsd.org3a1638d2015-07-10 06:21:53 +0000282 { "pubkeyacceptedkeytypes", oPubkeyAcceptedKeyTypes },
Darren Tucker07636982013-05-16 20:30:03 +1000283 { "ignoreunknown", oIgnoreUnknown },
Damien Miller01ed2272008-11-05 16:20:46 +1100284
Ben Lindstrom65366a82001-12-06 16:32:47 +0000285 { NULL, oBadOption }
Damien Miller5ce662a1999-11-11 17:57:39 +1100286};
287
Damien Miller5428f641999-11-25 11:54:57 +1100288/*
289 * Adds a local TCP/IP port forward to options. Never returns if there is an
290 * error.
291 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000292
Damien Miller4af51302000-04-16 11:18:38 +1000293void
Damien Miller7acefbb2014-07-18 14:11:24 +1000294add_local_forward(Options *options, const struct Forward *newfwd)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000295{
Damien Miller7acefbb2014-07-18 14:11:24 +1000296 struct Forward *fwd;
Ben Lindstrom99a4e142002-07-09 14:06:40 +0000297#ifndef NO_IPPORT_RESERVED_CONCEPT
Damien Miller95def091999-11-25 00:26:21 +1100298 extern uid_t original_real_uid;
Damien Miller7acefbb2014-07-18 14:11:24 +1000299 if (newfwd->listen_port < IPPORT_RESERVED && original_real_uid != 0 &&
300 newfwd->listen_path == NULL)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000301 fatal("Privileged ports can only be forwarded by root.");
Damien Millerbac2d8a2000-09-05 16:13:06 +1100302#endif
deraadt@openbsd.org657a5fb2015-04-24 01:36:00 +0000303 options->local_forwards = xreallocarray(options->local_forwards,
Damien Miller232cfb12010-06-26 09:50:30 +1000304 options->num_local_forwards + 1,
305 sizeof(*options->local_forwards));
Damien Miller95def091999-11-25 00:26:21 +1100306 fwd = &options->local_forwards[options->num_local_forwards++];
Damien Millerf91ee4c2005-03-01 21:24:33 +1100307
Damien Miller1a0442f2008-11-05 16:30:06 +1100308 fwd->listen_host = newfwd->listen_host;
Damien Millerf91ee4c2005-03-01 21:24:33 +1100309 fwd->listen_port = newfwd->listen_port;
Damien Miller7acefbb2014-07-18 14:11:24 +1000310 fwd->listen_path = newfwd->listen_path;
Damien Miller1a0442f2008-11-05 16:30:06 +1100311 fwd->connect_host = newfwd->connect_host;
Damien Millerf91ee4c2005-03-01 21:24:33 +1100312 fwd->connect_port = newfwd->connect_port;
Damien Miller7acefbb2014-07-18 14:11:24 +1000313 fwd->connect_path = newfwd->connect_path;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000314}
315
Damien Miller5428f641999-11-25 11:54:57 +1100316/*
317 * Adds a remote TCP/IP port forward to options. Never returns if there is
318 * an error.
319 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000320
Damien Miller4af51302000-04-16 11:18:38 +1000321void
Damien Miller7acefbb2014-07-18 14:11:24 +1000322add_remote_forward(Options *options, const struct Forward *newfwd)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000323{
Damien Miller7acefbb2014-07-18 14:11:24 +1000324 struct Forward *fwd;
Damien Miller232cfb12010-06-26 09:50:30 +1000325
deraadt@openbsd.org657a5fb2015-04-24 01:36:00 +0000326 options->remote_forwards = xreallocarray(options->remote_forwards,
Damien Miller232cfb12010-06-26 09:50:30 +1000327 options->num_remote_forwards + 1,
328 sizeof(*options->remote_forwards));
Damien Miller95def091999-11-25 00:26:21 +1100329 fwd = &options->remote_forwards[options->num_remote_forwards++];
Damien Millerf91ee4c2005-03-01 21:24:33 +1100330
Damien Miller1a0442f2008-11-05 16:30:06 +1100331 fwd->listen_host = newfwd->listen_host;
Damien Millerf91ee4c2005-03-01 21:24:33 +1100332 fwd->listen_port = newfwd->listen_port;
Damien Miller7acefbb2014-07-18 14:11:24 +1000333 fwd->listen_path = newfwd->listen_path;
Damien Miller1a0442f2008-11-05 16:30:06 +1100334 fwd->connect_host = newfwd->connect_host;
Damien Millerf91ee4c2005-03-01 21:24:33 +1100335 fwd->connect_port = newfwd->connect_port;
Damien Miller7acefbb2014-07-18 14:11:24 +1000336 fwd->connect_path = newfwd->connect_path;
Darren Tucker68afb8c2011-10-02 18:59:03 +1100337 fwd->handle = newfwd->handle;
Damien Miller388f6fc2010-05-21 14:57:35 +1000338 fwd->allocated_port = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000339}
340
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000341static void
342clear_forwardings(Options *options)
343{
344 int i;
345
Damien Millerf91ee4c2005-03-01 21:24:33 +1100346 for (i = 0; i < options->num_local_forwards; i++) {
Darren Tuckera627d422013-06-02 07:31:17 +1000347 free(options->local_forwards[i].listen_host);
Damien Miller7acefbb2014-07-18 14:11:24 +1000348 free(options->local_forwards[i].listen_path);
Darren Tuckera627d422013-06-02 07:31:17 +1000349 free(options->local_forwards[i].connect_host);
Damien Miller7acefbb2014-07-18 14:11:24 +1000350 free(options->local_forwards[i].connect_path);
Damien Millerf91ee4c2005-03-01 21:24:33 +1100351 }
Damien Miller232cfb12010-06-26 09:50:30 +1000352 if (options->num_local_forwards > 0) {
Darren Tuckera627d422013-06-02 07:31:17 +1000353 free(options->local_forwards);
Damien Miller232cfb12010-06-26 09:50:30 +1000354 options->local_forwards = NULL;
355 }
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000356 options->num_local_forwards = 0;
Damien Millerf91ee4c2005-03-01 21:24:33 +1100357 for (i = 0; i < options->num_remote_forwards; i++) {
Darren Tuckera627d422013-06-02 07:31:17 +1000358 free(options->remote_forwards[i].listen_host);
Damien Miller7acefbb2014-07-18 14:11:24 +1000359 free(options->remote_forwards[i].listen_path);
Darren Tuckera627d422013-06-02 07:31:17 +1000360 free(options->remote_forwards[i].connect_host);
Damien Miller7acefbb2014-07-18 14:11:24 +1000361 free(options->remote_forwards[i].connect_path);
Damien Millerf91ee4c2005-03-01 21:24:33 +1100362 }
Damien Miller232cfb12010-06-26 09:50:30 +1000363 if (options->num_remote_forwards > 0) {
Darren Tuckera627d422013-06-02 07:31:17 +1000364 free(options->remote_forwards);
Damien Miller232cfb12010-06-26 09:50:30 +1000365 options->remote_forwards = NULL;
366 }
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000367 options->num_remote_forwards = 0;
Damien Miller7b58e802005-12-13 19:33:19 +1100368 options->tun_open = SSH_TUNMODE_NO;
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000369}
370
Darren Tucker19104782013-04-05 11:13:08 +1100371void
djm@openbsd.org4e44a792015-09-24 06:15:11 +0000372add_certificate_file(Options *options, const char *path, int userprovided)
373{
374 int i;
375
376 if (options->num_certificate_files >= SSH_MAX_CERTIFICATE_FILES)
377 fatal("Too many certificate files specified (max %d)",
378 SSH_MAX_CERTIFICATE_FILES);
379
380 /* Avoid registering duplicates */
381 for (i = 0; i < options->num_certificate_files; i++) {
382 if (options->certificate_file_userprovided[i] == userprovided &&
383 strcmp(options->certificate_files[i], path) == 0) {
384 debug2("%s: ignoring duplicate key %s", __func__, path);
385 return;
386 }
387 }
388
389 options->certificate_file_userprovided[options->num_certificate_files] =
390 userprovided;
391 options->certificate_files[options->num_certificate_files++] =
392 xstrdup(path);
393}
394
395void
Darren Tucker19104782013-04-05 11:13:08 +1100396add_identity_file(Options *options, const char *dir, const char *filename,
397 int userprovided)
398{
399 char *path;
Damien Miller15271902014-05-15 13:47:56 +1000400 int i;
Darren Tucker19104782013-04-05 11:13:08 +1100401
402 if (options->num_identity_files >= SSH_MAX_IDENTITY_FILES)
403 fatal("Too many identity files specified (max %d)",
404 SSH_MAX_IDENTITY_FILES);
405
406 if (dir == NULL) /* no dir, filename is absolute */
407 path = xstrdup(filename);
408 else
409 (void)xasprintf(&path, "%.100s%.100s", dir, filename);
410
Damien Miller15271902014-05-15 13:47:56 +1000411 /* Avoid registering duplicates */
412 for (i = 0; i < options->num_identity_files; i++) {
413 if (options->identity_file_userprovided[i] == userprovided &&
414 strcmp(options->identity_files[i], path) == 0) {
415 debug2("%s: ignoring duplicate key %s", __func__, path);
416 free(path);
417 return;
418 }
419 }
420
Darren Tucker19104782013-04-05 11:13:08 +1100421 options->identity_file_userprovided[options->num_identity_files] =
422 userprovided;
423 options->identity_files[options->num_identity_files++] = path;
424}
425
Damien Miller194fd902013-10-15 12:13:05 +1100426int
427default_ssh_port(void)
428{
429 static int port;
430 struct servent *sp;
431
432 if (port == 0) {
433 sp = getservbyname(SSH_SERVICE_NAME, "tcp");
434 port = sp ? ntohs(sp->s_port) : SSH_DEFAULT_PORT;
435 }
436 return port;
437}
438
439/*
440 * Execute a command in a shell.
441 * Return its exit status or -1 on abnormal exit.
442 */
443static int
444execute_in_shell(const char *cmd)
445{
dtucker@openbsd.org97e184e2015-10-25 23:14:03 +0000446 char *shell;
Damien Miller194fd902013-10-15 12:13:05 +1100447 pid_t pid;
448 int devnull, status;
449 extern uid_t original_real_uid;
450
451 if ((shell = getenv("SHELL")) == NULL)
452 shell = _PATH_BSHELL;
453
Damien Miller194fd902013-10-15 12:13:05 +1100454 /* Need this to redirect subprocess stdin/out */
455 if ((devnull = open(_PATH_DEVNULL, O_RDWR)) == -1)
456 fatal("open(/dev/null): %s", strerror(errno));
457
458 debug("Executing command: '%.500s'", cmd);
459
460 /* Fork and execute the command. */
461 if ((pid = fork()) == 0) {
djm@openbsd.orga4aef3e2015-10-27 08:54:52 +0000462 char *argv[4];
Damien Miller194fd902013-10-15 12:13:05 +1100463
464 /* Child. Permanently give up superuser privileges. */
465 permanently_drop_suid(original_real_uid);
466
467 /* Redirect child stdin and stdout. Leave stderr */
468 if (dup2(devnull, STDIN_FILENO) == -1)
469 fatal("dup2: %s", strerror(errno));
470 if (dup2(devnull, STDOUT_FILENO) == -1)
471 fatal("dup2: %s", strerror(errno));
472 if (devnull > STDERR_FILENO)
473 close(devnull);
474 closefrom(STDERR_FILENO + 1);
475
djm@openbsd.orga4aef3e2015-10-27 08:54:52 +0000476 argv[0] = shell;
477 argv[1] = "-c";
478 argv[2] = xstrdup(cmd);
479 argv[3] = NULL;
480
Damien Miller194fd902013-10-15 12:13:05 +1100481 execv(argv[0], argv);
482 error("Unable to execute '%.100s': %s", cmd, strerror(errno));
483 /* Die with signal to make this error apparent to parent. */
484 signal(SIGTERM, SIG_DFL);
485 kill(getpid(), SIGTERM);
486 _exit(1);
487 }
488 /* Parent. */
489 if (pid < 0)
490 fatal("%s: fork: %.100s", __func__, strerror(errno));
491
492 close(devnull);
Damien Miller194fd902013-10-15 12:13:05 +1100493
494 while (waitpid(pid, &status, 0) == -1) {
495 if (errno != EINTR && errno != EAGAIN)
496 fatal("%s: waitpid: %s", __func__, strerror(errno));
497 }
498 if (!WIFEXITED(status)) {
499 error("command '%.100s' exited abnormally", cmd);
500 return -1;
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000501 }
Damien Miller194fd902013-10-15 12:13:05 +1100502 debug3("command returned status %d", WEXITSTATUS(status));
503 return WEXITSTATUS(status);
504}
505
506/*
507 * Parse and execute a Match directive.
508 */
509static int
510match_cfg_line(Options *options, char **condition, struct passwd *pw,
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000511 const char *host_arg, const char *original_host, int post_canon,
512 const char *filename, int linenum)
Damien Miller194fd902013-10-15 12:13:05 +1100513{
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000514 char *arg, *oattrib, *attrib, *cmd, *cp = *condition, *host, *criteria;
Damien Miller084bcd22013-10-23 16:30:51 +1100515 const char *ruser;
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000516 int r, port, this_result, result = 1, attributes = 0, negate;
Damien Miller194fd902013-10-15 12:13:05 +1100517 char thishost[NI_MAXHOST], shorthost[NI_MAXHOST], portstr[NI_MAXSERV];
518
519 /*
520 * Configuration is likely to be incomplete at this point so we
521 * must be prepared to use default values.
522 */
523 port = options->port <= 0 ? default_ssh_port() : options->port;
524 ruser = options->user == NULL ? pw->pw_name : options->user;
Damien Miller084bcd22013-10-23 16:30:51 +1100525 if (options->hostname != NULL) {
Damien Millereff5cad2013-10-23 16:31:10 +1100526 /* NB. Please keep in sync with ssh.c:main() */
Damien Miller084bcd22013-10-23 16:30:51 +1100527 host = percent_expand(options->hostname,
528 "h", host_arg, (char *)NULL);
529 } else
530 host = xstrdup(host_arg);
Damien Miller194fd902013-10-15 12:13:05 +1100531
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000532 debug2("checking match for '%s' host %s originally %s",
533 cp, host, original_host);
534 while ((oattrib = attrib = strdelim(&cp)) && *attrib != '\0') {
535 criteria = NULL;
536 this_result = 1;
537 if ((negate = attrib[0] == '!'))
538 attrib++;
539 /* criteria "all" and "canonical" have no argument */
Damien Millercf31f382013-10-24 21:02:56 +1100540 if (strcasecmp(attrib, "all") == 0) {
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000541 if (attributes > 1 ||
Damien Millercf31f382013-10-24 21:02:56 +1100542 ((arg = strdelim(&cp)) != NULL && *arg != '\0')) {
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000543 error("%.200s line %d: '%s' cannot be combined "
544 "with other Match attributes",
545 filename, linenum, oattrib);
Damien Millercf31f382013-10-24 21:02:56 +1100546 result = -1;
547 goto out;
548 }
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000549 if (result)
550 result = negate ? 0 : 1;
Damien Millercf31f382013-10-24 21:02:56 +1100551 goto out;
552 }
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000553 attributes++;
554 if (strcasecmp(attrib, "canonical") == 0) {
555 r = !!post_canon; /* force bitmask member to boolean */
556 if (r == (negate ? 1 : 0))
557 this_result = result = 0;
558 debug3("%.200s line %d: %smatched '%s'",
559 filename, linenum,
560 this_result ? "" : "not ", oattrib);
561 continue;
562 }
563 /* All other criteria require an argument */
Damien Miller194fd902013-10-15 12:13:05 +1100564 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
565 error("Missing Match criteria for %s", attrib);
Damien Miller084bcd22013-10-23 16:30:51 +1100566 result = -1;
567 goto out;
Damien Miller194fd902013-10-15 12:13:05 +1100568 }
Damien Miller194fd902013-10-15 12:13:05 +1100569 if (strcasecmp(attrib, "host") == 0) {
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000570 criteria = xstrdup(host);
djm@openbsd.orge661a862015-05-04 06:10:48 +0000571 r = match_hostname(host, arg) == 1;
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000572 if (r == (negate ? 1 : 0))
573 this_result = result = 0;
Damien Miller194fd902013-10-15 12:13:05 +1100574 } else if (strcasecmp(attrib, "originalhost") == 0) {
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000575 criteria = xstrdup(original_host);
djm@openbsd.orge661a862015-05-04 06:10:48 +0000576 r = match_hostname(original_host, arg) == 1;
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000577 if (r == (negate ? 1 : 0))
578 this_result = result = 0;
Damien Miller194fd902013-10-15 12:13:05 +1100579 } else if (strcasecmp(attrib, "user") == 0) {
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000580 criteria = xstrdup(ruser);
djm@openbsd.orge661a862015-05-04 06:10:48 +0000581 r = match_pattern_list(ruser, arg, 0) == 1;
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000582 if (r == (negate ? 1 : 0))
583 this_result = result = 0;
Damien Miller194fd902013-10-15 12:13:05 +1100584 } else if (strcasecmp(attrib, "localuser") == 0) {
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000585 criteria = xstrdup(pw->pw_name);
djm@openbsd.orge661a862015-05-04 06:10:48 +0000586 r = match_pattern_list(pw->pw_name, arg, 0) == 1;
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000587 if (r == (negate ? 1 : 0))
588 this_result = result = 0;
Damien Miller8a04be72013-10-23 16:29:40 +1100589 } else if (strcasecmp(attrib, "exec") == 0) {
Damien Miller194fd902013-10-15 12:13:05 +1100590 if (gethostname(thishost, sizeof(thishost)) == -1)
591 fatal("gethostname: %s", strerror(errno));
592 strlcpy(shorthost, thishost, sizeof(shorthost));
593 shorthost[strcspn(thishost, ".")] = '\0';
594 snprintf(portstr, sizeof(portstr), "%d", port);
595
596 cmd = percent_expand(arg,
597 "L", shorthost,
598 "d", pw->pw_dir,
599 "h", host,
600 "l", thishost,
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000601 "n", original_host,
Damien Miller194fd902013-10-15 12:13:05 +1100602 "p", portstr,
603 "r", ruser,
604 "u", pw->pw_name,
605 (char *)NULL);
Damien Miller06287802014-02-24 15:56:45 +1100606 if (result != 1) {
607 /* skip execution if prior predicate failed */
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000608 debug3("%.200s line %d: skipped exec "
609 "\"%.100s\"", filename, linenum, cmd);
610 free(cmd);
611 continue;
Damien Miller06287802014-02-24 15:56:45 +1100612 }
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000613 r = execute_in_shell(cmd);
614 if (r == -1) {
615 fatal("%.200s line %d: match exec "
616 "'%.100s' error", filename,
617 linenum, cmd);
618 }
619 criteria = xstrdup(cmd);
Damien Miller194fd902013-10-15 12:13:05 +1100620 free(cmd);
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000621 /* Force exit status to boolean */
622 r = r == 0;
623 if (r == (negate ? 1 : 0))
624 this_result = result = 0;
Damien Miller194fd902013-10-15 12:13:05 +1100625 } else {
626 error("Unsupported Match attribute %s", attrib);
Damien Miller084bcd22013-10-23 16:30:51 +1100627 result = -1;
628 goto out;
Damien Miller194fd902013-10-15 12:13:05 +1100629 }
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000630 debug3("%.200s line %d: %smatched '%s \"%.100s\"' ",
631 filename, linenum, this_result ? "": "not ",
632 oattrib, criteria);
633 free(criteria);
Damien Miller194fd902013-10-15 12:13:05 +1100634 }
Damien Millercf31f382013-10-24 21:02:56 +1100635 if (attributes == 0) {
636 error("One or more attributes required for Match");
637 result = -1;
638 goto out;
639 }
Damien Miller084bcd22013-10-23 16:30:51 +1100640 out:
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000641 if (result != -1)
642 debug2("match %sfound", result ? "" : "not ");
643 *condition = cp;
Damien Miller084bcd22013-10-23 16:30:51 +1100644 free(host);
Damien Miller194fd902013-10-15 12:13:05 +1100645 return result;
646}
647
Damien Miller0faf7472013-10-17 11:47:23 +1100648/* Check and prepare a domain name: removes trailing '.' and lowercases */
649static void
650valid_domain(char *name, const char *filename, int linenum)
651{
652 size_t i, l = strlen(name);
653 u_char c, last = '\0';
654
655 if (l == 0)
656 fatal("%s line %d: empty hostname suffix", filename, linenum);
657 if (!isalpha((u_char)name[0]) && !isdigit((u_char)name[0]))
658 fatal("%s line %d: hostname suffix \"%.100s\" "
659 "starts with invalid character", filename, linenum, name);
660 for (i = 0; i < l; i++) {
661 c = tolower((u_char)name[i]);
662 name[i] = (char)c;
663 if (last == '.' && c == '.')
664 fatal("%s line %d: hostname suffix \"%.100s\" contains "
665 "consecutive separators", filename, linenum, name);
666 if (c != '.' && c != '-' && !isalnum(c) &&
667 c != '_') /* technically invalid, but common */
668 fatal("%s line %d: hostname suffix \"%.100s\" contains "
669 "invalid characters", filename, linenum, name);
670 last = c;
671 }
672 if (name[l - 1] == '.')
673 name[l - 1] = '\0';
674}
675
Damien Miller5428f641999-11-25 11:54:57 +1100676/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000677 * Returns the number of the token pointed to by cp or oBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100678 */
Damien Miller4af51302000-04-16 11:18:38 +1000679static OpCodes
Darren Tucker07636982013-05-16 20:30:03 +1000680parse_token(const char *cp, const char *filename, int linenum,
681 const char *ignored_unknown)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000682{
Darren Tucker07636982013-05-16 20:30:03 +1000683 int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000684
Damien Miller95def091999-11-25 00:26:21 +1100685 for (i = 0; keywords[i].name; i++)
Darren Tucker07636982013-05-16 20:30:03 +1000686 if (strcmp(cp, keywords[i].name) == 0)
Damien Miller95def091999-11-25 00:26:21 +1100687 return keywords[i].opcode;
djm@openbsd.orge661a862015-05-04 06:10:48 +0000688 if (ignored_unknown != NULL &&
689 match_pattern_list(cp, ignored_unknown, 1) == 1)
Darren Tucker07636982013-05-16 20:30:03 +1000690 return oIgnoredUnknownOption;
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000691 error("%s: line %d: Bad configuration option: %s",
692 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100693 return oBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000694}
695
Damien Millere9fc72e2013-10-15 12:14:12 +1100696/* Multistate option parsing */
697struct multistate {
698 char *key;
699 int value;
700};
701static const struct multistate multistate_flag[] = {
702 { "true", 1 },
703 { "false", 0 },
704 { "yes", 1 },
705 { "no", 0 },
706 { NULL, -1 }
707};
708static const struct multistate multistate_yesnoask[] = {
709 { "true", 1 },
710 { "false", 0 },
711 { "yes", 1 },
712 { "no", 0 },
713 { "ask", 2 },
714 { NULL, -1 }
715};
jcs@openbsd.orgf361df42015-11-15 22:26:49 +0000716static const struct multistate multistate_yesnoaskconfirm[] = {
717 { "true", 1 },
718 { "false", 0 },
719 { "yes", 1 },
720 { "no", 0 },
721 { "ask", 2 },
722 { "confirm", 3 },
723 { NULL, -1 }
724};
Damien Millere9fc72e2013-10-15 12:14:12 +1100725static const struct multistate multistate_addressfamily[] = {
726 { "inet", AF_INET },
727 { "inet6", AF_INET6 },
728 { "any", AF_UNSPEC },
729 { NULL, -1 }
730};
731static const struct multistate multistate_controlmaster[] = {
732 { "true", SSHCTL_MASTER_YES },
733 { "yes", SSHCTL_MASTER_YES },
734 { "false", SSHCTL_MASTER_NO },
735 { "no", SSHCTL_MASTER_NO },
736 { "auto", SSHCTL_MASTER_AUTO },
737 { "ask", SSHCTL_MASTER_ASK },
738 { "autoask", SSHCTL_MASTER_AUTO_ASK },
739 { NULL, -1 }
740};
741static const struct multistate multistate_tunnel[] = {
742 { "ethernet", SSH_TUNMODE_ETHERNET },
743 { "point-to-point", SSH_TUNMODE_POINTOPOINT },
744 { "true", SSH_TUNMODE_DEFAULT },
745 { "yes", SSH_TUNMODE_DEFAULT },
746 { "false", SSH_TUNMODE_NO },
747 { "no", SSH_TUNMODE_NO },
748 { NULL, -1 }
749};
750static const struct multistate multistate_requesttty[] = {
751 { "true", REQUEST_TTY_YES },
752 { "yes", REQUEST_TTY_YES },
753 { "false", REQUEST_TTY_NO },
754 { "no", REQUEST_TTY_NO },
755 { "force", REQUEST_TTY_FORCE },
756 { "auto", REQUEST_TTY_AUTO },
757 { NULL, -1 }
758};
Damien Miller38505592013-10-17 11:48:13 +1100759static const struct multistate multistate_canonicalizehostname[] = {
Damien Miller0faf7472013-10-17 11:47:23 +1100760 { "true", SSH_CANONICALISE_YES },
761 { "false", SSH_CANONICALISE_NO },
762 { "yes", SSH_CANONICALISE_YES },
763 { "no", SSH_CANONICALISE_NO },
764 { "always", SSH_CANONICALISE_ALWAYS },
765 { NULL, -1 }
766};
Damien Millere9fc72e2013-10-15 12:14:12 +1100767
Damien Miller5428f641999-11-25 11:54:57 +1100768/*
769 * Processes a single option line as used in the configuration files. This
770 * only sets those values that have not already been set.
771 */
Damien Miller61f08ac2003-02-24 11:56:27 +1100772#define WHITESPACE " \t\r\n"
Damien Miller2ccf6611999-11-15 15:25:10 +1100773int
Damien Miller194fd902013-10-15 12:13:05 +1100774process_config_line(Options *options, struct passwd *pw, const char *host,
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000775 const char *original_host, char *line, const char *filename,
776 int linenum, int *activep, int flags)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000777{
Damien Miller295ee632011-05-29 21:42:31 +1000778 char *s, **charptr, *endofnumber, *keyword, *arg, *arg2;
779 char **cpptr, fwdarg[256];
Darren Tucker07636982013-05-16 20:30:03 +1000780 u_int i, *uintptr, max_entries = 0;
Damien Miller194fd902013-10-15 12:13:05 +1100781 int negated, opcode, *intptr, value, value2, cmdline = 0;
Darren Tucker1e44c5d2008-01-01 20:32:26 +1100782 LogLevel *log_level_ptr;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000783 long long val64;
Damien Miller61f08ac2003-02-24 11:56:27 +1100784 size_t len;
Damien Miller7acefbb2014-07-18 14:11:24 +1000785 struct Forward fwd;
Damien Millere9fc72e2013-10-15 12:14:12 +1100786 const struct multistate *multistate_ptr;
Damien Miller0faf7472013-10-17 11:47:23 +1100787 struct allowed_cname *cname;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000788
Damien Miller194fd902013-10-15 12:13:05 +1100789 if (activep == NULL) { /* We are processing a command line directive */
790 cmdline = 1;
791 activep = &cmdline;
792 }
793
Damien Millerc652cac2003-05-14 13:40:54 +1000794 /* Strip trailing whitespace */
djm@openbsd.org26e0bcf2015-03-30 00:00:29 +0000795 if ((len = strlen(line)) == 0)
796 return 0;
797 for (len--; len > 0; len--) {
Damien Millerc652cac2003-05-14 13:40:54 +1000798 if (strchr(WHITESPACE, line[len]) == NULL)
799 break;
800 line[len] = '\0';
801 }
802
Damien Millerbe484b52000-07-15 14:14:16 +1000803 s = line;
804 /* Get the keyword. (Each line is supposed to begin with a keyword). */
Damien Miller928b2362006-03-26 13:53:32 +1100805 if ((keyword = strdelim(&s)) == NULL)
806 return 0;
Damien Millerbe484b52000-07-15 14:14:16 +1000807 /* Ignore leading whitespace. */
808 if (*keyword == '\0')
809 keyword = strdelim(&s);
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000810 if (keyword == NULL || !*keyword || *keyword == '\n' || *keyword == '#')
Damien Miller95def091999-11-25 00:26:21 +1100811 return 0;
Darren Tucker07636982013-05-16 20:30:03 +1000812 /* Match lowercase keyword */
Damien Millere9fc72e2013-10-15 12:14:12 +1100813 lowercase(keyword);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000814
Darren Tucker07636982013-05-16 20:30:03 +1000815 opcode = parse_token(keyword, filename, linenum,
816 options->ignored_unknown);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000817
Damien Miller95def091999-11-25 00:26:21 +1100818 switch (opcode) {
819 case oBadOption:
Damien Miller5428f641999-11-25 11:54:57 +1100820 /* don't panic, but count bad options */
821 return -1;
Damien Miller95def091999-11-25 00:26:21 +1100822 /* NOTREACHED */
Darren Tucker07636982013-05-16 20:30:03 +1000823 case oIgnoredUnknownOption:
824 debug("%s line %d: Ignored unknown option \"%s\"",
825 filename, linenum, keyword);
826 return 0;
Damien Millerb78d5eb2003-05-16 11:39:04 +1000827 case oConnectTimeout:
828 intptr = &options->connection_timeout;
Damien Miller509b0102003-12-17 16:33:10 +1100829parse_time:
Damien Millerb78d5eb2003-05-16 11:39:04 +1000830 arg = strdelim(&s);
831 if (!arg || *arg == '\0')
832 fatal("%s line %d: missing time value.",
833 filename, linenum);
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000834 if (strcmp(arg, "none") == 0)
835 value = -1;
836 else if ((value = convtime(arg)) == -1)
Damien Millerb78d5eb2003-05-16 11:39:04 +1000837 fatal("%s line %d: invalid time value.",
838 filename, linenum);
Darren Tuckera52c5b62007-02-19 22:09:45 +1100839 if (*activep && *intptr == -1)
Damien Millerb78d5eb2003-05-16 11:39:04 +1000840 *intptr = value;
841 break;
842
Damien Miller95def091999-11-25 00:26:21 +1100843 case oForwardAgent:
844 intptr = &options->forward_agent;
Damien Millere9fc72e2013-10-15 12:14:12 +1100845 parse_flag:
846 multistate_ptr = multistate_flag;
847 parse_multistate:
Damien Millerbe484b52000-07-15 14:14:16 +1000848 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000849 if (!arg || *arg == '\0')
Damien Millere9fc72e2013-10-15 12:14:12 +1100850 fatal("%s line %d: missing argument.",
851 filename, linenum);
852 value = -1;
853 for (i = 0; multistate_ptr[i].key != NULL; i++) {
854 if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
855 value = multistate_ptr[i].value;
856 break;
857 }
858 }
859 if (value == -1)
860 fatal("%s line %d: unsupported option \"%s\".",
861 filename, linenum, arg);
Damien Miller95def091999-11-25 00:26:21 +1100862 if (*activep && *intptr == -1)
863 *intptr = value;
864 break;
865
866 case oForwardX11:
867 intptr = &options->forward_x11;
868 goto parse_flag;
869
Darren Tucker0a118da2003-10-15 15:54:32 +1000870 case oForwardX11Trusted:
871 intptr = &options->forward_x11_trusted;
872 goto parse_flag;
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000873
Damien Miller1ab6a512010-06-26 10:02:24 +1000874 case oForwardX11Timeout:
875 intptr = &options->forward_x11_timeout;
876 goto parse_time;
Darren Tucker0a118da2003-10-15 15:54:32 +1000877
Damien Miller95def091999-11-25 00:26:21 +1100878 case oGatewayPorts:
Damien Miller7acefbb2014-07-18 14:11:24 +1000879 intptr = &options->fwd_opts.gateway_ports;
Damien Miller95def091999-11-25 00:26:21 +1100880 goto parse_flag;
881
Darren Tuckere7d4b192006-07-12 22:17:10 +1000882 case oExitOnForwardFailure:
883 intptr = &options->exit_on_forward_failure;
884 goto parse_flag;
885
Damien Miller95def091999-11-25 00:26:21 +1100886 case oUsePrivilegedPort:
887 intptr = &options->use_privileged_port;
888 goto parse_flag;
889
Damien Miller95def091999-11-25 00:26:21 +1100890 case oPasswordAuthentication:
891 intptr = &options->password_authentication;
892 goto parse_flag;
893
Damien Miller874d77b2000-10-14 16:23:11 +1100894 case oKbdInteractiveAuthentication:
895 intptr = &options->kbd_interactive_authentication;
896 goto parse_flag;
897
898 case oKbdInteractiveDevices:
899 charptr = &options->kbd_interactive_devices;
900 goto parse_string;
901
Damien Miller0bc1bd82000-11-13 22:57:25 +1100902 case oPubkeyAuthentication:
903 intptr = &options->pubkey_authentication;
Damien Millere247cc42000-05-07 12:03:14 +1000904 goto parse_flag;
905
Damien Miller95def091999-11-25 00:26:21 +1100906 case oRSAAuthentication:
907 intptr = &options->rsa_authentication;
908 goto parse_flag;
909
910 case oRhostsRSAAuthentication:
911 intptr = &options->rhosts_rsa_authentication;
912 goto parse_flag;
913
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000914 case oHostbasedAuthentication:
915 intptr = &options->hostbased_authentication;
916 goto parse_flag;
917
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000918 case oChallengeResponseAuthentication:
Ben Lindstrom551ea372001-06-05 18:56:16 +0000919 intptr = &options->challenge_response_authentication;
Damien Miller95def091999-11-25 00:26:21 +1100920 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000921
Darren Tucker0efd1552003-08-26 11:49:55 +1000922 case oGssAuthentication:
923 intptr = &options->gss_authentication;
924 goto parse_flag;
925
926 case oGssDelegateCreds:
927 intptr = &options->gss_deleg_creds;
928 goto parse_flag;
929
Damien Miller95def091999-11-25 00:26:21 +1100930 case oBatchMode:
931 intptr = &options->batch_mode;
932 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000933
Damien Miller95def091999-11-25 00:26:21 +1100934 case oCheckHostIP:
935 intptr = &options->check_host_ip;
Damien Miller10288242008-06-30 00:04:03 +1000936 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000937
Damien Miller37876e92003-05-15 10:19:46 +1000938 case oVerifyHostKeyDNS:
939 intptr = &options->verify_host_key_dns;
Damien Millere9fc72e2013-10-15 12:14:12 +1100940 multistate_ptr = multistate_yesnoask;
941 goto parse_multistate;
Damien Miller37876e92003-05-15 10:19:46 +1000942
Damien Miller95def091999-11-25 00:26:21 +1100943 case oStrictHostKeyChecking:
944 intptr = &options->strict_host_key_checking;
Damien Millere9fc72e2013-10-15 12:14:12 +1100945 multistate_ptr = multistate_yesnoask;
946 goto parse_multistate;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000947
Damien Miller95def091999-11-25 00:26:21 +1100948 case oCompression:
949 intptr = &options->compression;
950 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000951
Damien Miller12c150e2003-12-17 16:31:10 +1100952 case oTCPKeepAlive:
953 intptr = &options->tcp_keep_alive;
Damien Miller95def091999-11-25 00:26:21 +1100954 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000955
Ben Lindstrom3cecc9a2001-10-03 17:39:38 +0000956 case oNoHostAuthenticationForLocalhost:
957 intptr = &options->no_host_authentication_for_localhost;
958 goto parse_flag;
959
Damien Miller95def091999-11-25 00:26:21 +1100960 case oNumberOfPasswordPrompts:
961 intptr = &options->number_of_password_prompts;
962 goto parse_int;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000963
Damien Miller95def091999-11-25 00:26:21 +1100964 case oCompressionLevel:
965 intptr = &options->compression_level;
966 goto parse_int;
967
Damien Millera5539d22003-04-09 20:50:06 +1000968 case oRekeyLimit:
Damien Millera5539d22003-04-09 20:50:06 +1000969 arg = strdelim(&s);
970 if (!arg || *arg == '\0')
Darren Tuckerc53c2af2013-05-16 20:28:16 +1000971 fatal("%.200s line %d: Missing argument.", filename,
972 linenum);
973 if (strcmp(arg, "default") == 0) {
974 val64 = 0;
975 } else {
Darren Tuckerb7ee8522013-05-16 20:33:10 +1000976 if (scan_scaled(arg, &val64) == -1)
977 fatal("%.200s line %d: Bad number '%s': %s",
978 filename, linenum, arg, strerror(errno));
979 /* check for too-large or too-small limits */
980 if (val64 > UINT_MAX)
Darren Tuckerc53c2af2013-05-16 20:28:16 +1000981 fatal("%.200s line %d: RekeyLimit too large",
982 filename, linenum);
983 if (val64 != 0 && val64 < 16)
984 fatal("%.200s line %d: RekeyLimit too small",
985 filename, linenum);
Damien Millera5539d22003-04-09 20:50:06 +1000986 }
Damien Miller3dff1762008-02-10 22:25:52 +1100987 if (*activep && options->rekey_limit == -1)
988 options->rekey_limit = (u_int32_t)val64;
Darren Tuckerc53c2af2013-05-16 20:28:16 +1000989 if (s != NULL) { /* optional rekey interval present */
990 if (strcmp(s, "none") == 0) {
991 (void)strdelim(&s); /* discard */
992 break;
993 }
994 intptr = &options->rekey_interval;
995 goto parse_time;
996 }
Damien Millera5539d22003-04-09 20:50:06 +1000997 break;
998
Damien Miller95def091999-11-25 00:26:21 +1100999 case oIdentityFile:
Damien Millerbe484b52000-07-15 14:14:16 +10001000 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +10001001 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +11001002 fatal("%.200s line %d: Missing argument.", filename, linenum);
1003 if (*activep) {
Damien Miller0bc1bd82000-11-13 22:57:25 +11001004 intptr = &options->num_identity_files;
Damien Millereba71ba2000-04-29 23:57:08 +10001005 if (*intptr >= SSH_MAX_IDENTITY_FILES)
Damien Miller95def091999-11-25 00:26:21 +11001006 fatal("%.200s line %d: Too many identity files specified (max %d).",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001007 filename, linenum, SSH_MAX_IDENTITY_FILES);
djm@openbsd.org957fbce2014-10-08 22:20:25 +00001008 add_identity_file(options, NULL,
1009 arg, flags & SSHCONF_USERCONF);
Damien Miller95def091999-11-25 00:26:21 +11001010 }
1011 break;
1012
djm@openbsd.org4e44a792015-09-24 06:15:11 +00001013 case oCertificateFile:
1014 arg = strdelim(&s);
1015 if (!arg || *arg == '\0')
1016 fatal("%.200s line %d: Missing argument.",
1017 filename, linenum);
1018 if (*activep) {
1019 intptr = &options->num_certificate_files;
1020 if (*intptr >= SSH_MAX_CERTIFICATE_FILES) {
1021 fatal("%.200s line %d: Too many certificate "
1022 "files specified (max %d).",
1023 filename, linenum,
1024 SSH_MAX_CERTIFICATE_FILES);
1025 }
1026 add_certificate_file(options, arg,
1027 flags & SSHCONF_USERCONF);
1028 }
1029 break;
1030
Damien Millerd3a18572000-06-07 19:55:44 +10001031 case oXAuthLocation:
1032 charptr=&options->xauth_location;
1033 goto parse_string;
1034
Damien Miller95def091999-11-25 00:26:21 +11001035 case oUser:
1036 charptr = &options->user;
1037parse_string:
Damien Millerbe484b52000-07-15 14:14:16 +10001038 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +10001039 if (!arg || *arg == '\0')
Damien Miller295ee632011-05-29 21:42:31 +10001040 fatal("%.200s line %d: Missing argument.",
1041 filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +11001042 if (*activep && *charptr == NULL)
Damien Miller37023962000-07-11 17:31:38 +10001043 *charptr = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +11001044 break;
1045
1046 case oGlobalKnownHostsFile:
Damien Miller295ee632011-05-29 21:42:31 +10001047 cpptr = (char **)&options->system_hostfiles;
1048 uintptr = &options->num_system_hostfiles;
1049 max_entries = SSH_MAX_HOSTS_FILES;
1050parse_char_array:
1051 if (*activep && *uintptr == 0) {
1052 while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1053 if ((*uintptr) >= max_entries)
1054 fatal("%s line %d: "
1055 "too many authorized keys files.",
1056 filename, linenum);
1057 cpptr[(*uintptr)++] = xstrdup(arg);
1058 }
1059 }
1060 return 0;
Damien Miller95def091999-11-25 00:26:21 +11001061
1062 case oUserKnownHostsFile:
Damien Miller295ee632011-05-29 21:42:31 +10001063 cpptr = (char **)&options->user_hostfiles;
1064 uintptr = &options->num_user_hostfiles;
1065 max_entries = SSH_MAX_HOSTS_FILES;
1066 goto parse_char_array;
Damien Millereba71ba2000-04-29 23:57:08 +10001067
Damien Miller95def091999-11-25 00:26:21 +11001068 case oHostName:
1069 charptr = &options->hostname;
1070 goto parse_string;
1071
Ben Lindstrom4dccfa52000-12-28 16:40:05 +00001072 case oHostKeyAlias:
1073 charptr = &options->host_key_alias;
1074 goto parse_string;
1075
Ben Lindstromb9be60a2001-03-11 01:49:19 +00001076 case oPreferredAuthentications:
1077 charptr = &options->preferred_authentications;
1078 goto parse_string;
1079
Ben Lindstrome0f88042001-04-30 13:06:24 +00001080 case oBindAddress:
1081 charptr = &options->bind_address;
1082 goto parse_string;
1083
Damien Miller7ea845e2010-02-12 09:21:02 +11001084 case oPKCS11Provider:
1085 charptr = &options->pkcs11_provider;
Ben Lindstromf7db3bb2001-08-06 21:35:51 +00001086 goto parse_string;
Ben Lindstromae996bf2001-08-06 21:27:53 +00001087
Damien Miller95def091999-11-25 00:26:21 +11001088 case oProxyCommand:
Damien Millerd27b9472005-12-13 19:29:02 +11001089 charptr = &options->proxy_command;
1090parse_command:
Darren Tuckera99c1b72003-06-28 12:40:12 +10001091 if (s == NULL)
1092 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller61f08ac2003-02-24 11:56:27 +11001093 len = strspn(s, WHITESPACE "=");
Damien Miller95def091999-11-25 00:26:21 +11001094 if (*activep && *charptr == NULL)
Damien Miller61f08ac2003-02-24 11:56:27 +11001095 *charptr = xstrdup(s + len);
Damien Miller95def091999-11-25 00:26:21 +11001096 return 0;
1097
1098 case oPort:
1099 intptr = &options->port;
1100parse_int:
Damien Millerbe484b52000-07-15 14:14:16 +10001101 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +10001102 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +11001103 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +10001104 if (arg[0] < '0' || arg[0] > '9')
Damien Miller95def091999-11-25 00:26:21 +11001105 fatal("%.200s line %d: Bad number.", filename, linenum);
Damien Miller5428f641999-11-25 11:54:57 +11001106
1107 /* Octal, decimal, or hex format? */
Damien Miller37023962000-07-11 17:31:38 +10001108 value = strtol(arg, &endofnumber, 0);
1109 if (arg == endofnumber)
Damien Miller5428f641999-11-25 11:54:57 +11001110 fatal("%.200s line %d: Bad number.", filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +11001111 if (*activep && *intptr == -1)
1112 *intptr = value;
1113 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001114
Damien Miller95def091999-11-25 00:26:21 +11001115 case oConnectionAttempts:
1116 intptr = &options->connection_attempts;
1117 goto parse_int;
Damien Miller5ce662a1999-11-11 17:57:39 +11001118
Damien Miller95def091999-11-25 00:26:21 +11001119 case oCipher:
1120 intptr = &options->cipher;
Damien Millerbe484b52000-07-15 14:14:16 +10001121 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +10001122 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +10001123 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +10001124 value = cipher_number(arg);
Damien Miller95def091999-11-25 00:26:21 +11001125 if (value == -1)
1126 fatal("%.200s line %d: Bad cipher '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001127 filename, linenum, arg ? arg : "<NONE>");
Damien Miller95def091999-11-25 00:26:21 +11001128 if (*activep && *intptr == -1)
1129 *intptr = value;
1130 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001131
Damien Miller78928792000-04-12 20:17:38 +10001132 case oCiphers:
Damien Millerbe484b52000-07-15 14:14:16 +10001133 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +10001134 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +10001135 fatal("%.200s line %d: Missing argument.", filename, linenum);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +00001136 if (!ciphers_valid(*arg == '+' ? arg + 1 : arg))
Damien Miller30c3d422000-05-09 11:02:59 +10001137 fatal("%.200s line %d: Bad SSH2 cipher spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001138 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +10001139 if (*activep && options->ciphers == NULL)
Damien Miller37023962000-07-11 17:31:38 +10001140 options->ciphers = xstrdup(arg);
Damien Miller78928792000-04-12 20:17:38 +10001141 break;
1142
Ben Lindstrom06b33aa2001-02-15 03:01:59 +00001143 case oMacs:
1144 arg = strdelim(&s);
1145 if (!arg || *arg == '\0')
1146 fatal("%.200s line %d: Missing argument.", filename, linenum);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +00001147 if (!mac_valid(*arg == '+' ? arg + 1 : arg))
Ben Lindstrom06b33aa2001-02-15 03:01:59 +00001148 fatal("%.200s line %d: Bad SSH2 Mac spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001149 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstrom06b33aa2001-02-15 03:01:59 +00001150 if (*activep && options->macs == NULL)
1151 options->macs = xstrdup(arg);
1152 break;
1153
Damien Millerd5f62bf2010-09-24 22:11:14 +10001154 case oKexAlgorithms:
1155 arg = strdelim(&s);
1156 if (!arg || *arg == '\0')
1157 fatal("%.200s line %d: Missing argument.",
1158 filename, linenum);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +00001159 if (!kex_names_valid(*arg == '+' ? arg + 1 : arg))
Damien Millerd5f62bf2010-09-24 22:11:14 +10001160 fatal("%.200s line %d: Bad SSH2 KexAlgorithms '%s'.",
1161 filename, linenum, arg ? arg : "<NONE>");
1162 if (*activep && options->kex_algorithms == NULL)
1163 options->kex_algorithms = xstrdup(arg);
1164 break;
1165
Ben Lindstrom982dbbc2001-04-17 18:11:36 +00001166 case oHostKeyAlgorithms:
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00001167 charptr = &options->hostkeyalgorithms;
1168parse_keytypes:
Ben Lindstrom982dbbc2001-04-17 18:11:36 +00001169 arg = strdelim(&s);
1170 if (!arg || *arg == '\0')
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00001171 fatal("%.200s line %d: Missing argument.",
1172 filename, linenum);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +00001173 if (!sshkey_names_valid2(*arg == '+' ? arg + 1 : arg, 1))
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00001174 fatal("%s line %d: Bad key types '%s'.",
1175 filename, linenum, arg ? arg : "<NONE>");
1176 if (*activep && *charptr == NULL)
1177 *charptr = xstrdup(arg);
Ben Lindstrom982dbbc2001-04-17 18:11:36 +00001178 break;
1179
Damien Miller78928792000-04-12 20:17:38 +10001180 case oProtocol:
1181 intptr = &options->protocol;
Damien Millerbe484b52000-07-15 14:14:16 +10001182 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +10001183 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +10001184 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +10001185 value = proto_spec(arg);
Damien Miller78928792000-04-12 20:17:38 +10001186 if (value == SSH_PROTO_UNKNOWN)
1187 fatal("%.200s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001188 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +10001189 if (*activep && *intptr == SSH_PROTO_UNKNOWN)
1190 *intptr = value;
1191 break;
1192
Damien Miller95def091999-11-25 00:26:21 +11001193 case oLogLevel:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001194 log_level_ptr = &options->log_level;
Damien Millerbe484b52000-07-15 14:14:16 +10001195 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +10001196 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001197 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +00001198 fatal("%.200s line %d: unsupported log level '%s'",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001199 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001200 if (*activep && *log_level_ptr == SYSLOG_LEVEL_NOT_SET)
1201 *log_level_ptr = (LogLevel) value;
Damien Miller95def091999-11-25 00:26:21 +11001202 break;
1203
Ben Lindstrom62c25a42001-09-12 18:01:59 +00001204 case oLocalForward:
Damien Miller95def091999-11-25 00:26:21 +11001205 case oRemoteForward:
Damien Millera699d952008-11-03 19:27:34 +11001206 case oDynamicForward:
Damien Millerbe484b52000-07-15 14:14:16 +10001207 arg = strdelim(&s);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001208 if (arg == NULL || *arg == '\0')
Ben Lindstrom62c25a42001-09-12 18:01:59 +00001209 fatal("%.200s line %d: Missing port argument.",
1210 filename, linenum);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001211
Damien Millera699d952008-11-03 19:27:34 +11001212 if (opcode == oLocalForward ||
1213 opcode == oRemoteForward) {
1214 arg2 = strdelim(&s);
1215 if (arg2 == NULL || *arg2 == '\0')
1216 fatal("%.200s line %d: Missing target argument.",
1217 filename, linenum);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001218
Damien Millera699d952008-11-03 19:27:34 +11001219 /* construct a string for parse_forward */
1220 snprintf(fwdarg, sizeof(fwdarg), "%s:%s", arg, arg2);
1221 } else if (opcode == oDynamicForward) {
1222 strlcpy(fwdarg, arg, sizeof(fwdarg));
1223 }
1224
1225 if (parse_forward(&fwd, fwdarg,
Damien Miller4bf648f2009-02-14 16:28:21 +11001226 opcode == oDynamicForward ? 1 : 0,
1227 opcode == oRemoteForward ? 1 : 0) == 0)
Ben Lindstrom62c25a42001-09-12 18:01:59 +00001228 fatal("%.200s line %d: Bad forwarding specification.",
1229 filename, linenum);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001230
Ben Lindstrom62c25a42001-09-12 18:01:59 +00001231 if (*activep) {
Damien Millera699d952008-11-03 19:27:34 +11001232 if (opcode == oLocalForward ||
1233 opcode == oDynamicForward)
Damien Millerf91ee4c2005-03-01 21:24:33 +11001234 add_local_forward(options, &fwd);
Ben Lindstrom62c25a42001-09-12 18:01:59 +00001235 else if (opcode == oRemoteForward)
Damien Millerf91ee4c2005-03-01 21:24:33 +11001236 add_remote_forward(options, &fwd);
Ben Lindstrom62c25a42001-09-12 18:01:59 +00001237 }
Damien Miller95def091999-11-25 00:26:21 +11001238 break;
1239
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +00001240 case oClearAllForwardings:
1241 intptr = &options->clear_forwardings;
1242 goto parse_flag;
1243
Damien Miller95def091999-11-25 00:26:21 +11001244 case oHost:
Damien Miller194fd902013-10-15 12:13:05 +11001245 if (cmdline)
1246 fatal("Host directive not supported as a command-line "
1247 "option");
Damien Miller95def091999-11-25 00:26:21 +11001248 *activep = 0;
Damien Millerfe924212011-05-15 08:44:45 +10001249 arg2 = NULL;
1250 while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1251 negated = *arg == '!';
1252 if (negated)
1253 arg++;
Damien Miller37023962000-07-11 17:31:38 +10001254 if (match_pattern(host, arg)) {
Damien Millerfe924212011-05-15 08:44:45 +10001255 if (negated) {
1256 debug("%.200s line %d: Skipping Host "
1257 "block because of negated match "
1258 "for %.100s", filename, linenum,
1259 arg);
1260 *activep = 0;
1261 break;
1262 }
1263 if (!*activep)
1264 arg2 = arg; /* logged below */
Damien Miller95def091999-11-25 00:26:21 +11001265 *activep = 1;
Damien Miller95def091999-11-25 00:26:21 +11001266 }
Damien Millerfe924212011-05-15 08:44:45 +10001267 }
1268 if (*activep)
1269 debug("%.200s line %d: Applying options for %.100s",
1270 filename, linenum, arg2);
Damien Millerbe484b52000-07-15 14:14:16 +10001271 /* Avoid garbage check below, as strdelim is done. */
Damien Miller95def091999-11-25 00:26:21 +11001272 return 0;
1273
Damien Miller194fd902013-10-15 12:13:05 +11001274 case oMatch:
1275 if (cmdline)
1276 fatal("Host directive not supported as a command-line "
1277 "option");
djm@openbsd.org957fbce2014-10-08 22:20:25 +00001278 value = match_cfg_line(options, &s, pw, host, original_host,
1279 flags & SSHCONF_POSTCANON, filename, linenum);
Damien Miller194fd902013-10-15 12:13:05 +11001280 if (value < 0)
1281 fatal("%.200s line %d: Bad Match condition", filename,
1282 linenum);
1283 *activep = value;
1284 break;
1285
Damien Miller95def091999-11-25 00:26:21 +11001286 case oEscapeChar:
1287 intptr = &options->escape_char;
Damien Millerbe484b52000-07-15 14:14:16 +10001288 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +10001289 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +11001290 fatal("%.200s line %d: Missing argument.", filename, linenum);
djm@openbsd.org08823322015-05-22 04:45:52 +00001291 if (strcmp(arg, "none") == 0)
1292 value = SSH_ESCAPECHAR_NONE;
1293 else if (arg[1] == '\0')
1294 value = (u_char) arg[0];
1295 else if (arg[0] == '^' && arg[2] == 0 &&
Ben Lindstrom46c16222000-12-22 01:43:59 +00001296 (u_char) arg[1] >= 64 && (u_char) arg[1] < 128)
1297 value = (u_char) arg[1] & 31;
Damien Miller95def091999-11-25 00:26:21 +11001298 else {
1299 fatal("%.200s line %d: Bad escape character.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001300 filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +11001301 /* NOTREACHED */
1302 value = 0; /* Avoid compiler warning. */
1303 }
1304 if (*activep && *intptr == -1)
1305 *intptr = value;
1306 break;
1307
Damien Miller20a8f972003-05-18 20:50:30 +10001308 case oAddressFamily:
Darren Tucker0a4f04b2003-07-03 20:37:47 +10001309 intptr = &options->address_family;
Damien Millere9fc72e2013-10-15 12:14:12 +11001310 multistate_ptr = multistate_addressfamily;
1311 goto parse_multistate;
Damien Miller20a8f972003-05-18 20:50:30 +10001312
Ben Lindstromb6df73b2002-11-09 15:52:31 +00001313 case oEnableSSHKeysign:
1314 intptr = &options->enable_ssh_keysign;
1315 goto parse_flag;
1316
Damien Millerbd394c32004-03-08 23:12:36 +11001317 case oIdentitiesOnly:
1318 intptr = &options->identities_only;
1319 goto parse_flag;
1320
Damien Miller509b0102003-12-17 16:33:10 +11001321 case oServerAliveInterval:
1322 intptr = &options->server_alive_interval;
1323 goto parse_time;
1324
1325 case oServerAliveCountMax:
1326 intptr = &options->server_alive_count_max;
1327 goto parse_int;
1328
Darren Tucker46bc0752004-05-02 22:11:30 +10001329 case oSendEnv:
1330 while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1331 if (strchr(arg, '=') != NULL)
1332 fatal("%s line %d: Invalid environment name.",
1333 filename, linenum);
Damien Millerf8e7acc2005-03-05 11:22:50 +11001334 if (!*activep)
1335 continue;
Darren Tucker46bc0752004-05-02 22:11:30 +10001336 if (options->num_send_env >= MAX_SEND_ENV)
1337 fatal("%s line %d: too many send env.",
1338 filename, linenum);
1339 options->send_env[options->num_send_env++] =
1340 xstrdup(arg);
1341 }
1342 break;
1343
Damien Miller0e220db2004-06-15 10:34:08 +10001344 case oControlPath:
1345 charptr = &options->control_path;
1346 goto parse_string;
1347
1348 case oControlMaster:
1349 intptr = &options->control_master;
Damien Millere9fc72e2013-10-15 12:14:12 +11001350 multistate_ptr = multistate_controlmaster;
1351 goto parse_multistate;
Damien Miller0e220db2004-06-15 10:34:08 +10001352
Damien Millere11e1ea2010-08-03 16:04:46 +10001353 case oControlPersist:
1354 /* no/false/yes/true, or a time spec */
1355 intptr = &options->control_persist;
1356 arg = strdelim(&s);
1357 if (!arg || *arg == '\0')
1358 fatal("%.200s line %d: Missing ControlPersist"
1359 " argument.", filename, linenum);
1360 value = 0;
1361 value2 = 0; /* timeout */
1362 if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
1363 value = 0;
1364 else if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
1365 value = 1;
1366 else if ((value2 = convtime(arg)) >= 0)
1367 value = 1;
1368 else
1369 fatal("%.200s line %d: Bad ControlPersist argument.",
1370 filename, linenum);
1371 if (*activep && *intptr == -1) {
1372 *intptr = value;
1373 options->control_persist_timeout = value2;
1374 }
1375 break;
1376
Damien Millere1776152005-03-01 21:47:37 +11001377 case oHashKnownHosts:
1378 intptr = &options->hash_known_hosts;
1379 goto parse_flag;
1380
Damien Millerd27b9472005-12-13 19:29:02 +11001381 case oTunnel:
1382 intptr = &options->tun_open;
Damien Millere9fc72e2013-10-15 12:14:12 +11001383 multistate_ptr = multistate_tunnel;
1384 goto parse_multistate;
Damien Millerd27b9472005-12-13 19:29:02 +11001385
1386 case oTunnelDevice:
1387 arg = strdelim(&s);
1388 if (!arg || *arg == '\0')
1389 fatal("%.200s line %d: Missing argument.", filename, linenum);
1390 value = a2tun(arg, &value2);
Damien Miller7b58e802005-12-13 19:33:19 +11001391 if (value == SSH_TUNID_ERR)
Damien Millerd27b9472005-12-13 19:29:02 +11001392 fatal("%.200s line %d: Bad tun device.", filename, linenum);
1393 if (*activep) {
1394 options->tun_local = value;
1395 options->tun_remote = value2;
1396 }
1397 break;
1398
1399 case oLocalCommand:
1400 charptr = &options->local_command;
1401 goto parse_command;
1402
1403 case oPermitLocalCommand:
1404 intptr = &options->permit_local_command;
1405 goto parse_flag;
1406
Damien Miller10288242008-06-30 00:04:03 +10001407 case oVisualHostKey:
1408 intptr = &options->visual_host_key;
1409 goto parse_flag;
1410
Damien Miller0dac6fb2010-11-20 15:19:38 +11001411 case oIPQoS:
1412 arg = strdelim(&s);
1413 if ((value = parse_ipqos(arg)) == -1)
1414 fatal("%s line %d: Bad IPQoS value: %s",
1415 filename, linenum, arg);
1416 arg = strdelim(&s);
1417 if (arg == NULL)
1418 value2 = value;
1419 else if ((value2 = parse_ipqos(arg)) == -1)
1420 fatal("%s line %d: Bad IPQoS value: %s",
1421 filename, linenum, arg);
1422 if (*activep) {
1423 options->ip_qos_interactive = value;
1424 options->ip_qos_bulk = value2;
1425 }
1426 break;
1427
Damien Miller21771e22011-05-15 08:45:50 +10001428 case oRequestTTY:
Damien Miller21771e22011-05-15 08:45:50 +10001429 intptr = &options->request_tty;
Damien Millere9fc72e2013-10-15 12:14:12 +11001430 multistate_ptr = multistate_requesttty;
1431 goto parse_multistate;
Damien Miller21771e22011-05-15 08:45:50 +10001432
Darren Tucker07636982013-05-16 20:30:03 +10001433 case oIgnoreUnknown:
1434 charptr = &options->ignored_unknown;
1435 goto parse_string;
1436
Damien Miller1262b662013-08-21 02:44:24 +10001437 case oProxyUseFdpass:
1438 intptr = &options->proxy_use_fdpass;
1439 goto parse_flag;
1440
Damien Miller0faf7472013-10-17 11:47:23 +11001441 case oCanonicalDomains:
1442 value = options->num_canonical_domains != 0;
1443 while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1444 valid_domain(arg, filename, linenum);
1445 if (!*activep || value)
1446 continue;
1447 if (options->num_canonical_domains >= MAX_CANON_DOMAINS)
1448 fatal("%s line %d: too many hostname suffixes.",
1449 filename, linenum);
1450 options->canonical_domains[
1451 options->num_canonical_domains++] = xstrdup(arg);
1452 }
1453 break;
1454
Damien Miller38505592013-10-17 11:48:13 +11001455 case oCanonicalizePermittedCNAMEs:
Damien Miller0faf7472013-10-17 11:47:23 +11001456 value = options->num_permitted_cnames != 0;
1457 while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1458 /* Either '*' for everything or 'list:list' */
1459 if (strcmp(arg, "*") == 0)
1460 arg2 = arg;
1461 else {
1462 lowercase(arg);
1463 if ((arg2 = strchr(arg, ':')) == NULL ||
1464 arg2[1] == '\0') {
1465 fatal("%s line %d: "
1466 "Invalid permitted CNAME \"%s\"",
1467 filename, linenum, arg);
1468 }
1469 *arg2 = '\0';
1470 arg2++;
1471 }
1472 if (!*activep || value)
1473 continue;
1474 if (options->num_permitted_cnames >= MAX_CANON_DOMAINS)
1475 fatal("%s line %d: too many permitted CNAMEs.",
1476 filename, linenum);
1477 cname = options->permitted_cnames +
1478 options->num_permitted_cnames++;
1479 cname->source_list = xstrdup(arg);
1480 cname->target_list = xstrdup(arg2);
1481 }
1482 break;
1483
Damien Miller38505592013-10-17 11:48:13 +11001484 case oCanonicalizeHostname:
1485 intptr = &options->canonicalize_hostname;
1486 multistate_ptr = multistate_canonicalizehostname;
Damien Miller0faf7472013-10-17 11:47:23 +11001487 goto parse_multistate;
1488
Damien Miller38505592013-10-17 11:48:13 +11001489 case oCanonicalizeMaxDots:
1490 intptr = &options->canonicalize_max_dots;
Damien Miller0faf7472013-10-17 11:47:23 +11001491 goto parse_int;
1492
Damien Miller38505592013-10-17 11:48:13 +11001493 case oCanonicalizeFallbackLocal:
1494 intptr = &options->canonicalize_fallback_local;
Damien Miller0faf7472013-10-17 11:47:23 +11001495 goto parse_flag;
1496
Damien Miller7acefbb2014-07-18 14:11:24 +10001497 case oStreamLocalBindMask:
1498 arg = strdelim(&s);
1499 if (!arg || *arg == '\0')
1500 fatal("%.200s line %d: Missing StreamLocalBindMask argument.", filename, linenum);
1501 /* Parse mode in octal format */
1502 value = strtol(arg, &endofnumber, 8);
1503 if (arg == endofnumber || value < 0 || value > 0777)
1504 fatal("%.200s line %d: Bad mask.", filename, linenum);
1505 options->fwd_opts.streamlocal_bind_mask = (mode_t)value;
1506 break;
1507
1508 case oStreamLocalBindUnlink:
1509 intptr = &options->fwd_opts.streamlocal_bind_unlink;
1510 goto parse_flag;
1511
djm@openbsd.org5e39a492014-12-04 02:24:32 +00001512 case oRevokedHostKeys:
1513 charptr = &options->revoked_host_keys;
1514 goto parse_string;
1515
djm@openbsd.org56d1c832014-12-21 22:27:55 +00001516 case oFingerprintHash:
djm@openbsd.orge752c6d2015-01-08 13:44:36 +00001517 intptr = &options->fingerprint_hash;
djm@openbsd.org56d1c832014-12-21 22:27:55 +00001518 arg = strdelim(&s);
1519 if (!arg || *arg == '\0')
1520 fatal("%.200s line %d: Missing argument.",
1521 filename, linenum);
1522 if ((value = ssh_digest_alg_by_name(arg)) == -1)
1523 fatal("%.200s line %d: Invalid hash algorithm \"%s\".",
1524 filename, linenum, arg);
djm@openbsd.orge752c6d2015-01-08 13:44:36 +00001525 if (*activep && *intptr == -1)
1526 *intptr = value;
djm@openbsd.org56d1c832014-12-21 22:27:55 +00001527 break;
1528
djm@openbsd.org8d4f8722015-01-26 03:04:45 +00001529 case oUpdateHostkeys:
1530 intptr = &options->update_hostkeys;
djm@openbsd.org523463a2015-02-16 22:13:32 +00001531 multistate_ptr = multistate_yesnoask;
1532 goto parse_multistate;
djm@openbsd.org8d4f8722015-01-26 03:04:45 +00001533
djm@openbsd.org46347ed2015-01-30 11:43:14 +00001534 case oHostbasedKeyTypes:
1535 charptr = &options->hostbased_key_types;
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00001536 goto parse_keytypes;
1537
1538 case oPubkeyAcceptedKeyTypes:
1539 charptr = &options->pubkey_key_types;
1540 goto parse_keytypes;
djm@openbsd.org46347ed2015-01-30 11:43:14 +00001541
jcs@openbsd.orgf361df42015-11-15 22:26:49 +00001542 case oAddKeysToAgent:
1543 intptr = &options->add_keys_to_agent;
1544 multistate_ptr = multistate_yesnoaskconfirm;
1545 goto parse_multistate;
1546
Ben Lindstrom4daea862002-06-09 20:04:02 +00001547 case oDeprecated:
Ben Lindstrom2e17b082002-06-09 20:13:27 +00001548 debug("%s line %d: Deprecated option \"%s\"",
Ben Lindstrom4daea862002-06-09 20:04:02 +00001549 filename, linenum, keyword);
Ben Lindstrom2e17b082002-06-09 20:13:27 +00001550 return 0;
Ben Lindstrom4daea862002-06-09 20:04:02 +00001551
Damien Millerf9b3feb2003-05-16 11:38:32 +10001552 case oUnsupported:
1553 error("%s line %d: Unsupported option \"%s\"",
1554 filename, linenum, keyword);
1555 return 0;
1556
Damien Miller95def091999-11-25 00:26:21 +11001557 default:
djm@openbsd.org957fbce2014-10-08 22:20:25 +00001558 fatal("%s: Unimplemented opcode %d", __func__, opcode);
Damien Miller95def091999-11-25 00:26:21 +11001559 }
1560
1561 /* Check that there is no garbage at end of line. */
Ben Lindstrom226cfa02001-01-22 05:34:40 +00001562 if ((arg = strdelim(&s)) != NULL && *arg != '\0') {
Damien Miller37023962000-07-11 17:31:38 +10001563 fatal("%.200s line %d: garbage at end of line; \"%.200s\".",
Damien Miller0dc1bef2005-07-17 17:22:45 +10001564 filename, linenum, arg);
Damien Miller37023962000-07-11 17:31:38 +10001565 }
Damien Miller95def091999-11-25 00:26:21 +11001566 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001567}
1568
1569
Damien Miller5428f641999-11-25 11:54:57 +11001570/*
1571 * Reads the config file and modifies the options accordingly. Options
1572 * should already be initialized before this call. This never returns if
Ben Lindstromedc0cf22001-09-12 18:32:20 +00001573 * there is an error. If the file does not exist, this returns 0.
Damien Miller5428f641999-11-25 11:54:57 +11001574 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001575
Ben Lindstromedc0cf22001-09-12 18:32:20 +00001576int
Damien Miller194fd902013-10-15 12:13:05 +11001577read_config_file(const char *filename, struct passwd *pw, const char *host,
djm@openbsd.org957fbce2014-10-08 22:20:25 +00001578 const char *original_host, Options *options, int flags)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001579{
Damien Miller95def091999-11-25 00:26:21 +11001580 FILE *f;
1581 char line[1024];
1582 int active, linenum;
1583 int bad_options = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001584
Damien Miller57a44762004-04-20 20:11:57 +10001585 if ((f = fopen(filename, "r")) == NULL)
Ben Lindstromedc0cf22001-09-12 18:32:20 +00001586 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001587
Darren Tuckeraefa3682013-04-05 11:18:35 +11001588 if (flags & SSHCONF_CHECKPERM) {
Damien Miller57a44762004-04-20 20:11:57 +10001589 struct stat sb;
Darren Tuckerfc959702004-07-17 16:12:08 +10001590
Damien Miller33793852004-06-15 10:27:55 +10001591 if (fstat(fileno(f), &sb) == -1)
Damien Miller57a44762004-04-20 20:11:57 +10001592 fatal("fstat %s: %s", filename, strerror(errno));
Damien Miller57a44762004-04-20 20:11:57 +10001593 if (((sb.st_uid != 0 && sb.st_uid != getuid()) ||
Damien Miller33793852004-06-15 10:27:55 +10001594 (sb.st_mode & 022) != 0))
Damien Miller57a44762004-04-20 20:11:57 +10001595 fatal("Bad owner or permissions on %s", filename);
Damien Miller57a44762004-04-20 20:11:57 +10001596 }
1597
Damien Miller95def091999-11-25 00:26:21 +11001598 debug("Reading configuration data %.200s", filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001599
Damien Miller5428f641999-11-25 11:54:57 +11001600 /*
1601 * Mark that we are now processing the options. This flag is turned
1602 * on/off by Host specifications.
1603 */
Damien Miller95def091999-11-25 00:26:21 +11001604 active = 1;
1605 linenum = 0;
1606 while (fgets(line, sizeof(line), f)) {
1607 /* Update line number counter. */
1608 linenum++;
djm@openbsd.org957fbce2014-10-08 22:20:25 +00001609 if (process_config_line(options, pw, host, original_host,
1610 line, filename, linenum, &active, flags) != 0)
Damien Miller95def091999-11-25 00:26:21 +11001611 bad_options++;
1612 }
1613 fclose(f);
1614 if (bad_options > 0)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +00001615 fatal("%s: terminating, %d bad configuration options",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001616 filename, bad_options);
Ben Lindstromedc0cf22001-09-12 18:32:20 +00001617 return 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001618}
1619
Damien Miller13f97b22014-02-24 15:57:55 +11001620/* Returns 1 if a string option is unset or set to "none" or 0 otherwise. */
1621int
1622option_clear_or_none(const char *o)
1623{
1624 return o == NULL || strcasecmp(o, "none") == 0;
1625}
1626
Damien Miller5428f641999-11-25 11:54:57 +11001627/*
1628 * Initializes options to special values that indicate that they have not yet
1629 * been set. Read_config_file will only set options with this value. Options
1630 * are processed in the following order: command line, user config file,
1631 * system config file. Last, fill_default_options is called.
1632 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001633
Damien Miller4af51302000-04-16 11:18:38 +10001634void
Damien Miller95def091999-11-25 00:26:21 +11001635initialize_options(Options * options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001636{
Damien Miller95def091999-11-25 00:26:21 +11001637 memset(options, 'X', sizeof(*options));
1638 options->forward_agent = -1;
1639 options->forward_x11 = -1;
Darren Tucker0a118da2003-10-15 15:54:32 +10001640 options->forward_x11_trusted = -1;
Damien Miller1ab6a512010-06-26 10:02:24 +10001641 options->forward_x11_timeout = -1;
Darren Tuckere7d4b192006-07-12 22:17:10 +10001642 options->exit_on_forward_failure = -1;
Damien Millerd3a18572000-06-07 19:55:44 +10001643 options->xauth_location = NULL;
Damien Miller7acefbb2014-07-18 14:11:24 +10001644 options->fwd_opts.gateway_ports = -1;
1645 options->fwd_opts.streamlocal_bind_mask = (mode_t)-1;
1646 options->fwd_opts.streamlocal_bind_unlink = -1;
Damien Miller95def091999-11-25 00:26:21 +11001647 options->use_privileged_port = -1;
Damien Miller95def091999-11-25 00:26:21 +11001648 options->rsa_authentication = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +11001649 options->pubkey_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +00001650 options->challenge_response_authentication = -1;
Darren Tucker0efd1552003-08-26 11:49:55 +10001651 options->gss_authentication = -1;
1652 options->gss_deleg_creds = -1;
Damien Miller95def091999-11-25 00:26:21 +11001653 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +11001654 options->kbd_interactive_authentication = -1;
1655 options->kbd_interactive_devices = NULL;
Damien Miller95def091999-11-25 00:26:21 +11001656 options->rhosts_rsa_authentication = -1;
Ben Lindstrom5eabda32001-04-12 23:34:34 +00001657 options->hostbased_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +11001658 options->batch_mode = -1;
1659 options->check_host_ip = -1;
1660 options->strict_host_key_checking = -1;
1661 options->compression = -1;
Damien Miller12c150e2003-12-17 16:31:10 +11001662 options->tcp_keep_alive = -1;
Damien Miller95def091999-11-25 00:26:21 +11001663 options->compression_level = -1;
1664 options->port = -1;
Darren Tucker0a4f04b2003-07-03 20:37:47 +10001665 options->address_family = -1;
Damien Miller95def091999-11-25 00:26:21 +11001666 options->connection_attempts = -1;
Damien Millerb78d5eb2003-05-16 11:39:04 +10001667 options->connection_timeout = -1;
Damien Miller95def091999-11-25 00:26:21 +11001668 options->number_of_password_prompts = -1;
1669 options->cipher = -1;
Damien Miller78928792000-04-12 20:17:38 +10001670 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +00001671 options->macs = NULL;
Damien Millerd5f62bf2010-09-24 22:11:14 +10001672 options->kex_algorithms = NULL;
Ben Lindstrom982dbbc2001-04-17 18:11:36 +00001673 options->hostkeyalgorithms = NULL;
Damien Miller78928792000-04-12 20:17:38 +10001674 options->protocol = SSH_PROTO_UNKNOWN;
Damien Miller95def091999-11-25 00:26:21 +11001675 options->num_identity_files = 0;
djm@openbsd.org4e44a792015-09-24 06:15:11 +00001676 options->num_certificate_files = 0;
Damien Miller95def091999-11-25 00:26:21 +11001677 options->hostname = NULL;
Ben Lindstrom4dccfa52000-12-28 16:40:05 +00001678 options->host_key_alias = NULL;
Damien Miller95def091999-11-25 00:26:21 +11001679 options->proxy_command = NULL;
1680 options->user = NULL;
1681 options->escape_char = -1;
Damien Miller295ee632011-05-29 21:42:31 +10001682 options->num_system_hostfiles = 0;
1683 options->num_user_hostfiles = 0;
Damien Miller232cfb12010-06-26 09:50:30 +10001684 options->local_forwards = NULL;
Damien Miller95def091999-11-25 00:26:21 +11001685 options->num_local_forwards = 0;
Damien Miller232cfb12010-06-26 09:50:30 +10001686 options->remote_forwards = NULL;
Damien Miller95def091999-11-25 00:26:21 +11001687 options->num_remote_forwards = 0;
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +00001688 options->clear_forwardings = -1;
Damien Millerfcd93202002-02-05 12:26:34 +11001689 options->log_level = SYSLOG_LEVEL_NOT_SET;
Ben Lindstromb9be60a2001-03-11 01:49:19 +00001690 options->preferred_authentications = NULL;
Ben Lindstrome0f88042001-04-30 13:06:24 +00001691 options->bind_address = NULL;
Damien Miller7ea845e2010-02-12 09:21:02 +11001692 options->pkcs11_provider = NULL;
Ben Lindstromb6df73b2002-11-09 15:52:31 +00001693 options->enable_ssh_keysign = - 1;
Ben Lindstrom3cecc9a2001-10-03 17:39:38 +00001694 options->no_host_authentication_for_localhost = - 1;
Damien Millerbd394c32004-03-08 23:12:36 +11001695 options->identities_only = - 1;
Damien Millera5539d22003-04-09 20:50:06 +10001696 options->rekey_limit = - 1;
Darren Tuckerc53c2af2013-05-16 20:28:16 +10001697 options->rekey_interval = -1;
Damien Miller37876e92003-05-15 10:19:46 +10001698 options->verify_host_key_dns = -1;
Damien Miller509b0102003-12-17 16:33:10 +11001699 options->server_alive_interval = -1;
1700 options->server_alive_count_max = -1;
Darren Tucker46bc0752004-05-02 22:11:30 +10001701 options->num_send_env = 0;
Damien Miller0e220db2004-06-15 10:34:08 +10001702 options->control_path = NULL;
1703 options->control_master = -1;
Damien Millere11e1ea2010-08-03 16:04:46 +10001704 options->control_persist = -1;
1705 options->control_persist_timeout = 0;
Damien Millere1776152005-03-01 21:47:37 +11001706 options->hash_known_hosts = -1;
Damien Millerd27b9472005-12-13 19:29:02 +11001707 options->tun_open = -1;
1708 options->tun_local = -1;
1709 options->tun_remote = -1;
1710 options->local_command = NULL;
1711 options->permit_local_command = -1;
jcs@openbsd.orgf361df42015-11-15 22:26:49 +00001712 options->add_keys_to_agent = -1;
Damien Miller10288242008-06-30 00:04:03 +10001713 options->visual_host_key = -1;
Damien Miller0dac6fb2010-11-20 15:19:38 +11001714 options->ip_qos_interactive = -1;
1715 options->ip_qos_bulk = -1;
Damien Miller21771e22011-05-15 08:45:50 +10001716 options->request_tty = -1;
Damien Miller1262b662013-08-21 02:44:24 +10001717 options->proxy_use_fdpass = -1;
Darren Tucker07636982013-05-16 20:30:03 +10001718 options->ignored_unknown = NULL;
Damien Miller0faf7472013-10-17 11:47:23 +11001719 options->num_canonical_domains = 0;
1720 options->num_permitted_cnames = 0;
Damien Miller38505592013-10-17 11:48:13 +11001721 options->canonicalize_max_dots = -1;
1722 options->canonicalize_fallback_local = -1;
1723 options->canonicalize_hostname = -1;
djm@openbsd.org5e39a492014-12-04 02:24:32 +00001724 options->revoked_host_keys = NULL;
djm@openbsd.org56d1c832014-12-21 22:27:55 +00001725 options->fingerprint_hash = -1;
djm@openbsd.org8d4f8722015-01-26 03:04:45 +00001726 options->update_hostkeys = -1;
djm@openbsd.org46347ed2015-01-30 11:43:14 +00001727 options->hostbased_key_types = NULL;
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00001728 options->pubkey_key_types = NULL;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001729}
1730
Damien Miller5428f641999-11-25 11:54:57 +11001731/*
Damien Miller13f97b22014-02-24 15:57:55 +11001732 * A petite version of fill_default_options() that just fills the options
1733 * needed for hostname canonicalization to proceed.
1734 */
1735void
1736fill_default_options_for_canonicalization(Options *options)
1737{
1738 if (options->canonicalize_max_dots == -1)
1739 options->canonicalize_max_dots = 1;
1740 if (options->canonicalize_fallback_local == -1)
1741 options->canonicalize_fallback_local = 1;
1742 if (options->canonicalize_hostname == -1)
1743 options->canonicalize_hostname = SSH_CANONICALISE_NO;
1744}
1745
1746/*
Damien Miller5428f641999-11-25 11:54:57 +11001747 * Called after processing other sources of option data, this fills those
1748 * options for which no value has been specified with their default values.
1749 */
Damien Miller4af51302000-04-16 11:18:38 +10001750void
Damien Miller95def091999-11-25 00:26:21 +11001751fill_default_options(Options * options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001752{
Damien Miller95def091999-11-25 00:26:21 +11001753 if (options->forward_agent == -1)
Damien Millerb1715dc2000-05-30 13:44:51 +10001754 options->forward_agent = 0;
Damien Miller95def091999-11-25 00:26:21 +11001755 if (options->forward_x11 == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +11001756 options->forward_x11 = 0;
Darren Tucker0a118da2003-10-15 15:54:32 +10001757 if (options->forward_x11_trusted == -1)
1758 options->forward_x11_trusted = 0;
Damien Miller1ab6a512010-06-26 10:02:24 +10001759 if (options->forward_x11_timeout == -1)
1760 options->forward_x11_timeout = 1200;
Darren Tuckere7d4b192006-07-12 22:17:10 +10001761 if (options->exit_on_forward_failure == -1)
1762 options->exit_on_forward_failure = 0;
Damien Millerd3a18572000-06-07 19:55:44 +10001763 if (options->xauth_location == NULL)
Ben Lindstrom1bf11f62001-06-09 01:48:01 +00001764 options->xauth_location = _PATH_XAUTH;
Damien Miller7acefbb2014-07-18 14:11:24 +10001765 if (options->fwd_opts.gateway_ports == -1)
1766 options->fwd_opts.gateway_ports = 0;
1767 if (options->fwd_opts.streamlocal_bind_mask == (mode_t)-1)
1768 options->fwd_opts.streamlocal_bind_mask = 0177;
1769 if (options->fwd_opts.streamlocal_bind_unlink == -1)
1770 options->fwd_opts.streamlocal_bind_unlink = 0;
Damien Miller95def091999-11-25 00:26:21 +11001771 if (options->use_privileged_port == -1)
Ben Lindstromcebc8582001-03-08 03:39:10 +00001772 options->use_privileged_port = 0;
Damien Miller95def091999-11-25 00:26:21 +11001773 if (options->rsa_authentication == -1)
1774 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +11001775 if (options->pubkey_authentication == -1)
1776 options->pubkey_authentication = 1;
Ben Lindstrom551ea372001-06-05 18:56:16 +00001777 if (options->challenge_response_authentication == -1)
Ben Lindstrom0076d752001-08-06 20:53:26 +00001778 options->challenge_response_authentication = 1;
Darren Tucker0efd1552003-08-26 11:49:55 +10001779 if (options->gss_authentication == -1)
Darren Tuckera044f472003-10-15 15:52:03 +10001780 options->gss_authentication = 0;
Darren Tucker0efd1552003-08-26 11:49:55 +10001781 if (options->gss_deleg_creds == -1)
1782 options->gss_deleg_creds = 0;
Damien Miller95def091999-11-25 00:26:21 +11001783 if (options->password_authentication == -1)
1784 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +11001785 if (options->kbd_interactive_authentication == -1)
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +00001786 options->kbd_interactive_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +11001787 if (options->rhosts_rsa_authentication == -1)
Ben Lindstrom2bf82762002-06-11 15:53:05 +00001788 options->rhosts_rsa_authentication = 0;
Ben Lindstrom5eabda32001-04-12 23:34:34 +00001789 if (options->hostbased_authentication == -1)
1790 options->hostbased_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +11001791 if (options->batch_mode == -1)
1792 options->batch_mode = 0;
1793 if (options->check_host_ip == -1)
1794 options->check_host_ip = 1;
1795 if (options->strict_host_key_checking == -1)
1796 options->strict_host_key_checking = 2; /* 2 is default */
1797 if (options->compression == -1)
1798 options->compression = 0;
Damien Miller12c150e2003-12-17 16:31:10 +11001799 if (options->tcp_keep_alive == -1)
1800 options->tcp_keep_alive = 1;
Damien Miller95def091999-11-25 00:26:21 +11001801 if (options->compression_level == -1)
1802 options->compression_level = 6;
1803 if (options->port == -1)
1804 options->port = 0; /* Filled in ssh_connect. */
Darren Tucker0a4f04b2003-07-03 20:37:47 +10001805 if (options->address_family == -1)
1806 options->address_family = AF_UNSPEC;
Damien Miller95def091999-11-25 00:26:21 +11001807 if (options->connection_attempts == -1)
Ben Lindstromf9cedb92001-08-06 21:07:11 +00001808 options->connection_attempts = 1;
Damien Miller95def091999-11-25 00:26:21 +11001809 if (options->number_of_password_prompts == -1)
1810 options->number_of_password_prompts = 3;
1811 /* Selected in ssh_login(). */
1812 if (options->cipher == -1)
1813 options->cipher = SSH_CIPHER_NOT_SET;
Ben Lindstrom982dbbc2001-04-17 18:11:36 +00001814 /* options->hostkeyalgorithms, default set in myproposals.h */
Damien Miller78928792000-04-12 20:17:38 +10001815 if (options->protocol == SSH_PROTO_UNKNOWN)
Darren Tuckerbad50762009-10-11 21:51:08 +11001816 options->protocol = SSH_PROTO_2;
jcs@openbsd.orgf361df42015-11-15 22:26:49 +00001817 if (options->add_keys_to_agent == -1)
1818 options->add_keys_to_agent = 0;
Damien Miller95def091999-11-25 00:26:21 +11001819 if (options->num_identity_files == 0) {
Damien Miller0bc1bd82000-11-13 22:57:25 +11001820 if (options->protocol & SSH_PROTO_1) {
Darren Tucker19104782013-04-05 11:13:08 +11001821 add_identity_file(options, "~/",
1822 _PATH_SSH_CLIENT_IDENTITY, 0);
Damien Miller0bc1bd82000-11-13 22:57:25 +11001823 }
1824 if (options->protocol & SSH_PROTO_2) {
Darren Tucker19104782013-04-05 11:13:08 +11001825 add_identity_file(options, "~/",
1826 _PATH_SSH_CLIENT_ID_RSA, 0);
1827 add_identity_file(options, "~/",
1828 _PATH_SSH_CLIENT_ID_DSA, 0);
Damien Miller6af914a2010-09-10 11:39:26 +10001829#ifdef OPENSSL_HAS_ECC
Darren Tucker19104782013-04-05 11:13:08 +11001830 add_identity_file(options, "~/",
1831 _PATH_SSH_CLIENT_ID_ECDSA, 0);
Damien Miller6af914a2010-09-10 11:39:26 +10001832#endif
Damien Miller5be9d9e2013-12-07 11:24:01 +11001833 add_identity_file(options, "~/",
1834 _PATH_SSH_CLIENT_ID_ED25519, 0);
Damien Miller0bc1bd82000-11-13 22:57:25 +11001835 }
Damien Millereba71ba2000-04-29 23:57:08 +10001836 }
Damien Miller95def091999-11-25 00:26:21 +11001837 if (options->escape_char == -1)
1838 options->escape_char = '~';
Damien Miller295ee632011-05-29 21:42:31 +10001839 if (options->num_system_hostfiles == 0) {
1840 options->system_hostfiles[options->num_system_hostfiles++] =
1841 xstrdup(_PATH_SSH_SYSTEM_HOSTFILE);
1842 options->system_hostfiles[options->num_system_hostfiles++] =
1843 xstrdup(_PATH_SSH_SYSTEM_HOSTFILE2);
1844 }
1845 if (options->num_user_hostfiles == 0) {
1846 options->user_hostfiles[options->num_user_hostfiles++] =
1847 xstrdup(_PATH_SSH_USER_HOSTFILE);
1848 options->user_hostfiles[options->num_user_hostfiles++] =
1849 xstrdup(_PATH_SSH_USER_HOSTFILE2);
1850 }
Damien Millerfcd93202002-02-05 12:26:34 +11001851 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +00001852 options->log_level = SYSLOG_LEVEL_INFO;
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +00001853 if (options->clear_forwardings == 1)
1854 clear_forwardings(options);
Ben Lindstrom3cecc9a2001-10-03 17:39:38 +00001855 if (options->no_host_authentication_for_localhost == - 1)
1856 options->no_host_authentication_for_localhost = 0;
Damien Millerbd394c32004-03-08 23:12:36 +11001857 if (options->identities_only == -1)
1858 options->identities_only = 0;
Ben Lindstromb6df73b2002-11-09 15:52:31 +00001859 if (options->enable_ssh_keysign == -1)
1860 options->enable_ssh_keysign = 0;
Damien Millera5539d22003-04-09 20:50:06 +10001861 if (options->rekey_limit == -1)
1862 options->rekey_limit = 0;
Darren Tuckerc53c2af2013-05-16 20:28:16 +10001863 if (options->rekey_interval == -1)
1864 options->rekey_interval = 0;
Damien Miller37876e92003-05-15 10:19:46 +10001865 if (options->verify_host_key_dns == -1)
1866 options->verify_host_key_dns = 0;
Damien Miller509b0102003-12-17 16:33:10 +11001867 if (options->server_alive_interval == -1)
1868 options->server_alive_interval = 0;
1869 if (options->server_alive_count_max == -1)
1870 options->server_alive_count_max = 3;
Damien Miller0e220db2004-06-15 10:34:08 +10001871 if (options->control_master == -1)
1872 options->control_master = 0;
Damien Millere11e1ea2010-08-03 16:04:46 +10001873 if (options->control_persist == -1) {
1874 options->control_persist = 0;
1875 options->control_persist_timeout = 0;
1876 }
Damien Millere1776152005-03-01 21:47:37 +11001877 if (options->hash_known_hosts == -1)
1878 options->hash_known_hosts = 0;
Damien Millerd27b9472005-12-13 19:29:02 +11001879 if (options->tun_open == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001880 options->tun_open = SSH_TUNMODE_NO;
1881 if (options->tun_local == -1)
1882 options->tun_local = SSH_TUNID_ANY;
1883 if (options->tun_remote == -1)
1884 options->tun_remote = SSH_TUNID_ANY;
Damien Millerd27b9472005-12-13 19:29:02 +11001885 if (options->permit_local_command == -1)
1886 options->permit_local_command = 0;
Damien Miller10288242008-06-30 00:04:03 +10001887 if (options->visual_host_key == -1)
1888 options->visual_host_key = 0;
Damien Miller0dac6fb2010-11-20 15:19:38 +11001889 if (options->ip_qos_interactive == -1)
1890 options->ip_qos_interactive = IPTOS_LOWDELAY;
1891 if (options->ip_qos_bulk == -1)
1892 options->ip_qos_bulk = IPTOS_THROUGHPUT;
Damien Miller21771e22011-05-15 08:45:50 +10001893 if (options->request_tty == -1)
1894 options->request_tty = REQUEST_TTY_AUTO;
Damien Miller1262b662013-08-21 02:44:24 +10001895 if (options->proxy_use_fdpass == -1)
1896 options->proxy_use_fdpass = 0;
Damien Miller38505592013-10-17 11:48:13 +11001897 if (options->canonicalize_max_dots == -1)
1898 options->canonicalize_max_dots = 1;
1899 if (options->canonicalize_fallback_local == -1)
1900 options->canonicalize_fallback_local = 1;
1901 if (options->canonicalize_hostname == -1)
1902 options->canonicalize_hostname = SSH_CANONICALISE_NO;
djm@openbsd.org56d1c832014-12-21 22:27:55 +00001903 if (options->fingerprint_hash == -1)
1904 options->fingerprint_hash = SSH_FP_HASH_DEFAULT;
djm@openbsd.org8d4f8722015-01-26 03:04:45 +00001905 if (options->update_hostkeys == -1)
djm@openbsd.org15ad7502015-02-02 07:41:40 +00001906 options->update_hostkeys = 0;
djm@openbsd.orgf9eca242015-07-30 00:01:34 +00001907 if (kex_assemble_names(KEX_CLIENT_ENCRYPT, &options->ciphers) != 0 ||
1908 kex_assemble_names(KEX_CLIENT_MAC, &options->macs) != 0 ||
1909 kex_assemble_names(KEX_CLIENT_KEX, &options->kex_algorithms) != 0 ||
1910 kex_assemble_names(KEX_DEFAULT_PK_ALG,
1911 &options->hostbased_key_types) != 0 ||
1912 kex_assemble_names(KEX_DEFAULT_PK_ALG,
1913 &options->pubkey_key_types) != 0)
1914 fatal("%s: kex_assemble_names failed", __func__);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00001915
Damien Millere9fc72e2013-10-15 12:14:12 +11001916#define CLEAR_ON_NONE(v) \
1917 do { \
Damien Miller13f97b22014-02-24 15:57:55 +11001918 if (option_clear_or_none(v)) { \
Damien Millere9fc72e2013-10-15 12:14:12 +11001919 free(v); \
1920 v = NULL; \
1921 } \
1922 } while(0)
1923 CLEAR_ON_NONE(options->local_command);
1924 CLEAR_ON_NONE(options->proxy_command);
1925 CLEAR_ON_NONE(options->control_path);
djm@openbsd.org5e39a492014-12-04 02:24:32 +00001926 CLEAR_ON_NONE(options->revoked_host_keys);
Damien Miller95def091999-11-25 00:26:21 +11001927 /* options->user will be set in the main program if appropriate */
1928 /* options->hostname will be set in the main program if appropriate */
Ben Lindstrom4dccfa52000-12-28 16:40:05 +00001929 /* options->host_key_alias should not be set by default */
Ben Lindstromb9be60a2001-03-11 01:49:19 +00001930 /* options->preferred_authentications will be set in ssh */
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001931}
Damien Millerf91ee4c2005-03-01 21:24:33 +11001932
Damien Miller7acefbb2014-07-18 14:11:24 +10001933struct fwdarg {
1934 char *arg;
1935 int ispath;
1936};
1937
1938/*
1939 * parse_fwd_field
1940 * parses the next field in a port forwarding specification.
1941 * sets fwd to the parsed field and advances p past the colon
1942 * or sets it to NULL at end of string.
1943 * returns 0 on success, else non-zero.
1944 */
1945static int
1946parse_fwd_field(char **p, struct fwdarg *fwd)
1947{
1948 char *ep, *cp = *p;
1949 int ispath = 0;
1950
1951 if (*cp == '\0') {
1952 *p = NULL;
1953 return -1; /* end of string */
1954 }
1955
1956 /*
1957 * A field escaped with square brackets is used literally.
1958 * XXX - allow ']' to be escaped via backslash?
1959 */
1960 if (*cp == '[') {
1961 /* find matching ']' */
1962 for (ep = cp + 1; *ep != ']' && *ep != '\0'; ep++) {
1963 if (*ep == '/')
1964 ispath = 1;
1965 }
1966 /* no matching ']' or not at end of field. */
1967 if (ep[0] != ']' || (ep[1] != ':' && ep[1] != '\0'))
1968 return -1;
1969 /* NUL terminate the field and advance p past the colon */
1970 *ep++ = '\0';
1971 if (*ep != '\0')
1972 *ep++ = '\0';
1973 fwd->arg = cp + 1;
1974 fwd->ispath = ispath;
1975 *p = ep;
1976 return 0;
1977 }
1978
1979 for (cp = *p; *cp != '\0'; cp++) {
1980 switch (*cp) {
1981 case '\\':
1982 memmove(cp, cp + 1, strlen(cp + 1) + 1);
djm@openbsd.org78c2a4f2015-06-26 05:13:20 +00001983 if (*cp == '\0')
1984 return -1;
Damien Miller7acefbb2014-07-18 14:11:24 +10001985 break;
1986 case '/':
1987 ispath = 1;
1988 break;
1989 case ':':
1990 *cp++ = '\0';
1991 goto done;
1992 }
1993 }
1994done:
1995 fwd->arg = *p;
1996 fwd->ispath = ispath;
1997 *p = cp;
1998 return 0;
1999}
2000
Damien Millerf91ee4c2005-03-01 21:24:33 +11002001/*
2002 * parse_forward
2003 * parses a string containing a port forwarding specification of the form:
Damien Millera699d952008-11-03 19:27:34 +11002004 * dynamicfwd == 0
Damien Miller7acefbb2014-07-18 14:11:24 +10002005 * [listenhost:]listenport|listenpath:connecthost:connectport|connectpath
2006 * listenpath:connectpath
Damien Millera699d952008-11-03 19:27:34 +11002007 * dynamicfwd == 1
2008 * [listenhost:]listenport
Damien Millerf91ee4c2005-03-01 21:24:33 +11002009 * returns number of arguments parsed or zero on error
2010 */
2011int
Damien Miller7acefbb2014-07-18 14:11:24 +10002012parse_forward(struct Forward *fwd, const char *fwdspec, int dynamicfwd, int remotefwd)
Damien Millerf91ee4c2005-03-01 21:24:33 +11002013{
Damien Miller7acefbb2014-07-18 14:11:24 +10002014 struct fwdarg fwdargs[4];
2015 char *p, *cp;
Damien Millerf91ee4c2005-03-01 21:24:33 +11002016 int i;
Damien Millerf91ee4c2005-03-01 21:24:33 +11002017
Damien Miller7acefbb2014-07-18 14:11:24 +10002018 memset(fwd, 0, sizeof(*fwd));
2019 memset(fwdargs, 0, sizeof(fwdargs));
Damien Millerf91ee4c2005-03-01 21:24:33 +11002020
2021 cp = p = xstrdup(fwdspec);
2022
2023 /* skip leading spaces */
Damien Millerfdb23062013-11-21 13:57:15 +11002024 while (isspace((u_char)*cp))
Damien Millerf91ee4c2005-03-01 21:24:33 +11002025 cp++;
2026
Damien Miller7acefbb2014-07-18 14:11:24 +10002027 for (i = 0; i < 4; ++i) {
2028 if (parse_fwd_field(&cp, &fwdargs[i]) != 0)
Damien Millerf91ee4c2005-03-01 21:24:33 +11002029 break;
Damien Miller7acefbb2014-07-18 14:11:24 +10002030 }
Damien Millerf91ee4c2005-03-01 21:24:33 +11002031
Damien Millerf4b39532008-11-03 19:28:21 +11002032 /* Check for trailing garbage */
Damien Miller7acefbb2014-07-18 14:11:24 +10002033 if (cp != NULL && *cp != '\0') {
Damien Millerf91ee4c2005-03-01 21:24:33 +11002034 i = 0; /* failure */
Damien Miller7acefbb2014-07-18 14:11:24 +10002035 }
Damien Millerf91ee4c2005-03-01 21:24:33 +11002036
2037 switch (i) {
Damien Millera699d952008-11-03 19:27:34 +11002038 case 1:
Damien Miller7acefbb2014-07-18 14:11:24 +10002039 if (fwdargs[0].ispath) {
2040 fwd->listen_path = xstrdup(fwdargs[0].arg);
2041 fwd->listen_port = PORT_STREAMLOCAL;
2042 } else {
2043 fwd->listen_host = NULL;
2044 fwd->listen_port = a2port(fwdargs[0].arg);
2045 }
Damien Millera699d952008-11-03 19:27:34 +11002046 fwd->connect_host = xstrdup("socks");
2047 break;
2048
2049 case 2:
Damien Miller7acefbb2014-07-18 14:11:24 +10002050 if (fwdargs[0].ispath && fwdargs[1].ispath) {
2051 fwd->listen_path = xstrdup(fwdargs[0].arg);
2052 fwd->listen_port = PORT_STREAMLOCAL;
2053 fwd->connect_path = xstrdup(fwdargs[1].arg);
2054 fwd->connect_port = PORT_STREAMLOCAL;
2055 } else if (fwdargs[1].ispath) {
2056 fwd->listen_host = NULL;
2057 fwd->listen_port = a2port(fwdargs[0].arg);
2058 fwd->connect_path = xstrdup(fwdargs[1].arg);
2059 fwd->connect_port = PORT_STREAMLOCAL;
2060 } else {
2061 fwd->listen_host = xstrdup(fwdargs[0].arg);
2062 fwd->listen_port = a2port(fwdargs[1].arg);
2063 fwd->connect_host = xstrdup("socks");
2064 }
Damien Millera699d952008-11-03 19:27:34 +11002065 break;
2066
Damien Millerf91ee4c2005-03-01 21:24:33 +11002067 case 3:
Damien Miller7acefbb2014-07-18 14:11:24 +10002068 if (fwdargs[0].ispath) {
2069 fwd->listen_path = xstrdup(fwdargs[0].arg);
2070 fwd->listen_port = PORT_STREAMLOCAL;
2071 fwd->connect_host = xstrdup(fwdargs[1].arg);
2072 fwd->connect_port = a2port(fwdargs[2].arg);
2073 } else if (fwdargs[2].ispath) {
2074 fwd->listen_host = xstrdup(fwdargs[0].arg);
2075 fwd->listen_port = a2port(fwdargs[1].arg);
2076 fwd->connect_path = xstrdup(fwdargs[2].arg);
2077 fwd->connect_port = PORT_STREAMLOCAL;
2078 } else {
2079 fwd->listen_host = NULL;
2080 fwd->listen_port = a2port(fwdargs[0].arg);
2081 fwd->connect_host = xstrdup(fwdargs[1].arg);
2082 fwd->connect_port = a2port(fwdargs[2].arg);
2083 }
Damien Millerf91ee4c2005-03-01 21:24:33 +11002084 break;
2085
2086 case 4:
Damien Miller7acefbb2014-07-18 14:11:24 +10002087 fwd->listen_host = xstrdup(fwdargs[0].arg);
2088 fwd->listen_port = a2port(fwdargs[1].arg);
2089 fwd->connect_host = xstrdup(fwdargs[2].arg);
2090 fwd->connect_port = a2port(fwdargs[3].arg);
Damien Millerf91ee4c2005-03-01 21:24:33 +11002091 break;
2092 default:
2093 i = 0; /* failure */
2094 }
2095
Darren Tuckera627d422013-06-02 07:31:17 +10002096 free(p);
Damien Millerf91ee4c2005-03-01 21:24:33 +11002097
Damien Millera699d952008-11-03 19:27:34 +11002098 if (dynamicfwd) {
2099 if (!(i == 1 || i == 2))
2100 goto fail_free;
2101 } else {
Damien Miller7acefbb2014-07-18 14:11:24 +10002102 if (!(i == 3 || i == 4)) {
2103 if (fwd->connect_path == NULL &&
2104 fwd->listen_path == NULL)
2105 goto fail_free;
2106 }
2107 if (fwd->connect_port <= 0 && fwd->connect_path == NULL)
Damien Millera699d952008-11-03 19:27:34 +11002108 goto fail_free;
2109 }
2110
Damien Miller7acefbb2014-07-18 14:11:24 +10002111 if ((fwd->listen_port < 0 && fwd->listen_path == NULL) ||
2112 (!remotefwd && fwd->listen_port == 0))
Damien Millerf91ee4c2005-03-01 21:24:33 +11002113 goto fail_free;
Damien Millerf91ee4c2005-03-01 21:24:33 +11002114 if (fwd->connect_host != NULL &&
2115 strlen(fwd->connect_host) >= NI_MAXHOST)
2116 goto fail_free;
Damien Miller7acefbb2014-07-18 14:11:24 +10002117 /* XXX - if connecting to a remote socket, max sun len may not match this host */
2118 if (fwd->connect_path != NULL &&
2119 strlen(fwd->connect_path) >= PATH_MAX_SUN)
2120 goto fail_free;
Damien Miller4bf648f2009-02-14 16:28:21 +11002121 if (fwd->listen_host != NULL &&
2122 strlen(fwd->listen_host) >= NI_MAXHOST)
2123 goto fail_free;
Damien Miller7acefbb2014-07-18 14:11:24 +10002124 if (fwd->listen_path != NULL &&
2125 strlen(fwd->listen_path) >= PATH_MAX_SUN)
2126 goto fail_free;
Damien Millerf91ee4c2005-03-01 21:24:33 +11002127
2128 return (i);
2129
2130 fail_free:
Darren Tuckera627d422013-06-02 07:31:17 +10002131 free(fwd->connect_host);
2132 fwd->connect_host = NULL;
Damien Miller7acefbb2014-07-18 14:11:24 +10002133 free(fwd->connect_path);
2134 fwd->connect_path = NULL;
Darren Tuckera627d422013-06-02 07:31:17 +10002135 free(fwd->listen_host);
2136 fwd->listen_host = NULL;
Damien Miller7acefbb2014-07-18 14:11:24 +10002137 free(fwd->listen_path);
2138 fwd->listen_path = NULL;
Damien Millerf91ee4c2005-03-01 21:24:33 +11002139 return (0);
2140}
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002141
2142/* XXX the following is a near-vebatim copy from servconf.c; refactor */
2143static const char *
2144fmt_multistate_int(int val, const struct multistate *m)
2145{
2146 u_int i;
2147
2148 for (i = 0; m[i].key != NULL; i++) {
2149 if (m[i].value == val)
2150 return m[i].key;
2151 }
2152 return "UNKNOWN";
2153}
2154
2155static const char *
2156fmt_intarg(OpCodes code, int val)
2157{
2158 if (val == -1)
2159 return "unset";
2160 switch (code) {
2161 case oAddressFamily:
2162 return fmt_multistate_int(val, multistate_addressfamily);
2163 case oVerifyHostKeyDNS:
2164 case oStrictHostKeyChecking:
djm@openbsd.org523463a2015-02-16 22:13:32 +00002165 case oUpdateHostkeys:
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002166 return fmt_multistate_int(val, multistate_yesnoask);
2167 case oControlMaster:
2168 return fmt_multistate_int(val, multistate_controlmaster);
2169 case oTunnel:
2170 return fmt_multistate_int(val, multistate_tunnel);
2171 case oRequestTTY:
2172 return fmt_multistate_int(val, multistate_requesttty);
2173 case oCanonicalizeHostname:
2174 return fmt_multistate_int(val, multistate_canonicalizehostname);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002175 case oFingerprintHash:
2176 return ssh_digest_alg_name(val);
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002177 case oProtocol:
2178 switch (val) {
2179 case SSH_PROTO_1:
2180 return "1";
2181 case SSH_PROTO_2:
2182 return "2";
2183 case (SSH_PROTO_1|SSH_PROTO_2):
2184 return "2,1";
2185 default:
2186 return "UNKNOWN";
2187 }
2188 default:
2189 switch (val) {
2190 case 0:
2191 return "no";
2192 case 1:
2193 return "yes";
2194 default:
2195 return "UNKNOWN";
2196 }
2197 }
2198}
2199
2200static const char *
2201lookup_opcode_name(OpCodes code)
2202{
2203 u_int i;
2204
2205 for (i = 0; keywords[i].name != NULL; i++)
2206 if (keywords[i].opcode == code)
2207 return(keywords[i].name);
2208 return "UNKNOWN";
2209}
2210
2211static void
2212dump_cfg_int(OpCodes code, int val)
2213{
2214 printf("%s %d\n", lookup_opcode_name(code), val);
2215}
2216
2217static void
2218dump_cfg_fmtint(OpCodes code, int val)
2219{
2220 printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
2221}
2222
2223static void
2224dump_cfg_string(OpCodes code, const char *val)
2225{
2226 if (val == NULL)
2227 return;
2228 printf("%s %s\n", lookup_opcode_name(code), val);
2229}
2230
2231static void
2232dump_cfg_strarray(OpCodes code, u_int count, char **vals)
2233{
2234 u_int i;
2235
2236 for (i = 0; i < count; i++)
2237 printf("%s %s\n", lookup_opcode_name(code), vals[i]);
2238}
2239
2240static void
2241dump_cfg_strarray_oneline(OpCodes code, u_int count, char **vals)
2242{
2243 u_int i;
2244
2245 printf("%s", lookup_opcode_name(code));
2246 for (i = 0; i < count; i++)
2247 printf(" %s", vals[i]);
2248 printf("\n");
2249}
2250
2251static void
2252dump_cfg_forwards(OpCodes code, u_int count, const struct Forward *fwds)
2253{
2254 const struct Forward *fwd;
2255 u_int i;
2256
2257 /* oDynamicForward */
2258 for (i = 0; i < count; i++) {
2259 fwd = &fwds[i];
2260 if (code == oDynamicForward &&
2261 strcmp(fwd->connect_host, "socks") != 0)
2262 continue;
2263 if (code == oLocalForward &&
2264 strcmp(fwd->connect_host, "socks") == 0)
2265 continue;
2266 printf("%s", lookup_opcode_name(code));
2267 if (fwd->listen_port == PORT_STREAMLOCAL)
2268 printf(" %s", fwd->listen_path);
2269 else if (fwd->listen_host == NULL)
2270 printf(" %d", fwd->listen_port);
2271 else {
2272 printf(" [%s]:%d",
2273 fwd->listen_host, fwd->listen_port);
2274 }
2275 if (code != oDynamicForward) {
2276 if (fwd->connect_port == PORT_STREAMLOCAL)
2277 printf(" %s", fwd->connect_path);
2278 else if (fwd->connect_host == NULL)
2279 printf(" %d", fwd->connect_port);
2280 else {
2281 printf(" [%s]:%d",
2282 fwd->connect_host, fwd->connect_port);
2283 }
2284 }
2285 printf("\n");
2286 }
2287}
2288
2289void
2290dump_client_config(Options *o, const char *host)
2291{
2292 int i;
2293 char vbuf[5];
2294
djm@openbsd.org60a92472015-08-21 23:53:08 +00002295 /* This is normally prepared in ssh_kex2 */
2296 if (kex_assemble_names(KEX_DEFAULT_PK_ALG, &o->hostkeyalgorithms) != 0)
2297 fatal("%s: kex_assemble_names failed", __func__);
2298
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002299 /* Most interesting options first: user, host, port */
2300 dump_cfg_string(oUser, o->user);
2301 dump_cfg_string(oHostName, host);
2302 dump_cfg_int(oPort, o->port);
2303
2304 /* Flag options */
2305 dump_cfg_fmtint(oAddressFamily, o->address_family);
2306 dump_cfg_fmtint(oBatchMode, o->batch_mode);
2307 dump_cfg_fmtint(oCanonicalizeFallbackLocal, o->canonicalize_fallback_local);
2308 dump_cfg_fmtint(oCanonicalizeHostname, o->canonicalize_hostname);
2309 dump_cfg_fmtint(oChallengeResponseAuthentication, o->challenge_response_authentication);
2310 dump_cfg_fmtint(oCheckHostIP, o->check_host_ip);
2311 dump_cfg_fmtint(oCompression, o->compression);
2312 dump_cfg_fmtint(oControlMaster, o->control_master);
2313 dump_cfg_fmtint(oEnableSSHKeysign, o->enable_ssh_keysign);
2314 dump_cfg_fmtint(oExitOnForwardFailure, o->exit_on_forward_failure);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002315 dump_cfg_fmtint(oFingerprintHash, o->fingerprint_hash);
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002316 dump_cfg_fmtint(oForwardAgent, o->forward_agent);
2317 dump_cfg_fmtint(oForwardX11, o->forward_x11);
2318 dump_cfg_fmtint(oForwardX11Trusted, o->forward_x11_trusted);
2319 dump_cfg_fmtint(oGatewayPorts, o->fwd_opts.gateway_ports);
2320#ifdef GSSAPI
2321 dump_cfg_fmtint(oGssAuthentication, o->gss_authentication);
2322 dump_cfg_fmtint(oGssDelegateCreds, o->gss_deleg_creds);
2323#endif /* GSSAPI */
2324 dump_cfg_fmtint(oHashKnownHosts, o->hash_known_hosts);
2325 dump_cfg_fmtint(oHostbasedAuthentication, o->hostbased_authentication);
2326 dump_cfg_fmtint(oIdentitiesOnly, o->identities_only);
2327 dump_cfg_fmtint(oKbdInteractiveAuthentication, o->kbd_interactive_authentication);
2328 dump_cfg_fmtint(oNoHostAuthenticationForLocalhost, o->no_host_authentication_for_localhost);
2329 dump_cfg_fmtint(oPasswordAuthentication, o->password_authentication);
2330 dump_cfg_fmtint(oPermitLocalCommand, o->permit_local_command);
2331 dump_cfg_fmtint(oProtocol, o->protocol);
2332 dump_cfg_fmtint(oProxyUseFdpass, o->proxy_use_fdpass);
2333 dump_cfg_fmtint(oPubkeyAuthentication, o->pubkey_authentication);
2334 dump_cfg_fmtint(oRequestTTY, o->request_tty);
2335 dump_cfg_fmtint(oRhostsRSAAuthentication, o->rhosts_rsa_authentication);
2336 dump_cfg_fmtint(oRSAAuthentication, o->rsa_authentication);
2337 dump_cfg_fmtint(oStreamLocalBindUnlink, o->fwd_opts.streamlocal_bind_unlink);
2338 dump_cfg_fmtint(oStrictHostKeyChecking, o->strict_host_key_checking);
2339 dump_cfg_fmtint(oTCPKeepAlive, o->tcp_keep_alive);
2340 dump_cfg_fmtint(oTunnel, o->tun_open);
2341 dump_cfg_fmtint(oUsePrivilegedPort, o->use_privileged_port);
2342 dump_cfg_fmtint(oVerifyHostKeyDNS, o->verify_host_key_dns);
2343 dump_cfg_fmtint(oVisualHostKey, o->visual_host_key);
djm@openbsd.org8d4f8722015-01-26 03:04:45 +00002344 dump_cfg_fmtint(oUpdateHostkeys, o->update_hostkeys);
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002345
2346 /* Integer options */
2347 dump_cfg_int(oCanonicalizeMaxDots, o->canonicalize_max_dots);
2348 dump_cfg_int(oCompressionLevel, o->compression_level);
2349 dump_cfg_int(oConnectionAttempts, o->connection_attempts);
2350 dump_cfg_int(oForwardX11Timeout, o->forward_x11_timeout);
2351 dump_cfg_int(oNumberOfPasswordPrompts, o->number_of_password_prompts);
2352 dump_cfg_int(oServerAliveCountMax, o->server_alive_count_max);
2353 dump_cfg_int(oServerAliveInterval, o->server_alive_interval);
2354
2355 /* String options */
2356 dump_cfg_string(oBindAddress, o->bind_address);
2357 dump_cfg_string(oCiphers, o->ciphers ? o->ciphers : KEX_CLIENT_ENCRYPT);
2358 dump_cfg_string(oControlPath, o->control_path);
djm@openbsd.org60a92472015-08-21 23:53:08 +00002359 dump_cfg_string(oHostKeyAlgorithms, o->hostkeyalgorithms);
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002360 dump_cfg_string(oHostKeyAlias, o->host_key_alias);
djm@openbsd.org46347ed2015-01-30 11:43:14 +00002361 dump_cfg_string(oHostbasedKeyTypes, o->hostbased_key_types);
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002362 dump_cfg_string(oKbdInteractiveDevices, o->kbd_interactive_devices);
2363 dump_cfg_string(oKexAlgorithms, o->kex_algorithms ? o->kex_algorithms : KEX_CLIENT_KEX);
2364 dump_cfg_string(oLocalCommand, o->local_command);
2365 dump_cfg_string(oLogLevel, log_level_name(o->log_level));
2366 dump_cfg_string(oMacs, o->macs ? o->macs : KEX_CLIENT_MAC);
2367 dump_cfg_string(oPKCS11Provider, o->pkcs11_provider);
2368 dump_cfg_string(oPreferredAuthentications, o->preferred_authentications);
2369 dump_cfg_string(oProxyCommand, o->proxy_command);
djm@openbsd.org0c46bbe2015-10-07 15:59:12 +00002370 dump_cfg_string(oPubkeyAcceptedKeyTypes, o->pubkey_key_types);
djm@openbsd.org5e39a492014-12-04 02:24:32 +00002371 dump_cfg_string(oRevokedHostKeys, o->revoked_host_keys);
djm@openbsd.org46347ed2015-01-30 11:43:14 +00002372 dump_cfg_string(oXAuthLocation, o->xauth_location);
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002373
djm@openbsd.org46347ed2015-01-30 11:43:14 +00002374 /* Forwards */
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002375 dump_cfg_forwards(oDynamicForward, o->num_local_forwards, o->local_forwards);
2376 dump_cfg_forwards(oLocalForward, o->num_local_forwards, o->local_forwards);
2377 dump_cfg_forwards(oRemoteForward, o->num_remote_forwards, o->remote_forwards);
2378
2379 /* String array options */
2380 dump_cfg_strarray(oIdentityFile, o->num_identity_files, o->identity_files);
2381 dump_cfg_strarray_oneline(oCanonicalDomains, o->num_canonical_domains, o->canonical_domains);
2382 dump_cfg_strarray_oneline(oGlobalKnownHostsFile, o->num_system_hostfiles, o->system_hostfiles);
2383 dump_cfg_strarray_oneline(oUserKnownHostsFile, o->num_user_hostfiles, o->user_hostfiles);
2384 dump_cfg_strarray(oSendEnv, o->num_send_env, o->send_env);
2385
2386 /* Special cases */
2387
2388 /* oConnectTimeout */
2389 if (o->connection_timeout == -1)
2390 printf("connecttimeout none\n");
2391 else
2392 dump_cfg_int(oConnectTimeout, o->connection_timeout);
2393
2394 /* oTunnelDevice */
2395 printf("tunneldevice");
2396 if (o->tun_local == SSH_TUNID_ANY)
2397 printf(" any");
2398 else
2399 printf(" %d", o->tun_local);
2400 if (o->tun_remote == SSH_TUNID_ANY)
2401 printf(":any");
2402 else
2403 printf(":%d", o->tun_remote);
2404 printf("\n");
2405
2406 /* oCanonicalizePermittedCNAMEs */
2407 if ( o->num_permitted_cnames > 0) {
2408 printf("canonicalizePermittedcnames");
2409 for (i = 0; i < o->num_permitted_cnames; i++) {
2410 printf(" %s:%s", o->permitted_cnames[i].source_list,
2411 o->permitted_cnames[i].target_list);
2412 }
2413 printf("\n");
2414 }
2415
2416 /* oCipher */
2417 if (o->cipher != SSH_CIPHER_NOT_SET)
2418 printf("Cipher %s\n", cipher_name(o->cipher));
2419
2420 /* oControlPersist */
2421 if (o->control_persist == 0 || o->control_persist_timeout == 0)
2422 dump_cfg_fmtint(oControlPersist, o->control_persist);
2423 else
2424 dump_cfg_int(oControlPersist, o->control_persist_timeout);
2425
2426 /* oEscapeChar */
2427 if (o->escape_char == SSH_ESCAPECHAR_NONE)
2428 printf("escapechar none\n");
2429 else {
2430 vis(vbuf, o->escape_char, VIS_WHITE, 0);
2431 printf("escapechar %s\n", vbuf);
2432 }
2433
2434 /* oIPQoS */
2435 printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
2436 printf("%s\n", iptos2str(o->ip_qos_bulk));
2437
2438 /* oRekeyLimit */
2439 printf("rekeylimit %lld %d\n",
2440 (long long)o->rekey_limit, o->rekey_interval);
2441
2442 /* oStreamLocalBindMask */
2443 printf("streamlocalbindmask 0%o\n",
2444 o->fwd_opts.streamlocal_bind_mask);
2445}