Home | History | Annotate | Line # | Download | only in dist
readconf.c revision 1.14
      1  1.11  christos /*	$NetBSD: readconf.c,v 1.14 2015/07/03 01:00:00 christos Exp $	*/
      2  1.14  christos /* $OpenBSD: readconf.c,v 1.237 2015/06/26 05:13:20 djm Exp $ */
      3   1.1  christos /*
      4   1.1  christos  * Author: Tatu Ylonen <ylo (at) cs.hut.fi>
      5   1.1  christos  * Copyright (c) 1995 Tatu Ylonen <ylo (at) cs.hut.fi>, Espoo, Finland
      6   1.1  christos  *                    All rights reserved
      7   1.1  christos  * Functions for reading the configuration files.
      8   1.1  christos  *
      9   1.1  christos  * As far as I am concerned, the code I have written for this software
     10   1.1  christos  * can be used freely for any purpose.  Any derived versions of this
     11   1.1  christos  * software must be clearly marked as such, and if the derived work is
     12   1.1  christos  * incompatible with the protocol description in the RFC file, it must be
     13   1.1  christos  * called by a name other than "ssh" or "Secure Shell".
     14   1.1  christos  */
     15   1.1  christos 
     16   1.2  christos #include "includes.h"
     17  1.11  christos __RCSID("$NetBSD: readconf.c,v 1.14 2015/07/03 01:00:00 christos Exp $");
     18   1.1  christos #include <sys/types.h>
     19   1.1  christos #include <sys/stat.h>
     20   1.1  christos #include <sys/socket.h>
     21  1.12  christos #include <sys/wait.h>
     22  1.12  christos #include <sys/un.h>
     23   1.1  christos 
     24   1.1  christos #include <netinet/in.h>
     25   1.5  christos #include <netinet/ip.h>
     26   1.1  christos 
     27   1.1  christos #include <ctype.h>
     28   1.1  christos #include <errno.h>
     29  1.12  christos #include <fcntl.h>
     30   1.1  christos #include <netdb.h>
     31  1.12  christos #include <paths.h>
     32  1.12  christos #include <pwd.h>
     33   1.1  christos #include <signal.h>
     34   1.1  christos #include <stdio.h>
     35   1.1  christos #include <string.h>
     36   1.1  christos #include <unistd.h>
     37   1.2  christos #include <limits.h>
     38  1.11  christos #include <util.h>
     39  1.13  christos #include <vis.h>
     40   1.1  christos 
     41   1.1  christos #include "xmalloc.h"
     42   1.1  christos #include "ssh.h"
     43   1.1  christos #include "compat.h"
     44   1.1  christos #include "cipher.h"
     45   1.1  christos #include "pathnames.h"
     46   1.1  christos #include "log.h"
     47  1.13  christos #include "sshkey.h"
     48  1.12  christos #include "misc.h"
     49   1.1  christos #include "readconf.h"
     50   1.1  christos #include "match.h"
     51   1.1  christos #include "kex.h"
     52   1.1  christos #include "mac.h"
     53  1.11  christos #include "fmt_scaled.h"
     54  1.12  christos #include "uidswap.h"
     55  1.13  christos #include "myproposal.h"
     56  1.13  christos #include "digest.h"
     57   1.1  christos 
     58   1.1  christos /* Format of the configuration file:
     59   1.1  christos 
     60   1.1  christos    # Configuration data is parsed as follows:
     61   1.1  christos    #  1. command line options
     62   1.1  christos    #  2. user-specific file
     63   1.1  christos    #  3. system-wide file
     64   1.1  christos    # Any configuration value is only changed the first time it is set.
     65   1.1  christos    # Thus, host-specific definitions should be at the beginning of the
     66   1.1  christos    # configuration file, and defaults at the end.
     67   1.1  christos 
     68   1.1  christos    # Host-specific declarations.  These may override anything above.  A single
     69   1.1  christos    # host may match multiple declarations; these are processed in the order
     70   1.1  christos    # that they are given in.
     71   1.1  christos 
     72   1.1  christos    Host *.ngs.fi ngs.fi
     73   1.1  christos      User foo
     74   1.1  christos 
     75   1.1  christos    Host fake.com
     76   1.1  christos      HostName another.host.name.real.org
     77   1.1  christos      User blaah
     78   1.1  christos      Port 34289
     79   1.1  christos      ForwardX11 no
     80   1.1  christos      ForwardAgent no
     81   1.1  christos 
     82   1.1  christos    Host books.com
     83   1.1  christos      RemoteForward 9999 shadows.cs.hut.fi:9999
     84   1.1  christos      Cipher 3des
     85   1.1  christos 
     86   1.1  christos    Host fascist.blob.com
     87   1.1  christos      Port 23123
     88   1.1  christos      User tylonen
     89   1.1  christos      PasswordAuthentication no
     90   1.1  christos 
     91   1.1  christos    Host puukko.hut.fi
     92   1.1  christos      User t35124p
     93   1.1  christos      ProxyCommand ssh-proxy %h %p
     94   1.1  christos 
     95   1.1  christos    Host *.fr
     96   1.1  christos      PublicKeyAuthentication no
     97   1.1  christos 
     98   1.1  christos    Host *.su
     99   1.1  christos      Cipher none
    100   1.1  christos      PasswordAuthentication no
    101   1.1  christos 
    102   1.1  christos    Host vpn.fake.com
    103   1.1  christos      Tunnel yes
    104   1.1  christos      TunnelDevice 3
    105   1.1  christos 
    106   1.1  christos    # Defaults for various options
    107   1.1  christos    Host *
    108   1.1  christos      ForwardAgent no
    109   1.1  christos      ForwardX11 no
    110   1.1  christos      PasswordAuthentication yes
    111   1.1  christos      RSAAuthentication yes
    112   1.1  christos      RhostsRSAAuthentication yes
    113   1.1  christos      StrictHostKeyChecking yes
    114   1.1  christos      TcpKeepAlive no
    115   1.1  christos      IdentityFile ~/.ssh/identity
    116   1.1  christos      Port 22
    117   1.1  christos      EscapeChar ~
    118   1.1  christos 
    119   1.1  christos */
    120   1.1  christos 
    121   1.1  christos /* Keyword tokens. */
    122   1.1  christos 
    123   1.1  christos typedef enum {
    124   1.1  christos 	oBadOption,
    125  1.12  christos 	oHost, oMatch,
    126   1.4      adam 	oForwardAgent, oForwardX11, oForwardX11Trusted, oForwardX11Timeout,
    127   1.4      adam 	oGatewayPorts, oExitOnForwardFailure,
    128   1.1  christos 	oPasswordAuthentication, oRSAAuthentication,
    129   1.1  christos 	oChallengeResponseAuthentication, oXAuthLocation,
    130   1.2  christos #if defined(KRB4) || defined(KRB5)
    131   1.2  christos 	oKerberosAuthentication,
    132   1.2  christos #endif
    133   1.2  christos #if defined(AFS) || defined(KRB5)
    134   1.2  christos 	oKerberosTgtPassing,
    135   1.2  christos #endif
    136   1.2  christos #ifdef AFS
    137   1.2  christos 	oAFSTokenPassing,
    138   1.2  christos #endif
    139   1.1  christos 	oIdentityFile, oHostName, oPort, oCipher, oRemoteForward, oLocalForward,
    140  1.12  christos 	oUser, oEscapeChar, oRhostsRSAAuthentication, oProxyCommand,
    141   1.1  christos 	oGlobalKnownHostsFile, oUserKnownHostsFile, oConnectionAttempts,
    142   1.1  christos 	oBatchMode, oCheckHostIP, oStrictHostKeyChecking, oCompression,
    143   1.1  christos 	oCompressionLevel, oTCPKeepAlive, oNumberOfPasswordPrompts,
    144   1.1  christos 	oUsePrivilegedPort, oLogLevel, oCiphers, oProtocol, oMacs,
    145  1.13  christos 	oPubkeyAuthentication,
    146   1.1  christos 	oKbdInteractiveAuthentication, oKbdInteractiveDevices, oHostKeyAlias,
    147   1.1  christos 	oDynamicForward, oPreferredAuthentications, oHostbasedAuthentication,
    148   1.4      adam 	oHostKeyAlgorithms, oBindAddress, oPKCS11Provider,
    149   1.1  christos 	oClearAllForwardings, oNoHostAuthenticationForLocalhost,
    150   1.1  christos 	oEnableSSHKeysign, oRekeyLimit, oVerifyHostKeyDNS, oConnectTimeout,
    151   1.1  christos 	oAddressFamily, oGssAuthentication, oGssDelegateCreds,
    152   1.1  christos 	oServerAliveInterval, oServerAliveCountMax, oIdentitiesOnly,
    153   1.4      adam 	oSendEnv, oControlPath, oControlMaster, oControlPersist,
    154   1.4      adam 	oHashKnownHosts,
    155   1.1  christos 	oTunnel, oTunnelDevice, oLocalCommand, oPermitLocalCommand,
    156  1.12  christos 	oVisualHostKey, oUseRoaming,
    157  1.12  christos 	oKexAlgorithms, oIPQoS, oRequestTTY, oIgnoreUnknown, oProxyUseFdpass,
    158  1.12  christos 	oCanonicalDomains, oCanonicalizeHostname, oCanonicalizeMaxDots,
    159  1.12  christos 	oCanonicalizeFallbackLocal, oCanonicalizePermittedCNAMEs,
    160  1.13  christos 	oStreamLocalBindMask, oStreamLocalBindUnlink, oRevokedHostKeys,
    161  1.13  christos 	oFingerprintHash, oUpdateHostkeys, oHostbasedKeyTypes,
    162   1.2  christos 	oNoneEnabled, oTcpRcvBufPoll, oTcpRcvBuf, oNoneSwitch, oHPNDisabled,
    163   1.2  christos 	oHPNBufferSize,
    164   1.7       tls 	oSendVersionFirst,
    165  1.12  christos 	oIgnoredUnknownOption, oDeprecated, oUnsupported
    166   1.1  christos } OpCodes;
    167   1.1  christos 
    168   1.1  christos /* Textual representations of the tokens. */
    169   1.1  christos 
    170   1.1  christos static struct {
    171   1.1  christos 	const char *name;
    172   1.1  christos 	OpCodes opcode;
    173   1.1  christos } keywords[] = {
    174   1.1  christos 	{ "forwardagent", oForwardAgent },
    175   1.1  christos 	{ "forwardx11", oForwardX11 },
    176   1.1  christos 	{ "forwardx11trusted", oForwardX11Trusted },
    177   1.4      adam 	{ "forwardx11timeout", oForwardX11Timeout },
    178   1.1  christos 	{ "exitonforwardfailure", oExitOnForwardFailure },
    179   1.1  christos 	{ "xauthlocation", oXAuthLocation },
    180   1.1  christos 	{ "gatewayports", oGatewayPorts },
    181   1.1  christos 	{ "useprivilegedport", oUsePrivilegedPort },
    182   1.1  christos 	{ "rhostsauthentication", oDeprecated },
    183   1.1  christos 	{ "passwordauthentication", oPasswordAuthentication },
    184   1.1  christos 	{ "kbdinteractiveauthentication", oKbdInteractiveAuthentication },
    185   1.1  christos 	{ "kbdinteractivedevices", oKbdInteractiveDevices },
    186   1.1  christos 	{ "rsaauthentication", oRSAAuthentication },
    187   1.1  christos 	{ "pubkeyauthentication", oPubkeyAuthentication },
    188   1.1  christos 	{ "dsaauthentication", oPubkeyAuthentication },		    /* alias */
    189   1.1  christos 	{ "rhostsrsaauthentication", oRhostsRSAAuthentication },
    190   1.1  christos 	{ "hostbasedauthentication", oHostbasedAuthentication },
    191   1.1  christos 	{ "challengeresponseauthentication", oChallengeResponseAuthentication },
    192   1.1  christos 	{ "skeyauthentication", oChallengeResponseAuthentication }, /* alias */
    193   1.1  christos 	{ "tisauthentication", oChallengeResponseAuthentication },  /* alias */
    194   1.2  christos #if defined(KRB4) || defined(KRB5)
    195   1.2  christos 	{ "kerberosauthentication", oKerberosAuthentication },
    196   1.2  christos #endif
    197   1.2  christos #if defined(AFS) || defined(KRB5)
    198   1.2  christos 	{ "kerberostgtpassing", oKerberosTgtPassing },
    199   1.2  christos 	{ "kerberos5tgtpassing", oKerberosTgtPassing },		/* alias */
    200   1.2  christos 	{ "kerberos4tgtpassing", oKerberosTgtPassing },		/* alias */
    201   1.2  christos #endif
    202   1.2  christos #ifdef AFS
    203   1.2  christos 	{ "afstokenpassing", oAFSTokenPassing },
    204   1.2  christos #endif
    205   1.1  christos #if defined(GSSAPI)
    206   1.1  christos 	{ "gssapiauthentication", oGssAuthentication },
    207   1.1  christos 	{ "gssapidelegatecredentials", oGssDelegateCreds },
    208   1.1  christos #else
    209   1.1  christos 	{ "gssapiauthentication", oUnsupported },
    210   1.1  christos 	{ "gssapidelegatecredentials", oUnsupported },
    211   1.1  christos #endif
    212   1.1  christos 	{ "fallbacktorsh", oDeprecated },
    213   1.1  christos 	{ "usersh", oDeprecated },
    214   1.1  christos 	{ "identityfile", oIdentityFile },
    215   1.1  christos 	{ "identityfile2", oIdentityFile },			/* obsolete */
    216   1.1  christos 	{ "identitiesonly", oIdentitiesOnly },
    217   1.1  christos 	{ "hostname", oHostName },
    218   1.1  christos 	{ "hostkeyalias", oHostKeyAlias },
    219   1.1  christos 	{ "proxycommand", oProxyCommand },
    220   1.1  christos 	{ "port", oPort },
    221   1.1  christos 	{ "cipher", oCipher },
    222   1.1  christos 	{ "ciphers", oCiphers },
    223   1.1  christos 	{ "macs", oMacs },
    224   1.1  christos 	{ "protocol", oProtocol },
    225   1.1  christos 	{ "remoteforward", oRemoteForward },
    226   1.1  christos 	{ "localforward", oLocalForward },
    227   1.1  christos 	{ "user", oUser },
    228   1.1  christos 	{ "host", oHost },
    229  1.12  christos 	{ "match", oMatch },
    230   1.1  christos 	{ "escapechar", oEscapeChar },
    231   1.1  christos 	{ "globalknownhostsfile", oGlobalKnownHostsFile },
    232   1.6  christos 	{ "globalknownhostsfile2", oDeprecated },
    233   1.1  christos 	{ "userknownhostsfile", oUserKnownHostsFile },
    234  1.13  christos 	{ "userknownhostsfile2", oDeprecated },
    235   1.1  christos 	{ "connectionattempts", oConnectionAttempts },
    236   1.1  christos 	{ "batchmode", oBatchMode },
    237   1.1  christos 	{ "checkhostip", oCheckHostIP },
    238   1.1  christos 	{ "stricthostkeychecking", oStrictHostKeyChecking },
    239   1.1  christos 	{ "compression", oCompression },
    240   1.1  christos 	{ "compressionlevel", oCompressionLevel },
    241   1.1  christos 	{ "tcpkeepalive", oTCPKeepAlive },
    242   1.1  christos 	{ "keepalive", oTCPKeepAlive },				/* obsolete */
    243   1.1  christos 	{ "numberofpasswordprompts", oNumberOfPasswordPrompts },
    244   1.1  christos 	{ "loglevel", oLogLevel },
    245   1.1  christos 	{ "dynamicforward", oDynamicForward },
    246   1.1  christos 	{ "preferredauthentications", oPreferredAuthentications },
    247   1.1  christos 	{ "hostkeyalgorithms", oHostKeyAlgorithms },
    248   1.1  christos 	{ "bindaddress", oBindAddress },
    249   1.4      adam #ifdef ENABLE_PKCS11
    250   1.4      adam 	{ "smartcarddevice", oPKCS11Provider },
    251   1.4      adam 	{ "pkcs11provider", oPKCS11Provider },
    252   1.1  christos #else
    253   1.1  christos 	{ "smartcarddevice", oUnsupported },
    254   1.4      adam 	{ "pkcs11provider", oUnsupported },
    255   1.1  christos #endif
    256   1.1  christos 	{ "clearallforwardings", oClearAllForwardings },
    257   1.1  christos 	{ "enablesshkeysign", oEnableSSHKeysign },
    258   1.1  christos 	{ "verifyhostkeydns", oVerifyHostKeyDNS },
    259   1.1  christos 	{ "nohostauthenticationforlocalhost", oNoHostAuthenticationForLocalhost },
    260   1.1  christos 	{ "rekeylimit", oRekeyLimit },
    261   1.1  christos 	{ "connecttimeout", oConnectTimeout },
    262   1.1  christos 	{ "addressfamily", oAddressFamily },
    263   1.1  christos 	{ "serveraliveinterval", oServerAliveInterval },
    264   1.1  christos 	{ "serveralivecountmax", oServerAliveCountMax },
    265   1.1  christos 	{ "sendenv", oSendEnv },
    266   1.1  christos 	{ "controlpath", oControlPath },
    267   1.1  christos 	{ "controlmaster", oControlMaster },
    268   1.4      adam 	{ "controlpersist", oControlPersist },
    269   1.1  christos 	{ "hashknownhosts", oHashKnownHosts },
    270   1.1  christos 	{ "tunnel", oTunnel },
    271   1.1  christos 	{ "tunneldevice", oTunnelDevice },
    272   1.1  christos 	{ "localcommand", oLocalCommand },
    273   1.1  christos 	{ "permitlocalcommand", oPermitLocalCommand },
    274   1.1  christos 	{ "visualhostkey", oVisualHostKey },
    275   1.3  christos 	{ "useroaming", oUseRoaming },
    276   1.5  christos 	{ "kexalgorithms", oKexAlgorithms },
    277   1.5  christos 	{ "ipqos", oIPQoS },
    278   1.6  christos 	{ "requesttty", oRequestTTY },
    279  1.12  christos 	{ "proxyusefdpass", oProxyUseFdpass },
    280  1.12  christos 	{ "canonicaldomains", oCanonicalDomains },
    281  1.12  christos 	{ "canonicalizefallbacklocal", oCanonicalizeFallbackLocal },
    282  1.12  christos 	{ "canonicalizehostname", oCanonicalizeHostname },
    283  1.12  christos 	{ "canonicalizemaxdots", oCanonicalizeMaxDots },
    284  1.12  christos 	{ "canonicalizepermittedcnames", oCanonicalizePermittedCNAMEs },
    285  1.12  christos 	{ "streamlocalbindmask", oStreamLocalBindMask },
    286  1.12  christos 	{ "streamlocalbindunlink", oStreamLocalBindUnlink },
    287  1.13  christos 	{ "revokedhostkeys", oRevokedHostKeys },
    288  1.13  christos 	{ "fingerprinthash", oFingerprintHash },
    289  1.13  christos 	{ "updatehostkeys", oUpdateHostkeys },
    290  1.13  christos 	{ "hostbasedkeytypes", oHostbasedKeyTypes },
    291   1.2  christos 	{ "noneenabled", oNoneEnabled },
    292   1.2  christos 	{ "tcprcvbufpoll", oTcpRcvBufPoll },
    293   1.2  christos 	{ "tcprcvbuf", oTcpRcvBuf },
    294   1.2  christos 	{ "noneswitch", oNoneSwitch },
    295   1.2  christos 	{ "hpndisabled", oHPNDisabled },
    296   1.2  christos 	{ "hpnbuffersize", oHPNBufferSize },
    297   1.7       tls 	{ "sendversionfirst", oSendVersionFirst },
    298  1.12  christos 	{ "ignoreunknown", oIgnoreUnknown },
    299   1.1  christos 	{ NULL, oBadOption }
    300   1.1  christos };
    301   1.1  christos 
    302   1.1  christos /*
    303   1.1  christos  * Adds a local TCP/IP port forward to options.  Never returns if there is an
    304   1.1  christos  * error.
    305   1.1  christos  */
    306   1.1  christos 
    307   1.1  christos void
    308  1.12  christos add_local_forward(Options *options, const struct Forward *newfwd)
    309   1.1  christos {
    310  1.12  christos 	struct Forward *fwd;
    311   1.1  christos 	extern uid_t original_real_uid;
    312   1.4      adam 
    313  1.12  christos 	if (newfwd->listen_port < IPPORT_RESERVED && original_real_uid != 0 &&
    314  1.12  christos 	    newfwd->listen_path == NULL)
    315   1.1  christos 		fatal("Privileged ports can only be forwarded by root.");
    316  1.14  christos 	options->local_forwards = xreallocarray(options->local_forwards,
    317   1.4      adam 	    options->num_local_forwards + 1,
    318   1.4      adam 	    sizeof(*options->local_forwards));
    319   1.1  christos 	fwd = &options->local_forwards[options->num_local_forwards++];
    320   1.1  christos 
    321   1.1  christos 	fwd->listen_host = newfwd->listen_host;
    322   1.1  christos 	fwd->listen_port = newfwd->listen_port;
    323  1.12  christos 	fwd->listen_path = newfwd->listen_path;
    324   1.1  christos 	fwd->connect_host = newfwd->connect_host;
    325   1.1  christos 	fwd->connect_port = newfwd->connect_port;
    326  1.12  christos 	fwd->connect_path = newfwd->connect_path;
    327   1.1  christos }
    328   1.1  christos 
    329   1.1  christos /*
    330   1.1  christos  * Adds a remote TCP/IP port forward to options.  Never returns if there is
    331   1.1  christos  * an error.
    332   1.1  christos  */
    333   1.1  christos 
    334   1.1  christos void
    335  1.12  christos add_remote_forward(Options *options, const struct Forward *newfwd)
    336   1.1  christos {
    337  1.12  christos 	struct Forward *fwd;
    338   1.4      adam 
    339  1.14  christos 	options->remote_forwards = xreallocarray(options->remote_forwards,
    340   1.4      adam 	    options->num_remote_forwards + 1,
    341   1.4      adam 	    sizeof(*options->remote_forwards));
    342   1.1  christos 	fwd = &options->remote_forwards[options->num_remote_forwards++];
    343   1.1  christos 
    344   1.1  christos 	fwd->listen_host = newfwd->listen_host;
    345   1.1  christos 	fwd->listen_port = newfwd->listen_port;
    346  1.12  christos 	fwd->listen_path = newfwd->listen_path;
    347   1.1  christos 	fwd->connect_host = newfwd->connect_host;
    348   1.1  christos 	fwd->connect_port = newfwd->connect_port;
    349  1.12  christos 	fwd->connect_path = newfwd->connect_path;
    350   1.8  christos 	fwd->handle = newfwd->handle;
    351   1.4      adam 	fwd->allocated_port = 0;
    352   1.1  christos }
    353   1.1  christos 
    354   1.1  christos static void
    355   1.1  christos clear_forwardings(Options *options)
    356   1.1  christos {
    357   1.1  christos 	int i;
    358   1.1  christos 
    359   1.1  christos 	for (i = 0; i < options->num_local_forwards; i++) {
    360  1.11  christos 		free(options->local_forwards[i].listen_host);
    361  1.12  christos 		free(options->local_forwards[i].listen_path);
    362  1.11  christos 		free(options->local_forwards[i].connect_host);
    363  1.12  christos 		free(options->local_forwards[i].connect_path);
    364   1.1  christos 	}
    365   1.4      adam 	if (options->num_local_forwards > 0) {
    366  1.11  christos 		free(options->local_forwards);
    367   1.4      adam 		options->local_forwards = NULL;
    368   1.4      adam 	}
    369   1.1  christos 	options->num_local_forwards = 0;
    370   1.1  christos 	for (i = 0; i < options->num_remote_forwards; i++) {
    371  1.11  christos 		free(options->remote_forwards[i].listen_host);
    372  1.12  christos 		free(options->remote_forwards[i].listen_path);
    373  1.11  christos 		free(options->remote_forwards[i].connect_host);
    374  1.12  christos 		free(options->remote_forwards[i].connect_path);
    375   1.1  christos 	}
    376   1.4      adam 	if (options->num_remote_forwards > 0) {
    377  1.11  christos 		free(options->remote_forwards);
    378   1.4      adam 		options->remote_forwards = NULL;
    379   1.4      adam 	}
    380   1.1  christos 	options->num_remote_forwards = 0;
    381   1.1  christos 	options->tun_open = SSH_TUNMODE_NO;
    382   1.1  christos }
    383   1.1  christos 
    384   1.9   mlelstv void
    385   1.9   mlelstv add_identity_file(Options *options, const char *dir, const char *filename,
    386   1.9   mlelstv     int userprovided)
    387   1.9   mlelstv {
    388   1.9   mlelstv 	char *path;
    389  1.12  christos 	int i;
    390   1.9   mlelstv 
    391   1.9   mlelstv 	if (options->num_identity_files >= SSH_MAX_IDENTITY_FILES)
    392   1.9   mlelstv 		fatal("Too many identity files specified (max %d)",
    393   1.9   mlelstv 		    SSH_MAX_IDENTITY_FILES);
    394   1.9   mlelstv 
    395   1.9   mlelstv 	if (dir == NULL) /* no dir, filename is absolute */
    396   1.9   mlelstv 		path = xstrdup(filename);
    397   1.9   mlelstv 	else
    398   1.9   mlelstv 		(void)xasprintf(&path, "%.100s%.100s", dir, filename);
    399   1.9   mlelstv 
    400  1.12  christos 	/* Avoid registering duplicates */
    401  1.12  christos 	for (i = 0; i < options->num_identity_files; i++) {
    402  1.12  christos 		if (options->identity_file_userprovided[i] == userprovided &&
    403  1.12  christos 		    strcmp(options->identity_files[i], path) == 0) {
    404  1.12  christos 			debug2("%s: ignoring duplicate key %s", __func__, path);
    405  1.12  christos 			free(path);
    406  1.12  christos 			return;
    407  1.12  christos 		}
    408  1.12  christos 	}
    409  1.12  christos 
    410   1.9   mlelstv 	options->identity_file_userprovided[options->num_identity_files] =
    411   1.9   mlelstv 	    userprovided;
    412   1.9   mlelstv 	options->identity_files[options->num_identity_files++] = path;
    413   1.9   mlelstv }
    414   1.9   mlelstv 
    415  1.12  christos int
    416  1.12  christos default_ssh_port(void)
    417  1.12  christos {
    418  1.12  christos 	static int port;
    419  1.12  christos 	struct servent *sp;
    420  1.12  christos 
    421  1.12  christos 	if (port == 0) {
    422  1.12  christos 		sp = getservbyname(SSH_SERVICE_NAME, "tcp");
    423  1.12  christos 		port = sp ? ntohs(sp->s_port) : SSH_DEFAULT_PORT;
    424  1.12  christos 	}
    425  1.12  christos 	return port;
    426  1.12  christos }
    427  1.12  christos 
    428  1.12  christos /*
    429  1.12  christos  * Execute a command in a shell.
    430  1.12  christos  * Return its exit status or -1 on abnormal exit.
    431  1.12  christos  */
    432  1.12  christos static int
    433  1.12  christos execute_in_shell(const char *cmd)
    434  1.12  christos {
    435  1.12  christos 	const char *shell;
    436  1.12  christos 	char *command_string;
    437  1.12  christos 	pid_t pid;
    438  1.12  christos 	int devnull, status;
    439  1.12  christos 	extern uid_t original_real_uid;
    440  1.12  christos 
    441  1.12  christos 	if ((shell = getenv("SHELL")) == NULL)
    442  1.12  christos 		shell = _PATH_BSHELL;
    443  1.12  christos 
    444  1.12  christos 	/*
    445  1.12  christos 	 * Use "exec" to avoid "sh -c" processes on some platforms
    446  1.12  christos 	 * (e.g. Solaris)
    447  1.12  christos 	 */
    448  1.12  christos 	xasprintf(&command_string, "exec %s", cmd);
    449  1.12  christos 
    450  1.12  christos 	/* Need this to redirect subprocess stdin/out */
    451  1.12  christos 	if ((devnull = open(_PATH_DEVNULL, O_RDWR)) == -1)
    452  1.12  christos 		fatal("open(/dev/null): %s", strerror(errno));
    453  1.12  christos 
    454  1.12  christos 	debug("Executing command: '%.500s'", cmd);
    455  1.12  christos 
    456  1.12  christos 	/* Fork and execute the command. */
    457  1.12  christos 	if ((pid = fork()) == 0) {
    458  1.12  christos 		char *argv[4];
    459  1.12  christos 
    460  1.12  christos 		/* Child.  Permanently give up superuser privileges. */
    461  1.12  christos 		permanently_drop_suid(original_real_uid);
    462  1.12  christos 
    463  1.12  christos 		/* Redirect child stdin and stdout. Leave stderr */
    464  1.12  christos 		if (dup2(devnull, STDIN_FILENO) == -1)
    465  1.12  christos 			fatal("dup2: %s", strerror(errno));
    466  1.12  christos 		if (dup2(devnull, STDOUT_FILENO) == -1)
    467  1.12  christos 			fatal("dup2: %s", strerror(errno));
    468  1.12  christos 		if (devnull > STDERR_FILENO)
    469  1.12  christos 			close(devnull);
    470  1.12  christos 		closefrom(STDERR_FILENO + 1);
    471  1.12  christos 
    472  1.12  christos 		argv[0] = __UNCONST(shell);
    473  1.12  christos 		argv[1] = __UNCONST("-c");
    474  1.12  christos 		argv[2] = command_string;
    475  1.12  christos 		argv[3] = NULL;
    476  1.12  christos 
    477  1.12  christos 		execv(argv[0], argv);
    478  1.12  christos 		error("Unable to execute '%.100s': %s", cmd, strerror(errno));
    479  1.12  christos 		/* Die with signal to make this error apparent to parent. */
    480  1.12  christos 		signal(SIGTERM, SIG_DFL);
    481  1.12  christos 		kill(getpid(), SIGTERM);
    482  1.12  christos 		_exit(1);
    483  1.12  christos 	}
    484  1.12  christos 	/* Parent. */
    485  1.12  christos 	if (pid < 0)
    486  1.12  christos 		fatal("%s: fork: %.100s", __func__, strerror(errno));
    487  1.12  christos 
    488  1.12  christos 	close(devnull);
    489  1.12  christos 	free(command_string);
    490  1.12  christos 
    491  1.12  christos 	while (waitpid(pid, &status, 0) == -1) {
    492  1.12  christos 		if (errno != EINTR && errno != EAGAIN)
    493  1.12  christos 			fatal("%s: waitpid: %s", __func__, strerror(errno));
    494  1.12  christos 	}
    495  1.12  christos 	if (!WIFEXITED(status)) {
    496  1.12  christos 		error("command '%.100s' exited abnormally", cmd);
    497  1.12  christos 		return -1;
    498  1.13  christos 	}
    499  1.12  christos 	debug3("command returned status %d", WEXITSTATUS(status));
    500  1.12  christos 	return WEXITSTATUS(status);
    501  1.12  christos }
    502  1.12  christos 
    503  1.12  christos /*
    504  1.12  christos  * Parse and execute a Match directive.
    505  1.12  christos  */
    506  1.12  christos static int
    507  1.12  christos match_cfg_line(Options *options, char **condition, struct passwd *pw,
    508  1.13  christos     const char *host_arg, const char *original_host, int post_canon,
    509  1.13  christos     const char *filename, int linenum)
    510  1.12  christos {
    511  1.13  christos 	char *arg, *oattrib, *attrib, *cmd, *cp = *condition, *host, *criteria;
    512  1.12  christos 	const char *ruser;
    513  1.13  christos 	int r, port, this_result, result = 1, attributes = 0, negate;
    514  1.12  christos 	char thishost[NI_MAXHOST], shorthost[NI_MAXHOST], portstr[NI_MAXSERV];
    515  1.12  christos 
    516  1.12  christos 	/*
    517  1.12  christos 	 * Configuration is likely to be incomplete at this point so we
    518  1.12  christos 	 * must be prepared to use default values.
    519  1.12  christos 	 */
    520  1.12  christos 	port = options->port <= 0 ? default_ssh_port() : options->port;
    521  1.12  christos 	ruser = options->user == NULL ? pw->pw_name : options->user;
    522  1.12  christos 	if (options->hostname != NULL) {
    523  1.12  christos 		/* NB. Please keep in sync with ssh.c:main() */
    524  1.12  christos 		host = percent_expand(options->hostname,
    525  1.12  christos 		    "h", host_arg, (char *)NULL);
    526  1.12  christos 	} else
    527  1.12  christos 		host = xstrdup(host_arg);
    528  1.12  christos 
    529  1.13  christos 	debug2("checking match for '%s' host %s originally %s",
    530  1.13  christos 	    cp, host, original_host);
    531  1.13  christos 	while ((oattrib = attrib = strdelim(&cp)) && *attrib != '\0') {
    532  1.13  christos 		criteria = NULL;
    533  1.13  christos 		this_result = 1;
    534  1.13  christos 		if ((negate = attrib[0] == '!'))
    535  1.13  christos 			attrib++;
    536  1.13  christos 		/* criteria "all" and "canonical" have no argument */
    537  1.12  christos 		if (strcasecmp(attrib, "all") == 0) {
    538  1.13  christos 			if (attributes > 1 ||
    539  1.12  christos 			    ((arg = strdelim(&cp)) != NULL && *arg != '\0')) {
    540  1.13  christos 				error("%.200s line %d: '%s' cannot be combined "
    541  1.13  christos 				    "with other Match attributes",
    542  1.13  christos 				    filename, linenum, oattrib);
    543  1.12  christos 				result = -1;
    544  1.12  christos 				goto out;
    545  1.12  christos 			}
    546  1.13  christos 			if (result)
    547  1.13  christos 				result = negate ? 0 : 1;
    548  1.12  christos 			goto out;
    549  1.12  christos 		}
    550  1.13  christos 		attributes++;
    551  1.13  christos 		if (strcasecmp(attrib, "canonical") == 0) {
    552  1.13  christos 			r = !!post_canon;  /* force bitmask member to boolean */
    553  1.13  christos 			if (r == (negate ? 1 : 0))
    554  1.13  christos 				this_result = result = 0;
    555  1.13  christos 			debug3("%.200s line %d: %smatched '%s'",
    556  1.13  christos 			    filename, linenum,
    557  1.13  christos 			    this_result ? "" : "not ", oattrib);
    558  1.13  christos 			continue;
    559  1.13  christos 		}
    560  1.13  christos 		/* All other criteria require an argument */
    561  1.12  christos 		if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
    562  1.12  christos 			error("Missing Match criteria for %s", attrib);
    563  1.12  christos 			result = -1;
    564  1.12  christos 			goto out;
    565  1.12  christos 		}
    566  1.12  christos 		if (strcasecmp(attrib, "host") == 0) {
    567  1.13  christos 			criteria = xstrdup(host);
    568  1.14  christos 			r = match_hostname(host, arg) == 1;
    569  1.13  christos 			if (r == (negate ? 1 : 0))
    570  1.13  christos 				this_result = result = 0;
    571  1.12  christos 		} else if (strcasecmp(attrib, "originalhost") == 0) {
    572  1.13  christos 			criteria = xstrdup(original_host);
    573  1.14  christos 			r = match_hostname(original_host, arg) == 1;
    574  1.13  christos 			if (r == (negate ? 1 : 0))
    575  1.13  christos 				this_result = result = 0;
    576  1.12  christos 		} else if (strcasecmp(attrib, "user") == 0) {
    577  1.13  christos 			criteria = xstrdup(ruser);
    578  1.14  christos 			r = match_pattern_list(ruser, arg, 0) == 1;
    579  1.13  christos 			if (r == (negate ? 1 : 0))
    580  1.13  christos 				this_result = result = 0;
    581  1.12  christos 		} else if (strcasecmp(attrib, "localuser") == 0) {
    582  1.13  christos 			criteria = xstrdup(pw->pw_name);
    583  1.14  christos 			r = match_pattern_list(pw->pw_name, arg, 0) == 1;
    584  1.13  christos 			if (r == (negate ? 1 : 0))
    585  1.13  christos 				this_result = result = 0;
    586  1.12  christos 		} else if (strcasecmp(attrib, "exec") == 0) {
    587  1.12  christos 			if (gethostname(thishost, sizeof(thishost)) == -1)
    588  1.12  christos 				fatal("gethostname: %s", strerror(errno));
    589  1.12  christos 			strlcpy(shorthost, thishost, sizeof(shorthost));
    590  1.12  christos 			shorthost[strcspn(thishost, ".")] = '\0';
    591  1.12  christos 			snprintf(portstr, sizeof(portstr), "%d", port);
    592  1.12  christos 
    593  1.12  christos 			cmd = percent_expand(arg,
    594  1.12  christos 			    "L", shorthost,
    595  1.12  christos 			    "d", pw->pw_dir,
    596  1.12  christos 			    "h", host,
    597  1.12  christos 			    "l", thishost,
    598  1.13  christos 			    "n", original_host,
    599  1.12  christos 			    "p", portstr,
    600  1.12  christos 			    "r", ruser,
    601  1.12  christos 			    "u", pw->pw_name,
    602  1.12  christos 			    (char *)NULL);
    603  1.12  christos 			if (result != 1) {
    604  1.12  christos 				/* skip execution if prior predicate failed */
    605  1.13  christos 				debug3("%.200s line %d: skipped exec "
    606  1.13  christos 				    "\"%.100s\"", filename, linenum, cmd);
    607  1.13  christos 				free(cmd);
    608  1.13  christos 				continue;
    609  1.13  christos 			}
    610  1.13  christos 			r = execute_in_shell(cmd);
    611  1.13  christos 			if (r == -1) {
    612  1.13  christos 				fatal("%.200s line %d: match exec "
    613  1.13  christos 				    "'%.100s' error", filename,
    614  1.13  christos 				    linenum, cmd);
    615  1.12  christos 			}
    616  1.13  christos 			criteria = xstrdup(cmd);
    617  1.12  christos 			free(cmd);
    618  1.13  christos 			/* Force exit status to boolean */
    619  1.13  christos 			r = r == 0;
    620  1.13  christos 			if (r == (negate ? 1 : 0))
    621  1.13  christos 				this_result = result = 0;
    622  1.12  christos 		} else {
    623  1.12  christos 			error("Unsupported Match attribute %s", attrib);
    624  1.12  christos 			result = -1;
    625  1.12  christos 			goto out;
    626  1.12  christos 		}
    627  1.13  christos 		debug3("%.200s line %d: %smatched '%s \"%.100s\"' ",
    628  1.13  christos 		    filename, linenum, this_result ? "": "not ",
    629  1.13  christos 		    oattrib, criteria);
    630  1.13  christos 		free(criteria);
    631  1.12  christos 	}
    632  1.12  christos 	if (attributes == 0) {
    633  1.12  christos 		error("One or more attributes required for Match");
    634  1.12  christos 		result = -1;
    635  1.12  christos 		goto out;
    636  1.12  christos 	}
    637  1.13  christos  out:
    638  1.13  christos 	if (result != -1)
    639  1.13  christos 		debug2("match %sfound", result ? "" : "not ");
    640  1.12  christos 	*condition = cp;
    641  1.12  christos 	free(host);
    642  1.12  christos 	return result;
    643  1.12  christos }
    644  1.12  christos 
    645  1.12  christos /* Check and prepare a domain name: removes trailing '.' and lowercases */
    646  1.12  christos static void
    647  1.12  christos valid_domain(char *name, const char *filename, int linenum)
    648  1.12  christos {
    649  1.12  christos 	size_t i, l = strlen(name);
    650  1.12  christos 	u_char c, last = '\0';
    651  1.12  christos 
    652  1.12  christos 	if (l == 0)
    653  1.12  christos 		fatal("%s line %d: empty hostname suffix", filename, linenum);
    654  1.12  christos 	if (!isalpha((u_char)name[0]) && !isdigit((u_char)name[0]))
    655  1.12  christos 		fatal("%s line %d: hostname suffix \"%.100s\" "
    656  1.12  christos 		    "starts with invalid character", filename, linenum, name);
    657  1.12  christos 	for (i = 0; i < l; i++) {
    658  1.12  christos 		c = tolower((u_char)name[i]);
    659  1.12  christos 		name[i] = (char)c;
    660  1.12  christos 		if (last == '.' && c == '.')
    661  1.12  christos 			fatal("%s line %d: hostname suffix \"%.100s\" contains "
    662  1.12  christos 			    "consecutive separators", filename, linenum, name);
    663  1.12  christos 		if (c != '.' && c != '-' && !isalnum(c) &&
    664  1.12  christos 		    c != '_') /* technically invalid, but common */
    665  1.12  christos 			fatal("%s line %d: hostname suffix \"%.100s\" contains "
    666  1.12  christos 			    "invalid characters", filename, linenum, name);
    667  1.12  christos 		last = c;
    668  1.12  christos 	}
    669  1.12  christos 	if (name[l - 1] == '.')
    670  1.12  christos 		name[l - 1] = '\0';
    671  1.12  christos }
    672  1.12  christos 
    673   1.1  christos /*
    674   1.1  christos  * Returns the number of the token pointed to by cp or oBadOption.
    675   1.1  christos  */
    676   1.1  christos static OpCodes
    677  1.11  christos parse_token(const char *cp, const char *filename, int linenum,
    678  1.11  christos     const char *ignored_unknown)
    679   1.1  christos {
    680  1.11  christos 	int i;
    681   1.1  christos 
    682   1.1  christos 	for (i = 0; keywords[i].name; i++)
    683  1.11  christos 		if (strcmp(cp, keywords[i].name) == 0)
    684   1.1  christos 			return keywords[i].opcode;
    685  1.14  christos 	if (ignored_unknown != NULL &&
    686  1.14  christos 	    match_pattern_list(cp, ignored_unknown, 1) == 1)
    687  1.11  christos 		return oIgnoredUnknownOption;
    688   1.1  christos 	error("%s: line %d: Bad configuration option: %s",
    689   1.1  christos 	    filename, linenum, cp);
    690   1.1  christos 	return oBadOption;
    691   1.1  christos }
    692   1.1  christos 
    693  1.12  christos /* Multistate option parsing */
    694  1.12  christos struct multistate {
    695  1.12  christos 	const char *key;
    696  1.12  christos 	int value;
    697  1.12  christos };
    698  1.12  christos static const struct multistate multistate_flag[] = {
    699  1.12  christos 	{ "true",			1 },
    700  1.12  christos 	{ "false",			0 },
    701  1.12  christos 	{ "yes",			1 },
    702  1.12  christos 	{ "no",				0 },
    703  1.12  christos 	{ NULL, -1 }
    704  1.12  christos };
    705  1.12  christos static const struct multistate multistate_yesnoask[] = {
    706  1.12  christos 	{ "true",			1 },
    707  1.12  christos 	{ "false",			0 },
    708  1.12  christos 	{ "yes",			1 },
    709  1.12  christos 	{ "no",				0 },
    710  1.12  christos 	{ "ask",			2 },
    711  1.12  christos 	{ NULL, -1 }
    712  1.12  christos };
    713  1.12  christos static const struct multistate multistate_addressfamily[] = {
    714  1.12  christos 	{ "inet",			AF_INET },
    715  1.12  christos 	{ "inet6",			AF_INET6 },
    716  1.12  christos 	{ "any",			AF_UNSPEC },
    717  1.12  christos 	{ NULL, -1 }
    718  1.12  christos };
    719  1.12  christos static const struct multistate multistate_controlmaster[] = {
    720  1.12  christos 	{ "true",			SSHCTL_MASTER_YES },
    721  1.12  christos 	{ "yes",			SSHCTL_MASTER_YES },
    722  1.12  christos 	{ "false",			SSHCTL_MASTER_NO },
    723  1.12  christos 	{ "no",				SSHCTL_MASTER_NO },
    724  1.12  christos 	{ "auto",			SSHCTL_MASTER_AUTO },
    725  1.12  christos 	{ "ask",			SSHCTL_MASTER_ASK },
    726  1.12  christos 	{ "autoask",			SSHCTL_MASTER_AUTO_ASK },
    727  1.12  christos 	{ NULL, -1 }
    728  1.12  christos };
    729  1.12  christos static const struct multistate multistate_tunnel[] = {
    730  1.12  christos 	{ "ethernet",			SSH_TUNMODE_ETHERNET },
    731  1.12  christos 	{ "point-to-point",		SSH_TUNMODE_POINTOPOINT },
    732  1.12  christos 	{ "true",			SSH_TUNMODE_DEFAULT },
    733  1.12  christos 	{ "yes",			SSH_TUNMODE_DEFAULT },
    734  1.12  christos 	{ "false",			SSH_TUNMODE_NO },
    735  1.12  christos 	{ "no",				SSH_TUNMODE_NO },
    736  1.12  christos 	{ NULL, -1 }
    737  1.12  christos };
    738  1.12  christos static const struct multistate multistate_requesttty[] = {
    739  1.12  christos 	{ "true",			REQUEST_TTY_YES },
    740  1.12  christos 	{ "yes",			REQUEST_TTY_YES },
    741  1.12  christos 	{ "false",			REQUEST_TTY_NO },
    742  1.12  christos 	{ "no",				REQUEST_TTY_NO },
    743  1.12  christos 	{ "force",			REQUEST_TTY_FORCE },
    744  1.12  christos 	{ "auto",			REQUEST_TTY_AUTO },
    745  1.12  christos 	{ NULL, -1 }
    746  1.12  christos };
    747  1.12  christos static const struct multistate multistate_canonicalizehostname[] = {
    748  1.12  christos 	{ "true",			SSH_CANONICALISE_YES },
    749  1.12  christos 	{ "false",			SSH_CANONICALISE_NO },
    750  1.12  christos 	{ "yes",			SSH_CANONICALISE_YES },
    751  1.12  christos 	{ "no",				SSH_CANONICALISE_NO },
    752  1.12  christos 	{ "always",			SSH_CANONICALISE_ALWAYS },
    753  1.12  christos 	{ NULL, -1 }
    754  1.12  christos };
    755  1.12  christos 
    756   1.1  christos /*
    757   1.1  christos  * Processes a single option line as used in the configuration files. This
    758   1.1  christos  * only sets those values that have not already been set.
    759   1.1  christos  */
    760   1.1  christos #define WHITESPACE " \t\r\n"
    761   1.1  christos int
    762  1.12  christos process_config_line(Options *options, struct passwd *pw, const char *host,
    763  1.13  christos     const char *original_host, char *line, const char *filename,
    764  1.13  christos     int linenum, int *activep, int flags)
    765   1.1  christos {
    766   1.6  christos 	char *s, **charptr, *endofnumber, *keyword, *arg, *arg2;
    767   1.6  christos 	char **cpptr, fwdarg[256];
    768  1.11  christos 	u_int i, *uintptr, max_entries = 0;
    769  1.12  christos 	int negated, opcode, *intptr, value, value2, cmdline = 0;
    770   1.1  christos 	LogLevel *log_level_ptr;
    771  1.11  christos 	long long val64;
    772   1.1  christos 	size_t len;
    773  1.12  christos 	struct Forward fwd;
    774  1.12  christos 	const struct multistate *multistate_ptr;
    775  1.12  christos 	struct allowed_cname *cname;
    776  1.12  christos 
    777  1.12  christos 	if (activep == NULL) { /* We are processing a command line directive */
    778  1.12  christos 		cmdline = 1;
    779  1.12  christos 		activep = &cmdline;
    780  1.12  christos 	}
    781   1.1  christos 
    782   1.1  christos 	/* Strip trailing whitespace */
    783  1.14  christos 	if ((len = strlen(line)) == 0)
    784  1.14  christos 		return 0;
    785  1.14  christos 	for (len--; len > 0; len--) {
    786   1.1  christos 		if (strchr(WHITESPACE, line[len]) == NULL)
    787   1.1  christos 			break;
    788   1.1  christos 		line[len] = '\0';
    789   1.1  christos 	}
    790   1.1  christos 
    791   1.1  christos 	s = line;
    792   1.1  christos 	/* Get the keyword. (Each line is supposed to begin with a keyword). */
    793   1.1  christos 	if ((keyword = strdelim(&s)) == NULL)
    794   1.1  christos 		return 0;
    795   1.1  christos 	/* Ignore leading whitespace. */
    796   1.1  christos 	if (*keyword == '\0')
    797   1.1  christos 		keyword = strdelim(&s);
    798   1.1  christos 	if (keyword == NULL || !*keyword || *keyword == '\n' || *keyword == '#')
    799   1.1  christos 		return 0;
    800  1.11  christos 	/* Match lowercase keyword */
    801  1.12  christos 	lowercase(keyword);
    802   1.1  christos 
    803  1.11  christos 	opcode = parse_token(keyword, filename, linenum,
    804  1.11  christos 	    options->ignored_unknown);
    805   1.1  christos 
    806   1.1  christos 	switch (opcode) {
    807   1.1  christos 	case oBadOption:
    808   1.1  christos 		/* don't panic, but count bad options */
    809   1.1  christos 		return -1;
    810   1.1  christos 		/* NOTREACHED */
    811  1.11  christos 	case oIgnoredUnknownOption:
    812  1.11  christos 		debug("%s line %d: Ignored unknown option \"%s\"",
    813  1.11  christos 		    filename, linenum, keyword);
    814  1.11  christos 		return 0;
    815   1.1  christos 	case oConnectTimeout:
    816   1.1  christos 		intptr = &options->connection_timeout;
    817   1.1  christos parse_time:
    818   1.1  christos 		arg = strdelim(&s);
    819   1.1  christos 		if (!arg || *arg == '\0')
    820   1.1  christos 			fatal("%s line %d: missing time value.",
    821   1.1  christos 			    filename, linenum);
    822  1.13  christos 		if (strcmp(arg, "none") == 0)
    823  1.13  christos 			value = -1;
    824  1.13  christos 		else if ((value = convtime(arg)) == -1)
    825   1.1  christos 			fatal("%s line %d: invalid time value.",
    826   1.1  christos 			    filename, linenum);
    827   1.1  christos 		if (*activep && *intptr == -1)
    828   1.1  christos 			*intptr = value;
    829   1.1  christos 		break;
    830   1.1  christos 
    831   1.1  christos 	case oForwardAgent:
    832   1.1  christos 		intptr = &options->forward_agent;
    833  1.12  christos  parse_flag:
    834  1.12  christos 		multistate_ptr = multistate_flag;
    835  1.12  christos  parse_multistate:
    836   1.1  christos 		arg = strdelim(&s);
    837   1.1  christos 		if (!arg || *arg == '\0')
    838  1.12  christos 			fatal("%s line %d: missing argument.",
    839  1.12  christos 			    filename, linenum);
    840  1.12  christos 		value = -1;
    841  1.12  christos 		for (i = 0; multistate_ptr[i].key != NULL; i++) {
    842  1.12  christos 			if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
    843  1.12  christos 				value = multistate_ptr[i].value;
    844  1.12  christos 				break;
    845  1.12  christos 			}
    846  1.12  christos 		}
    847  1.12  christos 		if (value == -1)
    848  1.12  christos 			fatal("%s line %d: unsupported option \"%s\".",
    849  1.12  christos 			    filename, linenum, arg);
    850   1.1  christos 		if (*activep && *intptr == -1)
    851   1.1  christos 			*intptr = value;
    852   1.1  christos 		break;
    853   1.1  christos 
    854   1.1  christos 	case oForwardX11:
    855   1.1  christos 		intptr = &options->forward_x11;
    856   1.1  christos 		goto parse_flag;
    857   1.1  christos 
    858   1.1  christos 	case oForwardX11Trusted:
    859   1.1  christos 		intptr = &options->forward_x11_trusted;
    860   1.1  christos 		goto parse_flag;
    861  1.13  christos 
    862   1.4      adam 	case oForwardX11Timeout:
    863   1.4      adam 		intptr = &options->forward_x11_timeout;
    864   1.4      adam 		goto parse_time;
    865   1.1  christos 
    866   1.1  christos 	case oGatewayPorts:
    867  1.12  christos 		intptr = &options->fwd_opts.gateway_ports;
    868   1.1  christos 		goto parse_flag;
    869   1.1  christos 
    870   1.1  christos 	case oExitOnForwardFailure:
    871   1.1  christos 		intptr = &options->exit_on_forward_failure;
    872   1.1  christos 		goto parse_flag;
    873   1.1  christos 
    874   1.1  christos 	case oUsePrivilegedPort:
    875   1.1  christos 		intptr = &options->use_privileged_port;
    876   1.1  christos 		goto parse_flag;
    877   1.1  christos 
    878   1.1  christos 	case oPasswordAuthentication:
    879   1.1  christos 		intptr = &options->password_authentication;
    880   1.1  christos 		goto parse_flag;
    881   1.1  christos 
    882   1.1  christos 	case oKbdInteractiveAuthentication:
    883   1.1  christos 		intptr = &options->kbd_interactive_authentication;
    884   1.1  christos 		goto parse_flag;
    885   1.1  christos 
    886   1.1  christos 	case oKbdInteractiveDevices:
    887   1.1  christos 		charptr = &options->kbd_interactive_devices;
    888   1.1  christos 		goto parse_string;
    889   1.1  christos 
    890   1.1  christos 	case oPubkeyAuthentication:
    891   1.1  christos 		intptr = &options->pubkey_authentication;
    892   1.1  christos 		goto parse_flag;
    893   1.1  christos 
    894   1.1  christos 	case oRSAAuthentication:
    895   1.1  christos 		intptr = &options->rsa_authentication;
    896   1.1  christos 		goto parse_flag;
    897   1.1  christos 
    898   1.1  christos 	case oRhostsRSAAuthentication:
    899   1.1  christos 		intptr = &options->rhosts_rsa_authentication;
    900   1.1  christos 		goto parse_flag;
    901   1.1  christos 
    902   1.1  christos 	case oHostbasedAuthentication:
    903   1.1  christos 		intptr = &options->hostbased_authentication;
    904   1.1  christos 		goto parse_flag;
    905   1.1  christos 
    906   1.1  christos 	case oChallengeResponseAuthentication:
    907   1.1  christos 		intptr = &options->challenge_response_authentication;
    908   1.1  christos 		goto parse_flag;
    909   1.1  christos 
    910   1.2  christos #if defined(KRB4) || defined(KRB5)
    911   1.2  christos 	case oKerberosAuthentication:
    912   1.2  christos 		intptr = &options->kerberos_authentication;
    913   1.2  christos 		goto parse_flag;
    914   1.2  christos #endif
    915   1.2  christos #if defined(AFS) || defined(KRB5)
    916   1.2  christos 	case oKerberosTgtPassing:
    917   1.2  christos 		intptr = &options->kerberos_tgt_passing;
    918   1.2  christos 		goto parse_flag;
    919   1.2  christos #endif
    920   1.2  christos 
    921   1.1  christos 	case oGssAuthentication:
    922   1.1  christos 		intptr = &options->gss_authentication;
    923   1.1  christos 		goto parse_flag;
    924   1.1  christos 
    925   1.2  christos #ifdef AFS
    926   1.2  christos 	case oAFSTokenPassing:
    927   1.2  christos 		intptr = &options->afs_token_passing;
    928   1.2  christos  		goto parse_flag;
    929   1.2  christos #endif
    930   1.2  christos 
    931   1.1  christos 	case oGssDelegateCreds:
    932   1.1  christos 		intptr = &options->gss_deleg_creds;
    933   1.1  christos 		goto parse_flag;
    934   1.1  christos 
    935   1.1  christos 	case oBatchMode:
    936   1.1  christos 		intptr = &options->batch_mode;
    937   1.1  christos 		goto parse_flag;
    938   1.1  christos 
    939   1.1  christos 	case oCheckHostIP:
    940   1.1  christos 		intptr = &options->check_host_ip;
    941   1.1  christos 		goto parse_flag;
    942   1.1  christos 
    943   1.2  christos 	case oNoneEnabled:
    944   1.2  christos 		intptr = &options->none_enabled;
    945   1.2  christos 		goto parse_flag;
    946   1.2  christos 
    947   1.2  christos 	/* we check to see if the command comes from the */
    948   1.2  christos 	/* command line or not. If it does then enable it */
    949   1.2  christos 	/* otherwise fail. NONE should never be a default configuration */
    950   1.2  christos 	case oNoneSwitch:
    951   1.2  christos 		if(strcmp(filename,"command-line")==0)
    952   1.2  christos 		{
    953   1.2  christos 		    intptr = &options->none_switch;
    954   1.2  christos 		    goto parse_flag;
    955   1.2  christos 		} else {
    956   1.2  christos 		    error("NoneSwitch is found in %.200s.\nYou may only use this configuration option from the command line", filename);
    957   1.2  christos 		    error("Continuing...");
    958   1.2  christos 		    debug("NoneSwitch directive found in %.200s.", filename);
    959   1.2  christos 		    return 0;
    960   1.2  christos 	        }
    961   1.2  christos 
    962   1.2  christos 	case oHPNDisabled:
    963   1.2  christos 		intptr = &options->hpn_disabled;
    964   1.2  christos 		goto parse_flag;
    965   1.2  christos 
    966   1.2  christos 	case oHPNBufferSize:
    967   1.2  christos 		intptr = &options->hpn_buffer_size;
    968   1.2  christos 		goto parse_int;
    969   1.2  christos 
    970   1.2  christos 	case oTcpRcvBufPoll:
    971   1.2  christos 		intptr = &options->tcp_rcv_buf_poll;
    972   1.2  christos 		goto parse_flag;
    973   1.2  christos 
    974   1.1  christos 	case oVerifyHostKeyDNS:
    975   1.1  christos 		intptr = &options->verify_host_key_dns;
    976  1.12  christos 		multistate_ptr = multistate_yesnoask;
    977  1.12  christos 		goto parse_multistate;
    978   1.1  christos 
    979   1.1  christos 	case oStrictHostKeyChecking:
    980   1.1  christos 		intptr = &options->strict_host_key_checking;
    981  1.12  christos 		multistate_ptr = multistate_yesnoask;
    982  1.12  christos 		goto parse_multistate;
    983   1.1  christos 
    984   1.1  christos 	case oCompression:
    985   1.1  christos 		intptr = &options->compression;
    986   1.1  christos 		goto parse_flag;
    987   1.1  christos 
    988   1.1  christos 	case oTCPKeepAlive:
    989   1.1  christos 		intptr = &options->tcp_keep_alive;
    990   1.1  christos 		goto parse_flag;
    991   1.1  christos 
    992   1.1  christos 	case oNoHostAuthenticationForLocalhost:
    993   1.1  christos 		intptr = &options->no_host_authentication_for_localhost;
    994   1.1  christos 		goto parse_flag;
    995   1.1  christos 
    996   1.1  christos 	case oNumberOfPasswordPrompts:
    997   1.1  christos 		intptr = &options->number_of_password_prompts;
    998   1.1  christos 		goto parse_int;
    999   1.1  christos 
   1000   1.1  christos 	case oCompressionLevel:
   1001   1.1  christos 		intptr = &options->compression_level;
   1002   1.1  christos 		goto parse_int;
   1003   1.1  christos 
   1004   1.1  christos 	case oRekeyLimit:
   1005   1.1  christos 		arg = strdelim(&s);
   1006   1.1  christos 		if (!arg || *arg == '\0')
   1007  1.11  christos 			fatal("%.200s line %d: Missing argument.", filename,
   1008  1.11  christos 			    linenum);
   1009  1.11  christos 		if (strcmp(arg, "default") == 0) {
   1010  1.11  christos 			val64 = 0;
   1011  1.11  christos 		} else {
   1012  1.11  christos 			if (scan_scaled(arg, &val64) == -1)
   1013  1.11  christos 				fatal("%.200s line %d: Bad number '%s': %s",
   1014  1.11  christos 				    filename, linenum, arg, strerror(errno));
   1015  1.11  christos 			/* check for too-large or too-small limits */
   1016  1.11  christos 			if (val64 > UINT_MAX)
   1017  1.11  christos 				fatal("%.200s line %d: RekeyLimit too large",
   1018  1.11  christos 				    filename, linenum);
   1019  1.11  christos 			if (val64 != 0 && val64 < 16)
   1020  1.11  christos 				fatal("%.200s line %d: RekeyLimit too small",
   1021  1.11  christos 				    filename, linenum);
   1022   1.1  christos 		}
   1023   1.1  christos 		if (*activep && options->rekey_limit == -1)
   1024   1.1  christos 			options->rekey_limit = (u_int32_t)val64;
   1025  1.11  christos 		if (s != NULL) { /* optional rekey interval present */
   1026  1.11  christos 			if (strcmp(s, "none") == 0) {
   1027  1.11  christos 				(void)strdelim(&s);	/* discard */
   1028  1.11  christos 				break;
   1029  1.11  christos 			}
   1030  1.11  christos 			intptr = &options->rekey_interval;
   1031  1.11  christos 			goto parse_time;
   1032  1.11  christos 		}
   1033   1.1  christos 		break;
   1034   1.1  christos 
   1035   1.1  christos 	case oIdentityFile:
   1036   1.1  christos 		arg = strdelim(&s);
   1037   1.1  christos 		if (!arg || *arg == '\0')
   1038   1.1  christos 			fatal("%.200s line %d: Missing argument.", filename, linenum);
   1039   1.1  christos 		if (*activep) {
   1040   1.1  christos 			intptr = &options->num_identity_files;
   1041   1.1  christos 			if (*intptr >= SSH_MAX_IDENTITY_FILES)
   1042   1.1  christos 				fatal("%.200s line %d: Too many identity files specified (max %d).",
   1043   1.1  christos 				    filename, linenum, SSH_MAX_IDENTITY_FILES);
   1044  1.13  christos 			add_identity_file(options, NULL,
   1045  1.13  christos 			    arg, flags & SSHCONF_USERCONF);
   1046   1.1  christos 		}
   1047   1.1  christos 		break;
   1048   1.1  christos 
   1049   1.1  christos 	case oXAuthLocation:
   1050   1.1  christos 		charptr=&options->xauth_location;
   1051   1.1  christos 		goto parse_string;
   1052   1.1  christos 
   1053   1.1  christos 	case oUser:
   1054   1.1  christos 		charptr = &options->user;
   1055   1.1  christos parse_string:
   1056   1.1  christos 		arg = strdelim(&s);
   1057   1.1  christos 		if (!arg || *arg == '\0')
   1058   1.6  christos 			fatal("%.200s line %d: Missing argument.",
   1059   1.6  christos 			    filename, linenum);
   1060   1.1  christos 		if (*activep && *charptr == NULL)
   1061   1.1  christos 			*charptr = xstrdup(arg);
   1062   1.1  christos 		break;
   1063   1.1  christos 
   1064   1.1  christos 	case oGlobalKnownHostsFile:
   1065   1.6  christos 		cpptr = (char **)&options->system_hostfiles;
   1066   1.6  christos 		uintptr = &options->num_system_hostfiles;
   1067   1.6  christos 		max_entries = SSH_MAX_HOSTS_FILES;
   1068   1.6  christos parse_char_array:
   1069   1.6  christos 		if (*activep && *uintptr == 0) {
   1070   1.6  christos 			while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
   1071   1.6  christos 				if ((*uintptr) >= max_entries)
   1072   1.6  christos 					fatal("%s line %d: "
   1073   1.6  christos 					    "too many authorized keys files.",
   1074   1.6  christos 					    filename, linenum);
   1075   1.6  christos 				cpptr[(*uintptr)++] = xstrdup(arg);
   1076   1.6  christos 			}
   1077   1.6  christos 		}
   1078   1.6  christos 		return 0;
   1079   1.1  christos 
   1080   1.1  christos 	case oUserKnownHostsFile:
   1081   1.6  christos 		cpptr = (char **)&options->user_hostfiles;
   1082   1.6  christos 		uintptr = &options->num_user_hostfiles;
   1083   1.6  christos 		max_entries = SSH_MAX_HOSTS_FILES;
   1084   1.6  christos 		goto parse_char_array;
   1085   1.1  christos 
   1086   1.1  christos 	case oHostName:
   1087   1.1  christos 		charptr = &options->hostname;
   1088   1.1  christos 		goto parse_string;
   1089   1.1  christos 
   1090   1.1  christos 	case oHostKeyAlias:
   1091   1.1  christos 		charptr = &options->host_key_alias;
   1092   1.1  christos 		goto parse_string;
   1093   1.1  christos 
   1094   1.1  christos 	case oPreferredAuthentications:
   1095   1.1  christos 		charptr = &options->preferred_authentications;
   1096   1.1  christos 		goto parse_string;
   1097   1.1  christos 
   1098   1.1  christos 	case oBindAddress:
   1099   1.1  christos 		charptr = &options->bind_address;
   1100   1.1  christos 		goto parse_string;
   1101   1.1  christos 
   1102   1.4      adam 	case oPKCS11Provider:
   1103   1.4      adam 		charptr = &options->pkcs11_provider;
   1104   1.1  christos 		goto parse_string;
   1105   1.1  christos 
   1106   1.1  christos 	case oProxyCommand:
   1107   1.1  christos 		charptr = &options->proxy_command;
   1108   1.1  christos parse_command:
   1109   1.1  christos 		if (s == NULL)
   1110   1.1  christos 			fatal("%.200s line %d: Missing argument.", filename, linenum);
   1111   1.1  christos 		len = strspn(s, WHITESPACE "=");
   1112   1.1  christos 		if (*activep && *charptr == NULL)
   1113   1.1  christos 			*charptr = xstrdup(s + len);
   1114   1.1  christos 		return 0;
   1115   1.1  christos 
   1116   1.1  christos 	case oPort:
   1117   1.1  christos 		intptr = &options->port;
   1118   1.1  christos parse_int:
   1119   1.1  christos 		arg = strdelim(&s);
   1120   1.1  christos 		if (!arg || *arg == '\0')
   1121   1.1  christos 			fatal("%.200s line %d: Missing argument.", filename, linenum);
   1122   1.1  christos 		if (arg[0] < '0' || arg[0] > '9')
   1123   1.1  christos 			fatal("%.200s line %d: Bad number.", filename, linenum);
   1124   1.1  christos 
   1125   1.1  christos 		/* Octal, decimal, or hex format? */
   1126   1.1  christos 		value = strtol(arg, &endofnumber, 0);
   1127   1.1  christos 		if (arg == endofnumber)
   1128   1.1  christos 			fatal("%.200s line %d: Bad number.", filename, linenum);
   1129   1.1  christos 		if (*activep && *intptr == -1)
   1130   1.1  christos 			*intptr = value;
   1131   1.1  christos 		break;
   1132   1.1  christos 
   1133   1.1  christos 	case oConnectionAttempts:
   1134   1.1  christos 		intptr = &options->connection_attempts;
   1135   1.1  christos 		goto parse_int;
   1136   1.1  christos 
   1137   1.2  christos 	case oTcpRcvBuf:
   1138   1.2  christos 		intptr = &options->tcp_rcv_buf;
   1139   1.2  christos 		goto parse_int;
   1140   1.2  christos 
   1141   1.1  christos 	case oCipher:
   1142   1.1  christos 		intptr = &options->cipher;
   1143   1.1  christos 		arg = strdelim(&s);
   1144   1.1  christos 		if (!arg || *arg == '\0')
   1145   1.1  christos 			fatal("%.200s line %d: Missing argument.", filename, linenum);
   1146   1.1  christos 		value = cipher_number(arg);
   1147   1.1  christos 		if (value == -1)
   1148   1.1  christos 			fatal("%.200s line %d: Bad cipher '%s'.",
   1149   1.1  christos 			    filename, linenum, arg ? arg : "<NONE>");
   1150   1.1  christos 		if (*activep && *intptr == -1)
   1151   1.1  christos 			*intptr = value;
   1152   1.1  christos 		break;
   1153   1.1  christos 
   1154   1.1  christos 	case oCiphers:
   1155   1.1  christos 		arg = strdelim(&s);
   1156   1.1  christos 		if (!arg || *arg == '\0')
   1157   1.1  christos 			fatal("%.200s line %d: Missing argument.", filename, linenum);
   1158   1.1  christos 		if (!ciphers_valid(arg))
   1159   1.1  christos 			fatal("%.200s line %d: Bad SSH2 cipher spec '%s'.",
   1160   1.1  christos 			    filename, linenum, arg ? arg : "<NONE>");
   1161   1.1  christos 		if (*activep && options->ciphers == NULL)
   1162   1.1  christos 			options->ciphers = xstrdup(arg);
   1163   1.1  christos 		break;
   1164   1.1  christos 
   1165   1.1  christos 	case oMacs:
   1166   1.1  christos 		arg = strdelim(&s);
   1167   1.1  christos 		if (!arg || *arg == '\0')
   1168   1.1  christos 			fatal("%.200s line %d: Missing argument.", filename, linenum);
   1169   1.1  christos 		if (!mac_valid(arg))
   1170   1.1  christos 			fatal("%.200s line %d: Bad SSH2 Mac spec '%s'.",
   1171   1.1  christos 			    filename, linenum, arg ? arg : "<NONE>");
   1172   1.1  christos 		if (*activep && options->macs == NULL)
   1173   1.1  christos 			options->macs = xstrdup(arg);
   1174   1.1  christos 		break;
   1175   1.1  christos 
   1176   1.5  christos 	case oKexAlgorithms:
   1177   1.5  christos 		arg = strdelim(&s);
   1178   1.5  christos 		if (!arg || *arg == '\0')
   1179   1.5  christos 			fatal("%.200s line %d: Missing argument.",
   1180   1.5  christos 			    filename, linenum);
   1181   1.5  christos 		if (!kex_names_valid(arg))
   1182   1.5  christos 			fatal("%.200s line %d: Bad SSH2 KexAlgorithms '%s'.",
   1183   1.5  christos 			    filename, linenum, arg ? arg : "<NONE>");
   1184   1.5  christos 		if (*activep && options->kex_algorithms == NULL)
   1185   1.5  christos 			options->kex_algorithms = xstrdup(arg);
   1186   1.5  christos 		break;
   1187   1.5  christos 
   1188   1.1  christos 	case oHostKeyAlgorithms:
   1189   1.1  christos 		arg = strdelim(&s);
   1190   1.1  christos 		if (!arg || *arg == '\0')
   1191   1.1  christos 			fatal("%.200s line %d: Missing argument.", filename, linenum);
   1192  1.13  christos 		if (!sshkey_names_valid2(arg, 1))
   1193   1.1  christos 			fatal("%.200s line %d: Bad protocol 2 host key algorithms '%s'.",
   1194   1.1  christos 			    filename, linenum, arg ? arg : "<NONE>");
   1195   1.1  christos 		if (*activep && options->hostkeyalgorithms == NULL)
   1196   1.1  christos 			options->hostkeyalgorithms = xstrdup(arg);
   1197   1.1  christos 		break;
   1198   1.1  christos 
   1199   1.1  christos 	case oProtocol:
   1200   1.1  christos 		intptr = &options->protocol;
   1201   1.1  christos 		arg = strdelim(&s);
   1202   1.1  christos 		if (!arg || *arg == '\0')
   1203   1.1  christos 			fatal("%.200s line %d: Missing argument.", filename, linenum);
   1204   1.1  christos 		value = proto_spec(arg);
   1205   1.1  christos 		if (value == SSH_PROTO_UNKNOWN)
   1206   1.1  christos 			fatal("%.200s line %d: Bad protocol spec '%s'.",
   1207   1.1  christos 			    filename, linenum, arg ? arg : "<NONE>");
   1208   1.1  christos 		if (*activep && *intptr == SSH_PROTO_UNKNOWN)
   1209   1.1  christos 			*intptr = value;
   1210   1.1  christos 		break;
   1211   1.1  christos 
   1212   1.1  christos 	case oLogLevel:
   1213   1.1  christos 		log_level_ptr = &options->log_level;
   1214   1.1  christos 		arg = strdelim(&s);
   1215   1.1  christos 		value = log_level_number(arg);
   1216   1.1  christos 		if (value == SYSLOG_LEVEL_NOT_SET)
   1217   1.1  christos 			fatal("%.200s line %d: unsupported log level '%s'",
   1218   1.1  christos 			    filename, linenum, arg ? arg : "<NONE>");
   1219   1.1  christos 		if (*activep && *log_level_ptr == SYSLOG_LEVEL_NOT_SET)
   1220   1.1  christos 			*log_level_ptr = (LogLevel) value;
   1221   1.1  christos 		break;
   1222   1.1  christos 
   1223   1.1  christos 	case oLocalForward:
   1224   1.1  christos 	case oRemoteForward:
   1225   1.1  christos 	case oDynamicForward:
   1226   1.1  christos 		arg = strdelim(&s);
   1227   1.1  christos 		if (arg == NULL || *arg == '\0')
   1228   1.1  christos 			fatal("%.200s line %d: Missing port argument.",
   1229   1.1  christos 			    filename, linenum);
   1230   1.1  christos 
   1231   1.1  christos 		if (opcode == oLocalForward ||
   1232   1.1  christos 		    opcode == oRemoteForward) {
   1233   1.1  christos 			arg2 = strdelim(&s);
   1234   1.1  christos 			if (arg2 == NULL || *arg2 == '\0')
   1235   1.1  christos 				fatal("%.200s line %d: Missing target argument.",
   1236   1.1  christos 				    filename, linenum);
   1237   1.1  christos 
   1238   1.1  christos 			/* construct a string for parse_forward */
   1239   1.1  christos 			snprintf(fwdarg, sizeof(fwdarg), "%s:%s", arg, arg2);
   1240   1.1  christos 		} else if (opcode == oDynamicForward) {
   1241   1.1  christos 			strlcpy(fwdarg, arg, sizeof(fwdarg));
   1242   1.1  christos 		}
   1243   1.1  christos 
   1244   1.1  christos 		if (parse_forward(&fwd, fwdarg,
   1245   1.1  christos 		    opcode == oDynamicForward ? 1 : 0,
   1246   1.1  christos 		    opcode == oRemoteForward ? 1 : 0) == 0)
   1247   1.1  christos 			fatal("%.200s line %d: Bad forwarding specification.",
   1248   1.1  christos 			    filename, linenum);
   1249   1.1  christos 
   1250   1.1  christos 		if (*activep) {
   1251   1.1  christos 			if (opcode == oLocalForward ||
   1252   1.1  christos 			    opcode == oDynamicForward)
   1253   1.1  christos 				add_local_forward(options, &fwd);
   1254   1.1  christos 			else if (opcode == oRemoteForward)
   1255   1.1  christos 				add_remote_forward(options, &fwd);
   1256   1.1  christos 		}
   1257   1.1  christos 		break;
   1258   1.1  christos 
   1259   1.1  christos 	case oClearAllForwardings:
   1260   1.1  christos 		intptr = &options->clear_forwardings;
   1261   1.1  christos 		goto parse_flag;
   1262   1.1  christos 
   1263   1.1  christos 	case oHost:
   1264  1.12  christos 		if (cmdline)
   1265  1.12  christos 			fatal("Host directive not supported as a command-line "
   1266  1.12  christos 			    "option");
   1267   1.1  christos 		*activep = 0;
   1268   1.6  christos 		arg2 = NULL;
   1269   1.6  christos 		while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
   1270   1.6  christos 			negated = *arg == '!';
   1271   1.6  christos 			if (negated)
   1272   1.6  christos 				arg++;
   1273   1.1  christos 			if (match_pattern(host, arg)) {
   1274   1.6  christos 				if (negated) {
   1275   1.6  christos 					debug("%.200s line %d: Skipping Host "
   1276   1.6  christos 					    "block because of negated match "
   1277   1.6  christos 					    "for %.100s", filename, linenum,
   1278   1.6  christos 					    arg);
   1279   1.6  christos 					*activep = 0;
   1280   1.6  christos 					break;
   1281   1.6  christos 				}
   1282   1.6  christos 				if (!*activep)
   1283   1.6  christos 					arg2 = arg; /* logged below */
   1284   1.1  christos 				*activep = 1;
   1285   1.1  christos 			}
   1286   1.6  christos 		}
   1287   1.6  christos 		if (*activep)
   1288   1.6  christos 			debug("%.200s line %d: Applying options for %.100s",
   1289   1.6  christos 			    filename, linenum, arg2);
   1290   1.1  christos 		/* Avoid garbage check below, as strdelim is done. */
   1291   1.1  christos 		return 0;
   1292   1.1  christos 
   1293  1.12  christos 	case oMatch:
   1294  1.12  christos 		if (cmdline)
   1295  1.12  christos 			fatal("Host directive not supported as a command-line "
   1296  1.12  christos 			    "option");
   1297  1.13  christos 		value = match_cfg_line(options, &s, pw, host, original_host,
   1298  1.13  christos 		    flags & SSHCONF_POSTCANON, filename, linenum);
   1299  1.12  christos 		if (value < 0)
   1300  1.12  christos 			fatal("%.200s line %d: Bad Match condition", filename,
   1301  1.12  christos 			    linenum);
   1302  1.12  christos 		*activep = value;
   1303  1.12  christos 		break;
   1304  1.12  christos 
   1305   1.1  christos 	case oEscapeChar:
   1306   1.1  christos 		intptr = &options->escape_char;
   1307   1.1  christos 		arg = strdelim(&s);
   1308   1.1  christos 		if (!arg || *arg == '\0')
   1309   1.1  christos 			fatal("%.200s line %d: Missing argument.", filename, linenum);
   1310   1.2  christos 		value = 0;	/* To avoid compiler warning... */
   1311  1.14  christos 		if (strcmp(arg, "none") == 0)
   1312  1.14  christos 			value = SSH_ESCAPECHAR_NONE;
   1313  1.14  christos 		else if (arg[1] == '\0')
   1314  1.14  christos 			value = (u_char) arg[0];
   1315  1.14  christos 		else if (arg[0] == '^' && arg[2] == 0 &&
   1316   1.1  christos 		    (u_char) arg[1] >= 64 && (u_char) arg[1] < 128)
   1317   1.1  christos 			value = (u_char) arg[1] & 31;
   1318   1.1  christos 		else {
   1319   1.1  christos 			fatal("%.200s line %d: Bad escape character.",
   1320   1.1  christos 			    filename, linenum);
   1321   1.1  christos 			/* NOTREACHED */
   1322   1.1  christos 			value = 0;	/* Avoid compiler warning. */
   1323   1.1  christos 		}
   1324   1.1  christos 		if (*activep && *intptr == -1)
   1325   1.1  christos 			*intptr = value;
   1326   1.1  christos 		break;
   1327   1.1  christos 
   1328   1.1  christos 	case oAddressFamily:
   1329   1.1  christos 		intptr = &options->address_family;
   1330  1.12  christos 		multistate_ptr = multistate_addressfamily;
   1331  1.12  christos 		goto parse_multistate;
   1332   1.1  christos 
   1333   1.1  christos 	case oEnableSSHKeysign:
   1334   1.1  christos 		intptr = &options->enable_ssh_keysign;
   1335   1.1  christos 		goto parse_flag;
   1336   1.1  christos 
   1337   1.1  christos 	case oIdentitiesOnly:
   1338   1.1  christos 		intptr = &options->identities_only;
   1339   1.1  christos 		goto parse_flag;
   1340   1.1  christos 
   1341   1.1  christos 	case oServerAliveInterval:
   1342   1.1  christos 		intptr = &options->server_alive_interval;
   1343   1.1  christos 		goto parse_time;
   1344   1.1  christos 
   1345   1.1  christos 	case oServerAliveCountMax:
   1346   1.1  christos 		intptr = &options->server_alive_count_max;
   1347   1.1  christos 		goto parse_int;
   1348   1.1  christos 
   1349   1.1  christos 	case oSendEnv:
   1350   1.1  christos 		while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
   1351   1.1  christos 			if (strchr(arg, '=') != NULL)
   1352   1.1  christos 				fatal("%s line %d: Invalid environment name.",
   1353   1.1  christos 				    filename, linenum);
   1354   1.1  christos 			if (!*activep)
   1355   1.1  christos 				continue;
   1356   1.1  christos 			if (options->num_send_env >= MAX_SEND_ENV)
   1357   1.1  christos 				fatal("%s line %d: too many send env.",
   1358   1.1  christos 				    filename, linenum);
   1359   1.1  christos 			options->send_env[options->num_send_env++] =
   1360   1.1  christos 			    xstrdup(arg);
   1361   1.1  christos 		}
   1362   1.1  christos 		break;
   1363   1.1  christos 
   1364   1.1  christos 	case oControlPath:
   1365   1.1  christos 		charptr = &options->control_path;
   1366   1.1  christos 		goto parse_string;
   1367   1.1  christos 
   1368   1.1  christos 	case oControlMaster:
   1369   1.1  christos 		intptr = &options->control_master;
   1370  1.12  christos 		multistate_ptr = multistate_controlmaster;
   1371  1.12  christos 		goto parse_multistate;
   1372   1.1  christos 
   1373   1.4      adam 	case oControlPersist:
   1374   1.4      adam 		/* no/false/yes/true, or a time spec */
   1375   1.4      adam 		intptr = &options->control_persist;
   1376   1.4      adam 		arg = strdelim(&s);
   1377   1.4      adam 		if (!arg || *arg == '\0')
   1378   1.4      adam 			fatal("%.200s line %d: Missing ControlPersist"
   1379   1.4      adam 			    " argument.", filename, linenum);
   1380   1.4      adam 		value = 0;
   1381   1.4      adam 		value2 = 0;	/* timeout */
   1382   1.4      adam 		if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
   1383   1.4      adam 			value = 0;
   1384   1.4      adam 		else if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
   1385   1.4      adam 			value = 1;
   1386   1.4      adam 		else if ((value2 = convtime(arg)) >= 0)
   1387   1.4      adam 			value = 1;
   1388   1.4      adam 		else
   1389   1.4      adam 			fatal("%.200s line %d: Bad ControlPersist argument.",
   1390   1.4      adam 			    filename, linenum);
   1391   1.4      adam 		if (*activep && *intptr == -1) {
   1392   1.4      adam 			*intptr = value;
   1393   1.4      adam 			options->control_persist_timeout = value2;
   1394   1.4      adam 		}
   1395   1.4      adam 		break;
   1396   1.4      adam 
   1397   1.1  christos 	case oHashKnownHosts:
   1398   1.1  christos 		intptr = &options->hash_known_hosts;
   1399   1.1  christos 		goto parse_flag;
   1400   1.1  christos 
   1401   1.1  christos 	case oTunnel:
   1402   1.1  christos 		intptr = &options->tun_open;
   1403  1.12  christos 		multistate_ptr = multistate_tunnel;
   1404  1.12  christos 		goto parse_multistate;
   1405   1.1  christos 
   1406   1.1  christos 	case oTunnelDevice:
   1407   1.1  christos 		arg = strdelim(&s);
   1408   1.1  christos 		if (!arg || *arg == '\0')
   1409   1.1  christos 			fatal("%.200s line %d: Missing argument.", filename, linenum);
   1410   1.1  christos 		value = a2tun(arg, &value2);
   1411   1.1  christos 		if (value == SSH_TUNID_ERR)
   1412   1.1  christos 			fatal("%.200s line %d: Bad tun device.", filename, linenum);
   1413   1.1  christos 		if (*activep) {
   1414   1.1  christos 			options->tun_local = value;
   1415   1.1  christos 			options->tun_remote = value2;
   1416   1.1  christos 		}
   1417   1.1  christos 		break;
   1418   1.1  christos 
   1419   1.1  christos 	case oLocalCommand:
   1420   1.1  christos 		charptr = &options->local_command;
   1421   1.1  christos 		goto parse_command;
   1422   1.1  christos 
   1423   1.1  christos 	case oPermitLocalCommand:
   1424   1.1  christos 		intptr = &options->permit_local_command;
   1425   1.1  christos 		goto parse_flag;
   1426   1.1  christos 
   1427   1.1  christos 	case oVisualHostKey:
   1428   1.1  christos 		intptr = &options->visual_host_key;
   1429   1.1  christos 		goto parse_flag;
   1430   1.1  christos 
   1431   1.5  christos 	case oIPQoS:
   1432   1.5  christos 		arg = strdelim(&s);
   1433   1.5  christos 		if ((value = parse_ipqos(arg)) == -1)
   1434   1.5  christos 			fatal("%s line %d: Bad IPQoS value: %s",
   1435   1.5  christos 			    filename, linenum, arg);
   1436   1.5  christos 		arg = strdelim(&s);
   1437   1.5  christos 		if (arg == NULL)
   1438   1.5  christos 			value2 = value;
   1439   1.5  christos 		else if ((value2 = parse_ipqos(arg)) == -1)
   1440   1.5  christos 			fatal("%s line %d: Bad IPQoS value: %s",
   1441   1.5  christos 			    filename, linenum, arg);
   1442   1.5  christos 		if (*activep) {
   1443   1.5  christos 			options->ip_qos_interactive = value;
   1444   1.5  christos 			options->ip_qos_bulk = value2;
   1445   1.5  christos 		}
   1446   1.5  christos 		break;
   1447   1.5  christos 
   1448   1.3  christos 	case oUseRoaming:
   1449   1.3  christos 		intptr = &options->use_roaming;
   1450   1.3  christos 		goto parse_flag;
   1451   1.3  christos 
   1452   1.6  christos 	case oRequestTTY:
   1453   1.6  christos 		intptr = &options->request_tty;
   1454  1.12  christos 		multistate_ptr = multistate_requesttty;
   1455  1.12  christos 		goto parse_multistate;
   1456   1.6  christos 
   1457   1.7       tls 	case oSendVersionFirst:
   1458   1.7       tls 		intptr = &options->send_version_first;
   1459   1.7       tls 		goto parse_flag;
   1460   1.7       tls 
   1461  1.11  christos 	case oIgnoreUnknown:
   1462  1.11  christos 		charptr = &options->ignored_unknown;
   1463  1.11  christos 		goto parse_string;
   1464  1.11  christos 
   1465  1.12  christos 	case oProxyUseFdpass:
   1466  1.12  christos 		intptr = &options->proxy_use_fdpass;
   1467  1.12  christos 		goto parse_flag;
   1468  1.12  christos 
   1469  1.12  christos 	case oCanonicalDomains:
   1470  1.12  christos 		value = options->num_canonical_domains != 0;
   1471  1.12  christos 		while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
   1472  1.12  christos 			valid_domain(arg, filename, linenum);
   1473  1.12  christos 			if (!*activep || value)
   1474  1.12  christos 				continue;
   1475  1.12  christos 			if (options->num_canonical_domains >= MAX_CANON_DOMAINS)
   1476  1.12  christos 				fatal("%s line %d: too many hostname suffixes.",
   1477  1.12  christos 				    filename, linenum);
   1478  1.12  christos 			options->canonical_domains[
   1479  1.12  christos 			    options->num_canonical_domains++] = xstrdup(arg);
   1480  1.12  christos 		}
   1481  1.12  christos 		break;
   1482  1.12  christos 
   1483  1.12  christos 	case oCanonicalizePermittedCNAMEs:
   1484  1.12  christos 		value = options->num_permitted_cnames != 0;
   1485  1.12  christos 		while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
   1486  1.12  christos 			/* Either '*' for everything or 'list:list' */
   1487  1.12  christos 			if (strcmp(arg, "*") == 0)
   1488  1.12  christos 				arg2 = arg;
   1489  1.12  christos 			else {
   1490  1.12  christos 				lowercase(arg);
   1491  1.12  christos 				if ((arg2 = strchr(arg, ':')) == NULL ||
   1492  1.12  christos 				    arg2[1] == '\0') {
   1493  1.12  christos 					fatal("%s line %d: "
   1494  1.12  christos 					    "Invalid permitted CNAME \"%s\"",
   1495  1.12  christos 					    filename, linenum, arg);
   1496  1.12  christos 				}
   1497  1.12  christos 				*arg2 = '\0';
   1498  1.12  christos 				arg2++;
   1499  1.12  christos 			}
   1500  1.12  christos 			if (!*activep || value)
   1501  1.12  christos 				continue;
   1502  1.12  christos 			if (options->num_permitted_cnames >= MAX_CANON_DOMAINS)
   1503  1.12  christos 				fatal("%s line %d: too many permitted CNAMEs.",
   1504  1.12  christos 				    filename, linenum);
   1505  1.12  christos 			cname = options->permitted_cnames +
   1506  1.12  christos 			    options->num_permitted_cnames++;
   1507  1.12  christos 			cname->source_list = xstrdup(arg);
   1508  1.12  christos 			cname->target_list = xstrdup(arg2);
   1509  1.12  christos 		}
   1510  1.12  christos 		break;
   1511  1.12  christos 
   1512  1.12  christos 	case oCanonicalizeHostname:
   1513  1.12  christos 		intptr = &options->canonicalize_hostname;
   1514  1.12  christos 		multistate_ptr = multistate_canonicalizehostname;
   1515  1.12  christos 		goto parse_multistate;
   1516  1.12  christos 
   1517  1.12  christos 	case oCanonicalizeMaxDots:
   1518  1.12  christos 		intptr = &options->canonicalize_max_dots;
   1519  1.12  christos 		goto parse_int;
   1520  1.12  christos 
   1521  1.12  christos 	case oCanonicalizeFallbackLocal:
   1522  1.12  christos 		intptr = &options->canonicalize_fallback_local;
   1523  1.12  christos 		goto parse_flag;
   1524  1.12  christos 
   1525  1.12  christos 	case oStreamLocalBindMask:
   1526  1.12  christos 		arg = strdelim(&s);
   1527  1.12  christos 		if (!arg || *arg == '\0')
   1528  1.12  christos 			fatal("%.200s line %d: Missing StreamLocalBindMask argument.", filename, linenum);
   1529  1.12  christos 		/* Parse mode in octal format */
   1530  1.12  christos 		value = strtol(arg, &endofnumber, 8);
   1531  1.12  christos 		if (arg == endofnumber || value < 0 || value > 0777)
   1532  1.12  christos 			fatal("%.200s line %d: Bad mask.", filename, linenum);
   1533  1.12  christos 		options->fwd_opts.streamlocal_bind_mask = (mode_t)value;
   1534  1.12  christos 		break;
   1535  1.12  christos 
   1536  1.12  christos 	case oStreamLocalBindUnlink:
   1537  1.12  christos 		intptr = &options->fwd_opts.streamlocal_bind_unlink;
   1538  1.12  christos 		goto parse_flag;
   1539  1.12  christos 
   1540  1.13  christos 	case oRevokedHostKeys:
   1541  1.13  christos 		charptr = &options->revoked_host_keys;
   1542  1.13  christos 		goto parse_string;
   1543  1.13  christos 
   1544  1.13  christos 	case oFingerprintHash:
   1545  1.13  christos 		intptr = &options->fingerprint_hash;
   1546  1.13  christos 		arg = strdelim(&s);
   1547  1.13  christos 		if (!arg || *arg == '\0')
   1548  1.13  christos 			fatal("%.200s line %d: Missing argument.",
   1549  1.13  christos 			    filename, linenum);
   1550  1.13  christos 		if ((value = ssh_digest_alg_by_name(arg)) == -1)
   1551  1.13  christos 			fatal("%.200s line %d: Invalid hash algorithm \"%s\".",
   1552  1.13  christos 			    filename, linenum, arg);
   1553  1.13  christos 		if (*activep && *intptr == -1)
   1554  1.13  christos 			*intptr = value;
   1555  1.13  christos 		break;
   1556  1.13  christos 
   1557  1.13  christos 	case oUpdateHostkeys:
   1558  1.13  christos 		intptr = &options->update_hostkeys;
   1559  1.13  christos 		multistate_ptr = multistate_yesnoask;
   1560  1.13  christos 		goto parse_multistate;
   1561  1.13  christos 
   1562  1.13  christos 	case oHostbasedKeyTypes:
   1563  1.13  christos 		charptr = &options->hostbased_key_types;
   1564  1.13  christos 		arg = strdelim(&s);
   1565  1.13  christos 		if (!arg || *arg == '\0')
   1566  1.13  christos 			fatal("%.200s line %d: Missing argument.",
   1567  1.13  christos 			    filename, linenum);
   1568  1.13  christos 		if (!sshkey_names_valid2(arg, 1))
   1569  1.13  christos 			fatal("%s line %d: Bad key types '%s'.",
   1570  1.13  christos 				filename, linenum, arg ? arg : "<NONE>");
   1571  1.13  christos 		if (*activep && *charptr == NULL)
   1572  1.13  christos 			*charptr = xstrdup(arg);
   1573  1.13  christos 		break;
   1574  1.13  christos 
   1575   1.1  christos 	case oDeprecated:
   1576   1.1  christos 		debug("%s line %d: Deprecated option \"%s\"",
   1577   1.1  christos 		    filename, linenum, keyword);
   1578   1.1  christos 		return 0;
   1579   1.1  christos 
   1580   1.1  christos 	case oUnsupported:
   1581   1.1  christos 		error("%s line %d: Unsupported option \"%s\"",
   1582   1.1  christos 		    filename, linenum, keyword);
   1583   1.1  christos 		return 0;
   1584   1.1  christos 
   1585   1.1  christos 	default:
   1586  1.13  christos 		fatal("%s: Unimplemented opcode %d", __func__, opcode);
   1587   1.1  christos 	}
   1588   1.1  christos 
   1589   1.1  christos 	/* Check that there is no garbage at end of line. */
   1590   1.1  christos 	if ((arg = strdelim(&s)) != NULL && *arg != '\0') {
   1591   1.1  christos 		fatal("%.200s line %d: garbage at end of line; \"%.200s\".",
   1592   1.1  christos 		    filename, linenum, arg);
   1593   1.1  christos 	}
   1594   1.1  christos 	return 0;
   1595   1.1  christos }
   1596   1.1  christos 
   1597   1.1  christos 
   1598   1.1  christos /*
   1599   1.1  christos  * Reads the config file and modifies the options accordingly.  Options
   1600   1.1  christos  * should already be initialized before this call.  This never returns if
   1601   1.1  christos  * there is an error.  If the file does not exist, this returns 0.
   1602   1.1  christos  */
   1603   1.1  christos 
   1604   1.1  christos int
   1605  1.12  christos read_config_file(const char *filename, struct passwd *pw, const char *host,
   1606  1.13  christos     const char *original_host, Options *options, int flags)
   1607   1.1  christos {
   1608   1.1  christos 	FILE *f;
   1609   1.1  christos 	char line[1024];
   1610   1.1  christos 	int active, linenum;
   1611   1.1  christos 	int bad_options = 0;
   1612   1.1  christos 
   1613   1.1  christos 	if ((f = fopen(filename, "r")) == NULL)
   1614   1.1  christos 		return 0;
   1615   1.1  christos 
   1616   1.9   mlelstv 	if (flags & SSHCONF_CHECKPERM) {
   1617   1.1  christos 		struct stat sb;
   1618   1.1  christos 
   1619   1.1  christos 		if (fstat(fileno(f), &sb) == -1)
   1620   1.1  christos 			fatal("fstat %s: %s", filename, strerror(errno));
   1621   1.1  christos 		if (((sb.st_uid != 0 && sb.st_uid != getuid()) ||
   1622   1.1  christos 		    (sb.st_mode & 022) != 0))
   1623   1.1  christos 			fatal("Bad owner or permissions on %s", filename);
   1624   1.1  christos 	}
   1625   1.1  christos 
   1626   1.1  christos 	debug("Reading configuration data %.200s", filename);
   1627   1.1  christos 
   1628   1.1  christos 	/*
   1629   1.1  christos 	 * Mark that we are now processing the options.  This flag is turned
   1630   1.1  christos 	 * on/off by Host specifications.
   1631   1.1  christos 	 */
   1632   1.1  christos 	active = 1;
   1633   1.1  christos 	linenum = 0;
   1634   1.1  christos 	while (fgets(line, sizeof(line), f)) {
   1635   1.1  christos 		/* Update line number counter. */
   1636   1.1  christos 		linenum++;
   1637  1.13  christos 		if (process_config_line(options, pw, host, original_host,
   1638  1.13  christos 		    line, filename, linenum, &active, flags) != 0)
   1639   1.1  christos 			bad_options++;
   1640   1.1  christos 	}
   1641   1.1  christos 	fclose(f);
   1642   1.1  christos 	if (bad_options > 0)
   1643   1.1  christos 		fatal("%s: terminating, %d bad configuration options",
   1644   1.1  christos 		    filename, bad_options);
   1645   1.1  christos 	return 1;
   1646   1.1  christos }
   1647   1.1  christos 
   1648  1.12  christos /* Returns 1 if a string option is unset or set to "none" or 0 otherwise. */
   1649  1.12  christos int
   1650  1.12  christos option_clear_or_none(const char *o)
   1651  1.12  christos {
   1652  1.12  christos 	return o == NULL || strcasecmp(o, "none") == 0;
   1653  1.12  christos }
   1654  1.12  christos 
   1655   1.1  christos /*
   1656   1.1  christos  * Initializes options to special values that indicate that they have not yet
   1657   1.1  christos  * been set.  Read_config_file will only set options with this value. Options
   1658   1.1  christos  * are processed in the following order: command line, user config file,
   1659   1.1  christos  * system config file.  Last, fill_default_options is called.
   1660   1.1  christos  */
   1661   1.1  christos 
   1662   1.1  christos void
   1663   1.1  christos initialize_options(Options * options)
   1664   1.1  christos {
   1665   1.1  christos 	memset(options, 'X', sizeof(*options));
   1666   1.1  christos 	options->forward_agent = -1;
   1667   1.1  christos 	options->forward_x11 = -1;
   1668   1.1  christos 	options->forward_x11_trusted = -1;
   1669   1.4      adam 	options->forward_x11_timeout = -1;
   1670   1.1  christos 	options->exit_on_forward_failure = -1;
   1671   1.1  christos 	options->xauth_location = NULL;
   1672  1.12  christos 	options->fwd_opts.gateway_ports = -1;
   1673  1.12  christos 	options->fwd_opts.streamlocal_bind_mask = (mode_t)-1;
   1674  1.12  christos 	options->fwd_opts.streamlocal_bind_unlink = -1;
   1675   1.1  christos 	options->use_privileged_port = -1;
   1676   1.1  christos 	options->rsa_authentication = -1;
   1677   1.1  christos 	options->pubkey_authentication = -1;
   1678   1.1  christos 	options->challenge_response_authentication = -1;
   1679   1.2  christos #if defined(KRB4) || defined(KRB5)
   1680   1.2  christos 	options->kerberos_authentication = -1;
   1681   1.2  christos #endif
   1682   1.2  christos #if defined(AFS) || defined(KRB5)
   1683   1.2  christos 	options->kerberos_tgt_passing = -1;
   1684   1.2  christos #endif
   1685   1.2  christos #ifdef AFS
   1686   1.2  christos 	options->afs_token_passing = -1;
   1687   1.2  christos #endif
   1688   1.1  christos 	options->gss_authentication = -1;
   1689   1.1  christos 	options->gss_deleg_creds = -1;
   1690   1.1  christos 	options->password_authentication = -1;
   1691   1.1  christos 	options->kbd_interactive_authentication = -1;
   1692   1.1  christos 	options->kbd_interactive_devices = NULL;
   1693   1.1  christos 	options->rhosts_rsa_authentication = -1;
   1694   1.1  christos 	options->hostbased_authentication = -1;
   1695   1.1  christos 	options->batch_mode = -1;
   1696   1.1  christos 	options->check_host_ip = -1;
   1697   1.1  christos 	options->strict_host_key_checking = -1;
   1698   1.1  christos 	options->compression = -1;
   1699   1.1  christos 	options->tcp_keep_alive = -1;
   1700   1.1  christos 	options->compression_level = -1;
   1701   1.1  christos 	options->port = -1;
   1702   1.1  christos 	options->address_family = -1;
   1703   1.1  christos 	options->connection_attempts = -1;
   1704   1.1  christos 	options->connection_timeout = -1;
   1705   1.1  christos 	options->number_of_password_prompts = -1;
   1706   1.1  christos 	options->cipher = -1;
   1707   1.1  christos 	options->ciphers = NULL;
   1708   1.1  christos 	options->macs = NULL;
   1709   1.5  christos 	options->kex_algorithms = NULL;
   1710   1.1  christos 	options->hostkeyalgorithms = NULL;
   1711   1.1  christos 	options->protocol = SSH_PROTO_UNKNOWN;
   1712   1.1  christos 	options->num_identity_files = 0;
   1713   1.1  christos 	options->hostname = NULL;
   1714   1.1  christos 	options->host_key_alias = NULL;
   1715   1.1  christos 	options->proxy_command = NULL;
   1716   1.1  christos 	options->user = NULL;
   1717   1.1  christos 	options->escape_char = -1;
   1718   1.6  christos 	options->num_system_hostfiles = 0;
   1719   1.6  christos 	options->num_user_hostfiles = 0;
   1720   1.4      adam 	options->local_forwards = NULL;
   1721   1.1  christos 	options->num_local_forwards = 0;
   1722   1.4      adam 	options->remote_forwards = NULL;
   1723   1.1  christos 	options->num_remote_forwards = 0;
   1724   1.1  christos 	options->clear_forwardings = -1;
   1725   1.1  christos 	options->log_level = SYSLOG_LEVEL_NOT_SET;
   1726   1.1  christos 	options->preferred_authentications = NULL;
   1727   1.1  christos 	options->bind_address = NULL;
   1728   1.4      adam 	options->pkcs11_provider = NULL;
   1729   1.1  christos 	options->enable_ssh_keysign = - 1;
   1730   1.1  christos 	options->no_host_authentication_for_localhost = - 1;
   1731   1.1  christos 	options->identities_only = - 1;
   1732   1.1  christos 	options->rekey_limit = - 1;
   1733  1.11  christos 	options->rekey_interval = -1;
   1734   1.1  christos 	options->verify_host_key_dns = -1;
   1735   1.1  christos 	options->server_alive_interval = -1;
   1736   1.1  christos 	options->server_alive_count_max = -1;
   1737   1.1  christos 	options->num_send_env = 0;
   1738   1.1  christos 	options->control_path = NULL;
   1739   1.1  christos 	options->control_master = -1;
   1740   1.4      adam 	options->control_persist = -1;
   1741   1.4      adam 	options->control_persist_timeout = 0;
   1742   1.1  christos 	options->hash_known_hosts = -1;
   1743   1.1  christos 	options->tun_open = -1;
   1744   1.1  christos 	options->tun_local = -1;
   1745   1.1  christos 	options->tun_remote = -1;
   1746   1.1  christos 	options->local_command = NULL;
   1747   1.1  christos 	options->permit_local_command = -1;
   1748   1.3  christos 	options->use_roaming = -1;
   1749   1.1  christos 	options->visual_host_key = -1;
   1750   1.5  christos 	options->ip_qos_interactive = -1;
   1751   1.5  christos 	options->ip_qos_bulk = -1;
   1752   1.6  christos 	options->request_tty = -1;
   1753  1.12  christos 	options->proxy_use_fdpass = -1;
   1754  1.11  christos 	options->ignored_unknown = NULL;
   1755  1.12  christos 	options->num_canonical_domains = 0;
   1756  1.12  christos 	options->num_permitted_cnames = 0;
   1757  1.12  christos 	options->canonicalize_max_dots = -1;
   1758  1.12  christos 	options->canonicalize_fallback_local = -1;
   1759  1.12  christos 	options->canonicalize_hostname = -1;
   1760  1.13  christos 	options->revoked_host_keys = NULL;
   1761  1.13  christos 	options->fingerprint_hash = -1;
   1762  1.13  christos 	options->update_hostkeys = -1;
   1763  1.13  christos 	options->hostbased_key_types = NULL;
   1764   1.2  christos 	options->none_switch = -1;
   1765   1.2  christos 	options->none_enabled = -1;
   1766   1.2  christos 	options->hpn_disabled = -1;
   1767   1.2  christos 	options->hpn_buffer_size = -1;
   1768   1.2  christos 	options->tcp_rcv_buf_poll = -1;
   1769   1.2  christos 	options->tcp_rcv_buf = -1;
   1770   1.7       tls 	options->send_version_first = -1;
   1771   1.1  christos }
   1772   1.1  christos 
   1773   1.1  christos /*
   1774  1.12  christos  * A petite version of fill_default_options() that just fills the options
   1775  1.12  christos  * needed for hostname canonicalization to proceed.
   1776  1.12  christos  */
   1777  1.12  christos void
   1778  1.12  christos fill_default_options_for_canonicalization(Options *options)
   1779  1.12  christos {
   1780  1.12  christos 	if (options->canonicalize_max_dots == -1)
   1781  1.12  christos 		options->canonicalize_max_dots = 1;
   1782  1.12  christos 	if (options->canonicalize_fallback_local == -1)
   1783  1.12  christos 		options->canonicalize_fallback_local = 1;
   1784  1.12  christos 	if (options->canonicalize_hostname == -1)
   1785  1.12  christos 		options->canonicalize_hostname = SSH_CANONICALISE_NO;
   1786  1.12  christos }
   1787  1.12  christos 
   1788  1.12  christos /*
   1789   1.1  christos  * Called after processing other sources of option data, this fills those
   1790   1.1  christos  * options for which no value has been specified with their default values.
   1791   1.1  christos  */
   1792   1.1  christos void
   1793   1.1  christos fill_default_options(Options * options)
   1794   1.1  christos {
   1795   1.1  christos 	if (options->forward_agent == -1)
   1796   1.1  christos 		options->forward_agent = 0;
   1797   1.1  christos 	if (options->forward_x11 == -1)
   1798   1.1  christos 		options->forward_x11 = 0;
   1799   1.1  christos 	if (options->forward_x11_trusted == -1)
   1800   1.1  christos 		options->forward_x11_trusted = 0;
   1801   1.4      adam 	if (options->forward_x11_timeout == -1)
   1802   1.4      adam 		options->forward_x11_timeout = 1200;
   1803   1.1  christos 	if (options->exit_on_forward_failure == -1)
   1804   1.1  christos 		options->exit_on_forward_failure = 0;
   1805   1.1  christos 	if (options->xauth_location == NULL)
   1806   1.5  christos 		options->xauth_location = __UNCONST(_PATH_XAUTH);
   1807  1.12  christos 	if (options->fwd_opts.gateway_ports == -1)
   1808  1.12  christos 		options->fwd_opts.gateway_ports = 0;
   1809  1.12  christos 	if (options->fwd_opts.streamlocal_bind_mask == (mode_t)-1)
   1810  1.12  christos 		options->fwd_opts.streamlocal_bind_mask = 0177;
   1811  1.12  christos 	if (options->fwd_opts.streamlocal_bind_unlink == -1)
   1812  1.12  christos 		options->fwd_opts.streamlocal_bind_unlink = 0;
   1813   1.1  christos 	if (options->use_privileged_port == -1)
   1814   1.1  christos 		options->use_privileged_port = 0;
   1815   1.1  christos 	if (options->rsa_authentication == -1)
   1816   1.1  christos 		options->rsa_authentication = 1;
   1817   1.1  christos 	if (options->pubkey_authentication == -1)
   1818   1.1  christos 		options->pubkey_authentication = 1;
   1819   1.1  christos 	if (options->challenge_response_authentication == -1)
   1820   1.1  christos 		options->challenge_response_authentication = 1;
   1821   1.2  christos #if defined(KRB4) || defined(KRB5)
   1822   1.2  christos 	if (options->kerberos_authentication == -1)
   1823   1.2  christos 		options->kerberos_authentication = 1;
   1824   1.2  christos #endif
   1825   1.2  christos #if defined(AFS) || defined(KRB5)
   1826   1.2  christos 	if (options->kerberos_tgt_passing == -1)
   1827   1.2  christos 		options->kerberos_tgt_passing = 1;
   1828   1.2  christos #endif
   1829   1.2  christos #ifdef AFS
   1830   1.2  christos 	if (options->afs_token_passing == -1)
   1831   1.2  christos 		options->afs_token_passing = 1;
   1832   1.2  christos #endif
   1833   1.1  christos 	if (options->gss_authentication == -1)
   1834   1.1  christos 		options->gss_authentication = 0;
   1835   1.1  christos 	if (options->gss_deleg_creds == -1)
   1836   1.1  christos 		options->gss_deleg_creds = 0;
   1837   1.1  christos 	if (options->password_authentication == -1)
   1838   1.1  christos 		options->password_authentication = 1;
   1839   1.1  christos 	if (options->kbd_interactive_authentication == -1)
   1840   1.1  christos 		options->kbd_interactive_authentication = 1;
   1841   1.1  christos 	if (options->rhosts_rsa_authentication == -1)
   1842   1.1  christos 		options->rhosts_rsa_authentication = 0;
   1843   1.1  christos 	if (options->hostbased_authentication == -1)
   1844   1.1  christos 		options->hostbased_authentication = 0;
   1845   1.1  christos 	if (options->batch_mode == -1)
   1846   1.1  christos 		options->batch_mode = 0;
   1847   1.1  christos 	if (options->check_host_ip == -1)
   1848   1.1  christos 		options->check_host_ip = 1;
   1849   1.1  christos 	if (options->strict_host_key_checking == -1)
   1850   1.1  christos 		options->strict_host_key_checking = 2;	/* 2 is default */
   1851   1.1  christos 	if (options->compression == -1)
   1852   1.1  christos 		options->compression = 0;
   1853   1.1  christos 	if (options->tcp_keep_alive == -1)
   1854   1.1  christos 		options->tcp_keep_alive = 1;
   1855   1.1  christos 	if (options->compression_level == -1)
   1856   1.1  christos 		options->compression_level = 6;
   1857   1.1  christos 	if (options->port == -1)
   1858   1.1  christos 		options->port = 0;	/* Filled in ssh_connect. */
   1859   1.1  christos 	if (options->address_family == -1)
   1860   1.1  christos 		options->address_family = AF_UNSPEC;
   1861   1.1  christos 	if (options->connection_attempts == -1)
   1862   1.1  christos 		options->connection_attempts = 1;
   1863   1.1  christos 	if (options->number_of_password_prompts == -1)
   1864   1.1  christos 		options->number_of_password_prompts = 3;
   1865   1.1  christos 	/* Selected in ssh_login(). */
   1866   1.1  christos 	if (options->cipher == -1)
   1867   1.1  christos 		options->cipher = SSH_CIPHER_NOT_SET;
   1868   1.1  christos 	/* options->ciphers, default set in myproposals.h */
   1869   1.1  christos 	/* options->macs, default set in myproposals.h */
   1870   1.5  christos 	/* options->kex_algorithms, default set in myproposals.h */
   1871   1.1  christos 	/* options->hostkeyalgorithms, default set in myproposals.h */
   1872   1.1  christos 	if (options->protocol == SSH_PROTO_UNKNOWN)
   1873   1.4      adam 		options->protocol = SSH_PROTO_2;
   1874   1.1  christos 	if (options->num_identity_files == 0) {
   1875   1.1  christos 		if (options->protocol & SSH_PROTO_1) {
   1876  1.10   mlelstv 			add_identity_file(options, "~/",
   1877  1.10   mlelstv 			    _PATH_SSH_CLIENT_IDENTITY, 0);
   1878   1.1  christos 		}
   1879   1.1  christos 		if (options->protocol & SSH_PROTO_2) {
   1880  1.10   mlelstv 			add_identity_file(options, "~/",
   1881  1.10   mlelstv 			    _PATH_SSH_CLIENT_ID_RSA, 0);
   1882  1.10   mlelstv 			add_identity_file(options, "~/",
   1883  1.10   mlelstv 			    _PATH_SSH_CLIENT_ID_DSA, 0);
   1884  1.10   mlelstv 			add_identity_file(options, "~/",
   1885  1.10   mlelstv 			    _PATH_SSH_CLIENT_ID_ECDSA, 0);
   1886  1.12  christos 			add_identity_file(options, "~/",
   1887  1.12  christos 			    _PATH_SSH_CLIENT_ID_ED25519, 0);
   1888   1.1  christos 		}
   1889   1.1  christos 	}
   1890   1.1  christos 	if (options->escape_char == -1)
   1891   1.1  christos 		options->escape_char = '~';
   1892   1.6  christos 	if (options->num_system_hostfiles == 0) {
   1893   1.6  christos 		options->system_hostfiles[options->num_system_hostfiles++] =
   1894   1.6  christos 		    xstrdup(_PATH_SSH_SYSTEM_HOSTFILE);
   1895   1.6  christos 		options->system_hostfiles[options->num_system_hostfiles++] =
   1896   1.6  christos 		    xstrdup(_PATH_SSH_SYSTEM_HOSTFILE2);
   1897   1.6  christos 	}
   1898   1.6  christos 	if (options->num_user_hostfiles == 0) {
   1899   1.6  christos 		options->user_hostfiles[options->num_user_hostfiles++] =
   1900   1.6  christos 		    xstrdup(_PATH_SSH_USER_HOSTFILE);
   1901   1.6  christos 		options->user_hostfiles[options->num_user_hostfiles++] =
   1902   1.6  christos 		    xstrdup(_PATH_SSH_USER_HOSTFILE2);
   1903   1.6  christos 	}
   1904   1.1  christos 	if (options->log_level == SYSLOG_LEVEL_NOT_SET)
   1905   1.1  christos 		options->log_level = SYSLOG_LEVEL_INFO;
   1906   1.1  christos 	if (options->clear_forwardings == 1)
   1907   1.1  christos 		clear_forwardings(options);
   1908   1.1  christos 	if (options->no_host_authentication_for_localhost == - 1)
   1909   1.1  christos 		options->no_host_authentication_for_localhost = 0;
   1910   1.1  christos 	if (options->identities_only == -1)
   1911   1.1  christos 		options->identities_only = 0;
   1912   1.1  christos 	if (options->enable_ssh_keysign == -1)
   1913   1.1  christos 		options->enable_ssh_keysign = 0;
   1914   1.1  christos 	if (options->rekey_limit == -1)
   1915   1.1  christos 		options->rekey_limit = 0;
   1916  1.11  christos 	if (options->rekey_interval == -1)
   1917  1.11  christos 		options->rekey_interval = 0;
   1918   1.1  christos 	if (options->verify_host_key_dns == -1)
   1919   1.1  christos 		options->verify_host_key_dns = 0;
   1920   1.1  christos 	if (options->server_alive_interval == -1)
   1921   1.1  christos 		options->server_alive_interval = 0;
   1922   1.1  christos 	if (options->server_alive_count_max == -1)
   1923   1.1  christos 		options->server_alive_count_max = 3;
   1924   1.2  christos 	if (options->none_switch == -1)
   1925   1.2  christos 	        options->none_switch = 0;
   1926   1.2  christos 	if (options->hpn_disabled == -1)
   1927   1.2  christos 	        options->hpn_disabled = 0;
   1928   1.2  christos 	if (options->hpn_buffer_size > -1)
   1929   1.2  christos 	{
   1930   1.2  christos 	  /* if a user tries to set the size to 0 set it to 1KB */
   1931   1.2  christos 		if (options->hpn_buffer_size == 0)
   1932   1.2  christos 		options->hpn_buffer_size = 1024;
   1933   1.2  christos 		/*limit the buffer to 64MB*/
   1934   1.2  christos 		if (options->hpn_buffer_size > 65536)
   1935   1.2  christos 		{
   1936   1.2  christos 			options->hpn_buffer_size = 65536*1024;
   1937   1.2  christos 			debug("User requested buffer larger than 64MB. Request reverted to 64MB");
   1938   1.2  christos 		}
   1939   1.2  christos 		debug("hpn_buffer_size set to %d", options->hpn_buffer_size);
   1940   1.2  christos 	}
   1941   1.2  christos 	if (options->tcp_rcv_buf == 0)
   1942   1.2  christos 		options->tcp_rcv_buf = 1;
   1943   1.2  christos 	if (options->tcp_rcv_buf > -1)
   1944   1.2  christos 		options->tcp_rcv_buf *=1024;
   1945   1.2  christos 	if (options->tcp_rcv_buf_poll == -1)
   1946   1.2  christos 		options->tcp_rcv_buf_poll = 1;
   1947   1.1  christos 	if (options->control_master == -1)
   1948   1.1  christos 		options->control_master = 0;
   1949   1.4      adam 	if (options->control_persist == -1) {
   1950   1.4      adam 		options->control_persist = 0;
   1951   1.4      adam 		options->control_persist_timeout = 0;
   1952   1.4      adam 	}
   1953   1.1  christos 	if (options->hash_known_hosts == -1)
   1954   1.1  christos 		options->hash_known_hosts = 0;
   1955   1.1  christos 	if (options->tun_open == -1)
   1956   1.1  christos 		options->tun_open = SSH_TUNMODE_NO;
   1957   1.1  christos 	if (options->tun_local == -1)
   1958   1.1  christos 		options->tun_local = SSH_TUNID_ANY;
   1959   1.1  christos 	if (options->tun_remote == -1)
   1960   1.1  christos 		options->tun_remote = SSH_TUNID_ANY;
   1961   1.1  christos 	if (options->permit_local_command == -1)
   1962   1.1  christos 		options->permit_local_command = 0;
   1963   1.3  christos 	if (options->use_roaming == -1)
   1964   1.3  christos 		options->use_roaming = 1;
   1965   1.1  christos 	if (options->visual_host_key == -1)
   1966   1.1  christos 		options->visual_host_key = 0;
   1967   1.5  christos 	if (options->ip_qos_interactive == -1)
   1968   1.5  christos 		options->ip_qos_interactive = IPTOS_LOWDELAY;
   1969   1.5  christos 	if (options->ip_qos_bulk == -1)
   1970   1.5  christos 		options->ip_qos_bulk = IPTOS_THROUGHPUT;
   1971   1.6  christos 	if (options->request_tty == -1)
   1972   1.6  christos 		options->request_tty = REQUEST_TTY_AUTO;
   1973  1.12  christos 	if (options->proxy_use_fdpass == -1)
   1974  1.12  christos 		options->proxy_use_fdpass = 0;
   1975  1.12  christos 	if (options->canonicalize_max_dots == -1)
   1976  1.12  christos 		options->canonicalize_max_dots = 1;
   1977  1.12  christos 	if (options->canonicalize_fallback_local == -1)
   1978  1.12  christos 		options->canonicalize_fallback_local = 1;
   1979  1.12  christos 	if (options->canonicalize_hostname == -1)
   1980  1.12  christos 		options->canonicalize_hostname = SSH_CANONICALISE_NO;
   1981  1.13  christos 	if (options->fingerprint_hash == -1)
   1982  1.13  christos 		options->fingerprint_hash = SSH_FP_HASH_DEFAULT;
   1983  1.13  christos 	if (options->update_hostkeys == -1)
   1984  1.13  christos 		options->update_hostkeys = 0;
   1985  1.13  christos 	if (options->hostbased_key_types == NULL)
   1986  1.13  christos 		options->hostbased_key_types = xstrdup("*");
   1987  1.13  christos 
   1988   1.7       tls 	if (options->send_version_first == -1)
   1989   1.7       tls 		options->send_version_first = 1;
   1990  1.12  christos #define CLEAR_ON_NONE(v) \
   1991  1.12  christos 	do { \
   1992  1.12  christos 		if (option_clear_or_none(v)) { \
   1993  1.12  christos 			free(v); \
   1994  1.12  christos 			v = NULL; \
   1995  1.12  christos 		} \
   1996  1.12  christos 	} while(0)
   1997  1.12  christos 	CLEAR_ON_NONE(options->local_command);
   1998  1.12  christos 	CLEAR_ON_NONE(options->proxy_command);
   1999  1.12  christos 	CLEAR_ON_NONE(options->control_path);
   2000  1.13  christos 	CLEAR_ON_NONE(options->revoked_host_keys);
   2001   1.1  christos 	/* options->user will be set in the main program if appropriate */
   2002   1.1  christos 	/* options->hostname will be set in the main program if appropriate */
   2003   1.1  christos 	/* options->host_key_alias should not be set by default */
   2004   1.1  christos 	/* options->preferred_authentications will be set in ssh */
   2005   1.1  christos }
   2006   1.1  christos 
   2007  1.12  christos struct fwdarg {
   2008  1.12  christos 	char *arg;
   2009  1.12  christos 	int ispath;
   2010  1.12  christos };
   2011  1.12  christos 
   2012  1.12  christos /*
   2013  1.12  christos  * parse_fwd_field
   2014  1.12  christos  * parses the next field in a port forwarding specification.
   2015  1.12  christos  * sets fwd to the parsed field and advances p past the colon
   2016  1.12  christos  * or sets it to NULL at end of string.
   2017  1.12  christos  * returns 0 on success, else non-zero.
   2018  1.12  christos  */
   2019  1.12  christos static int
   2020  1.12  christos parse_fwd_field(char **p, struct fwdarg *fwd)
   2021  1.12  christos {
   2022  1.12  christos 	char *ep, *cp = *p;
   2023  1.12  christos 	int ispath = 0;
   2024  1.12  christos 
   2025  1.12  christos 	if (*cp == '\0') {
   2026  1.12  christos 		*p = NULL;
   2027  1.12  christos 		return -1;	/* end of string */
   2028  1.12  christos 	}
   2029  1.12  christos 
   2030  1.12  christos 	/*
   2031  1.12  christos 	 * A field escaped with square brackets is used literally.
   2032  1.12  christos 	 * XXX - allow ']' to be escaped via backslash?
   2033  1.12  christos 	 */
   2034  1.12  christos 	if (*cp == '[') {
   2035  1.12  christos 		/* find matching ']' */
   2036  1.12  christos 		for (ep = cp + 1; *ep != ']' && *ep != '\0'; ep++) {
   2037  1.12  christos 			if (*ep == '/')
   2038  1.12  christos 				ispath = 1;
   2039  1.12  christos 		}
   2040  1.12  christos 		/* no matching ']' or not at end of field. */
   2041  1.12  christos 		if (ep[0] != ']' || (ep[1] != ':' && ep[1] != '\0'))
   2042  1.12  christos 			return -1;
   2043  1.12  christos 		/* NUL terminate the field and advance p past the colon */
   2044  1.12  christos 		*ep++ = '\0';
   2045  1.12  christos 		if (*ep != '\0')
   2046  1.12  christos 			*ep++ = '\0';
   2047  1.12  christos 		fwd->arg = cp + 1;
   2048  1.12  christos 		fwd->ispath = ispath;
   2049  1.12  christos 		*p = ep;
   2050  1.12  christos 		return 0;
   2051  1.12  christos 	}
   2052  1.12  christos 
   2053  1.12  christos 	for (cp = *p; *cp != '\0'; cp++) {
   2054  1.12  christos 		switch (*cp) {
   2055  1.12  christos 		case '\\':
   2056  1.12  christos 			memmove(cp, cp + 1, strlen(cp + 1) + 1);
   2057  1.14  christos 			if (*cp == '\0')
   2058  1.14  christos 				return -1;
   2059  1.12  christos 			break;
   2060  1.12  christos 		case '/':
   2061  1.12  christos 			ispath = 1;
   2062  1.12  christos 			break;
   2063  1.12  christos 		case ':':
   2064  1.12  christos 			*cp++ = '\0';
   2065  1.12  christos 			goto done;
   2066  1.12  christos 		}
   2067  1.12  christos 	}
   2068  1.12  christos done:
   2069  1.12  christos 	fwd->arg = *p;
   2070  1.12  christos 	fwd->ispath = ispath;
   2071  1.12  christos 	*p = cp;
   2072  1.12  christos 	return 0;
   2073  1.12  christos }
   2074  1.12  christos 
   2075   1.1  christos /*
   2076   1.1  christos  * parse_forward
   2077   1.1  christos  * parses a string containing a port forwarding specification of the form:
   2078   1.1  christos  *   dynamicfwd == 0
   2079  1.12  christos  *	[listenhost:]listenport|listenpath:connecthost:connectport|connectpath
   2080  1.12  christos  *	listenpath:connectpath
   2081   1.1  christos  *   dynamicfwd == 1
   2082   1.1  christos  *	[listenhost:]listenport
   2083   1.1  christos  * returns number of arguments parsed or zero on error
   2084   1.1  christos  */
   2085   1.1  christos int
   2086  1.12  christos parse_forward(struct Forward *fwd, const char *fwdspec, int dynamicfwd, int remotefwd)
   2087   1.1  christos {
   2088  1.12  christos 	struct fwdarg fwdargs[4];
   2089  1.12  christos 	char *p, *cp;
   2090   1.1  christos 	int i;
   2091   1.1  christos 
   2092  1.12  christos 	memset(fwd, 0, sizeof(*fwd));
   2093  1.12  christos 	memset(fwdargs, 0, sizeof(fwdargs));
   2094   1.1  christos 
   2095   1.1  christos 	cp = p = xstrdup(fwdspec);
   2096   1.1  christos 
   2097   1.1  christos 	/* skip leading spaces */
   2098  1.12  christos 	while (isspace((u_char)*cp))
   2099   1.1  christos 		cp++;
   2100   1.1  christos 
   2101  1.12  christos 	for (i = 0; i < 4; ++i) {
   2102  1.12  christos 		if (parse_fwd_field(&cp, &fwdargs[i]) != 0)
   2103   1.1  christos 			break;
   2104  1.12  christos 	}
   2105   1.1  christos 
   2106   1.1  christos 	/* Check for trailing garbage */
   2107  1.12  christos 	if (cp != NULL && *cp != '\0') {
   2108   1.1  christos 		i = 0;	/* failure */
   2109  1.12  christos 	}
   2110   1.1  christos 
   2111   1.1  christos 	switch (i) {
   2112   1.1  christos 	case 1:
   2113  1.12  christos 		if (fwdargs[0].ispath) {
   2114  1.12  christos 			fwd->listen_path = xstrdup(fwdargs[0].arg);
   2115  1.12  christos 			fwd->listen_port = PORT_STREAMLOCAL;
   2116  1.12  christos 		} else {
   2117  1.12  christos 			fwd->listen_host = NULL;
   2118  1.12  christos 			fwd->listen_port = a2port(fwdargs[0].arg);
   2119  1.12  christos 		}
   2120   1.1  christos 		fwd->connect_host = xstrdup("socks");
   2121   1.1  christos 		break;
   2122   1.1  christos 
   2123   1.1  christos 	case 2:
   2124  1.12  christos 		if (fwdargs[0].ispath && fwdargs[1].ispath) {
   2125  1.12  christos 			fwd->listen_path = xstrdup(fwdargs[0].arg);
   2126  1.12  christos 			fwd->listen_port = PORT_STREAMLOCAL;
   2127  1.12  christos 			fwd->connect_path = xstrdup(fwdargs[1].arg);
   2128  1.12  christos 			fwd->connect_port = PORT_STREAMLOCAL;
   2129  1.12  christos 		} else if (fwdargs[1].ispath) {
   2130  1.12  christos 			fwd->listen_host = NULL;
   2131  1.12  christos 			fwd->listen_port = a2port(fwdargs[0].arg);
   2132  1.12  christos 			fwd->connect_path = xstrdup(fwdargs[1].arg);
   2133  1.12  christos 			fwd->connect_port = PORT_STREAMLOCAL;
   2134  1.12  christos 		} else {
   2135  1.12  christos 			fwd->listen_host = xstrdup(fwdargs[0].arg);
   2136  1.12  christos 			fwd->listen_port = a2port(fwdargs[1].arg);
   2137  1.12  christos 			fwd->connect_host = xstrdup("socks");
   2138  1.12  christos 		}
   2139   1.1  christos 		break;
   2140   1.1  christos 
   2141   1.1  christos 	case 3:
   2142  1.12  christos 		if (fwdargs[0].ispath) {
   2143  1.12  christos 			fwd->listen_path = xstrdup(fwdargs[0].arg);
   2144  1.12  christos 			fwd->listen_port = PORT_STREAMLOCAL;
   2145  1.12  christos 			fwd->connect_host = xstrdup(fwdargs[1].arg);
   2146  1.12  christos 			fwd->connect_port = a2port(fwdargs[2].arg);
   2147  1.12  christos 		} else if (fwdargs[2].ispath) {
   2148  1.12  christos 			fwd->listen_host = xstrdup(fwdargs[0].arg);
   2149  1.12  christos 			fwd->listen_port = a2port(fwdargs[1].arg);
   2150  1.12  christos 			fwd->connect_path = xstrdup(fwdargs[2].arg);
   2151  1.12  christos 			fwd->connect_port = PORT_STREAMLOCAL;
   2152  1.12  christos 		} else {
   2153  1.12  christos 			fwd->listen_host = NULL;
   2154  1.12  christos 			fwd->listen_port = a2port(fwdargs[0].arg);
   2155  1.12  christos 			fwd->connect_host = xstrdup(fwdargs[1].arg);
   2156  1.12  christos 			fwd->connect_port = a2port(fwdargs[2].arg);
   2157  1.12  christos 		}
   2158   1.1  christos 		break;
   2159   1.1  christos 
   2160   1.1  christos 	case 4:
   2161  1.12  christos 		fwd->listen_host = xstrdup(fwdargs[0].arg);
   2162  1.12  christos 		fwd->listen_port = a2port(fwdargs[1].arg);
   2163  1.12  christos 		fwd->connect_host = xstrdup(fwdargs[2].arg);
   2164  1.12  christos 		fwd->connect_port = a2port(fwdargs[3].arg);
   2165   1.1  christos 		break;
   2166   1.1  christos 	default:
   2167   1.1  christos 		i = 0; /* failure */
   2168   1.1  christos 	}
   2169   1.1  christos 
   2170  1.11  christos 	free(p);
   2171   1.1  christos 
   2172   1.1  christos 	if (dynamicfwd) {
   2173   1.1  christos 		if (!(i == 1 || i == 2))
   2174   1.1  christos 			goto fail_free;
   2175   1.1  christos 	} else {
   2176  1.12  christos 		if (!(i == 3 || i == 4)) {
   2177  1.12  christos 			if (fwd->connect_path == NULL &&
   2178  1.12  christos 			    fwd->listen_path == NULL)
   2179  1.12  christos 				goto fail_free;
   2180  1.12  christos 		}
   2181  1.12  christos 		if (fwd->connect_port <= 0 && fwd->connect_path == NULL)
   2182   1.1  christos 			goto fail_free;
   2183   1.1  christos 	}
   2184   1.1  christos 
   2185  1.12  christos 	if ((fwd->listen_port < 0 && fwd->listen_path == NULL) ||
   2186  1.12  christos 	    (!remotefwd && fwd->listen_port == 0))
   2187   1.1  christos 		goto fail_free;
   2188   1.1  christos 	if (fwd->connect_host != NULL &&
   2189   1.1  christos 	    strlen(fwd->connect_host) >= NI_MAXHOST)
   2190   1.1  christos 		goto fail_free;
   2191  1.12  christos 	/* XXX - if connecting to a remote socket, max sun len may not match this host */
   2192  1.12  christos 	if (fwd->connect_path != NULL &&
   2193  1.12  christos 	    strlen(fwd->connect_path) >= PATH_MAX_SUN)
   2194  1.12  christos 		goto fail_free;
   2195   1.1  christos 	if (fwd->listen_host != NULL &&
   2196   1.1  christos 	    strlen(fwd->listen_host) >= NI_MAXHOST)
   2197   1.1  christos 		goto fail_free;
   2198  1.12  christos 	if (fwd->listen_path != NULL &&
   2199  1.12  christos 	    strlen(fwd->listen_path) >= PATH_MAX_SUN)
   2200  1.12  christos 		goto fail_free;
   2201   1.1  christos 
   2202   1.1  christos 	return (i);
   2203   1.1  christos 
   2204   1.1  christos  fail_free:
   2205  1.11  christos 	free(fwd->connect_host);
   2206  1.11  christos 	fwd->connect_host = NULL;
   2207  1.12  christos 	free(fwd->connect_path);
   2208  1.12  christos 	fwd->connect_path = NULL;
   2209  1.11  christos 	free(fwd->listen_host);
   2210  1.11  christos 	fwd->listen_host = NULL;
   2211  1.12  christos 	free(fwd->listen_path);
   2212  1.12  christos 	fwd->listen_path = NULL;
   2213   1.1  christos 	return (0);
   2214   1.1  christos }
   2215  1.13  christos 
   2216  1.13  christos /* XXX the following is a near-vebatim copy from servconf.c; refactor */
   2217  1.13  christos static const char *
   2218  1.13  christos fmt_multistate_int(int val, const struct multistate *m)
   2219  1.13  christos {
   2220  1.13  christos 	u_int i;
   2221  1.13  christos 
   2222  1.13  christos 	for (i = 0; m[i].key != NULL; i++) {
   2223  1.13  christos 		if (m[i].value == val)
   2224  1.13  christos 			return m[i].key;
   2225  1.13  christos 	}
   2226  1.13  christos 	return "UNKNOWN";
   2227  1.13  christos }
   2228  1.13  christos 
   2229  1.13  christos static const char *
   2230  1.13  christos fmt_intarg(OpCodes code, int val)
   2231  1.13  christos {
   2232  1.13  christos 	if (val == -1)
   2233  1.13  christos 		return "unset";
   2234  1.13  christos 	switch (code) {
   2235  1.13  christos 	case oAddressFamily:
   2236  1.13  christos 		return fmt_multistate_int(val, multistate_addressfamily);
   2237  1.13  christos 	case oVerifyHostKeyDNS:
   2238  1.13  christos 	case oStrictHostKeyChecking:
   2239  1.13  christos 	case oUpdateHostkeys:
   2240  1.13  christos 		return fmt_multistate_int(val, multistate_yesnoask);
   2241  1.13  christos 	case oControlMaster:
   2242  1.13  christos 		return fmt_multistate_int(val, multistate_controlmaster);
   2243  1.13  christos 	case oTunnel:
   2244  1.13  christos 		return fmt_multistate_int(val, multistate_tunnel);
   2245  1.13  christos 	case oRequestTTY:
   2246  1.13  christos 		return fmt_multistate_int(val, multistate_requesttty);
   2247  1.13  christos 	case oCanonicalizeHostname:
   2248  1.13  christos 		return fmt_multistate_int(val, multistate_canonicalizehostname);
   2249  1.13  christos 	case oFingerprintHash:
   2250  1.13  christos 		return ssh_digest_alg_name(val);
   2251  1.13  christos 	case oProtocol:
   2252  1.13  christos 		switch (val) {
   2253  1.13  christos 		case SSH_PROTO_1:
   2254  1.13  christos 			return "1";
   2255  1.13  christos 		case SSH_PROTO_2:
   2256  1.13  christos 			return "2";
   2257  1.13  christos 		case (SSH_PROTO_1|SSH_PROTO_2):
   2258  1.13  christos 			return "2,1";
   2259  1.13  christos 		default:
   2260  1.13  christos 			return "UNKNOWN";
   2261  1.13  christos 		}
   2262  1.13  christos 	default:
   2263  1.13  christos 		switch (val) {
   2264  1.13  christos 		case 0:
   2265  1.13  christos 			return "no";
   2266  1.13  christos 		case 1:
   2267  1.13  christos 			return "yes";
   2268  1.13  christos 		default:
   2269  1.13  christos 			return "UNKNOWN";
   2270  1.13  christos 		}
   2271  1.13  christos 	}
   2272  1.13  christos }
   2273  1.13  christos 
   2274  1.13  christos static const char *
   2275  1.13  christos lookup_opcode_name(OpCodes code)
   2276  1.13  christos {
   2277  1.13  christos 	u_int i;
   2278  1.13  christos 
   2279  1.13  christos 	for (i = 0; keywords[i].name != NULL; i++)
   2280  1.13  christos 		if (keywords[i].opcode == code)
   2281  1.13  christos 			return(keywords[i].name);
   2282  1.13  christos 	return "UNKNOWN";
   2283  1.13  christos }
   2284  1.13  christos 
   2285  1.13  christos static void
   2286  1.13  christos dump_cfg_int(OpCodes code, int val)
   2287  1.13  christos {
   2288  1.13  christos 	printf("%s %d\n", lookup_opcode_name(code), val);
   2289  1.13  christos }
   2290  1.13  christos 
   2291  1.13  christos static void
   2292  1.13  christos dump_cfg_fmtint(OpCodes code, int val)
   2293  1.13  christos {
   2294  1.13  christos 	printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
   2295  1.13  christos }
   2296  1.13  christos 
   2297  1.13  christos static void
   2298  1.13  christos dump_cfg_string(OpCodes code, const char *val)
   2299  1.13  christos {
   2300  1.13  christos 	if (val == NULL)
   2301  1.13  christos 		return;
   2302  1.13  christos 	printf("%s %s\n", lookup_opcode_name(code), val);
   2303  1.13  christos }
   2304  1.13  christos 
   2305  1.13  christos static void
   2306  1.13  christos dump_cfg_strarray(OpCodes code, u_int count, char **vals)
   2307  1.13  christos {
   2308  1.13  christos 	u_int i;
   2309  1.13  christos 
   2310  1.13  christos 	for (i = 0; i < count; i++)
   2311  1.13  christos 		printf("%s %s\n", lookup_opcode_name(code), vals[i]);
   2312  1.13  christos }
   2313  1.13  christos 
   2314  1.13  christos static void
   2315  1.13  christos dump_cfg_strarray_oneline(OpCodes code, u_int count, char **vals)
   2316  1.13  christos {
   2317  1.13  christos 	u_int i;
   2318  1.13  christos 
   2319  1.13  christos 	printf("%s", lookup_opcode_name(code));
   2320  1.13  christos 	for (i = 0; i < count; i++)
   2321  1.13  christos 		printf(" %s",  vals[i]);
   2322  1.13  christos 	printf("\n");
   2323  1.13  christos }
   2324  1.13  christos 
   2325  1.13  christos static void
   2326  1.13  christos dump_cfg_forwards(OpCodes code, u_int count, const struct Forward *fwds)
   2327  1.13  christos {
   2328  1.13  christos 	const struct Forward *fwd;
   2329  1.13  christos 	u_int i;
   2330  1.13  christos 
   2331  1.13  christos 	/* oDynamicForward */
   2332  1.13  christos 	for (i = 0; i < count; i++) {
   2333  1.13  christos 		fwd = &fwds[i];
   2334  1.13  christos 		if (code == oDynamicForward &&
   2335  1.13  christos 		    strcmp(fwd->connect_host, "socks") != 0)
   2336  1.13  christos 			continue;
   2337  1.13  christos 		if (code == oLocalForward &&
   2338  1.13  christos 		    strcmp(fwd->connect_host, "socks") == 0)
   2339  1.13  christos 			continue;
   2340  1.13  christos 		printf("%s", lookup_opcode_name(code));
   2341  1.13  christos 		if (fwd->listen_port == PORT_STREAMLOCAL)
   2342  1.13  christos 			printf(" %s", fwd->listen_path);
   2343  1.13  christos 		else if (fwd->listen_host == NULL)
   2344  1.13  christos 			printf(" %d", fwd->listen_port);
   2345  1.13  christos 		else {
   2346  1.13  christos 			printf(" [%s]:%d",
   2347  1.13  christos 			    fwd->listen_host, fwd->listen_port);
   2348  1.13  christos 		}
   2349  1.13  christos 		if (code != oDynamicForward) {
   2350  1.13  christos 			if (fwd->connect_port == PORT_STREAMLOCAL)
   2351  1.13  christos 				printf(" %s", fwd->connect_path);
   2352  1.13  christos 			else if (fwd->connect_host == NULL)
   2353  1.13  christos 				printf(" %d", fwd->connect_port);
   2354  1.13  christos 			else {
   2355  1.13  christos 				printf(" [%s]:%d",
   2356  1.13  christos 				    fwd->connect_host, fwd->connect_port);
   2357  1.13  christos 			}
   2358  1.13  christos 		}
   2359  1.13  christos 		printf("\n");
   2360  1.13  christos 	}
   2361  1.13  christos }
   2362  1.13  christos 
   2363  1.13  christos void
   2364  1.13  christos dump_client_config(Options *o, const char *host)
   2365  1.13  christos {
   2366  1.13  christos 	int i;
   2367  1.13  christos 	char vbuf[5];
   2368  1.13  christos 
   2369  1.13  christos 	/* Most interesting options first: user, host, port */
   2370  1.13  christos 	dump_cfg_string(oUser, o->user);
   2371  1.13  christos 	dump_cfg_string(oHostName, host);
   2372  1.13  christos 	dump_cfg_int(oPort, o->port);
   2373  1.13  christos 
   2374  1.13  christos 	/* Flag options */
   2375  1.13  christos 	dump_cfg_fmtint(oAddressFamily, o->address_family);
   2376  1.13  christos 	dump_cfg_fmtint(oBatchMode, o->batch_mode);
   2377  1.13  christos 	dump_cfg_fmtint(oCanonicalizeFallbackLocal, o->canonicalize_fallback_local);
   2378  1.13  christos 	dump_cfg_fmtint(oCanonicalizeHostname, o->canonicalize_hostname);
   2379  1.13  christos 	dump_cfg_fmtint(oChallengeResponseAuthentication, o->challenge_response_authentication);
   2380  1.13  christos 	dump_cfg_fmtint(oCheckHostIP, o->check_host_ip);
   2381  1.13  christos 	dump_cfg_fmtint(oCompression, o->compression);
   2382  1.13  christos 	dump_cfg_fmtint(oControlMaster, o->control_master);
   2383  1.13  christos 	dump_cfg_fmtint(oEnableSSHKeysign, o->enable_ssh_keysign);
   2384  1.13  christos 	dump_cfg_fmtint(oExitOnForwardFailure, o->exit_on_forward_failure);
   2385  1.13  christos 	dump_cfg_fmtint(oFingerprintHash, o->fingerprint_hash);
   2386  1.13  christos 	dump_cfg_fmtint(oForwardAgent, o->forward_agent);
   2387  1.13  christos 	dump_cfg_fmtint(oForwardX11, o->forward_x11);
   2388  1.13  christos 	dump_cfg_fmtint(oForwardX11Trusted, o->forward_x11_trusted);
   2389  1.13  christos 	dump_cfg_fmtint(oGatewayPorts, o->fwd_opts.gateway_ports);
   2390  1.13  christos #ifdef GSSAPI
   2391  1.13  christos 	dump_cfg_fmtint(oGssAuthentication, o->gss_authentication);
   2392  1.13  christos 	dump_cfg_fmtint(oGssDelegateCreds, o->gss_deleg_creds);
   2393  1.13  christos #endif /* GSSAPI */
   2394  1.13  christos 	dump_cfg_fmtint(oHashKnownHosts, o->hash_known_hosts);
   2395  1.13  christos 	dump_cfg_fmtint(oHostbasedAuthentication, o->hostbased_authentication);
   2396  1.13  christos 	dump_cfg_fmtint(oIdentitiesOnly, o->identities_only);
   2397  1.13  christos 	dump_cfg_fmtint(oKbdInteractiveAuthentication, o->kbd_interactive_authentication);
   2398  1.13  christos 	dump_cfg_fmtint(oNoHostAuthenticationForLocalhost, o->no_host_authentication_for_localhost);
   2399  1.13  christos 	dump_cfg_fmtint(oPasswordAuthentication, o->password_authentication);
   2400  1.13  christos 	dump_cfg_fmtint(oPermitLocalCommand, o->permit_local_command);
   2401  1.13  christos 	dump_cfg_fmtint(oProtocol, o->protocol);
   2402  1.13  christos 	dump_cfg_fmtint(oProxyUseFdpass, o->proxy_use_fdpass);
   2403  1.13  christos 	dump_cfg_fmtint(oPubkeyAuthentication, o->pubkey_authentication);
   2404  1.13  christos 	dump_cfg_fmtint(oRequestTTY, o->request_tty);
   2405  1.13  christos 	dump_cfg_fmtint(oRhostsRSAAuthentication, o->rhosts_rsa_authentication);
   2406  1.13  christos 	dump_cfg_fmtint(oRSAAuthentication, o->rsa_authentication);
   2407  1.13  christos 	dump_cfg_fmtint(oStreamLocalBindUnlink, o->fwd_opts.streamlocal_bind_unlink);
   2408  1.13  christos 	dump_cfg_fmtint(oStrictHostKeyChecking, o->strict_host_key_checking);
   2409  1.13  christos 	dump_cfg_fmtint(oTCPKeepAlive, o->tcp_keep_alive);
   2410  1.13  christos 	dump_cfg_fmtint(oTunnel, o->tun_open);
   2411  1.13  christos 	dump_cfg_fmtint(oUsePrivilegedPort, o->use_privileged_port);
   2412  1.13  christos 	dump_cfg_fmtint(oVerifyHostKeyDNS, o->verify_host_key_dns);
   2413  1.13  christos 	dump_cfg_fmtint(oVisualHostKey, o->visual_host_key);
   2414  1.13  christos 	dump_cfg_fmtint(oUpdateHostkeys, o->update_hostkeys);
   2415  1.13  christos 
   2416  1.13  christos 	/* Integer options */
   2417  1.13  christos 	dump_cfg_int(oCanonicalizeMaxDots, o->canonicalize_max_dots);
   2418  1.13  christos 	dump_cfg_int(oCompressionLevel, o->compression_level);
   2419  1.13  christos 	dump_cfg_int(oConnectionAttempts, o->connection_attempts);
   2420  1.13  christos 	dump_cfg_int(oForwardX11Timeout, o->forward_x11_timeout);
   2421  1.13  christos 	dump_cfg_int(oNumberOfPasswordPrompts, o->number_of_password_prompts);
   2422  1.13  christos 	dump_cfg_int(oServerAliveCountMax, o->server_alive_count_max);
   2423  1.13  christos 	dump_cfg_int(oServerAliveInterval, o->server_alive_interval);
   2424  1.13  christos 
   2425  1.13  christos 	/* String options */
   2426  1.13  christos 	dump_cfg_string(oBindAddress, o->bind_address);
   2427  1.13  christos 	dump_cfg_string(oCiphers, o->ciphers ? o->ciphers : KEX_CLIENT_ENCRYPT);
   2428  1.13  christos 	dump_cfg_string(oControlPath, o->control_path);
   2429  1.13  christos 	dump_cfg_string(oHostKeyAlgorithms, o->hostkeyalgorithms ? o->hostkeyalgorithms : KEX_DEFAULT_PK_ALG);
   2430  1.13  christos 	dump_cfg_string(oHostKeyAlias, o->host_key_alias);
   2431  1.13  christos 	dump_cfg_string(oHostbasedKeyTypes, o->hostbased_key_types);
   2432  1.13  christos 	dump_cfg_string(oKbdInteractiveDevices, o->kbd_interactive_devices);
   2433  1.13  christos 	dump_cfg_string(oKexAlgorithms, o->kex_algorithms ? o->kex_algorithms : KEX_CLIENT_KEX);
   2434  1.13  christos 	dump_cfg_string(oLocalCommand, o->local_command);
   2435  1.13  christos 	dump_cfg_string(oLogLevel, log_level_name(o->log_level));
   2436  1.13  christos 	dump_cfg_string(oMacs, o->macs ? o->macs : KEX_CLIENT_MAC);
   2437  1.13  christos 	dump_cfg_string(oPKCS11Provider, o->pkcs11_provider);
   2438  1.13  christos 	dump_cfg_string(oPreferredAuthentications, o->preferred_authentications);
   2439  1.13  christos 	dump_cfg_string(oProxyCommand, o->proxy_command);
   2440  1.13  christos 	dump_cfg_string(oRevokedHostKeys, o->revoked_host_keys);
   2441  1.13  christos 	dump_cfg_string(oXAuthLocation, o->xauth_location);
   2442  1.13  christos 
   2443  1.13  christos 	/* Forwards */
   2444  1.13  christos 	dump_cfg_forwards(oDynamicForward, o->num_local_forwards, o->local_forwards);
   2445  1.13  christos 	dump_cfg_forwards(oLocalForward, o->num_local_forwards, o->local_forwards);
   2446  1.13  christos 	dump_cfg_forwards(oRemoteForward, o->num_remote_forwards, o->remote_forwards);
   2447  1.13  christos 
   2448  1.13  christos 	/* String array options */
   2449  1.13  christos 	dump_cfg_strarray(oIdentityFile, o->num_identity_files, o->identity_files);
   2450  1.13  christos 	dump_cfg_strarray_oneline(oCanonicalDomains, o->num_canonical_domains, o->canonical_domains);
   2451  1.13  christos 	dump_cfg_strarray_oneline(oGlobalKnownHostsFile, o->num_system_hostfiles, o->system_hostfiles);
   2452  1.13  christos 	dump_cfg_strarray_oneline(oUserKnownHostsFile, o->num_user_hostfiles, o->user_hostfiles);
   2453  1.13  christos 	dump_cfg_strarray(oSendEnv, o->num_send_env, o->send_env);
   2454  1.13  christos 
   2455  1.13  christos 	/* Special cases */
   2456  1.13  christos 
   2457  1.13  christos 	/* oConnectTimeout */
   2458  1.13  christos 	if (o->connection_timeout == -1)
   2459  1.13  christos 		printf("connecttimeout none\n");
   2460  1.13  christos 	else
   2461  1.13  christos 		dump_cfg_int(oConnectTimeout, o->connection_timeout);
   2462  1.13  christos 
   2463  1.13  christos 	/* oTunnelDevice */
   2464  1.13  christos 	printf("tunneldevice");
   2465  1.13  christos 	if (o->tun_local == SSH_TUNID_ANY)
   2466  1.13  christos 		printf(" any");
   2467  1.13  christos 	else
   2468  1.13  christos 		printf(" %d", o->tun_local);
   2469  1.13  christos 	if (o->tun_remote == SSH_TUNID_ANY)
   2470  1.13  christos 		printf(":any");
   2471  1.13  christos 	else
   2472  1.13  christos 		printf(":%d", o->tun_remote);
   2473  1.13  christos 	printf("\n");
   2474  1.13  christos 
   2475  1.13  christos 	/* oCanonicalizePermittedCNAMEs */
   2476  1.13  christos 	if ( o->num_permitted_cnames > 0) {
   2477  1.13  christos 		printf("canonicalizePermittedcnames");
   2478  1.13  christos 		for (i = 0; i < o->num_permitted_cnames; i++) {
   2479  1.13  christos 			printf(" %s:%s", o->permitted_cnames[i].source_list,
   2480  1.13  christos 			    o->permitted_cnames[i].target_list);
   2481  1.13  christos 		}
   2482  1.13  christos 		printf("\n");
   2483  1.13  christos 	}
   2484  1.13  christos 
   2485  1.13  christos 	/* oCipher */
   2486  1.13  christos 	if (o->cipher != SSH_CIPHER_NOT_SET)
   2487  1.13  christos 		printf("Cipher %s\n", cipher_name(o->cipher));
   2488  1.13  christos 
   2489  1.13  christos 	/* oControlPersist */
   2490  1.13  christos 	if (o->control_persist == 0 || o->control_persist_timeout == 0)
   2491  1.13  christos 		dump_cfg_fmtint(oControlPersist, o->control_persist);
   2492  1.13  christos 	else
   2493  1.13  christos 		dump_cfg_int(oControlPersist, o->control_persist_timeout);
   2494  1.13  christos 
   2495  1.13  christos 	/* oEscapeChar */
   2496  1.13  christos 	if (o->escape_char == SSH_ESCAPECHAR_NONE)
   2497  1.13  christos 		printf("escapechar none\n");
   2498  1.13  christos 	else {
   2499  1.13  christos 		vis(vbuf, o->escape_char, VIS_WHITE, 0);
   2500  1.13  christos 		printf("escapechar %s\n", vbuf);
   2501  1.13  christos 	}
   2502  1.13  christos 
   2503  1.13  christos 	/* oIPQoS */
   2504  1.13  christos 	printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
   2505  1.13  christos 	printf("%s\n", iptos2str(o->ip_qos_bulk));
   2506  1.13  christos 
   2507  1.13  christos 	/* oRekeyLimit */
   2508  1.13  christos 	printf("rekeylimit %lld %d\n",
   2509  1.13  christos 	    (long long)o->rekey_limit, o->rekey_interval);
   2510  1.13  christos 
   2511  1.13  christos 	/* oStreamLocalBindMask */
   2512  1.13  christos 	printf("streamlocalbindmask 0%o\n",
   2513  1.13  christos 	    o->fwd_opts.streamlocal_bind_mask);
   2514  1.13  christos }
   2515