blob: d63e5961d3314c7f3f44e294d0c9607cfd879ced [file] [log] [blame]
djm@openbsd.org0ccbd5e2016-04-06 06:42:17 +00001/* $OpenBSD: readconf.c,v 1.251 2016/04/06 06:42:17 djm 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;
Damien Miller95def091999-11-25 00:26:21 +1100297 extern uid_t original_real_uid;
Darren Tucker5f41f032016-04-08 21:14:13 +1000298 int i;
djm@openbsd.org0ccbd5e2016-04-06 06:42:17 +0000299
Damien Miller7acefbb2014-07-18 14:11:24 +1000300 if (newfwd->listen_port < IPPORT_RESERVED && original_real_uid != 0 &&
301 newfwd->listen_path == NULL)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +0000302 fatal("Privileged ports can only be forwarded by root.");
djm@openbsd.org0ccbd5e2016-04-06 06:42:17 +0000303 /* Don't add duplicates */
304 for (i = 0; i < options->num_local_forwards; i++) {
305 if (forward_equals(newfwd, options->local_forwards + i))
306 return;
307 }
deraadt@openbsd.org657a5fb2015-04-24 01:36:00 +0000308 options->local_forwards = xreallocarray(options->local_forwards,
Damien Miller232cfb12010-06-26 09:50:30 +1000309 options->num_local_forwards + 1,
310 sizeof(*options->local_forwards));
Damien Miller95def091999-11-25 00:26:21 +1100311 fwd = &options->local_forwards[options->num_local_forwards++];
Damien Millerf91ee4c2005-03-01 21:24:33 +1100312
Damien Miller1a0442f2008-11-05 16:30:06 +1100313 fwd->listen_host = newfwd->listen_host;
Damien Millerf91ee4c2005-03-01 21:24:33 +1100314 fwd->listen_port = newfwd->listen_port;
Damien Miller7acefbb2014-07-18 14:11:24 +1000315 fwd->listen_path = newfwd->listen_path;
Damien Miller1a0442f2008-11-05 16:30:06 +1100316 fwd->connect_host = newfwd->connect_host;
Damien Millerf91ee4c2005-03-01 21:24:33 +1100317 fwd->connect_port = newfwd->connect_port;
Damien Miller7acefbb2014-07-18 14:11:24 +1000318 fwd->connect_path = newfwd->connect_path;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000319}
320
Damien Miller5428f641999-11-25 11:54:57 +1100321/*
322 * Adds a remote TCP/IP port forward to options. Never returns if there is
323 * an error.
324 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000325
Damien Miller4af51302000-04-16 11:18:38 +1000326void
Damien Miller7acefbb2014-07-18 14:11:24 +1000327add_remote_forward(Options *options, const struct Forward *newfwd)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000328{
Damien Miller7acefbb2014-07-18 14:11:24 +1000329 struct Forward *fwd;
djm@openbsd.org0ccbd5e2016-04-06 06:42:17 +0000330 int i;
Damien Miller232cfb12010-06-26 09:50:30 +1000331
djm@openbsd.org0ccbd5e2016-04-06 06:42:17 +0000332 /* Don't add duplicates */
333 for (i = 0; i < options->num_remote_forwards; i++) {
334 if (forward_equals(newfwd, options->remote_forwards + i))
335 return;
336 }
deraadt@openbsd.org657a5fb2015-04-24 01:36:00 +0000337 options->remote_forwards = xreallocarray(options->remote_forwards,
Damien Miller232cfb12010-06-26 09:50:30 +1000338 options->num_remote_forwards + 1,
339 sizeof(*options->remote_forwards));
Damien Miller95def091999-11-25 00:26:21 +1100340 fwd = &options->remote_forwards[options->num_remote_forwards++];
Damien Millerf91ee4c2005-03-01 21:24:33 +1100341
Damien Miller1a0442f2008-11-05 16:30:06 +1100342 fwd->listen_host = newfwd->listen_host;
Damien Millerf91ee4c2005-03-01 21:24:33 +1100343 fwd->listen_port = newfwd->listen_port;
Damien Miller7acefbb2014-07-18 14:11:24 +1000344 fwd->listen_path = newfwd->listen_path;
Damien Miller1a0442f2008-11-05 16:30:06 +1100345 fwd->connect_host = newfwd->connect_host;
Damien Millerf91ee4c2005-03-01 21:24:33 +1100346 fwd->connect_port = newfwd->connect_port;
Damien Miller7acefbb2014-07-18 14:11:24 +1000347 fwd->connect_path = newfwd->connect_path;
Darren Tucker68afb8c2011-10-02 18:59:03 +1100348 fwd->handle = newfwd->handle;
Damien Miller388f6fc2010-05-21 14:57:35 +1000349 fwd->allocated_port = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000350}
351
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000352static void
353clear_forwardings(Options *options)
354{
355 int i;
356
Damien Millerf91ee4c2005-03-01 21:24:33 +1100357 for (i = 0; i < options->num_local_forwards; i++) {
Darren Tuckera627d422013-06-02 07:31:17 +1000358 free(options->local_forwards[i].listen_host);
Damien Miller7acefbb2014-07-18 14:11:24 +1000359 free(options->local_forwards[i].listen_path);
Darren Tuckera627d422013-06-02 07:31:17 +1000360 free(options->local_forwards[i].connect_host);
Damien Miller7acefbb2014-07-18 14:11:24 +1000361 free(options->local_forwards[i].connect_path);
Damien Millerf91ee4c2005-03-01 21:24:33 +1100362 }
Damien Miller232cfb12010-06-26 09:50:30 +1000363 if (options->num_local_forwards > 0) {
Darren Tuckera627d422013-06-02 07:31:17 +1000364 free(options->local_forwards);
Damien Miller232cfb12010-06-26 09:50:30 +1000365 options->local_forwards = NULL;
366 }
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000367 options->num_local_forwards = 0;
Damien Millerf91ee4c2005-03-01 21:24:33 +1100368 for (i = 0; i < options->num_remote_forwards; i++) {
Darren Tuckera627d422013-06-02 07:31:17 +1000369 free(options->remote_forwards[i].listen_host);
Damien Miller7acefbb2014-07-18 14:11:24 +1000370 free(options->remote_forwards[i].listen_path);
Darren Tuckera627d422013-06-02 07:31:17 +1000371 free(options->remote_forwards[i].connect_host);
Damien Miller7acefbb2014-07-18 14:11:24 +1000372 free(options->remote_forwards[i].connect_path);
Damien Millerf91ee4c2005-03-01 21:24:33 +1100373 }
Damien Miller232cfb12010-06-26 09:50:30 +1000374 if (options->num_remote_forwards > 0) {
Darren Tuckera627d422013-06-02 07:31:17 +1000375 free(options->remote_forwards);
Damien Miller232cfb12010-06-26 09:50:30 +1000376 options->remote_forwards = NULL;
377 }
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000378 options->num_remote_forwards = 0;
Damien Miller7b58e802005-12-13 19:33:19 +1100379 options->tun_open = SSH_TUNMODE_NO;
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +0000380}
381
Darren Tucker19104782013-04-05 11:13:08 +1100382void
djm@openbsd.org4e44a792015-09-24 06:15:11 +0000383add_certificate_file(Options *options, const char *path, int userprovided)
384{
385 int i;
386
387 if (options->num_certificate_files >= SSH_MAX_CERTIFICATE_FILES)
388 fatal("Too many certificate files specified (max %d)",
389 SSH_MAX_CERTIFICATE_FILES);
390
391 /* Avoid registering duplicates */
392 for (i = 0; i < options->num_certificate_files; i++) {
393 if (options->certificate_file_userprovided[i] == userprovided &&
394 strcmp(options->certificate_files[i], path) == 0) {
395 debug2("%s: ignoring duplicate key %s", __func__, path);
396 return;
397 }
398 }
399
400 options->certificate_file_userprovided[options->num_certificate_files] =
401 userprovided;
402 options->certificate_files[options->num_certificate_files++] =
403 xstrdup(path);
404}
405
406void
Darren Tucker19104782013-04-05 11:13:08 +1100407add_identity_file(Options *options, const char *dir, const char *filename,
408 int userprovided)
409{
410 char *path;
Damien Miller15271902014-05-15 13:47:56 +1000411 int i;
Darren Tucker19104782013-04-05 11:13:08 +1100412
413 if (options->num_identity_files >= SSH_MAX_IDENTITY_FILES)
414 fatal("Too many identity files specified (max %d)",
415 SSH_MAX_IDENTITY_FILES);
416
417 if (dir == NULL) /* no dir, filename is absolute */
418 path = xstrdup(filename);
419 else
420 (void)xasprintf(&path, "%.100s%.100s", dir, filename);
421
Damien Miller15271902014-05-15 13:47:56 +1000422 /* Avoid registering duplicates */
423 for (i = 0; i < options->num_identity_files; i++) {
424 if (options->identity_file_userprovided[i] == userprovided &&
425 strcmp(options->identity_files[i], path) == 0) {
426 debug2("%s: ignoring duplicate key %s", __func__, path);
427 free(path);
428 return;
429 }
430 }
431
Darren Tucker19104782013-04-05 11:13:08 +1100432 options->identity_file_userprovided[options->num_identity_files] =
433 userprovided;
434 options->identity_files[options->num_identity_files++] = path;
435}
436
Damien Miller194fd902013-10-15 12:13:05 +1100437int
438default_ssh_port(void)
439{
440 static int port;
441 struct servent *sp;
442
443 if (port == 0) {
444 sp = getservbyname(SSH_SERVICE_NAME, "tcp");
445 port = sp ? ntohs(sp->s_port) : SSH_DEFAULT_PORT;
446 }
447 return port;
448}
449
450/*
451 * Execute a command in a shell.
452 * Return its exit status or -1 on abnormal exit.
453 */
454static int
455execute_in_shell(const char *cmd)
456{
dtucker@openbsd.org97e184e2015-10-25 23:14:03 +0000457 char *shell;
Damien Miller194fd902013-10-15 12:13:05 +1100458 pid_t pid;
459 int devnull, status;
460 extern uid_t original_real_uid;
461
462 if ((shell = getenv("SHELL")) == NULL)
463 shell = _PATH_BSHELL;
464
Damien Miller194fd902013-10-15 12:13:05 +1100465 /* Need this to redirect subprocess stdin/out */
466 if ((devnull = open(_PATH_DEVNULL, O_RDWR)) == -1)
467 fatal("open(/dev/null): %s", strerror(errno));
468
469 debug("Executing command: '%.500s'", cmd);
470
471 /* Fork and execute the command. */
472 if ((pid = fork()) == 0) {
djm@openbsd.orga4aef3e2015-10-27 08:54:52 +0000473 char *argv[4];
Damien Miller194fd902013-10-15 12:13:05 +1100474
475 /* Child. Permanently give up superuser privileges. */
476 permanently_drop_suid(original_real_uid);
477
478 /* Redirect child stdin and stdout. Leave stderr */
479 if (dup2(devnull, STDIN_FILENO) == -1)
480 fatal("dup2: %s", strerror(errno));
481 if (dup2(devnull, STDOUT_FILENO) == -1)
482 fatal("dup2: %s", strerror(errno));
483 if (devnull > STDERR_FILENO)
484 close(devnull);
485 closefrom(STDERR_FILENO + 1);
486
djm@openbsd.orga4aef3e2015-10-27 08:54:52 +0000487 argv[0] = shell;
488 argv[1] = "-c";
489 argv[2] = xstrdup(cmd);
490 argv[3] = NULL;
491
Damien Miller194fd902013-10-15 12:13:05 +1100492 execv(argv[0], argv);
493 error("Unable to execute '%.100s': %s", cmd, strerror(errno));
494 /* Die with signal to make this error apparent to parent. */
495 signal(SIGTERM, SIG_DFL);
496 kill(getpid(), SIGTERM);
497 _exit(1);
498 }
499 /* Parent. */
500 if (pid < 0)
501 fatal("%s: fork: %.100s", __func__, strerror(errno));
502
503 close(devnull);
Damien Miller194fd902013-10-15 12:13:05 +1100504
505 while (waitpid(pid, &status, 0) == -1) {
506 if (errno != EINTR && errno != EAGAIN)
507 fatal("%s: waitpid: %s", __func__, strerror(errno));
508 }
509 if (!WIFEXITED(status)) {
510 error("command '%.100s' exited abnormally", cmd);
511 return -1;
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000512 }
Damien Miller194fd902013-10-15 12:13:05 +1100513 debug3("command returned status %d", WEXITSTATUS(status));
514 return WEXITSTATUS(status);
515}
516
517/*
518 * Parse and execute a Match directive.
519 */
520static int
521match_cfg_line(Options *options, char **condition, struct passwd *pw,
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000522 const char *host_arg, const char *original_host, int post_canon,
523 const char *filename, int linenum)
Damien Miller194fd902013-10-15 12:13:05 +1100524{
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000525 char *arg, *oattrib, *attrib, *cmd, *cp = *condition, *host, *criteria;
Damien Miller084bcd22013-10-23 16:30:51 +1100526 const char *ruser;
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000527 int r, port, this_result, result = 1, attributes = 0, negate;
Damien Miller194fd902013-10-15 12:13:05 +1100528 char thishost[NI_MAXHOST], shorthost[NI_MAXHOST], portstr[NI_MAXSERV];
529
530 /*
531 * Configuration is likely to be incomplete at this point so we
532 * must be prepared to use default values.
533 */
534 port = options->port <= 0 ? default_ssh_port() : options->port;
535 ruser = options->user == NULL ? pw->pw_name : options->user;
djm@openbsd.org5a622842016-02-08 23:40:12 +0000536 if (post_canon) {
537 host = xstrdup(options->hostname);
538 } else if (options->hostname != NULL) {
Damien Millereff5cad2013-10-23 16:31:10 +1100539 /* NB. Please keep in sync with ssh.c:main() */
Damien Miller084bcd22013-10-23 16:30:51 +1100540 host = percent_expand(options->hostname,
541 "h", host_arg, (char *)NULL);
djm@openbsd.org5a622842016-02-08 23:40:12 +0000542 } else {
Damien Miller084bcd22013-10-23 16:30:51 +1100543 host = xstrdup(host_arg);
djm@openbsd.org5a622842016-02-08 23:40:12 +0000544 }
Damien Miller194fd902013-10-15 12:13:05 +1100545
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000546 debug2("checking match for '%s' host %s originally %s",
547 cp, host, original_host);
548 while ((oattrib = attrib = strdelim(&cp)) && *attrib != '\0') {
549 criteria = NULL;
550 this_result = 1;
551 if ((negate = attrib[0] == '!'))
552 attrib++;
553 /* criteria "all" and "canonical" have no argument */
Damien Millercf31f382013-10-24 21:02:56 +1100554 if (strcasecmp(attrib, "all") == 0) {
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000555 if (attributes > 1 ||
Damien Millercf31f382013-10-24 21:02:56 +1100556 ((arg = strdelim(&cp)) != NULL && *arg != '\0')) {
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000557 error("%.200s line %d: '%s' cannot be combined "
558 "with other Match attributes",
559 filename, linenum, oattrib);
Damien Millercf31f382013-10-24 21:02:56 +1100560 result = -1;
561 goto out;
562 }
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000563 if (result)
564 result = negate ? 0 : 1;
Damien Millercf31f382013-10-24 21:02:56 +1100565 goto out;
566 }
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000567 attributes++;
568 if (strcasecmp(attrib, "canonical") == 0) {
569 r = !!post_canon; /* force bitmask member to boolean */
570 if (r == (negate ? 1 : 0))
571 this_result = result = 0;
572 debug3("%.200s line %d: %smatched '%s'",
573 filename, linenum,
574 this_result ? "" : "not ", oattrib);
575 continue;
576 }
577 /* All other criteria require an argument */
Damien Miller194fd902013-10-15 12:13:05 +1100578 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
579 error("Missing Match criteria for %s", attrib);
Damien Miller084bcd22013-10-23 16:30:51 +1100580 result = -1;
581 goto out;
Damien Miller194fd902013-10-15 12:13:05 +1100582 }
Damien Miller194fd902013-10-15 12:13:05 +1100583 if (strcasecmp(attrib, "host") == 0) {
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000584 criteria = xstrdup(host);
djm@openbsd.orge661a862015-05-04 06:10:48 +0000585 r = match_hostname(host, arg) == 1;
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000586 if (r == (negate ? 1 : 0))
587 this_result = result = 0;
Damien Miller194fd902013-10-15 12:13:05 +1100588 } else if (strcasecmp(attrib, "originalhost") == 0) {
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000589 criteria = xstrdup(original_host);
djm@openbsd.orge661a862015-05-04 06:10:48 +0000590 r = match_hostname(original_host, arg) == 1;
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000591 if (r == (negate ? 1 : 0))
592 this_result = result = 0;
Damien Miller194fd902013-10-15 12:13:05 +1100593 } else if (strcasecmp(attrib, "user") == 0) {
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000594 criteria = xstrdup(ruser);
djm@openbsd.orge661a862015-05-04 06:10:48 +0000595 r = match_pattern_list(ruser, arg, 0) == 1;
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000596 if (r == (negate ? 1 : 0))
597 this_result = result = 0;
Damien Miller194fd902013-10-15 12:13:05 +1100598 } else if (strcasecmp(attrib, "localuser") == 0) {
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000599 criteria = xstrdup(pw->pw_name);
djm@openbsd.orge661a862015-05-04 06:10:48 +0000600 r = match_pattern_list(pw->pw_name, arg, 0) == 1;
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000601 if (r == (negate ? 1 : 0))
602 this_result = result = 0;
Damien Miller8a04be72013-10-23 16:29:40 +1100603 } else if (strcasecmp(attrib, "exec") == 0) {
Damien Miller194fd902013-10-15 12:13:05 +1100604 if (gethostname(thishost, sizeof(thishost)) == -1)
605 fatal("gethostname: %s", strerror(errno));
606 strlcpy(shorthost, thishost, sizeof(shorthost));
607 shorthost[strcspn(thishost, ".")] = '\0';
608 snprintf(portstr, sizeof(portstr), "%d", port);
609
610 cmd = percent_expand(arg,
611 "L", shorthost,
612 "d", pw->pw_dir,
613 "h", host,
614 "l", thishost,
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000615 "n", original_host,
Damien Miller194fd902013-10-15 12:13:05 +1100616 "p", portstr,
617 "r", ruser,
618 "u", pw->pw_name,
619 (char *)NULL);
Damien Miller06287802014-02-24 15:56:45 +1100620 if (result != 1) {
621 /* skip execution if prior predicate failed */
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000622 debug3("%.200s line %d: skipped exec "
623 "\"%.100s\"", filename, linenum, cmd);
624 free(cmd);
625 continue;
Damien Miller06287802014-02-24 15:56:45 +1100626 }
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000627 r = execute_in_shell(cmd);
628 if (r == -1) {
629 fatal("%.200s line %d: match exec "
630 "'%.100s' error", filename,
631 linenum, cmd);
632 }
633 criteria = xstrdup(cmd);
Damien Miller194fd902013-10-15 12:13:05 +1100634 free(cmd);
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000635 /* Force exit status to boolean */
636 r = r == 0;
637 if (r == (negate ? 1 : 0))
638 this_result = result = 0;
Damien Miller194fd902013-10-15 12:13:05 +1100639 } else {
640 error("Unsupported Match attribute %s", attrib);
Damien Miller084bcd22013-10-23 16:30:51 +1100641 result = -1;
642 goto out;
Damien Miller194fd902013-10-15 12:13:05 +1100643 }
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000644 debug3("%.200s line %d: %smatched '%s \"%.100s\"' ",
645 filename, linenum, this_result ? "": "not ",
646 oattrib, criteria);
647 free(criteria);
Damien Miller194fd902013-10-15 12:13:05 +1100648 }
Damien Millercf31f382013-10-24 21:02:56 +1100649 if (attributes == 0) {
650 error("One or more attributes required for Match");
651 result = -1;
652 goto out;
653 }
Damien Miller084bcd22013-10-23 16:30:51 +1100654 out:
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000655 if (result != -1)
656 debug2("match %sfound", result ? "" : "not ");
657 *condition = cp;
Damien Miller084bcd22013-10-23 16:30:51 +1100658 free(host);
Damien Miller194fd902013-10-15 12:13:05 +1100659 return result;
660}
661
Damien Miller0faf7472013-10-17 11:47:23 +1100662/* Check and prepare a domain name: removes trailing '.' and lowercases */
663static void
664valid_domain(char *name, const char *filename, int linenum)
665{
666 size_t i, l = strlen(name);
667 u_char c, last = '\0';
668
669 if (l == 0)
670 fatal("%s line %d: empty hostname suffix", filename, linenum);
671 if (!isalpha((u_char)name[0]) && !isdigit((u_char)name[0]))
672 fatal("%s line %d: hostname suffix \"%.100s\" "
673 "starts with invalid character", filename, linenum, name);
674 for (i = 0; i < l; i++) {
675 c = tolower((u_char)name[i]);
676 name[i] = (char)c;
677 if (last == '.' && c == '.')
678 fatal("%s line %d: hostname suffix \"%.100s\" contains "
679 "consecutive separators", filename, linenum, name);
680 if (c != '.' && c != '-' && !isalnum(c) &&
681 c != '_') /* technically invalid, but common */
682 fatal("%s line %d: hostname suffix \"%.100s\" contains "
683 "invalid characters", filename, linenum, name);
684 last = c;
685 }
686 if (name[l - 1] == '.')
687 name[l - 1] = '\0';
688}
689
Damien Miller5428f641999-11-25 11:54:57 +1100690/*
Ben Lindstrom3704c262001-04-02 18:20:03 +0000691 * Returns the number of the token pointed to by cp or oBadOption.
Damien Miller5428f641999-11-25 11:54:57 +1100692 */
Damien Miller4af51302000-04-16 11:18:38 +1000693static OpCodes
Darren Tucker07636982013-05-16 20:30:03 +1000694parse_token(const char *cp, const char *filename, int linenum,
695 const char *ignored_unknown)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000696{
Darren Tucker07636982013-05-16 20:30:03 +1000697 int i;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000698
Damien Miller95def091999-11-25 00:26:21 +1100699 for (i = 0; keywords[i].name; i++)
Darren Tucker07636982013-05-16 20:30:03 +1000700 if (strcmp(cp, keywords[i].name) == 0)
Damien Miller95def091999-11-25 00:26:21 +1100701 return keywords[i].opcode;
djm@openbsd.orge661a862015-05-04 06:10:48 +0000702 if (ignored_unknown != NULL &&
703 match_pattern_list(cp, ignored_unknown, 1) == 1)
Darren Tucker07636982013-05-16 20:30:03 +1000704 return oIgnoredUnknownOption;
Ben Lindstromb5cdc662001-04-16 02:13:26 +0000705 error("%s: line %d: Bad configuration option: %s",
706 filename, linenum, cp);
Damien Miller95def091999-11-25 00:26:21 +1100707 return oBadOption;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000708}
709
Damien Millere9fc72e2013-10-15 12:14:12 +1100710/* Multistate option parsing */
711struct multistate {
712 char *key;
713 int value;
714};
715static const struct multistate multistate_flag[] = {
716 { "true", 1 },
717 { "false", 0 },
718 { "yes", 1 },
719 { "no", 0 },
720 { NULL, -1 }
721};
722static const struct multistate multistate_yesnoask[] = {
723 { "true", 1 },
724 { "false", 0 },
725 { "yes", 1 },
726 { "no", 0 },
727 { "ask", 2 },
728 { NULL, -1 }
729};
jcs@openbsd.orgf361df42015-11-15 22:26:49 +0000730static const struct multistate multistate_yesnoaskconfirm[] = {
731 { "true", 1 },
732 { "false", 0 },
733 { "yes", 1 },
734 { "no", 0 },
735 { "ask", 2 },
736 { "confirm", 3 },
737 { NULL, -1 }
738};
Damien Millere9fc72e2013-10-15 12:14:12 +1100739static const struct multistate multistate_addressfamily[] = {
740 { "inet", AF_INET },
741 { "inet6", AF_INET6 },
742 { "any", AF_UNSPEC },
743 { NULL, -1 }
744};
745static const struct multistate multistate_controlmaster[] = {
746 { "true", SSHCTL_MASTER_YES },
747 { "yes", SSHCTL_MASTER_YES },
748 { "false", SSHCTL_MASTER_NO },
749 { "no", SSHCTL_MASTER_NO },
750 { "auto", SSHCTL_MASTER_AUTO },
751 { "ask", SSHCTL_MASTER_ASK },
752 { "autoask", SSHCTL_MASTER_AUTO_ASK },
753 { NULL, -1 }
754};
755static const struct multistate multistate_tunnel[] = {
756 { "ethernet", SSH_TUNMODE_ETHERNET },
757 { "point-to-point", SSH_TUNMODE_POINTOPOINT },
758 { "true", SSH_TUNMODE_DEFAULT },
759 { "yes", SSH_TUNMODE_DEFAULT },
760 { "false", SSH_TUNMODE_NO },
761 { "no", SSH_TUNMODE_NO },
762 { NULL, -1 }
763};
764static const struct multistate multistate_requesttty[] = {
765 { "true", REQUEST_TTY_YES },
766 { "yes", REQUEST_TTY_YES },
767 { "false", REQUEST_TTY_NO },
768 { "no", REQUEST_TTY_NO },
769 { "force", REQUEST_TTY_FORCE },
770 { "auto", REQUEST_TTY_AUTO },
771 { NULL, -1 }
772};
Damien Miller38505592013-10-17 11:48:13 +1100773static const struct multistate multistate_canonicalizehostname[] = {
Damien Miller0faf7472013-10-17 11:47:23 +1100774 { "true", SSH_CANONICALISE_YES },
775 { "false", SSH_CANONICALISE_NO },
776 { "yes", SSH_CANONICALISE_YES },
777 { "no", SSH_CANONICALISE_NO },
778 { "always", SSH_CANONICALISE_ALWAYS },
779 { NULL, -1 }
780};
Damien Millere9fc72e2013-10-15 12:14:12 +1100781
Damien Miller5428f641999-11-25 11:54:57 +1100782/*
783 * Processes a single option line as used in the configuration files. This
784 * only sets those values that have not already been set.
785 */
Damien Miller61f08ac2003-02-24 11:56:27 +1100786#define WHITESPACE " \t\r\n"
Damien Miller2ccf6611999-11-15 15:25:10 +1100787int
Damien Miller194fd902013-10-15 12:13:05 +1100788process_config_line(Options *options, struct passwd *pw, const char *host,
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000789 const char *original_host, char *line, const char *filename,
790 int linenum, int *activep, int flags)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000791{
Damien Miller295ee632011-05-29 21:42:31 +1000792 char *s, **charptr, *endofnumber, *keyword, *arg, *arg2;
793 char **cpptr, fwdarg[256];
Darren Tucker07636982013-05-16 20:30:03 +1000794 u_int i, *uintptr, max_entries = 0;
Damien Miller194fd902013-10-15 12:13:05 +1100795 int negated, opcode, *intptr, value, value2, cmdline = 0;
Darren Tucker1e44c5d2008-01-01 20:32:26 +1100796 LogLevel *log_level_ptr;
Darren Tucker9113d0c2013-05-16 20:48:14 +1000797 long long val64;
Damien Miller61f08ac2003-02-24 11:56:27 +1100798 size_t len;
Damien Miller7acefbb2014-07-18 14:11:24 +1000799 struct Forward fwd;
Damien Millere9fc72e2013-10-15 12:14:12 +1100800 const struct multistate *multistate_ptr;
Damien Miller0faf7472013-10-17 11:47:23 +1100801 struct allowed_cname *cname;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000802
Damien Miller194fd902013-10-15 12:13:05 +1100803 if (activep == NULL) { /* We are processing a command line directive */
804 cmdline = 1;
805 activep = &cmdline;
806 }
807
Damien Millerc652cac2003-05-14 13:40:54 +1000808 /* Strip trailing whitespace */
djm@openbsd.org26e0bcf2015-03-30 00:00:29 +0000809 if ((len = strlen(line)) == 0)
810 return 0;
811 for (len--; len > 0; len--) {
Damien Millerc652cac2003-05-14 13:40:54 +1000812 if (strchr(WHITESPACE, line[len]) == NULL)
813 break;
814 line[len] = '\0';
815 }
816
Damien Millerbe484b52000-07-15 14:14:16 +1000817 s = line;
818 /* Get the keyword. (Each line is supposed to begin with a keyword). */
Damien Miller928b2362006-03-26 13:53:32 +1100819 if ((keyword = strdelim(&s)) == NULL)
820 return 0;
Damien Millerbe484b52000-07-15 14:14:16 +1000821 /* Ignore leading whitespace. */
822 if (*keyword == '\0')
823 keyword = strdelim(&s);
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000824 if (keyword == NULL || !*keyword || *keyword == '\n' || *keyword == '#')
Damien Miller95def091999-11-25 00:26:21 +1100825 return 0;
Darren Tucker07636982013-05-16 20:30:03 +1000826 /* Match lowercase keyword */
Damien Millere9fc72e2013-10-15 12:14:12 +1100827 lowercase(keyword);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000828
Darren Tucker07636982013-05-16 20:30:03 +1000829 opcode = parse_token(keyword, filename, linenum,
830 options->ignored_unknown);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000831
Damien Miller95def091999-11-25 00:26:21 +1100832 switch (opcode) {
833 case oBadOption:
Damien Miller5428f641999-11-25 11:54:57 +1100834 /* don't panic, but count bad options */
835 return -1;
Damien Miller95def091999-11-25 00:26:21 +1100836 /* NOTREACHED */
Darren Tucker07636982013-05-16 20:30:03 +1000837 case oIgnoredUnknownOption:
838 debug("%s line %d: Ignored unknown option \"%s\"",
839 filename, linenum, keyword);
840 return 0;
Damien Millerb78d5eb2003-05-16 11:39:04 +1000841 case oConnectTimeout:
842 intptr = &options->connection_timeout;
Damien Miller509b0102003-12-17 16:33:10 +1100843parse_time:
Damien Millerb78d5eb2003-05-16 11:39:04 +1000844 arg = strdelim(&s);
845 if (!arg || *arg == '\0')
846 fatal("%s line %d: missing time value.",
847 filename, linenum);
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000848 if (strcmp(arg, "none") == 0)
849 value = -1;
850 else if ((value = convtime(arg)) == -1)
Damien Millerb78d5eb2003-05-16 11:39:04 +1000851 fatal("%s line %d: invalid time value.",
852 filename, linenum);
Darren Tuckera52c5b62007-02-19 22:09:45 +1100853 if (*activep && *intptr == -1)
Damien Millerb78d5eb2003-05-16 11:39:04 +1000854 *intptr = value;
855 break;
856
Damien Miller95def091999-11-25 00:26:21 +1100857 case oForwardAgent:
858 intptr = &options->forward_agent;
Damien Millere9fc72e2013-10-15 12:14:12 +1100859 parse_flag:
860 multistate_ptr = multistate_flag;
861 parse_multistate:
Damien Millerbe484b52000-07-15 14:14:16 +1000862 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +1000863 if (!arg || *arg == '\0')
Damien Millere9fc72e2013-10-15 12:14:12 +1100864 fatal("%s line %d: missing argument.",
865 filename, linenum);
866 value = -1;
867 for (i = 0; multistate_ptr[i].key != NULL; i++) {
868 if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
869 value = multistate_ptr[i].value;
870 break;
871 }
872 }
873 if (value == -1)
874 fatal("%s line %d: unsupported option \"%s\".",
875 filename, linenum, arg);
Damien Miller95def091999-11-25 00:26:21 +1100876 if (*activep && *intptr == -1)
877 *intptr = value;
878 break;
879
880 case oForwardX11:
881 intptr = &options->forward_x11;
882 goto parse_flag;
883
Darren Tucker0a118da2003-10-15 15:54:32 +1000884 case oForwardX11Trusted:
885 intptr = &options->forward_x11_trusted;
886 goto parse_flag;
djm@openbsd.org957fbce2014-10-08 22:20:25 +0000887
Damien Miller1ab6a512010-06-26 10:02:24 +1000888 case oForwardX11Timeout:
889 intptr = &options->forward_x11_timeout;
890 goto parse_time;
Darren Tucker0a118da2003-10-15 15:54:32 +1000891
Damien Miller95def091999-11-25 00:26:21 +1100892 case oGatewayPorts:
Damien Miller7acefbb2014-07-18 14:11:24 +1000893 intptr = &options->fwd_opts.gateway_ports;
Damien Miller95def091999-11-25 00:26:21 +1100894 goto parse_flag;
895
Darren Tuckere7d4b192006-07-12 22:17:10 +1000896 case oExitOnForwardFailure:
897 intptr = &options->exit_on_forward_failure;
898 goto parse_flag;
899
Damien Miller95def091999-11-25 00:26:21 +1100900 case oUsePrivilegedPort:
901 intptr = &options->use_privileged_port;
902 goto parse_flag;
903
Damien Miller95def091999-11-25 00:26:21 +1100904 case oPasswordAuthentication:
905 intptr = &options->password_authentication;
906 goto parse_flag;
907
Damien Miller874d77b2000-10-14 16:23:11 +1100908 case oKbdInteractiveAuthentication:
909 intptr = &options->kbd_interactive_authentication;
910 goto parse_flag;
911
912 case oKbdInteractiveDevices:
913 charptr = &options->kbd_interactive_devices;
914 goto parse_string;
915
Damien Miller0bc1bd82000-11-13 22:57:25 +1100916 case oPubkeyAuthentication:
917 intptr = &options->pubkey_authentication;
Damien Millere247cc42000-05-07 12:03:14 +1000918 goto parse_flag;
919
Damien Miller95def091999-11-25 00:26:21 +1100920 case oRSAAuthentication:
921 intptr = &options->rsa_authentication;
922 goto parse_flag;
923
924 case oRhostsRSAAuthentication:
925 intptr = &options->rhosts_rsa_authentication;
926 goto parse_flag;
927
Ben Lindstrom5eabda32001-04-12 23:34:34 +0000928 case oHostbasedAuthentication:
929 intptr = &options->hostbased_authentication;
930 goto parse_flag;
931
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +0000932 case oChallengeResponseAuthentication:
Ben Lindstrom551ea372001-06-05 18:56:16 +0000933 intptr = &options->challenge_response_authentication;
Damien Miller95def091999-11-25 00:26:21 +1100934 goto parse_flag;
Damien Miller2aa0ab42003-05-15 12:05:28 +1000935
Darren Tucker0efd1552003-08-26 11:49:55 +1000936 case oGssAuthentication:
937 intptr = &options->gss_authentication;
938 goto parse_flag;
939
940 case oGssDelegateCreds:
941 intptr = &options->gss_deleg_creds;
942 goto parse_flag;
943
Damien Miller95def091999-11-25 00:26:21 +1100944 case oBatchMode:
945 intptr = &options->batch_mode;
946 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000947
Damien Miller95def091999-11-25 00:26:21 +1100948 case oCheckHostIP:
949 intptr = &options->check_host_ip;
Damien Miller10288242008-06-30 00:04:03 +1000950 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000951
Damien Miller37876e92003-05-15 10:19:46 +1000952 case oVerifyHostKeyDNS:
953 intptr = &options->verify_host_key_dns;
Damien Millere9fc72e2013-10-15 12:14:12 +1100954 multistate_ptr = multistate_yesnoask;
955 goto parse_multistate;
Damien Miller37876e92003-05-15 10:19:46 +1000956
Damien Miller95def091999-11-25 00:26:21 +1100957 case oStrictHostKeyChecking:
958 intptr = &options->strict_host_key_checking;
Damien Millere9fc72e2013-10-15 12:14:12 +1100959 multistate_ptr = multistate_yesnoask;
960 goto parse_multistate;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000961
Damien Miller95def091999-11-25 00:26:21 +1100962 case oCompression:
963 intptr = &options->compression;
964 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000965
Damien Miller12c150e2003-12-17 16:31:10 +1100966 case oTCPKeepAlive:
967 intptr = &options->tcp_keep_alive;
Damien Miller95def091999-11-25 00:26:21 +1100968 goto parse_flag;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000969
Ben Lindstrom3cecc9a2001-10-03 17:39:38 +0000970 case oNoHostAuthenticationForLocalhost:
971 intptr = &options->no_host_authentication_for_localhost;
972 goto parse_flag;
973
Damien Miller95def091999-11-25 00:26:21 +1100974 case oNumberOfPasswordPrompts:
975 intptr = &options->number_of_password_prompts;
976 goto parse_int;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000977
Damien Miller95def091999-11-25 00:26:21 +1100978 case oCompressionLevel:
979 intptr = &options->compression_level;
980 goto parse_int;
981
Damien Millera5539d22003-04-09 20:50:06 +1000982 case oRekeyLimit:
Damien Millera5539d22003-04-09 20:50:06 +1000983 arg = strdelim(&s);
984 if (!arg || *arg == '\0')
Darren Tuckerc53c2af2013-05-16 20:28:16 +1000985 fatal("%.200s line %d: Missing argument.", filename,
986 linenum);
987 if (strcmp(arg, "default") == 0) {
988 val64 = 0;
989 } else {
Darren Tuckerb7ee8522013-05-16 20:33:10 +1000990 if (scan_scaled(arg, &val64) == -1)
991 fatal("%.200s line %d: Bad number '%s': %s",
992 filename, linenum, arg, strerror(errno));
Darren Tuckerc53c2af2013-05-16 20:28:16 +1000993 if (val64 != 0 && val64 < 16)
994 fatal("%.200s line %d: RekeyLimit too small",
995 filename, linenum);
Damien Millera5539d22003-04-09 20:50:06 +1000996 }
Damien Miller3dff1762008-02-10 22:25:52 +1100997 if (*activep && options->rekey_limit == -1)
dtucker@openbsd.org921ff002016-01-29 02:54:45 +0000998 options->rekey_limit = val64;
Darren Tuckerc53c2af2013-05-16 20:28:16 +1000999 if (s != NULL) { /* optional rekey interval present */
1000 if (strcmp(s, "none") == 0) {
1001 (void)strdelim(&s); /* discard */
1002 break;
1003 }
1004 intptr = &options->rekey_interval;
1005 goto parse_time;
1006 }
Damien Millera5539d22003-04-09 20:50:06 +10001007 break;
1008
Damien Miller95def091999-11-25 00:26:21 +11001009 case oIdentityFile:
Damien Millerbe484b52000-07-15 14:14:16 +10001010 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +10001011 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +11001012 fatal("%.200s line %d: Missing argument.", filename, linenum);
1013 if (*activep) {
Damien Miller0bc1bd82000-11-13 22:57:25 +11001014 intptr = &options->num_identity_files;
Damien Millereba71ba2000-04-29 23:57:08 +10001015 if (*intptr >= SSH_MAX_IDENTITY_FILES)
Damien Miller95def091999-11-25 00:26:21 +11001016 fatal("%.200s line %d: Too many identity files specified (max %d).",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001017 filename, linenum, SSH_MAX_IDENTITY_FILES);
djm@openbsd.org957fbce2014-10-08 22:20:25 +00001018 add_identity_file(options, NULL,
1019 arg, flags & SSHCONF_USERCONF);
Damien Miller95def091999-11-25 00:26:21 +11001020 }
1021 break;
1022
djm@openbsd.org4e44a792015-09-24 06:15:11 +00001023 case oCertificateFile:
1024 arg = strdelim(&s);
1025 if (!arg || *arg == '\0')
1026 fatal("%.200s line %d: Missing argument.",
1027 filename, linenum);
1028 if (*activep) {
1029 intptr = &options->num_certificate_files;
1030 if (*intptr >= SSH_MAX_CERTIFICATE_FILES) {
1031 fatal("%.200s line %d: Too many certificate "
1032 "files specified (max %d).",
1033 filename, linenum,
1034 SSH_MAX_CERTIFICATE_FILES);
1035 }
1036 add_certificate_file(options, arg,
1037 flags & SSHCONF_USERCONF);
1038 }
1039 break;
1040
Damien Millerd3a18572000-06-07 19:55:44 +10001041 case oXAuthLocation:
1042 charptr=&options->xauth_location;
1043 goto parse_string;
1044
Damien Miller95def091999-11-25 00:26:21 +11001045 case oUser:
1046 charptr = &options->user;
1047parse_string:
Damien Millerbe484b52000-07-15 14:14:16 +10001048 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +10001049 if (!arg || *arg == '\0')
Damien Miller295ee632011-05-29 21:42:31 +10001050 fatal("%.200s line %d: Missing argument.",
1051 filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +11001052 if (*activep && *charptr == NULL)
Damien Miller37023962000-07-11 17:31:38 +10001053 *charptr = xstrdup(arg);
Damien Miller95def091999-11-25 00:26:21 +11001054 break;
1055
1056 case oGlobalKnownHostsFile:
Damien Miller295ee632011-05-29 21:42:31 +10001057 cpptr = (char **)&options->system_hostfiles;
1058 uintptr = &options->num_system_hostfiles;
1059 max_entries = SSH_MAX_HOSTS_FILES;
1060parse_char_array:
1061 if (*activep && *uintptr == 0) {
1062 while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1063 if ((*uintptr) >= max_entries)
1064 fatal("%s line %d: "
1065 "too many authorized keys files.",
1066 filename, linenum);
1067 cpptr[(*uintptr)++] = xstrdup(arg);
1068 }
1069 }
1070 return 0;
Damien Miller95def091999-11-25 00:26:21 +11001071
1072 case oUserKnownHostsFile:
Damien Miller295ee632011-05-29 21:42:31 +10001073 cpptr = (char **)&options->user_hostfiles;
1074 uintptr = &options->num_user_hostfiles;
1075 max_entries = SSH_MAX_HOSTS_FILES;
1076 goto parse_char_array;
Damien Millereba71ba2000-04-29 23:57:08 +10001077
Damien Miller95def091999-11-25 00:26:21 +11001078 case oHostName:
1079 charptr = &options->hostname;
1080 goto parse_string;
1081
Ben Lindstrom4dccfa52000-12-28 16:40:05 +00001082 case oHostKeyAlias:
1083 charptr = &options->host_key_alias;
1084 goto parse_string;
1085
Ben Lindstromb9be60a2001-03-11 01:49:19 +00001086 case oPreferredAuthentications:
1087 charptr = &options->preferred_authentications;
1088 goto parse_string;
1089
Ben Lindstrome0f88042001-04-30 13:06:24 +00001090 case oBindAddress:
1091 charptr = &options->bind_address;
1092 goto parse_string;
1093
Damien Miller7ea845e2010-02-12 09:21:02 +11001094 case oPKCS11Provider:
1095 charptr = &options->pkcs11_provider;
Ben Lindstromf7db3bb2001-08-06 21:35:51 +00001096 goto parse_string;
Ben Lindstromae996bf2001-08-06 21:27:53 +00001097
Damien Miller95def091999-11-25 00:26:21 +11001098 case oProxyCommand:
Damien Millerd27b9472005-12-13 19:29:02 +11001099 charptr = &options->proxy_command;
1100parse_command:
Darren Tuckera99c1b72003-06-28 12:40:12 +10001101 if (s == NULL)
1102 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller61f08ac2003-02-24 11:56:27 +11001103 len = strspn(s, WHITESPACE "=");
Damien Miller95def091999-11-25 00:26:21 +11001104 if (*activep && *charptr == NULL)
Damien Miller61f08ac2003-02-24 11:56:27 +11001105 *charptr = xstrdup(s + len);
Damien Miller95def091999-11-25 00:26:21 +11001106 return 0;
1107
1108 case oPort:
1109 intptr = &options->port;
1110parse_int:
Damien Millerbe484b52000-07-15 14:14:16 +10001111 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +10001112 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +11001113 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +10001114 if (arg[0] < '0' || arg[0] > '9')
Damien Miller95def091999-11-25 00:26:21 +11001115 fatal("%.200s line %d: Bad number.", filename, linenum);
Damien Miller5428f641999-11-25 11:54:57 +11001116
1117 /* Octal, decimal, or hex format? */
Damien Miller37023962000-07-11 17:31:38 +10001118 value = strtol(arg, &endofnumber, 0);
1119 if (arg == endofnumber)
Damien Miller5428f641999-11-25 11:54:57 +11001120 fatal("%.200s line %d: Bad number.", filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +11001121 if (*activep && *intptr == -1)
1122 *intptr = value;
1123 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001124
Damien Miller95def091999-11-25 00:26:21 +11001125 case oConnectionAttempts:
1126 intptr = &options->connection_attempts;
1127 goto parse_int;
Damien Miller5ce662a1999-11-11 17:57:39 +11001128
Damien Miller95def091999-11-25 00:26:21 +11001129 case oCipher:
1130 intptr = &options->cipher;
Damien Millerbe484b52000-07-15 14:14:16 +10001131 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +10001132 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +10001133 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +10001134 value = cipher_number(arg);
Damien Miller95def091999-11-25 00:26:21 +11001135 if (value == -1)
1136 fatal("%.200s line %d: Bad cipher '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001137 filename, linenum, arg ? arg : "<NONE>");
Damien Miller95def091999-11-25 00:26:21 +11001138 if (*activep && *intptr == -1)
1139 *intptr = value;
1140 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001141
Damien Miller78928792000-04-12 20:17:38 +10001142 case oCiphers:
Damien Millerbe484b52000-07-15 14:14:16 +10001143 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +10001144 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +10001145 fatal("%.200s line %d: Missing argument.", filename, linenum);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +00001146 if (!ciphers_valid(*arg == '+' ? arg + 1 : arg))
Damien Miller30c3d422000-05-09 11:02:59 +10001147 fatal("%.200s line %d: Bad SSH2 cipher spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001148 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +10001149 if (*activep && options->ciphers == NULL)
Damien Miller37023962000-07-11 17:31:38 +10001150 options->ciphers = xstrdup(arg);
Damien Miller78928792000-04-12 20:17:38 +10001151 break;
1152
Ben Lindstrom06b33aa2001-02-15 03:01:59 +00001153 case oMacs:
1154 arg = strdelim(&s);
1155 if (!arg || *arg == '\0')
1156 fatal("%.200s line %d: Missing argument.", filename, linenum);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +00001157 if (!mac_valid(*arg == '+' ? arg + 1 : arg))
Ben Lindstrom06b33aa2001-02-15 03:01:59 +00001158 fatal("%.200s line %d: Bad SSH2 Mac spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001159 filename, linenum, arg ? arg : "<NONE>");
Ben Lindstrom06b33aa2001-02-15 03:01:59 +00001160 if (*activep && options->macs == NULL)
1161 options->macs = xstrdup(arg);
1162 break;
1163
Damien Millerd5f62bf2010-09-24 22:11:14 +10001164 case oKexAlgorithms:
1165 arg = strdelim(&s);
1166 if (!arg || *arg == '\0')
1167 fatal("%.200s line %d: Missing argument.",
1168 filename, linenum);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +00001169 if (!kex_names_valid(*arg == '+' ? arg + 1 : arg))
Damien Millerd5f62bf2010-09-24 22:11:14 +10001170 fatal("%.200s line %d: Bad SSH2 KexAlgorithms '%s'.",
1171 filename, linenum, arg ? arg : "<NONE>");
1172 if (*activep && options->kex_algorithms == NULL)
1173 options->kex_algorithms = xstrdup(arg);
1174 break;
1175
Ben Lindstrom982dbbc2001-04-17 18:11:36 +00001176 case oHostKeyAlgorithms:
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00001177 charptr = &options->hostkeyalgorithms;
1178parse_keytypes:
Ben Lindstrom982dbbc2001-04-17 18:11:36 +00001179 arg = strdelim(&s);
1180 if (!arg || *arg == '\0')
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00001181 fatal("%.200s line %d: Missing argument.",
1182 filename, linenum);
djm@openbsd.orgf9eca242015-07-30 00:01:34 +00001183 if (!sshkey_names_valid2(*arg == '+' ? arg + 1 : arg, 1))
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00001184 fatal("%s line %d: Bad key types '%s'.",
1185 filename, linenum, arg ? arg : "<NONE>");
1186 if (*activep && *charptr == NULL)
1187 *charptr = xstrdup(arg);
Ben Lindstrom982dbbc2001-04-17 18:11:36 +00001188 break;
1189
Damien Miller78928792000-04-12 20:17:38 +10001190 case oProtocol:
1191 intptr = &options->protocol;
Damien Millerbe484b52000-07-15 14:14:16 +10001192 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +10001193 if (!arg || *arg == '\0')
Damien Millerb1715dc2000-05-30 13:44:51 +10001194 fatal("%.200s line %d: Missing argument.", filename, linenum);
Damien Miller37023962000-07-11 17:31:38 +10001195 value = proto_spec(arg);
Damien Miller78928792000-04-12 20:17:38 +10001196 if (value == SSH_PROTO_UNKNOWN)
1197 fatal("%.200s line %d: Bad protocol spec '%s'.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001198 filename, linenum, arg ? arg : "<NONE>");
Damien Miller78928792000-04-12 20:17:38 +10001199 if (*activep && *intptr == SSH_PROTO_UNKNOWN)
1200 *intptr = value;
1201 break;
1202
Damien Miller95def091999-11-25 00:26:21 +11001203 case oLogLevel:
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001204 log_level_ptr = &options->log_level;
Damien Millerbe484b52000-07-15 14:14:16 +10001205 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +10001206 value = log_level_number(arg);
Damien Millerfcd93202002-02-05 12:26:34 +11001207 if (value == SYSLOG_LEVEL_NOT_SET)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +00001208 fatal("%.200s line %d: unsupported log level '%s'",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001209 filename, linenum, arg ? arg : "<NONE>");
Darren Tucker1e44c5d2008-01-01 20:32:26 +11001210 if (*activep && *log_level_ptr == SYSLOG_LEVEL_NOT_SET)
1211 *log_level_ptr = (LogLevel) value;
Damien Miller95def091999-11-25 00:26:21 +11001212 break;
1213
Ben Lindstrom62c25a42001-09-12 18:01:59 +00001214 case oLocalForward:
Damien Miller95def091999-11-25 00:26:21 +11001215 case oRemoteForward:
Damien Millera699d952008-11-03 19:27:34 +11001216 case oDynamicForward:
Damien Millerbe484b52000-07-15 14:14:16 +10001217 arg = strdelim(&s);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001218 if (arg == NULL || *arg == '\0')
Ben Lindstrom62c25a42001-09-12 18:01:59 +00001219 fatal("%.200s line %d: Missing port argument.",
1220 filename, linenum);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001221
Damien Millera699d952008-11-03 19:27:34 +11001222 if (opcode == oLocalForward ||
1223 opcode == oRemoteForward) {
1224 arg2 = strdelim(&s);
1225 if (arg2 == NULL || *arg2 == '\0')
1226 fatal("%.200s line %d: Missing target argument.",
1227 filename, linenum);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001228
Damien Millera699d952008-11-03 19:27:34 +11001229 /* construct a string for parse_forward */
1230 snprintf(fwdarg, sizeof(fwdarg), "%s:%s", arg, arg2);
1231 } else if (opcode == oDynamicForward) {
1232 strlcpy(fwdarg, arg, sizeof(fwdarg));
1233 }
1234
1235 if (parse_forward(&fwd, fwdarg,
Damien Miller4bf648f2009-02-14 16:28:21 +11001236 opcode == oDynamicForward ? 1 : 0,
1237 opcode == oRemoteForward ? 1 : 0) == 0)
Ben Lindstrom62c25a42001-09-12 18:01:59 +00001238 fatal("%.200s line %d: Bad forwarding specification.",
1239 filename, linenum);
Damien Millerf91ee4c2005-03-01 21:24:33 +11001240
Ben Lindstrom62c25a42001-09-12 18:01:59 +00001241 if (*activep) {
Damien Millera699d952008-11-03 19:27:34 +11001242 if (opcode == oLocalForward ||
1243 opcode == oDynamicForward)
Damien Millerf91ee4c2005-03-01 21:24:33 +11001244 add_local_forward(options, &fwd);
Ben Lindstrom62c25a42001-09-12 18:01:59 +00001245 else if (opcode == oRemoteForward)
Damien Millerf91ee4c2005-03-01 21:24:33 +11001246 add_remote_forward(options, &fwd);
Ben Lindstrom62c25a42001-09-12 18:01:59 +00001247 }
Damien Miller95def091999-11-25 00:26:21 +11001248 break;
1249
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +00001250 case oClearAllForwardings:
1251 intptr = &options->clear_forwardings;
1252 goto parse_flag;
1253
Damien Miller95def091999-11-25 00:26:21 +11001254 case oHost:
Damien Miller194fd902013-10-15 12:13:05 +11001255 if (cmdline)
1256 fatal("Host directive not supported as a command-line "
1257 "option");
Damien Miller95def091999-11-25 00:26:21 +11001258 *activep = 0;
Damien Millerfe924212011-05-15 08:44:45 +10001259 arg2 = NULL;
1260 while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1261 negated = *arg == '!';
1262 if (negated)
1263 arg++;
Damien Miller37023962000-07-11 17:31:38 +10001264 if (match_pattern(host, arg)) {
Damien Millerfe924212011-05-15 08:44:45 +10001265 if (negated) {
1266 debug("%.200s line %d: Skipping Host "
1267 "block because of negated match "
1268 "for %.100s", filename, linenum,
1269 arg);
1270 *activep = 0;
1271 break;
1272 }
1273 if (!*activep)
1274 arg2 = arg; /* logged below */
Damien Miller95def091999-11-25 00:26:21 +11001275 *activep = 1;
Damien Miller95def091999-11-25 00:26:21 +11001276 }
Damien Millerfe924212011-05-15 08:44:45 +10001277 }
1278 if (*activep)
1279 debug("%.200s line %d: Applying options for %.100s",
1280 filename, linenum, arg2);
Damien Millerbe484b52000-07-15 14:14:16 +10001281 /* Avoid garbage check below, as strdelim is done. */
Damien Miller95def091999-11-25 00:26:21 +11001282 return 0;
1283
Damien Miller194fd902013-10-15 12:13:05 +11001284 case oMatch:
1285 if (cmdline)
1286 fatal("Host directive not supported as a command-line "
1287 "option");
djm@openbsd.org957fbce2014-10-08 22:20:25 +00001288 value = match_cfg_line(options, &s, pw, host, original_host,
1289 flags & SSHCONF_POSTCANON, filename, linenum);
Damien Miller194fd902013-10-15 12:13:05 +11001290 if (value < 0)
1291 fatal("%.200s line %d: Bad Match condition", filename,
1292 linenum);
1293 *activep = value;
1294 break;
1295
Damien Miller95def091999-11-25 00:26:21 +11001296 case oEscapeChar:
1297 intptr = &options->escape_char;
Damien Millerbe484b52000-07-15 14:14:16 +10001298 arg = strdelim(&s);
Damien Miller37023962000-07-11 17:31:38 +10001299 if (!arg || *arg == '\0')
Damien Miller95def091999-11-25 00:26:21 +11001300 fatal("%.200s line %d: Missing argument.", filename, linenum);
djm@openbsd.org08823322015-05-22 04:45:52 +00001301 if (strcmp(arg, "none") == 0)
1302 value = SSH_ESCAPECHAR_NONE;
1303 else if (arg[1] == '\0')
1304 value = (u_char) arg[0];
1305 else if (arg[0] == '^' && arg[2] == 0 &&
Ben Lindstrom46c16222000-12-22 01:43:59 +00001306 (u_char) arg[1] >= 64 && (u_char) arg[1] < 128)
1307 value = (u_char) arg[1] & 31;
Damien Miller95def091999-11-25 00:26:21 +11001308 else {
1309 fatal("%.200s line %d: Bad escape character.",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001310 filename, linenum);
Damien Miller95def091999-11-25 00:26:21 +11001311 /* NOTREACHED */
1312 value = 0; /* Avoid compiler warning. */
1313 }
1314 if (*activep && *intptr == -1)
1315 *intptr = value;
1316 break;
1317
Damien Miller20a8f972003-05-18 20:50:30 +10001318 case oAddressFamily:
Darren Tucker0a4f04b2003-07-03 20:37:47 +10001319 intptr = &options->address_family;
Damien Millere9fc72e2013-10-15 12:14:12 +11001320 multistate_ptr = multistate_addressfamily;
1321 goto parse_multistate;
Damien Miller20a8f972003-05-18 20:50:30 +10001322
Ben Lindstromb6df73b2002-11-09 15:52:31 +00001323 case oEnableSSHKeysign:
1324 intptr = &options->enable_ssh_keysign;
1325 goto parse_flag;
1326
Damien Millerbd394c32004-03-08 23:12:36 +11001327 case oIdentitiesOnly:
1328 intptr = &options->identities_only;
1329 goto parse_flag;
1330
Damien Miller509b0102003-12-17 16:33:10 +11001331 case oServerAliveInterval:
1332 intptr = &options->server_alive_interval;
1333 goto parse_time;
1334
1335 case oServerAliveCountMax:
1336 intptr = &options->server_alive_count_max;
1337 goto parse_int;
1338
Darren Tucker46bc0752004-05-02 22:11:30 +10001339 case oSendEnv:
1340 while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1341 if (strchr(arg, '=') != NULL)
1342 fatal("%s line %d: Invalid environment name.",
1343 filename, linenum);
Damien Millerf8e7acc2005-03-05 11:22:50 +11001344 if (!*activep)
1345 continue;
Darren Tucker46bc0752004-05-02 22:11:30 +10001346 if (options->num_send_env >= MAX_SEND_ENV)
1347 fatal("%s line %d: too many send env.",
1348 filename, linenum);
1349 options->send_env[options->num_send_env++] =
1350 xstrdup(arg);
1351 }
1352 break;
1353
Damien Miller0e220db2004-06-15 10:34:08 +10001354 case oControlPath:
1355 charptr = &options->control_path;
1356 goto parse_string;
1357
1358 case oControlMaster:
1359 intptr = &options->control_master;
Damien Millere9fc72e2013-10-15 12:14:12 +11001360 multistate_ptr = multistate_controlmaster;
1361 goto parse_multistate;
Damien Miller0e220db2004-06-15 10:34:08 +10001362
Damien Millere11e1ea2010-08-03 16:04:46 +10001363 case oControlPersist:
1364 /* no/false/yes/true, or a time spec */
1365 intptr = &options->control_persist;
1366 arg = strdelim(&s);
1367 if (!arg || *arg == '\0')
1368 fatal("%.200s line %d: Missing ControlPersist"
1369 " argument.", filename, linenum);
1370 value = 0;
1371 value2 = 0; /* timeout */
1372 if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
1373 value = 0;
1374 else if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
1375 value = 1;
1376 else if ((value2 = convtime(arg)) >= 0)
1377 value = 1;
1378 else
1379 fatal("%.200s line %d: Bad ControlPersist argument.",
1380 filename, linenum);
1381 if (*activep && *intptr == -1) {
1382 *intptr = value;
1383 options->control_persist_timeout = value2;
1384 }
1385 break;
1386
Damien Millere1776152005-03-01 21:47:37 +11001387 case oHashKnownHosts:
1388 intptr = &options->hash_known_hosts;
1389 goto parse_flag;
1390
Damien Millerd27b9472005-12-13 19:29:02 +11001391 case oTunnel:
1392 intptr = &options->tun_open;
Damien Millere9fc72e2013-10-15 12:14:12 +11001393 multistate_ptr = multistate_tunnel;
1394 goto parse_multistate;
Damien Millerd27b9472005-12-13 19:29:02 +11001395
1396 case oTunnelDevice:
1397 arg = strdelim(&s);
1398 if (!arg || *arg == '\0')
1399 fatal("%.200s line %d: Missing argument.", filename, linenum);
1400 value = a2tun(arg, &value2);
Damien Miller7b58e802005-12-13 19:33:19 +11001401 if (value == SSH_TUNID_ERR)
Damien Millerd27b9472005-12-13 19:29:02 +11001402 fatal("%.200s line %d: Bad tun device.", filename, linenum);
1403 if (*activep) {
1404 options->tun_local = value;
1405 options->tun_remote = value2;
1406 }
1407 break;
1408
1409 case oLocalCommand:
1410 charptr = &options->local_command;
1411 goto parse_command;
1412
1413 case oPermitLocalCommand:
1414 intptr = &options->permit_local_command;
1415 goto parse_flag;
1416
Damien Miller10288242008-06-30 00:04:03 +10001417 case oVisualHostKey:
1418 intptr = &options->visual_host_key;
1419 goto parse_flag;
1420
Damien Miller0dac6fb2010-11-20 15:19:38 +11001421 case oIPQoS:
1422 arg = strdelim(&s);
1423 if ((value = parse_ipqos(arg)) == -1)
1424 fatal("%s line %d: Bad IPQoS value: %s",
1425 filename, linenum, arg);
1426 arg = strdelim(&s);
1427 if (arg == NULL)
1428 value2 = value;
1429 else if ((value2 = parse_ipqos(arg)) == -1)
1430 fatal("%s line %d: Bad IPQoS value: %s",
1431 filename, linenum, arg);
1432 if (*activep) {
1433 options->ip_qos_interactive = value;
1434 options->ip_qos_bulk = value2;
1435 }
1436 break;
1437
Damien Miller21771e22011-05-15 08:45:50 +10001438 case oRequestTTY:
Damien Miller21771e22011-05-15 08:45:50 +10001439 intptr = &options->request_tty;
Damien Millere9fc72e2013-10-15 12:14:12 +11001440 multistate_ptr = multistate_requesttty;
1441 goto parse_multistate;
Damien Miller21771e22011-05-15 08:45:50 +10001442
Darren Tucker07636982013-05-16 20:30:03 +10001443 case oIgnoreUnknown:
1444 charptr = &options->ignored_unknown;
1445 goto parse_string;
1446
Damien Miller1262b662013-08-21 02:44:24 +10001447 case oProxyUseFdpass:
1448 intptr = &options->proxy_use_fdpass;
1449 goto parse_flag;
1450
Damien Miller0faf7472013-10-17 11:47:23 +11001451 case oCanonicalDomains:
1452 value = options->num_canonical_domains != 0;
1453 while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1454 valid_domain(arg, filename, linenum);
1455 if (!*activep || value)
1456 continue;
1457 if (options->num_canonical_domains >= MAX_CANON_DOMAINS)
1458 fatal("%s line %d: too many hostname suffixes.",
1459 filename, linenum);
1460 options->canonical_domains[
1461 options->num_canonical_domains++] = xstrdup(arg);
1462 }
1463 break;
1464
Damien Miller38505592013-10-17 11:48:13 +11001465 case oCanonicalizePermittedCNAMEs:
Damien Miller0faf7472013-10-17 11:47:23 +11001466 value = options->num_permitted_cnames != 0;
1467 while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1468 /* Either '*' for everything or 'list:list' */
1469 if (strcmp(arg, "*") == 0)
1470 arg2 = arg;
1471 else {
1472 lowercase(arg);
1473 if ((arg2 = strchr(arg, ':')) == NULL ||
1474 arg2[1] == '\0') {
1475 fatal("%s line %d: "
1476 "Invalid permitted CNAME \"%s\"",
1477 filename, linenum, arg);
1478 }
1479 *arg2 = '\0';
1480 arg2++;
1481 }
1482 if (!*activep || value)
1483 continue;
1484 if (options->num_permitted_cnames >= MAX_CANON_DOMAINS)
1485 fatal("%s line %d: too many permitted CNAMEs.",
1486 filename, linenum);
1487 cname = options->permitted_cnames +
1488 options->num_permitted_cnames++;
1489 cname->source_list = xstrdup(arg);
1490 cname->target_list = xstrdup(arg2);
1491 }
1492 break;
1493
Damien Miller38505592013-10-17 11:48:13 +11001494 case oCanonicalizeHostname:
1495 intptr = &options->canonicalize_hostname;
1496 multistate_ptr = multistate_canonicalizehostname;
Damien Miller0faf7472013-10-17 11:47:23 +11001497 goto parse_multistate;
1498
Damien Miller38505592013-10-17 11:48:13 +11001499 case oCanonicalizeMaxDots:
1500 intptr = &options->canonicalize_max_dots;
Damien Miller0faf7472013-10-17 11:47:23 +11001501 goto parse_int;
1502
Damien Miller38505592013-10-17 11:48:13 +11001503 case oCanonicalizeFallbackLocal:
1504 intptr = &options->canonicalize_fallback_local;
Damien Miller0faf7472013-10-17 11:47:23 +11001505 goto parse_flag;
1506
Damien Miller7acefbb2014-07-18 14:11:24 +10001507 case oStreamLocalBindMask:
1508 arg = strdelim(&s);
1509 if (!arg || *arg == '\0')
1510 fatal("%.200s line %d: Missing StreamLocalBindMask argument.", filename, linenum);
1511 /* Parse mode in octal format */
1512 value = strtol(arg, &endofnumber, 8);
1513 if (arg == endofnumber || value < 0 || value > 0777)
1514 fatal("%.200s line %d: Bad mask.", filename, linenum);
1515 options->fwd_opts.streamlocal_bind_mask = (mode_t)value;
1516 break;
1517
1518 case oStreamLocalBindUnlink:
1519 intptr = &options->fwd_opts.streamlocal_bind_unlink;
1520 goto parse_flag;
1521
djm@openbsd.org5e39a492014-12-04 02:24:32 +00001522 case oRevokedHostKeys:
1523 charptr = &options->revoked_host_keys;
1524 goto parse_string;
1525
djm@openbsd.org56d1c832014-12-21 22:27:55 +00001526 case oFingerprintHash:
djm@openbsd.orge752c6d2015-01-08 13:44:36 +00001527 intptr = &options->fingerprint_hash;
djm@openbsd.org56d1c832014-12-21 22:27:55 +00001528 arg = strdelim(&s);
1529 if (!arg || *arg == '\0')
1530 fatal("%.200s line %d: Missing argument.",
1531 filename, linenum);
1532 if ((value = ssh_digest_alg_by_name(arg)) == -1)
1533 fatal("%.200s line %d: Invalid hash algorithm \"%s\".",
1534 filename, linenum, arg);
djm@openbsd.orge752c6d2015-01-08 13:44:36 +00001535 if (*activep && *intptr == -1)
1536 *intptr = value;
djm@openbsd.org56d1c832014-12-21 22:27:55 +00001537 break;
1538
djm@openbsd.org8d4f8722015-01-26 03:04:45 +00001539 case oUpdateHostkeys:
1540 intptr = &options->update_hostkeys;
djm@openbsd.org523463a2015-02-16 22:13:32 +00001541 multistate_ptr = multistate_yesnoask;
1542 goto parse_multistate;
djm@openbsd.org8d4f8722015-01-26 03:04:45 +00001543
djm@openbsd.org46347ed2015-01-30 11:43:14 +00001544 case oHostbasedKeyTypes:
1545 charptr = &options->hostbased_key_types;
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00001546 goto parse_keytypes;
1547
1548 case oPubkeyAcceptedKeyTypes:
1549 charptr = &options->pubkey_key_types;
1550 goto parse_keytypes;
djm@openbsd.org46347ed2015-01-30 11:43:14 +00001551
jcs@openbsd.orgf361df42015-11-15 22:26:49 +00001552 case oAddKeysToAgent:
1553 intptr = &options->add_keys_to_agent;
1554 multistate_ptr = multistate_yesnoaskconfirm;
1555 goto parse_multistate;
1556
Ben Lindstrom4daea862002-06-09 20:04:02 +00001557 case oDeprecated:
Ben Lindstrom2e17b082002-06-09 20:13:27 +00001558 debug("%s line %d: Deprecated option \"%s\"",
Ben Lindstrom4daea862002-06-09 20:04:02 +00001559 filename, linenum, keyword);
Ben Lindstrom2e17b082002-06-09 20:13:27 +00001560 return 0;
Ben Lindstrom4daea862002-06-09 20:04:02 +00001561
Damien Millerf9b3feb2003-05-16 11:38:32 +10001562 case oUnsupported:
1563 error("%s line %d: Unsupported option \"%s\"",
1564 filename, linenum, keyword);
1565 return 0;
1566
Damien Miller95def091999-11-25 00:26:21 +11001567 default:
djm@openbsd.org957fbce2014-10-08 22:20:25 +00001568 fatal("%s: Unimplemented opcode %d", __func__, opcode);
Damien Miller95def091999-11-25 00:26:21 +11001569 }
1570
1571 /* Check that there is no garbage at end of line. */
Ben Lindstrom226cfa02001-01-22 05:34:40 +00001572 if ((arg = strdelim(&s)) != NULL && *arg != '\0') {
Damien Miller37023962000-07-11 17:31:38 +10001573 fatal("%.200s line %d: garbage at end of line; \"%.200s\".",
Damien Miller0dc1bef2005-07-17 17:22:45 +10001574 filename, linenum, arg);
Damien Miller37023962000-07-11 17:31:38 +10001575 }
Damien Miller95def091999-11-25 00:26:21 +11001576 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001577}
1578
1579
Damien Miller5428f641999-11-25 11:54:57 +11001580/*
1581 * Reads the config file and modifies the options accordingly. Options
1582 * should already be initialized before this call. This never returns if
Ben Lindstromedc0cf22001-09-12 18:32:20 +00001583 * there is an error. If the file does not exist, this returns 0.
Damien Miller5428f641999-11-25 11:54:57 +11001584 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001585
Ben Lindstromedc0cf22001-09-12 18:32:20 +00001586int
Damien Miller194fd902013-10-15 12:13:05 +11001587read_config_file(const char *filename, struct passwd *pw, const char *host,
djm@openbsd.org957fbce2014-10-08 22:20:25 +00001588 const char *original_host, Options *options, int flags)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001589{
Damien Miller95def091999-11-25 00:26:21 +11001590 FILE *f;
1591 char line[1024];
1592 int active, linenum;
1593 int bad_options = 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001594
Damien Miller57a44762004-04-20 20:11:57 +10001595 if ((f = fopen(filename, "r")) == NULL)
Ben Lindstromedc0cf22001-09-12 18:32:20 +00001596 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001597
Darren Tuckeraefa3682013-04-05 11:18:35 +11001598 if (flags & SSHCONF_CHECKPERM) {
Damien Miller57a44762004-04-20 20:11:57 +10001599 struct stat sb;
Darren Tuckerfc959702004-07-17 16:12:08 +10001600
Damien Miller33793852004-06-15 10:27:55 +10001601 if (fstat(fileno(f), &sb) == -1)
Damien Miller57a44762004-04-20 20:11:57 +10001602 fatal("fstat %s: %s", filename, strerror(errno));
Damien Miller57a44762004-04-20 20:11:57 +10001603 if (((sb.st_uid != 0 && sb.st_uid != getuid()) ||
Damien Miller33793852004-06-15 10:27:55 +10001604 (sb.st_mode & 022) != 0))
Damien Miller57a44762004-04-20 20:11:57 +10001605 fatal("Bad owner or permissions on %s", filename);
Damien Miller57a44762004-04-20 20:11:57 +10001606 }
1607
Damien Miller95def091999-11-25 00:26:21 +11001608 debug("Reading configuration data %.200s", filename);
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001609
Damien Miller5428f641999-11-25 11:54:57 +11001610 /*
1611 * Mark that we are now processing the options. This flag is turned
1612 * on/off by Host specifications.
1613 */
Damien Miller95def091999-11-25 00:26:21 +11001614 active = 1;
1615 linenum = 0;
1616 while (fgets(line, sizeof(line), f)) {
1617 /* Update line number counter. */
1618 linenum++;
djm@openbsd.org957fbce2014-10-08 22:20:25 +00001619 if (process_config_line(options, pw, host, original_host,
1620 line, filename, linenum, &active, flags) != 0)
Damien Miller95def091999-11-25 00:26:21 +11001621 bad_options++;
1622 }
1623 fclose(f);
1624 if (bad_options > 0)
Ben Lindstrom6df8ef42001-03-05 07:47:23 +00001625 fatal("%s: terminating, %d bad configuration options",
Damien Miller9f0f5c62001-12-21 14:45:46 +11001626 filename, bad_options);
Ben Lindstromedc0cf22001-09-12 18:32:20 +00001627 return 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001628}
1629
Damien Miller13f97b22014-02-24 15:57:55 +11001630/* Returns 1 if a string option is unset or set to "none" or 0 otherwise. */
1631int
1632option_clear_or_none(const char *o)
1633{
1634 return o == NULL || strcasecmp(o, "none") == 0;
1635}
1636
Damien Miller5428f641999-11-25 11:54:57 +11001637/*
1638 * Initializes options to special values that indicate that they have not yet
1639 * been set. Read_config_file will only set options with this value. Options
1640 * are processed in the following order: command line, user config file,
1641 * system config file. Last, fill_default_options is called.
1642 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001643
Damien Miller4af51302000-04-16 11:18:38 +10001644void
Damien Miller95def091999-11-25 00:26:21 +11001645initialize_options(Options * options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001646{
Damien Miller95def091999-11-25 00:26:21 +11001647 memset(options, 'X', sizeof(*options));
1648 options->forward_agent = -1;
1649 options->forward_x11 = -1;
Darren Tucker0a118da2003-10-15 15:54:32 +10001650 options->forward_x11_trusted = -1;
Damien Miller1ab6a512010-06-26 10:02:24 +10001651 options->forward_x11_timeout = -1;
Darren Tuckere7d4b192006-07-12 22:17:10 +10001652 options->exit_on_forward_failure = -1;
Damien Millerd3a18572000-06-07 19:55:44 +10001653 options->xauth_location = NULL;
Damien Miller7acefbb2014-07-18 14:11:24 +10001654 options->fwd_opts.gateway_ports = -1;
1655 options->fwd_opts.streamlocal_bind_mask = (mode_t)-1;
1656 options->fwd_opts.streamlocal_bind_unlink = -1;
Damien Miller95def091999-11-25 00:26:21 +11001657 options->use_privileged_port = -1;
Damien Miller95def091999-11-25 00:26:21 +11001658 options->rsa_authentication = -1;
Damien Miller0bc1bd82000-11-13 22:57:25 +11001659 options->pubkey_authentication = -1;
Ben Lindstrom551ea372001-06-05 18:56:16 +00001660 options->challenge_response_authentication = -1;
Darren Tucker0efd1552003-08-26 11:49:55 +10001661 options->gss_authentication = -1;
1662 options->gss_deleg_creds = -1;
Damien Miller95def091999-11-25 00:26:21 +11001663 options->password_authentication = -1;
Damien Miller874d77b2000-10-14 16:23:11 +11001664 options->kbd_interactive_authentication = -1;
1665 options->kbd_interactive_devices = NULL;
Damien Miller95def091999-11-25 00:26:21 +11001666 options->rhosts_rsa_authentication = -1;
Ben Lindstrom5eabda32001-04-12 23:34:34 +00001667 options->hostbased_authentication = -1;
Damien Miller95def091999-11-25 00:26:21 +11001668 options->batch_mode = -1;
1669 options->check_host_ip = -1;
1670 options->strict_host_key_checking = -1;
1671 options->compression = -1;
Damien Miller12c150e2003-12-17 16:31:10 +11001672 options->tcp_keep_alive = -1;
Damien Miller95def091999-11-25 00:26:21 +11001673 options->compression_level = -1;
1674 options->port = -1;
Darren Tucker0a4f04b2003-07-03 20:37:47 +10001675 options->address_family = -1;
Damien Miller95def091999-11-25 00:26:21 +11001676 options->connection_attempts = -1;
Damien Millerb78d5eb2003-05-16 11:39:04 +10001677 options->connection_timeout = -1;
Damien Miller95def091999-11-25 00:26:21 +11001678 options->number_of_password_prompts = -1;
1679 options->cipher = -1;
Damien Miller78928792000-04-12 20:17:38 +10001680 options->ciphers = NULL;
Ben Lindstrom06b33aa2001-02-15 03:01:59 +00001681 options->macs = NULL;
Damien Millerd5f62bf2010-09-24 22:11:14 +10001682 options->kex_algorithms = NULL;
Ben Lindstrom982dbbc2001-04-17 18:11:36 +00001683 options->hostkeyalgorithms = NULL;
Damien Miller78928792000-04-12 20:17:38 +10001684 options->protocol = SSH_PROTO_UNKNOWN;
Damien Miller95def091999-11-25 00:26:21 +11001685 options->num_identity_files = 0;
djm@openbsd.org4e44a792015-09-24 06:15:11 +00001686 options->num_certificate_files = 0;
Damien Miller95def091999-11-25 00:26:21 +11001687 options->hostname = NULL;
Ben Lindstrom4dccfa52000-12-28 16:40:05 +00001688 options->host_key_alias = NULL;
Damien Miller95def091999-11-25 00:26:21 +11001689 options->proxy_command = NULL;
1690 options->user = NULL;
1691 options->escape_char = -1;
Damien Miller295ee632011-05-29 21:42:31 +10001692 options->num_system_hostfiles = 0;
1693 options->num_user_hostfiles = 0;
Damien Miller232cfb12010-06-26 09:50:30 +10001694 options->local_forwards = NULL;
Damien Miller95def091999-11-25 00:26:21 +11001695 options->num_local_forwards = 0;
Damien Miller232cfb12010-06-26 09:50:30 +10001696 options->remote_forwards = NULL;
Damien Miller95def091999-11-25 00:26:21 +11001697 options->num_remote_forwards = 0;
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +00001698 options->clear_forwardings = -1;
Damien Millerfcd93202002-02-05 12:26:34 +11001699 options->log_level = SYSLOG_LEVEL_NOT_SET;
Ben Lindstromb9be60a2001-03-11 01:49:19 +00001700 options->preferred_authentications = NULL;
Ben Lindstrome0f88042001-04-30 13:06:24 +00001701 options->bind_address = NULL;
Damien Miller7ea845e2010-02-12 09:21:02 +11001702 options->pkcs11_provider = NULL;
Ben Lindstromb6df73b2002-11-09 15:52:31 +00001703 options->enable_ssh_keysign = - 1;
Ben Lindstrom3cecc9a2001-10-03 17:39:38 +00001704 options->no_host_authentication_for_localhost = - 1;
Damien Millerbd394c32004-03-08 23:12:36 +11001705 options->identities_only = - 1;
Damien Millera5539d22003-04-09 20:50:06 +10001706 options->rekey_limit = - 1;
Darren Tuckerc53c2af2013-05-16 20:28:16 +10001707 options->rekey_interval = -1;
Damien Miller37876e92003-05-15 10:19:46 +10001708 options->verify_host_key_dns = -1;
Damien Miller509b0102003-12-17 16:33:10 +11001709 options->server_alive_interval = -1;
1710 options->server_alive_count_max = -1;
Darren Tucker46bc0752004-05-02 22:11:30 +10001711 options->num_send_env = 0;
Damien Miller0e220db2004-06-15 10:34:08 +10001712 options->control_path = NULL;
1713 options->control_master = -1;
Damien Millere11e1ea2010-08-03 16:04:46 +10001714 options->control_persist = -1;
1715 options->control_persist_timeout = 0;
Damien Millere1776152005-03-01 21:47:37 +11001716 options->hash_known_hosts = -1;
Damien Millerd27b9472005-12-13 19:29:02 +11001717 options->tun_open = -1;
1718 options->tun_local = -1;
1719 options->tun_remote = -1;
1720 options->local_command = NULL;
1721 options->permit_local_command = -1;
jcs@openbsd.orgf361df42015-11-15 22:26:49 +00001722 options->add_keys_to_agent = -1;
Damien Miller10288242008-06-30 00:04:03 +10001723 options->visual_host_key = -1;
Damien Miller0dac6fb2010-11-20 15:19:38 +11001724 options->ip_qos_interactive = -1;
1725 options->ip_qos_bulk = -1;
Damien Miller21771e22011-05-15 08:45:50 +10001726 options->request_tty = -1;
Damien Miller1262b662013-08-21 02:44:24 +10001727 options->proxy_use_fdpass = -1;
Darren Tucker07636982013-05-16 20:30:03 +10001728 options->ignored_unknown = NULL;
Damien Miller0faf7472013-10-17 11:47:23 +11001729 options->num_canonical_domains = 0;
1730 options->num_permitted_cnames = 0;
Damien Miller38505592013-10-17 11:48:13 +11001731 options->canonicalize_max_dots = -1;
1732 options->canonicalize_fallback_local = -1;
1733 options->canonicalize_hostname = -1;
djm@openbsd.org5e39a492014-12-04 02:24:32 +00001734 options->revoked_host_keys = NULL;
djm@openbsd.org56d1c832014-12-21 22:27:55 +00001735 options->fingerprint_hash = -1;
djm@openbsd.org8d4f8722015-01-26 03:04:45 +00001736 options->update_hostkeys = -1;
djm@openbsd.org46347ed2015-01-30 11:43:14 +00001737 options->hostbased_key_types = NULL;
markus@openbsd.org3a1638d2015-07-10 06:21:53 +00001738 options->pubkey_key_types = NULL;
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001739}
1740
Damien Miller5428f641999-11-25 11:54:57 +11001741/*
Damien Miller13f97b22014-02-24 15:57:55 +11001742 * A petite version of fill_default_options() that just fills the options
1743 * needed for hostname canonicalization to proceed.
1744 */
1745void
1746fill_default_options_for_canonicalization(Options *options)
1747{
1748 if (options->canonicalize_max_dots == -1)
1749 options->canonicalize_max_dots = 1;
1750 if (options->canonicalize_fallback_local == -1)
1751 options->canonicalize_fallback_local = 1;
1752 if (options->canonicalize_hostname == -1)
1753 options->canonicalize_hostname = SSH_CANONICALISE_NO;
1754}
1755
1756/*
Damien Miller5428f641999-11-25 11:54:57 +11001757 * Called after processing other sources of option data, this fills those
1758 * options for which no value has been specified with their default values.
1759 */
Damien Miller4af51302000-04-16 11:18:38 +10001760void
Damien Miller95def091999-11-25 00:26:21 +11001761fill_default_options(Options * options)
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001762{
Damien Miller95def091999-11-25 00:26:21 +11001763 if (options->forward_agent == -1)
Damien Millerb1715dc2000-05-30 13:44:51 +10001764 options->forward_agent = 0;
Damien Miller95def091999-11-25 00:26:21 +11001765 if (options->forward_x11 == -1)
Damien Miller98c7ad62000-03-09 21:27:49 +11001766 options->forward_x11 = 0;
Darren Tucker0a118da2003-10-15 15:54:32 +10001767 if (options->forward_x11_trusted == -1)
1768 options->forward_x11_trusted = 0;
Damien Miller1ab6a512010-06-26 10:02:24 +10001769 if (options->forward_x11_timeout == -1)
1770 options->forward_x11_timeout = 1200;
Darren Tuckere7d4b192006-07-12 22:17:10 +10001771 if (options->exit_on_forward_failure == -1)
1772 options->exit_on_forward_failure = 0;
Damien Millerd3a18572000-06-07 19:55:44 +10001773 if (options->xauth_location == NULL)
Ben Lindstrom1bf11f62001-06-09 01:48:01 +00001774 options->xauth_location = _PATH_XAUTH;
Damien Miller7acefbb2014-07-18 14:11:24 +10001775 if (options->fwd_opts.gateway_ports == -1)
1776 options->fwd_opts.gateway_ports = 0;
1777 if (options->fwd_opts.streamlocal_bind_mask == (mode_t)-1)
1778 options->fwd_opts.streamlocal_bind_mask = 0177;
1779 if (options->fwd_opts.streamlocal_bind_unlink == -1)
1780 options->fwd_opts.streamlocal_bind_unlink = 0;
Damien Miller95def091999-11-25 00:26:21 +11001781 if (options->use_privileged_port == -1)
Ben Lindstromcebc8582001-03-08 03:39:10 +00001782 options->use_privileged_port = 0;
Damien Miller95def091999-11-25 00:26:21 +11001783 if (options->rsa_authentication == -1)
1784 options->rsa_authentication = 1;
Damien Miller0bc1bd82000-11-13 22:57:25 +11001785 if (options->pubkey_authentication == -1)
1786 options->pubkey_authentication = 1;
Ben Lindstrom551ea372001-06-05 18:56:16 +00001787 if (options->challenge_response_authentication == -1)
Ben Lindstrom0076d752001-08-06 20:53:26 +00001788 options->challenge_response_authentication = 1;
Darren Tucker0efd1552003-08-26 11:49:55 +10001789 if (options->gss_authentication == -1)
Darren Tuckera044f472003-10-15 15:52:03 +10001790 options->gss_authentication = 0;
Darren Tucker0efd1552003-08-26 11:49:55 +10001791 if (options->gss_deleg_creds == -1)
1792 options->gss_deleg_creds = 0;
Damien Miller95def091999-11-25 00:26:21 +11001793 if (options->password_authentication == -1)
1794 options->password_authentication = 1;
Damien Miller874d77b2000-10-14 16:23:11 +11001795 if (options->kbd_interactive_authentication == -1)
Ben Lindstrom95fb2dd2001-01-23 03:12:10 +00001796 options->kbd_interactive_authentication = 1;
Damien Miller95def091999-11-25 00:26:21 +11001797 if (options->rhosts_rsa_authentication == -1)
Ben Lindstrom2bf82762002-06-11 15:53:05 +00001798 options->rhosts_rsa_authentication = 0;
Ben Lindstrom5eabda32001-04-12 23:34:34 +00001799 if (options->hostbased_authentication == -1)
1800 options->hostbased_authentication = 0;
Damien Miller95def091999-11-25 00:26:21 +11001801 if (options->batch_mode == -1)
1802 options->batch_mode = 0;
1803 if (options->check_host_ip == -1)
1804 options->check_host_ip = 1;
1805 if (options->strict_host_key_checking == -1)
1806 options->strict_host_key_checking = 2; /* 2 is default */
1807 if (options->compression == -1)
1808 options->compression = 0;
Damien Miller12c150e2003-12-17 16:31:10 +11001809 if (options->tcp_keep_alive == -1)
1810 options->tcp_keep_alive = 1;
Damien Miller95def091999-11-25 00:26:21 +11001811 if (options->compression_level == -1)
1812 options->compression_level = 6;
1813 if (options->port == -1)
1814 options->port = 0; /* Filled in ssh_connect. */
Darren Tucker0a4f04b2003-07-03 20:37:47 +10001815 if (options->address_family == -1)
1816 options->address_family = AF_UNSPEC;
Damien Miller95def091999-11-25 00:26:21 +11001817 if (options->connection_attempts == -1)
Ben Lindstromf9cedb92001-08-06 21:07:11 +00001818 options->connection_attempts = 1;
Damien Miller95def091999-11-25 00:26:21 +11001819 if (options->number_of_password_prompts == -1)
1820 options->number_of_password_prompts = 3;
1821 /* Selected in ssh_login(). */
1822 if (options->cipher == -1)
1823 options->cipher = SSH_CIPHER_NOT_SET;
Ben Lindstrom982dbbc2001-04-17 18:11:36 +00001824 /* options->hostkeyalgorithms, default set in myproposals.h */
Damien Miller78928792000-04-12 20:17:38 +10001825 if (options->protocol == SSH_PROTO_UNKNOWN)
Darren Tuckerbad50762009-10-11 21:51:08 +11001826 options->protocol = SSH_PROTO_2;
jcs@openbsd.orgf361df42015-11-15 22:26:49 +00001827 if (options->add_keys_to_agent == -1)
1828 options->add_keys_to_agent = 0;
Damien Miller95def091999-11-25 00:26:21 +11001829 if (options->num_identity_files == 0) {
Damien Miller0bc1bd82000-11-13 22:57:25 +11001830 if (options->protocol & SSH_PROTO_1) {
Darren Tucker19104782013-04-05 11:13:08 +11001831 add_identity_file(options, "~/",
1832 _PATH_SSH_CLIENT_IDENTITY, 0);
Damien Miller0bc1bd82000-11-13 22:57:25 +11001833 }
1834 if (options->protocol & SSH_PROTO_2) {
Darren Tucker19104782013-04-05 11:13:08 +11001835 add_identity_file(options, "~/",
1836 _PATH_SSH_CLIENT_ID_RSA, 0);
1837 add_identity_file(options, "~/",
1838 _PATH_SSH_CLIENT_ID_DSA, 0);
Damien Miller6af914a2010-09-10 11:39:26 +10001839#ifdef OPENSSL_HAS_ECC
Darren Tucker19104782013-04-05 11:13:08 +11001840 add_identity_file(options, "~/",
1841 _PATH_SSH_CLIENT_ID_ECDSA, 0);
Damien Miller6af914a2010-09-10 11:39:26 +10001842#endif
Damien Miller5be9d9e2013-12-07 11:24:01 +11001843 add_identity_file(options, "~/",
1844 _PATH_SSH_CLIENT_ID_ED25519, 0);
Damien Miller0bc1bd82000-11-13 22:57:25 +11001845 }
Damien Millereba71ba2000-04-29 23:57:08 +10001846 }
Damien Miller95def091999-11-25 00:26:21 +11001847 if (options->escape_char == -1)
1848 options->escape_char = '~';
Damien Miller295ee632011-05-29 21:42:31 +10001849 if (options->num_system_hostfiles == 0) {
1850 options->system_hostfiles[options->num_system_hostfiles++] =
1851 xstrdup(_PATH_SSH_SYSTEM_HOSTFILE);
1852 options->system_hostfiles[options->num_system_hostfiles++] =
1853 xstrdup(_PATH_SSH_SYSTEM_HOSTFILE2);
1854 }
1855 if (options->num_user_hostfiles == 0) {
1856 options->user_hostfiles[options->num_user_hostfiles++] =
1857 xstrdup(_PATH_SSH_USER_HOSTFILE);
1858 options->user_hostfiles[options->num_user_hostfiles++] =
1859 xstrdup(_PATH_SSH_USER_HOSTFILE2);
1860 }
Damien Millerfcd93202002-02-05 12:26:34 +11001861 if (options->log_level == SYSLOG_LEVEL_NOT_SET)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +00001862 options->log_level = SYSLOG_LEVEL_INFO;
Ben Lindstrom2b7a0e92001-09-20 00:57:55 +00001863 if (options->clear_forwardings == 1)
1864 clear_forwardings(options);
Ben Lindstrom3cecc9a2001-10-03 17:39:38 +00001865 if (options->no_host_authentication_for_localhost == - 1)
1866 options->no_host_authentication_for_localhost = 0;
Damien Millerbd394c32004-03-08 23:12:36 +11001867 if (options->identities_only == -1)
1868 options->identities_only = 0;
Ben Lindstromb6df73b2002-11-09 15:52:31 +00001869 if (options->enable_ssh_keysign == -1)
1870 options->enable_ssh_keysign = 0;
Damien Millera5539d22003-04-09 20:50:06 +10001871 if (options->rekey_limit == -1)
1872 options->rekey_limit = 0;
Darren Tuckerc53c2af2013-05-16 20:28:16 +10001873 if (options->rekey_interval == -1)
1874 options->rekey_interval = 0;
Damien Miller37876e92003-05-15 10:19:46 +10001875 if (options->verify_host_key_dns == -1)
1876 options->verify_host_key_dns = 0;
Damien Miller509b0102003-12-17 16:33:10 +11001877 if (options->server_alive_interval == -1)
1878 options->server_alive_interval = 0;
1879 if (options->server_alive_count_max == -1)
1880 options->server_alive_count_max = 3;
Damien Miller0e220db2004-06-15 10:34:08 +10001881 if (options->control_master == -1)
1882 options->control_master = 0;
Damien Millere11e1ea2010-08-03 16:04:46 +10001883 if (options->control_persist == -1) {
1884 options->control_persist = 0;
1885 options->control_persist_timeout = 0;
1886 }
Damien Millere1776152005-03-01 21:47:37 +11001887 if (options->hash_known_hosts == -1)
1888 options->hash_known_hosts = 0;
Damien Millerd27b9472005-12-13 19:29:02 +11001889 if (options->tun_open == -1)
Damien Miller7b58e802005-12-13 19:33:19 +11001890 options->tun_open = SSH_TUNMODE_NO;
1891 if (options->tun_local == -1)
1892 options->tun_local = SSH_TUNID_ANY;
1893 if (options->tun_remote == -1)
1894 options->tun_remote = SSH_TUNID_ANY;
Damien Millerd27b9472005-12-13 19:29:02 +11001895 if (options->permit_local_command == -1)
1896 options->permit_local_command = 0;
Damien Miller10288242008-06-30 00:04:03 +10001897 if (options->visual_host_key == -1)
1898 options->visual_host_key = 0;
Damien Miller0dac6fb2010-11-20 15:19:38 +11001899 if (options->ip_qos_interactive == -1)
1900 options->ip_qos_interactive = IPTOS_LOWDELAY;
1901 if (options->ip_qos_bulk == -1)
1902 options->ip_qos_bulk = IPTOS_THROUGHPUT;
Damien Miller21771e22011-05-15 08:45:50 +10001903 if (options->request_tty == -1)
1904 options->request_tty = REQUEST_TTY_AUTO;
Damien Miller1262b662013-08-21 02:44:24 +10001905 if (options->proxy_use_fdpass == -1)
1906 options->proxy_use_fdpass = 0;
Damien Miller38505592013-10-17 11:48:13 +11001907 if (options->canonicalize_max_dots == -1)
1908 options->canonicalize_max_dots = 1;
1909 if (options->canonicalize_fallback_local == -1)
1910 options->canonicalize_fallback_local = 1;
1911 if (options->canonicalize_hostname == -1)
1912 options->canonicalize_hostname = SSH_CANONICALISE_NO;
djm@openbsd.org56d1c832014-12-21 22:27:55 +00001913 if (options->fingerprint_hash == -1)
1914 options->fingerprint_hash = SSH_FP_HASH_DEFAULT;
djm@openbsd.org8d4f8722015-01-26 03:04:45 +00001915 if (options->update_hostkeys == -1)
djm@openbsd.org15ad7502015-02-02 07:41:40 +00001916 options->update_hostkeys = 0;
djm@openbsd.orgf9eca242015-07-30 00:01:34 +00001917 if (kex_assemble_names(KEX_CLIENT_ENCRYPT, &options->ciphers) != 0 ||
1918 kex_assemble_names(KEX_CLIENT_MAC, &options->macs) != 0 ||
1919 kex_assemble_names(KEX_CLIENT_KEX, &options->kex_algorithms) != 0 ||
1920 kex_assemble_names(KEX_DEFAULT_PK_ALG,
1921 &options->hostbased_key_types) != 0 ||
1922 kex_assemble_names(KEX_DEFAULT_PK_ALG,
1923 &options->pubkey_key_types) != 0)
1924 fatal("%s: kex_assemble_names failed", __func__);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00001925
Damien Millere9fc72e2013-10-15 12:14:12 +11001926#define CLEAR_ON_NONE(v) \
1927 do { \
Damien Miller13f97b22014-02-24 15:57:55 +11001928 if (option_clear_or_none(v)) { \
Damien Millere9fc72e2013-10-15 12:14:12 +11001929 free(v); \
1930 v = NULL; \
1931 } \
1932 } while(0)
1933 CLEAR_ON_NONE(options->local_command);
1934 CLEAR_ON_NONE(options->proxy_command);
1935 CLEAR_ON_NONE(options->control_path);
djm@openbsd.org5e39a492014-12-04 02:24:32 +00001936 CLEAR_ON_NONE(options->revoked_host_keys);
Damien Miller95def091999-11-25 00:26:21 +11001937 /* options->user will be set in the main program if appropriate */
1938 /* options->hostname will be set in the main program if appropriate */
Ben Lindstrom4dccfa52000-12-28 16:40:05 +00001939 /* options->host_key_alias should not be set by default */
Ben Lindstromb9be60a2001-03-11 01:49:19 +00001940 /* options->preferred_authentications will be set in ssh */
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001941}
Damien Millerf91ee4c2005-03-01 21:24:33 +11001942
Damien Miller7acefbb2014-07-18 14:11:24 +10001943struct fwdarg {
1944 char *arg;
1945 int ispath;
1946};
1947
1948/*
1949 * parse_fwd_field
1950 * parses the next field in a port forwarding specification.
1951 * sets fwd to the parsed field and advances p past the colon
1952 * or sets it to NULL at end of string.
1953 * returns 0 on success, else non-zero.
1954 */
1955static int
1956parse_fwd_field(char **p, struct fwdarg *fwd)
1957{
1958 char *ep, *cp = *p;
1959 int ispath = 0;
1960
1961 if (*cp == '\0') {
1962 *p = NULL;
1963 return -1; /* end of string */
1964 }
1965
1966 /*
1967 * A field escaped with square brackets is used literally.
1968 * XXX - allow ']' to be escaped via backslash?
1969 */
1970 if (*cp == '[') {
1971 /* find matching ']' */
1972 for (ep = cp + 1; *ep != ']' && *ep != '\0'; ep++) {
1973 if (*ep == '/')
1974 ispath = 1;
1975 }
1976 /* no matching ']' or not at end of field. */
1977 if (ep[0] != ']' || (ep[1] != ':' && ep[1] != '\0'))
1978 return -1;
1979 /* NUL terminate the field and advance p past the colon */
1980 *ep++ = '\0';
1981 if (*ep != '\0')
1982 *ep++ = '\0';
1983 fwd->arg = cp + 1;
1984 fwd->ispath = ispath;
1985 *p = ep;
1986 return 0;
1987 }
1988
1989 for (cp = *p; *cp != '\0'; cp++) {
1990 switch (*cp) {
1991 case '\\':
1992 memmove(cp, cp + 1, strlen(cp + 1) + 1);
djm@openbsd.org78c2a4f2015-06-26 05:13:20 +00001993 if (*cp == '\0')
1994 return -1;
Damien Miller7acefbb2014-07-18 14:11:24 +10001995 break;
1996 case '/':
1997 ispath = 1;
1998 break;
1999 case ':':
2000 *cp++ = '\0';
2001 goto done;
2002 }
2003 }
2004done:
2005 fwd->arg = *p;
2006 fwd->ispath = ispath;
2007 *p = cp;
2008 return 0;
2009}
2010
Damien Millerf91ee4c2005-03-01 21:24:33 +11002011/*
2012 * parse_forward
2013 * parses a string containing a port forwarding specification of the form:
Damien Millera699d952008-11-03 19:27:34 +11002014 * dynamicfwd == 0
Damien Miller7acefbb2014-07-18 14:11:24 +10002015 * [listenhost:]listenport|listenpath:connecthost:connectport|connectpath
2016 * listenpath:connectpath
Damien Millera699d952008-11-03 19:27:34 +11002017 * dynamicfwd == 1
2018 * [listenhost:]listenport
Damien Millerf91ee4c2005-03-01 21:24:33 +11002019 * returns number of arguments parsed or zero on error
2020 */
2021int
Damien Miller7acefbb2014-07-18 14:11:24 +10002022parse_forward(struct Forward *fwd, const char *fwdspec, int dynamicfwd, int remotefwd)
Damien Millerf91ee4c2005-03-01 21:24:33 +11002023{
Damien Miller7acefbb2014-07-18 14:11:24 +10002024 struct fwdarg fwdargs[4];
2025 char *p, *cp;
Damien Millerf91ee4c2005-03-01 21:24:33 +11002026 int i;
Damien Millerf91ee4c2005-03-01 21:24:33 +11002027
Damien Miller7acefbb2014-07-18 14:11:24 +10002028 memset(fwd, 0, sizeof(*fwd));
2029 memset(fwdargs, 0, sizeof(fwdargs));
Damien Millerf91ee4c2005-03-01 21:24:33 +11002030
2031 cp = p = xstrdup(fwdspec);
2032
2033 /* skip leading spaces */
Damien Millerfdb23062013-11-21 13:57:15 +11002034 while (isspace((u_char)*cp))
Damien Millerf91ee4c2005-03-01 21:24:33 +11002035 cp++;
2036
Damien Miller7acefbb2014-07-18 14:11:24 +10002037 for (i = 0; i < 4; ++i) {
2038 if (parse_fwd_field(&cp, &fwdargs[i]) != 0)
Damien Millerf91ee4c2005-03-01 21:24:33 +11002039 break;
Damien Miller7acefbb2014-07-18 14:11:24 +10002040 }
Damien Millerf91ee4c2005-03-01 21:24:33 +11002041
Damien Millerf4b39532008-11-03 19:28:21 +11002042 /* Check for trailing garbage */
Damien Miller7acefbb2014-07-18 14:11:24 +10002043 if (cp != NULL && *cp != '\0') {
Damien Millerf91ee4c2005-03-01 21:24:33 +11002044 i = 0; /* failure */
Damien Miller7acefbb2014-07-18 14:11:24 +10002045 }
Damien Millerf91ee4c2005-03-01 21:24:33 +11002046
2047 switch (i) {
Damien Millera699d952008-11-03 19:27:34 +11002048 case 1:
Damien Miller7acefbb2014-07-18 14:11:24 +10002049 if (fwdargs[0].ispath) {
2050 fwd->listen_path = xstrdup(fwdargs[0].arg);
2051 fwd->listen_port = PORT_STREAMLOCAL;
2052 } else {
2053 fwd->listen_host = NULL;
2054 fwd->listen_port = a2port(fwdargs[0].arg);
2055 }
Damien Millera699d952008-11-03 19:27:34 +11002056 fwd->connect_host = xstrdup("socks");
2057 break;
2058
2059 case 2:
Damien Miller7acefbb2014-07-18 14:11:24 +10002060 if (fwdargs[0].ispath && fwdargs[1].ispath) {
2061 fwd->listen_path = xstrdup(fwdargs[0].arg);
2062 fwd->listen_port = PORT_STREAMLOCAL;
2063 fwd->connect_path = xstrdup(fwdargs[1].arg);
2064 fwd->connect_port = PORT_STREAMLOCAL;
2065 } else if (fwdargs[1].ispath) {
2066 fwd->listen_host = NULL;
2067 fwd->listen_port = a2port(fwdargs[0].arg);
2068 fwd->connect_path = xstrdup(fwdargs[1].arg);
2069 fwd->connect_port = PORT_STREAMLOCAL;
2070 } else {
2071 fwd->listen_host = xstrdup(fwdargs[0].arg);
2072 fwd->listen_port = a2port(fwdargs[1].arg);
2073 fwd->connect_host = xstrdup("socks");
2074 }
Damien Millera699d952008-11-03 19:27:34 +11002075 break;
2076
Damien Millerf91ee4c2005-03-01 21:24:33 +11002077 case 3:
Damien Miller7acefbb2014-07-18 14:11:24 +10002078 if (fwdargs[0].ispath) {
2079 fwd->listen_path = xstrdup(fwdargs[0].arg);
2080 fwd->listen_port = PORT_STREAMLOCAL;
2081 fwd->connect_host = xstrdup(fwdargs[1].arg);
2082 fwd->connect_port = a2port(fwdargs[2].arg);
2083 } else if (fwdargs[2].ispath) {
2084 fwd->listen_host = xstrdup(fwdargs[0].arg);
2085 fwd->listen_port = a2port(fwdargs[1].arg);
2086 fwd->connect_path = xstrdup(fwdargs[2].arg);
2087 fwd->connect_port = PORT_STREAMLOCAL;
2088 } else {
2089 fwd->listen_host = NULL;
2090 fwd->listen_port = a2port(fwdargs[0].arg);
2091 fwd->connect_host = xstrdup(fwdargs[1].arg);
2092 fwd->connect_port = a2port(fwdargs[2].arg);
2093 }
Damien Millerf91ee4c2005-03-01 21:24:33 +11002094 break;
2095
2096 case 4:
Damien Miller7acefbb2014-07-18 14:11:24 +10002097 fwd->listen_host = xstrdup(fwdargs[0].arg);
2098 fwd->listen_port = a2port(fwdargs[1].arg);
2099 fwd->connect_host = xstrdup(fwdargs[2].arg);
2100 fwd->connect_port = a2port(fwdargs[3].arg);
Damien Millerf91ee4c2005-03-01 21:24:33 +11002101 break;
2102 default:
2103 i = 0; /* failure */
2104 }
2105
Darren Tuckera627d422013-06-02 07:31:17 +10002106 free(p);
Damien Millerf91ee4c2005-03-01 21:24:33 +11002107
Damien Millera699d952008-11-03 19:27:34 +11002108 if (dynamicfwd) {
2109 if (!(i == 1 || i == 2))
2110 goto fail_free;
2111 } else {
Damien Miller7acefbb2014-07-18 14:11:24 +10002112 if (!(i == 3 || i == 4)) {
2113 if (fwd->connect_path == NULL &&
2114 fwd->listen_path == NULL)
2115 goto fail_free;
2116 }
2117 if (fwd->connect_port <= 0 && fwd->connect_path == NULL)
Damien Millera699d952008-11-03 19:27:34 +11002118 goto fail_free;
2119 }
2120
Damien Miller7acefbb2014-07-18 14:11:24 +10002121 if ((fwd->listen_port < 0 && fwd->listen_path == NULL) ||
2122 (!remotefwd && fwd->listen_port == 0))
Damien Millerf91ee4c2005-03-01 21:24:33 +11002123 goto fail_free;
Damien Millerf91ee4c2005-03-01 21:24:33 +11002124 if (fwd->connect_host != NULL &&
2125 strlen(fwd->connect_host) >= NI_MAXHOST)
2126 goto fail_free;
Damien Miller7acefbb2014-07-18 14:11:24 +10002127 /* XXX - if connecting to a remote socket, max sun len may not match this host */
2128 if (fwd->connect_path != NULL &&
2129 strlen(fwd->connect_path) >= PATH_MAX_SUN)
2130 goto fail_free;
Damien Miller4bf648f2009-02-14 16:28:21 +11002131 if (fwd->listen_host != NULL &&
2132 strlen(fwd->listen_host) >= NI_MAXHOST)
2133 goto fail_free;
Damien Miller7acefbb2014-07-18 14:11:24 +10002134 if (fwd->listen_path != NULL &&
2135 strlen(fwd->listen_path) >= PATH_MAX_SUN)
2136 goto fail_free;
Damien Millerf91ee4c2005-03-01 21:24:33 +11002137
2138 return (i);
2139
2140 fail_free:
Darren Tuckera627d422013-06-02 07:31:17 +10002141 free(fwd->connect_host);
2142 fwd->connect_host = NULL;
Damien Miller7acefbb2014-07-18 14:11:24 +10002143 free(fwd->connect_path);
2144 fwd->connect_path = NULL;
Darren Tuckera627d422013-06-02 07:31:17 +10002145 free(fwd->listen_host);
2146 fwd->listen_host = NULL;
Damien Miller7acefbb2014-07-18 14:11:24 +10002147 free(fwd->listen_path);
2148 fwd->listen_path = NULL;
Damien Millerf91ee4c2005-03-01 21:24:33 +11002149 return (0);
2150}
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002151
2152/* XXX the following is a near-vebatim copy from servconf.c; refactor */
2153static const char *
2154fmt_multistate_int(int val, const struct multistate *m)
2155{
2156 u_int i;
2157
2158 for (i = 0; m[i].key != NULL; i++) {
2159 if (m[i].value == val)
2160 return m[i].key;
2161 }
2162 return "UNKNOWN";
2163}
2164
2165static const char *
2166fmt_intarg(OpCodes code, int val)
2167{
2168 if (val == -1)
2169 return "unset";
2170 switch (code) {
2171 case oAddressFamily:
2172 return fmt_multistate_int(val, multistate_addressfamily);
2173 case oVerifyHostKeyDNS:
2174 case oStrictHostKeyChecking:
djm@openbsd.org523463a2015-02-16 22:13:32 +00002175 case oUpdateHostkeys:
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002176 return fmt_multistate_int(val, multistate_yesnoask);
2177 case oControlMaster:
2178 return fmt_multistate_int(val, multistate_controlmaster);
2179 case oTunnel:
2180 return fmt_multistate_int(val, multistate_tunnel);
2181 case oRequestTTY:
2182 return fmt_multistate_int(val, multistate_requesttty);
2183 case oCanonicalizeHostname:
2184 return fmt_multistate_int(val, multistate_canonicalizehostname);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002185 case oFingerprintHash:
2186 return ssh_digest_alg_name(val);
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002187 case oProtocol:
2188 switch (val) {
2189 case SSH_PROTO_1:
2190 return "1";
2191 case SSH_PROTO_2:
2192 return "2";
2193 case (SSH_PROTO_1|SSH_PROTO_2):
2194 return "2,1";
2195 default:
2196 return "UNKNOWN";
2197 }
2198 default:
2199 switch (val) {
2200 case 0:
2201 return "no";
2202 case 1:
2203 return "yes";
2204 default:
2205 return "UNKNOWN";
2206 }
2207 }
2208}
2209
2210static const char *
2211lookup_opcode_name(OpCodes code)
2212{
2213 u_int i;
2214
2215 for (i = 0; keywords[i].name != NULL; i++)
2216 if (keywords[i].opcode == code)
2217 return(keywords[i].name);
2218 return "UNKNOWN";
2219}
2220
2221static void
2222dump_cfg_int(OpCodes code, int val)
2223{
2224 printf("%s %d\n", lookup_opcode_name(code), val);
2225}
2226
2227static void
2228dump_cfg_fmtint(OpCodes code, int val)
2229{
2230 printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
2231}
2232
2233static void
2234dump_cfg_string(OpCodes code, const char *val)
2235{
2236 if (val == NULL)
2237 return;
2238 printf("%s %s\n", lookup_opcode_name(code), val);
2239}
2240
2241static void
2242dump_cfg_strarray(OpCodes code, u_int count, char **vals)
2243{
2244 u_int i;
2245
2246 for (i = 0; i < count; i++)
2247 printf("%s %s\n", lookup_opcode_name(code), vals[i]);
2248}
2249
2250static void
2251dump_cfg_strarray_oneline(OpCodes code, u_int count, char **vals)
2252{
2253 u_int i;
2254
2255 printf("%s", lookup_opcode_name(code));
2256 for (i = 0; i < count; i++)
2257 printf(" %s", vals[i]);
2258 printf("\n");
2259}
2260
2261static void
2262dump_cfg_forwards(OpCodes code, u_int count, const struct Forward *fwds)
2263{
2264 const struct Forward *fwd;
2265 u_int i;
2266
2267 /* oDynamicForward */
2268 for (i = 0; i < count; i++) {
2269 fwd = &fwds[i];
2270 if (code == oDynamicForward &&
2271 strcmp(fwd->connect_host, "socks") != 0)
2272 continue;
2273 if (code == oLocalForward &&
2274 strcmp(fwd->connect_host, "socks") == 0)
2275 continue;
2276 printf("%s", lookup_opcode_name(code));
2277 if (fwd->listen_port == PORT_STREAMLOCAL)
2278 printf(" %s", fwd->listen_path);
2279 else if (fwd->listen_host == NULL)
2280 printf(" %d", fwd->listen_port);
2281 else {
2282 printf(" [%s]:%d",
2283 fwd->listen_host, fwd->listen_port);
2284 }
2285 if (code != oDynamicForward) {
2286 if (fwd->connect_port == PORT_STREAMLOCAL)
2287 printf(" %s", fwd->connect_path);
2288 else if (fwd->connect_host == NULL)
2289 printf(" %d", fwd->connect_port);
2290 else {
2291 printf(" [%s]:%d",
2292 fwd->connect_host, fwd->connect_port);
2293 }
2294 }
2295 printf("\n");
2296 }
2297}
2298
2299void
2300dump_client_config(Options *o, const char *host)
2301{
2302 int i;
2303 char vbuf[5];
2304
djm@openbsd.org60a92472015-08-21 23:53:08 +00002305 /* This is normally prepared in ssh_kex2 */
2306 if (kex_assemble_names(KEX_DEFAULT_PK_ALG, &o->hostkeyalgorithms) != 0)
2307 fatal("%s: kex_assemble_names failed", __func__);
2308
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002309 /* Most interesting options first: user, host, port */
2310 dump_cfg_string(oUser, o->user);
2311 dump_cfg_string(oHostName, host);
2312 dump_cfg_int(oPort, o->port);
2313
2314 /* Flag options */
2315 dump_cfg_fmtint(oAddressFamily, o->address_family);
2316 dump_cfg_fmtint(oBatchMode, o->batch_mode);
2317 dump_cfg_fmtint(oCanonicalizeFallbackLocal, o->canonicalize_fallback_local);
2318 dump_cfg_fmtint(oCanonicalizeHostname, o->canonicalize_hostname);
2319 dump_cfg_fmtint(oChallengeResponseAuthentication, o->challenge_response_authentication);
2320 dump_cfg_fmtint(oCheckHostIP, o->check_host_ip);
2321 dump_cfg_fmtint(oCompression, o->compression);
2322 dump_cfg_fmtint(oControlMaster, o->control_master);
2323 dump_cfg_fmtint(oEnableSSHKeysign, o->enable_ssh_keysign);
2324 dump_cfg_fmtint(oExitOnForwardFailure, o->exit_on_forward_failure);
djm@openbsd.org56d1c832014-12-21 22:27:55 +00002325 dump_cfg_fmtint(oFingerprintHash, o->fingerprint_hash);
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002326 dump_cfg_fmtint(oForwardAgent, o->forward_agent);
2327 dump_cfg_fmtint(oForwardX11, o->forward_x11);
2328 dump_cfg_fmtint(oForwardX11Trusted, o->forward_x11_trusted);
2329 dump_cfg_fmtint(oGatewayPorts, o->fwd_opts.gateway_ports);
2330#ifdef GSSAPI
2331 dump_cfg_fmtint(oGssAuthentication, o->gss_authentication);
2332 dump_cfg_fmtint(oGssDelegateCreds, o->gss_deleg_creds);
2333#endif /* GSSAPI */
2334 dump_cfg_fmtint(oHashKnownHosts, o->hash_known_hosts);
2335 dump_cfg_fmtint(oHostbasedAuthentication, o->hostbased_authentication);
2336 dump_cfg_fmtint(oIdentitiesOnly, o->identities_only);
2337 dump_cfg_fmtint(oKbdInteractiveAuthentication, o->kbd_interactive_authentication);
2338 dump_cfg_fmtint(oNoHostAuthenticationForLocalhost, o->no_host_authentication_for_localhost);
2339 dump_cfg_fmtint(oPasswordAuthentication, o->password_authentication);
2340 dump_cfg_fmtint(oPermitLocalCommand, o->permit_local_command);
2341 dump_cfg_fmtint(oProtocol, o->protocol);
2342 dump_cfg_fmtint(oProxyUseFdpass, o->proxy_use_fdpass);
2343 dump_cfg_fmtint(oPubkeyAuthentication, o->pubkey_authentication);
2344 dump_cfg_fmtint(oRequestTTY, o->request_tty);
2345 dump_cfg_fmtint(oRhostsRSAAuthentication, o->rhosts_rsa_authentication);
2346 dump_cfg_fmtint(oRSAAuthentication, o->rsa_authentication);
2347 dump_cfg_fmtint(oStreamLocalBindUnlink, o->fwd_opts.streamlocal_bind_unlink);
2348 dump_cfg_fmtint(oStrictHostKeyChecking, o->strict_host_key_checking);
2349 dump_cfg_fmtint(oTCPKeepAlive, o->tcp_keep_alive);
2350 dump_cfg_fmtint(oTunnel, o->tun_open);
2351 dump_cfg_fmtint(oUsePrivilegedPort, o->use_privileged_port);
2352 dump_cfg_fmtint(oVerifyHostKeyDNS, o->verify_host_key_dns);
2353 dump_cfg_fmtint(oVisualHostKey, o->visual_host_key);
djm@openbsd.org8d4f8722015-01-26 03:04:45 +00002354 dump_cfg_fmtint(oUpdateHostkeys, o->update_hostkeys);
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002355
2356 /* Integer options */
2357 dump_cfg_int(oCanonicalizeMaxDots, o->canonicalize_max_dots);
2358 dump_cfg_int(oCompressionLevel, o->compression_level);
2359 dump_cfg_int(oConnectionAttempts, o->connection_attempts);
2360 dump_cfg_int(oForwardX11Timeout, o->forward_x11_timeout);
2361 dump_cfg_int(oNumberOfPasswordPrompts, o->number_of_password_prompts);
2362 dump_cfg_int(oServerAliveCountMax, o->server_alive_count_max);
2363 dump_cfg_int(oServerAliveInterval, o->server_alive_interval);
2364
2365 /* String options */
2366 dump_cfg_string(oBindAddress, o->bind_address);
2367 dump_cfg_string(oCiphers, o->ciphers ? o->ciphers : KEX_CLIENT_ENCRYPT);
2368 dump_cfg_string(oControlPath, o->control_path);
djm@openbsd.org60a92472015-08-21 23:53:08 +00002369 dump_cfg_string(oHostKeyAlgorithms, o->hostkeyalgorithms);
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002370 dump_cfg_string(oHostKeyAlias, o->host_key_alias);
djm@openbsd.org46347ed2015-01-30 11:43:14 +00002371 dump_cfg_string(oHostbasedKeyTypes, o->hostbased_key_types);
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002372 dump_cfg_string(oKbdInteractiveDevices, o->kbd_interactive_devices);
2373 dump_cfg_string(oKexAlgorithms, o->kex_algorithms ? o->kex_algorithms : KEX_CLIENT_KEX);
2374 dump_cfg_string(oLocalCommand, o->local_command);
2375 dump_cfg_string(oLogLevel, log_level_name(o->log_level));
2376 dump_cfg_string(oMacs, o->macs ? o->macs : KEX_CLIENT_MAC);
2377 dump_cfg_string(oPKCS11Provider, o->pkcs11_provider);
2378 dump_cfg_string(oPreferredAuthentications, o->preferred_authentications);
2379 dump_cfg_string(oProxyCommand, o->proxy_command);
djm@openbsd.org0c46bbe2015-10-07 15:59:12 +00002380 dump_cfg_string(oPubkeyAcceptedKeyTypes, o->pubkey_key_types);
djm@openbsd.org5e39a492014-12-04 02:24:32 +00002381 dump_cfg_string(oRevokedHostKeys, o->revoked_host_keys);
djm@openbsd.org46347ed2015-01-30 11:43:14 +00002382 dump_cfg_string(oXAuthLocation, o->xauth_location);
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002383
djm@openbsd.org46347ed2015-01-30 11:43:14 +00002384 /* Forwards */
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002385 dump_cfg_forwards(oDynamicForward, o->num_local_forwards, o->local_forwards);
2386 dump_cfg_forwards(oLocalForward, o->num_local_forwards, o->local_forwards);
2387 dump_cfg_forwards(oRemoteForward, o->num_remote_forwards, o->remote_forwards);
2388
2389 /* String array options */
2390 dump_cfg_strarray(oIdentityFile, o->num_identity_files, o->identity_files);
2391 dump_cfg_strarray_oneline(oCanonicalDomains, o->num_canonical_domains, o->canonical_domains);
2392 dump_cfg_strarray_oneline(oGlobalKnownHostsFile, o->num_system_hostfiles, o->system_hostfiles);
2393 dump_cfg_strarray_oneline(oUserKnownHostsFile, o->num_user_hostfiles, o->user_hostfiles);
2394 dump_cfg_strarray(oSendEnv, o->num_send_env, o->send_env);
2395
2396 /* Special cases */
2397
2398 /* oConnectTimeout */
2399 if (o->connection_timeout == -1)
2400 printf("connecttimeout none\n");
2401 else
2402 dump_cfg_int(oConnectTimeout, o->connection_timeout);
2403
2404 /* oTunnelDevice */
2405 printf("tunneldevice");
2406 if (o->tun_local == SSH_TUNID_ANY)
2407 printf(" any");
2408 else
2409 printf(" %d", o->tun_local);
2410 if (o->tun_remote == SSH_TUNID_ANY)
2411 printf(":any");
2412 else
2413 printf(":%d", o->tun_remote);
2414 printf("\n");
2415
2416 /* oCanonicalizePermittedCNAMEs */
2417 if ( o->num_permitted_cnames > 0) {
2418 printf("canonicalizePermittedcnames");
2419 for (i = 0; i < o->num_permitted_cnames; i++) {
2420 printf(" %s:%s", o->permitted_cnames[i].source_list,
2421 o->permitted_cnames[i].target_list);
2422 }
2423 printf("\n");
2424 }
2425
2426 /* oCipher */
2427 if (o->cipher != SSH_CIPHER_NOT_SET)
2428 printf("Cipher %s\n", cipher_name(o->cipher));
2429
2430 /* oControlPersist */
2431 if (o->control_persist == 0 || o->control_persist_timeout == 0)
2432 dump_cfg_fmtint(oControlPersist, o->control_persist);
2433 else
2434 dump_cfg_int(oControlPersist, o->control_persist_timeout);
2435
2436 /* oEscapeChar */
2437 if (o->escape_char == SSH_ESCAPECHAR_NONE)
2438 printf("escapechar none\n");
2439 else {
2440 vis(vbuf, o->escape_char, VIS_WHITE, 0);
2441 printf("escapechar %s\n", vbuf);
2442 }
2443
2444 /* oIPQoS */
2445 printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
2446 printf("%s\n", iptos2str(o->ip_qos_bulk));
2447
2448 /* oRekeyLimit */
dtucker@openbsd.org921ff002016-01-29 02:54:45 +00002449 printf("rekeylimit %llu %d\n",
2450 (unsigned long long)o->rekey_limit, o->rekey_interval);
djm@openbsd.org957fbce2014-10-08 22:20:25 +00002451
2452 /* oStreamLocalBindMask */
2453 printf("streamlocalbindmask 0%o\n",
2454 o->fwd_opts.streamlocal_bind_mask);
2455}