[BACK]Return to readconf.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / ssh

Annotation of src/usr.bin/ssh/readconf.c, Revision 1.253

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