[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.243

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