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

1.203   ! dtucker     1: /* $OpenBSD: readconf.c,v 1.202 2013/05/17 00:13:14 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>
                     18:
                     19: #include <netinet/in.h>
1.190     djm        20: #include <netinet/in_systm.h>
                     21: #include <netinet/ip.h>
1.148     stevesk    22:
                     23: #include <ctype.h>
1.154     stevesk    24: #include <errno.h>
1.155     stevesk    25: #include <netdb.h>
1.159     deraadt    26: #include <signal.h>
1.158     stevesk    27: #include <stdio.h>
1.157     stevesk    28: #include <string.h>
1.156     stevesk    29: #include <unistd.h>
1.200     dtucker    30: #include <util.h>
1.1       deraadt    31:
1.159     deraadt    32: #include "xmalloc.h"
1.1       deraadt    33: #include "ssh.h"
1.25      markus     34: #include "compat.h"
1.58      markus     35: #include "cipher.h"
1.55      markus     36: #include "pathnames.h"
1.58      markus     37: #include "log.h"
1.159     deraadt    38: #include "key.h"
1.58      markus     39: #include "readconf.h"
                     40: #include "match.h"
                     41: #include "misc.h"
1.159     deraadt    42: #include "buffer.h"
1.62      markus     43: #include "kex.h"
                     44: #include "mac.h"
1.1       deraadt    45:
                     46: /* Format of the configuration file:
                     47:
                     48:    # Configuration data is parsed as follows:
                     49:    #  1. command line options
                     50:    #  2. user-specific file
                     51:    #  3. system-wide file
                     52:    # Any configuration value is only changed the first time it is set.
                     53:    # Thus, host-specific definitions should be at the beginning of the
                     54:    # configuration file, and defaults at the end.
                     55:
                     56:    # Host-specific declarations.  These may override anything above.  A single
                     57:    # host may match multiple declarations; these are processed in the order
                     58:    # that they are given in.
                     59:
                     60:    Host *.ngs.fi ngs.fi
1.96      markus     61:      User foo
1.1       deraadt    62:
                     63:    Host fake.com
                     64:      HostName another.host.name.real.org
                     65:      User blaah
                     66:      Port 34289
                     67:      ForwardX11 no
                     68:      ForwardAgent no
                     69:
                     70:    Host books.com
                     71:      RemoteForward 9999 shadows.cs.hut.fi:9999
                     72:      Cipher 3des
                     73:
                     74:    Host fascist.blob.com
                     75:      Port 23123
                     76:      User tylonen
                     77:      PasswordAuthentication no
                     78:
                     79:    Host puukko.hut.fi
                     80:      User t35124p
                     81:      ProxyCommand ssh-proxy %h %p
                     82:
                     83:    Host *.fr
1.96      markus     84:      PublicKeyAuthentication no
1.1       deraadt    85:
                     86:    Host *.su
                     87:      Cipher none
                     88:      PasswordAuthentication no
                     89:
1.144     reyk       90:    Host vpn.fake.com
                     91:      Tunnel yes
                     92:      TunnelDevice 3
                     93:
1.1       deraadt    94:    # Defaults for various options
                     95:    Host *
                     96:      ForwardAgent no
1.50      markus     97:      ForwardX11 no
1.1       deraadt    98:      PasswordAuthentication yes
                     99:      RSAAuthentication yes
                    100:      RhostsRSAAuthentication yes
                    101:      StrictHostKeyChecking yes
1.126     markus    102:      TcpKeepAlive no
1.1       deraadt   103:      IdentityFile ~/.ssh/identity
                    104:      Port 22
                    105:      EscapeChar ~
                    106:
                    107: */
                    108:
                    109: /* Keyword tokens. */
                    110:
1.17      markus    111: typedef enum {
                    112:        oBadOption,
1.186     djm       113:        oForwardAgent, oForwardX11, oForwardX11Trusted, oForwardX11Timeout,
                    114:        oGatewayPorts, oExitOnForwardFailure,
1.100     deraadt   115:        oPasswordAuthentication, oRSAAuthentication,
1.59      markus    116:        oChallengeResponseAuthentication, oXAuthLocation,
1.17      markus    117:        oIdentityFile, oHostName, oPort, oCipher, oRemoteForward, oLocalForward,
                    118:        oUser, oHost, oEscapeChar, oRhostsRSAAuthentication, oProxyCommand,
                    119:        oGlobalKnownHostsFile, oUserKnownHostsFile, oConnectionAttempts,
                    120:        oBatchMode, oCheckHostIP, oStrictHostKeyChecking, oCompression,
1.126     markus    121:        oCompressionLevel, oTCPKeepAlive, oNumberOfPasswordPrompts,
1.62      markus    122:        oUsePrivilegedPort, oLogLevel, oCiphers, oProtocol, oMacs,
1.50      markus    123:        oGlobalKnownHostsFile2, oUserKnownHostsFile2, oPubkeyAuthentication,
1.67      markus    124:        oKbdInteractiveAuthentication, oKbdInteractiveDevices, oHostKeyAlias,
1.76      markus    125:        oDynamicForward, oPreferredAuthentications, oHostbasedAuthentication,
1.183     markus    126:        oHostKeyAlgorithms, oBindAddress, oPKCS11Provider,
1.96      markus    127:        oClearAllForwardings, oNoHostAuthenticationForLocalhost,
1.111     djm       128:        oEnableSSHKeysign, oRekeyLimit, oVerifyHostKeyDNS, oConnectTimeout,
1.118     markus    129:        oAddressFamily, oGssAuthentication, oGssDelegateCreds,
1.128     markus    130:        oServerAliveInterval, oServerAliveCountMax, oIdentitiesOnly,
1.187     djm       131:        oSendEnv, oControlPath, oControlMaster, oControlPersist,
                    132:        oHashKnownHosts,
1.144     reyk      133:        oTunnel, oTunnelDevice, oLocalCommand, oPermitLocalCommand,
1.182     dtucker   134:        oVisualHostKey, oUseRoaming, oZeroKnowledgePasswordAuthentication,
1.199     djm       135:        oKexAlgorithms, oIPQoS, oRequestTTY, oIgnoreUnknown,
                    136:        oIgnoredUnknownOption, oDeprecated, oUnsupported
1.1       deraadt   137: } OpCodes;
                    138:
                    139: /* Textual representations of the tokens. */
                    140:
1.17      markus    141: static struct {
                    142:        const char *name;
                    143:        OpCodes opcode;
                    144: } keywords[] = {
                    145:        { "forwardagent", oForwardAgent },
                    146:        { "forwardx11", oForwardX11 },
1.123     markus    147:        { "forwardx11trusted", oForwardX11Trusted },
1.186     djm       148:        { "forwardx11timeout", oForwardX11Timeout },
1.153     markus    149:        { "exitonforwardfailure", oExitOnForwardFailure },
1.34      markus    150:        { "xauthlocation", oXAuthLocation },
1.17      markus    151:        { "gatewayports", oGatewayPorts },
                    152:        { "useprivilegedport", oUsePrivilegedPort },
1.116     markus    153:        { "rhostsauthentication", oDeprecated },
1.17      markus    154:        { "passwordauthentication", oPasswordAuthentication },
1.48      markus    155:        { "kbdinteractiveauthentication", oKbdInteractiveAuthentication },
                    156:        { "kbdinteractivedevices", oKbdInteractiveDevices },
1.17      markus    157:        { "rsaauthentication", oRSAAuthentication },
1.50      markus    158:        { "pubkeyauthentication", oPubkeyAuthentication },
1.59      markus    159:        { "dsaauthentication", oPubkeyAuthentication },             /* alias */
1.72      markus    160:        { "rhostsrsaauthentication", oRhostsRSAAuthentication },
1.73      markus    161:        { "hostbasedauthentication", oHostbasedAuthentication },
1.59      markus    162:        { "challengeresponseauthentication", oChallengeResponseAuthentication },
                    163:        { "skeyauthentication", oChallengeResponseAuthentication }, /* alias */
                    164:        { "tisauthentication", oChallengeResponseAuthentication },  /* alias */
1.110     jakob     165:        { "kerberosauthentication", oUnsupported },
                    166:        { "kerberostgtpassing", oUnsupported },
                    167:        { "afstokenpassing", oUnsupported },
1.118     markus    168: #if defined(GSSAPI)
                    169:        { "gssapiauthentication", oGssAuthentication },
                    170:        { "gssapidelegatecredentials", oGssDelegateCreds },
                    171: #else
                    172:        { "gssapiauthentication", oUnsupported },
                    173:        { "gssapidelegatecredentials", oUnsupported },
                    174: #endif
1.96      markus    175:        { "fallbacktorsh", oDeprecated },
                    176:        { "usersh", oDeprecated },
1.17      markus    177:        { "identityfile", oIdentityFile },
1.174     stevesk   178:        { "identityfile2", oIdentityFile },                     /* obsolete */
1.128     markus    179:        { "identitiesonly", oIdentitiesOnly },
1.17      markus    180:        { "hostname", oHostName },
1.52      markus    181:        { "hostkeyalias", oHostKeyAlias },
1.17      markus    182:        { "proxycommand", oProxyCommand },
                    183:        { "port", oPort },
                    184:        { "cipher", oCipher },
1.25      markus    185:        { "ciphers", oCiphers },
1.62      markus    186:        { "macs", oMacs },
1.25      markus    187:        { "protocol", oProtocol },
1.17      markus    188:        { "remoteforward", oRemoteForward },
                    189:        { "localforward", oLocalForward },
                    190:        { "user", oUser },
                    191:        { "host", oHost },
                    192:        { "escapechar", oEscapeChar },
                    193:        { "globalknownhostsfile", oGlobalKnownHostsFile },
1.193     djm       194:        { "globalknownhostsfile2", oDeprecated },
1.174     stevesk   195:        { "userknownhostsfile", oUserKnownHostsFile },
1.193     djm       196:        { "userknownhostsfile2", oDeprecated },
1.17      markus    197:        { "connectionattempts", oConnectionAttempts },
                    198:        { "batchmode", oBatchMode },
                    199:        { "checkhostip", oCheckHostIP },
                    200:        { "stricthostkeychecking", oStrictHostKeyChecking },
                    201:        { "compression", oCompression },
                    202:        { "compressionlevel", oCompressionLevel },
1.126     markus    203:        { "tcpkeepalive", oTCPKeepAlive },
                    204:        { "keepalive", oTCPKeepAlive },                         /* obsolete */
1.17      markus    205:        { "numberofpasswordprompts", oNumberOfPasswordPrompts },
                    206:        { "loglevel", oLogLevel },
1.71      markus    207:        { "dynamicforward", oDynamicForward },
1.67      markus    208:        { "preferredauthentications", oPreferredAuthentications },
1.76      markus    209:        { "hostkeyalgorithms", oHostKeyAlgorithms },
1.77      markus    210:        { "bindaddress", oBindAddress },
1.183     markus    211: #ifdef ENABLE_PKCS11
                    212:        { "smartcarddevice", oPKCS11Provider },
                    213:        { "pkcs11provider", oPKCS11Provider },
1.110     jakob     214: #else
                    215:        { "smartcarddevice", oUnsupported },
1.183     markus    216:        { "pkcs11provider", oUnsupported },
1.110     jakob     217: #endif
1.93      deraadt   218:        { "clearallforwardings", oClearAllForwardings },
1.101     markus    219:        { "enablesshkeysign", oEnableSSHKeysign },
1.107     jakob     220:        { "verifyhostkeydns", oVerifyHostKeyDNS },
1.93      deraadt   221:        { "nohostauthenticationforlocalhost", oNoHostAuthenticationForLocalhost },
1.105     markus    222:        { "rekeylimit", oRekeyLimit },
1.111     djm       223:        { "connecttimeout", oConnectTimeout },
1.112     djm       224:        { "addressfamily", oAddressFamily },
1.127     markus    225:        { "serveraliveinterval", oServerAliveInterval },
                    226:        { "serveralivecountmax", oServerAliveCountMax },
1.130     djm       227:        { "sendenv", oSendEnv },
1.132     djm       228:        { "controlpath", oControlPath },
                    229:        { "controlmaster", oControlMaster },
1.187     djm       230:        { "controlpersist", oControlPersist },
1.136     djm       231:        { "hashknownhosts", oHashKnownHosts },
1.144     reyk      232:        { "tunnel", oTunnel },
                    233:        { "tunneldevice", oTunnelDevice },
                    234:        { "localcommand", oLocalCommand },
                    235:        { "permitlocalcommand", oPermitLocalCommand },
1.167     grunk     236:        { "visualhostkey", oVisualHostKey },
1.177     andreas   237:        { "useroaming", oUseRoaming },
1.171     djm       238: #ifdef JPAKE
                    239:        { "zeroknowledgepasswordauthentication",
                    240:            oZeroKnowledgePasswordAuthentication },
                    241: #else
                    242:        { "zeroknowledgepasswordauthentication", oUnsupported },
                    243: #endif
1.189     djm       244:        { "kexalgorithms", oKexAlgorithms },
1.190     djm       245:        { "ipqos", oIPQoS },
1.192     djm       246:        { "requesttty", oRequestTTY },
1.199     djm       247:        { "ignoreunknown", oIgnoreUnknown },
1.171     djm       248:
1.92      stevesk   249:        { NULL, oBadOption }
1.13      markus    250: };
                    251:
1.19      markus    252: /*
                    253:  * Adds a local TCP/IP port forward to options.  Never returns if there is an
                    254:  * error.
                    255:  */
1.1       deraadt   256:
1.26      markus    257: void
1.135     djm       258: add_local_forward(Options *options, const Forward *newfwd)
1.1       deraadt   259: {
1.17      markus    260:        Forward *fwd;
                    261:        extern uid_t original_real_uid;
1.185     djm       262:
1.135     djm       263:        if (newfwd->listen_port < IPPORT_RESERVED && original_real_uid != 0)
1.64      millert   264:                fatal("Privileged ports can only be forwarded by root.");
1.185     djm       265:        options->local_forwards = xrealloc(options->local_forwards,
                    266:            options->num_local_forwards + 1,
                    267:            sizeof(*options->local_forwards));
1.17      markus    268:        fwd = &options->local_forwards[options->num_local_forwards++];
1.135     djm       269:
1.172     stevesk   270:        fwd->listen_host = newfwd->listen_host;
1.135     djm       271:        fwd->listen_port = newfwd->listen_port;
1.172     stevesk   272:        fwd->connect_host = newfwd->connect_host;
1.135     djm       273:        fwd->connect_port = newfwd->connect_port;
1.1       deraadt   274: }
                    275:
1.19      markus    276: /*
                    277:  * Adds a remote TCP/IP port forward to options.  Never returns if there is
                    278:  * an error.
                    279:  */
1.1       deraadt   280:
1.26      markus    281: void
1.135     djm       282: add_remote_forward(Options *options, const Forward *newfwd)
1.1       deraadt   283: {
1.17      markus    284:        Forward *fwd;
1.185     djm       285:
                    286:        options->remote_forwards = xrealloc(options->remote_forwards,
                    287:            options->num_remote_forwards + 1,
                    288:            sizeof(*options->remote_forwards));
1.17      markus    289:        fwd = &options->remote_forwards[options->num_remote_forwards++];
1.135     djm       290:
1.172     stevesk   291:        fwd->listen_host = newfwd->listen_host;
1.135     djm       292:        fwd->listen_port = newfwd->listen_port;
1.172     stevesk   293:        fwd->connect_host = newfwd->connect_host;
1.135     djm       294:        fwd->connect_port = newfwd->connect_port;
1.194     markus    295:        fwd->handle = newfwd->handle;
1.184     markus    296:        fwd->allocated_port = 0;
1.1       deraadt   297: }
                    298:
1.90      stevesk   299: static void
                    300: clear_forwardings(Options *options)
                    301: {
                    302:        int i;
                    303:
1.135     djm       304:        for (i = 0; i < options->num_local_forwards; i++) {
1.202     djm       305:                free(options->local_forwards[i].listen_host);
                    306:                free(options->local_forwards[i].connect_host);
1.135     djm       307:        }
1.185     djm       308:        if (options->num_local_forwards > 0) {
1.202     djm       309:                free(options->local_forwards);
1.185     djm       310:                options->local_forwards = NULL;
                    311:        }
1.90      stevesk   312:        options->num_local_forwards = 0;
1.135     djm       313:        for (i = 0; i < options->num_remote_forwards; i++) {
1.202     djm       314:                free(options->remote_forwards[i].listen_host);
                    315:                free(options->remote_forwards[i].connect_host);
1.135     djm       316:        }
1.185     djm       317:        if (options->num_remote_forwards > 0) {
1.202     djm       318:                free(options->remote_forwards);
1.185     djm       319:                options->remote_forwards = NULL;
                    320:        }
1.90      stevesk   321:        options->num_remote_forwards = 0;
1.145     reyk      322:        options->tun_open = SSH_TUNMODE_NO;
1.90      stevesk   323: }
                    324:
1.195     dtucker   325: void
                    326: add_identity_file(Options *options, const char *dir, const char *filename,
                    327:     int userprovided)
                    328: {
                    329:        char *path;
                    330:
                    331:        if (options->num_identity_files >= SSH_MAX_IDENTITY_FILES)
                    332:                fatal("Too many identity files specified (max %d)",
                    333:                    SSH_MAX_IDENTITY_FILES);
                    334:
                    335:        if (dir == NULL) /* no dir, filename is absolute */
                    336:                path = xstrdup(filename);
                    337:        else
                    338:                (void)xasprintf(&path, "%.100s%.100s", dir, filename);
                    339:
                    340:        options->identity_file_userprovided[options->num_identity_files] =
                    341:            userprovided;
                    342:        options->identity_files[options->num_identity_files++] = path;
                    343: }
                    344:
1.19      markus    345: /*
1.70      stevesk   346:  * Returns the number of the token pointed to by cp or oBadOption.
1.19      markus    347:  */
1.1       deraadt   348:
1.26      markus    349: static OpCodes
1.199     djm       350: parse_token(const char *cp, const char *filename, int linenum,
                    351:     const char *ignored_unknown)
1.1       deraadt   352: {
1.199     djm       353:        int i;
1.1       deraadt   354:
1.17      markus    355:        for (i = 0; keywords[i].name; i++)
1.199     djm       356:                if (strcmp(cp, keywords[i].name) == 0)
1.17      markus    357:                        return keywords[i].opcode;
1.199     djm       358:        if (ignored_unknown != NULL && match_pattern_list(cp, ignored_unknown,
                    359:            strlen(ignored_unknown), 1) == 1)
                    360:                return oIgnoredUnknownOption;
1.75      stevesk   361:        error("%s: line %d: Bad configuration option: %s",
                    362:            filename, linenum, cp);
1.17      markus    363:        return oBadOption;
1.1       deraadt   364: }
                    365:
1.19      markus    366: /*
                    367:  * Processes a single option line as used in the configuration files. This
                    368:  * only sets those values that have not already been set.
                    369:  */
1.102     markus    370: #define WHITESPACE " \t\r\n"
1.1       deraadt   371:
1.14      markus    372: int
                    373: process_config_line(Options *options, const char *host,
1.17      markus    374:                    char *line, const char *filename, int linenum,
1.196     dtucker   375:                    int *activep, int userconfig)
1.1       deraadt   376: {
1.193     djm       377:        char *s, **charptr, *endofnumber, *keyword, *arg, *arg2;
                    378:        char **cpptr, fwdarg[256];
1.199     djm       379:        u_int i, *uintptr, max_entries = 0;
1.201     dtucker   380:        int negated, opcode, *intptr, value, value2;
1.164     dtucker   381:        LogLevel *log_level_ptr;
1.201     dtucker   382:        long long val64;
1.102     markus    383:        size_t len;
1.135     djm       384:        Forward fwd;
1.106     djm       385:
                    386:        /* Strip trailing whitespace */
1.139     deraadt   387:        for (len = strlen(line) - 1; len > 0; len--) {
1.106     djm       388:                if (strchr(WHITESPACE, line[len]) == NULL)
                    389:                        break;
                    390:                line[len] = '\0';
                    391:        }
1.1       deraadt   392:
1.42      provos    393:        s = line;
                    394:        /* Get the keyword. (Each line is supposed to begin with a keyword). */
1.149     djm       395:        if ((keyword = strdelim(&s)) == NULL)
                    396:                return 0;
1.42      provos    397:        /* Ignore leading whitespace. */
                    398:        if (*keyword == '\0')
1.43      markus    399:                keyword = strdelim(&s);
1.56      deraadt   400:        if (keyword == NULL || !*keyword || *keyword == '\n' || *keyword == '#')
1.17      markus    401:                return 0;
1.199     djm       402:        /* Match lowercase keyword */
                    403:        for (i = 0; i < strlen(keyword); i++)
                    404:                keyword[i] = tolower(keyword[i]);
1.17      markus    405:
1.199     djm       406:        opcode = parse_token(keyword, filename, linenum,
                    407:            options->ignored_unknown);
1.17      markus    408:
                    409:        switch (opcode) {
                    410:        case oBadOption:
1.19      markus    411:                /* don't panic, but count bad options */
                    412:                return -1;
1.17      markus    413:                /* NOTREACHED */
1.199     djm       414:        case oIgnoredUnknownOption:
                    415:                debug("%s line %d: Ignored unknown option \"%s\"",
                    416:                    filename, linenum, keyword);
                    417:                return 0;
1.111     djm       418:        case oConnectTimeout:
                    419:                intptr = &options->connection_timeout;
1.127     markus    420: parse_time:
1.111     djm       421:                arg = strdelim(&s);
                    422:                if (!arg || *arg == '\0')
                    423:                        fatal("%s line %d: missing time value.",
                    424:                            filename, linenum);
                    425:                if ((value = convtime(arg)) == -1)
                    426:                        fatal("%s line %d: invalid time value.",
                    427:                            filename, linenum);
1.160     dtucker   428:                if (*activep && *intptr == -1)
1.111     djm       429:                        *intptr = value;
                    430:                break;
                    431:
1.17      markus    432:        case oForwardAgent:
                    433:                intptr = &options->forward_agent;
                    434: parse_flag:
1.42      provos    435:                arg = strdelim(&s);
1.40      ho        436:                if (!arg || *arg == '\0')
1.17      markus    437:                        fatal("%.200s line %d: Missing yes/no argument.", filename, linenum);
                    438:                value = 0;      /* To avoid compiler warning... */
1.38      provos    439:                if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
1.17      markus    440:                        value = 1;
1.38      provos    441:                else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
1.17      markus    442:                        value = 0;
                    443:                else
                    444:                        fatal("%.200s line %d: Bad yes/no argument.", filename, linenum);
                    445:                if (*activep && *intptr == -1)
                    446:                        *intptr = value;
                    447:                break;
                    448:
                    449:        case oForwardX11:
                    450:                intptr = &options->forward_x11;
                    451:                goto parse_flag;
                    452:
1.123     markus    453:        case oForwardX11Trusted:
                    454:                intptr = &options->forward_x11_trusted;
                    455:                goto parse_flag;
1.186     djm       456:
                    457:        case oForwardX11Timeout:
                    458:                intptr = &options->forward_x11_timeout;
                    459:                goto parse_time;
1.123     markus    460:
1.17      markus    461:        case oGatewayPorts:
                    462:                intptr = &options->gateway_ports;
                    463:                goto parse_flag;
                    464:
1.153     markus    465:        case oExitOnForwardFailure:
                    466:                intptr = &options->exit_on_forward_failure;
                    467:                goto parse_flag;
                    468:
1.17      markus    469:        case oUsePrivilegedPort:
                    470:                intptr = &options->use_privileged_port;
                    471:                goto parse_flag;
                    472:
                    473:        case oPasswordAuthentication:
                    474:                intptr = &options->password_authentication;
                    475:                goto parse_flag;
                    476:
1.171     djm       477:        case oZeroKnowledgePasswordAuthentication:
                    478:                intptr = &options->zero_knowledge_password_authentication;
                    479:                goto parse_flag;
                    480:
1.48      markus    481:        case oKbdInteractiveAuthentication:
                    482:                intptr = &options->kbd_interactive_authentication;
                    483:                goto parse_flag;
                    484:
                    485:        case oKbdInteractiveDevices:
                    486:                charptr = &options->kbd_interactive_devices;
                    487:                goto parse_string;
                    488:
1.50      markus    489:        case oPubkeyAuthentication:
                    490:                intptr = &options->pubkey_authentication;
1.30      markus    491:                goto parse_flag;
                    492:
1.17      markus    493:        case oRSAAuthentication:
                    494:                intptr = &options->rsa_authentication;
                    495:                goto parse_flag;
                    496:
                    497:        case oRhostsRSAAuthentication:
                    498:                intptr = &options->rhosts_rsa_authentication;
                    499:                goto parse_flag;
                    500:
1.72      markus    501:        case oHostbasedAuthentication:
                    502:                intptr = &options->hostbased_authentication;
                    503:                goto parse_flag;
                    504:
1.59      markus    505:        case oChallengeResponseAuthentication:
1.78      markus    506:                intptr = &options->challenge_response_authentication;
1.17      markus    507:                goto parse_flag;
1.108     jakob     508:
1.118     markus    509:        case oGssAuthentication:
                    510:                intptr = &options->gss_authentication;
                    511:                goto parse_flag;
                    512:
                    513:        case oGssDelegateCreds:
                    514:                intptr = &options->gss_deleg_creds;
                    515:                goto parse_flag;
                    516:
1.17      markus    517:        case oBatchMode:
                    518:                intptr = &options->batch_mode;
                    519:                goto parse_flag;
                    520:
                    521:        case oCheckHostIP:
                    522:                intptr = &options->check_host_ip;
1.167     grunk     523:                goto parse_flag;
1.17      markus    524:
1.107     jakob     525:        case oVerifyHostKeyDNS:
                    526:                intptr = &options->verify_host_key_dns;
1.125     jakob     527:                goto parse_yesnoask;
1.107     jakob     528:
1.17      markus    529:        case oStrictHostKeyChecking:
                    530:                intptr = &options->strict_host_key_checking;
1.125     jakob     531: parse_yesnoask:
1.42      provos    532:                arg = strdelim(&s);
1.40      ho        533:                if (!arg || *arg == '\0')
1.60      stevesk   534:                        fatal("%.200s line %d: Missing yes/no/ask argument.",
1.93      deraadt   535:                            filename, linenum);
1.17      markus    536:                value = 0;      /* To avoid compiler warning... */
1.38      provos    537:                if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
1.17      markus    538:                        value = 1;
1.38      provos    539:                else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
1.17      markus    540:                        value = 0;
1.38      provos    541:                else if (strcmp(arg, "ask") == 0)
1.17      markus    542:                        value = 2;
                    543:                else
                    544:                        fatal("%.200s line %d: Bad yes/no/ask argument.", filename, linenum);
                    545:                if (*activep && *intptr == -1)
                    546:                        *intptr = value;
                    547:                break;
                    548:
                    549:        case oCompression:
                    550:                intptr = &options->compression;
                    551:                goto parse_flag;
                    552:
1.126     markus    553:        case oTCPKeepAlive:
                    554:                intptr = &options->tcp_keep_alive;
1.17      markus    555:                goto parse_flag;
                    556:
1.91      markus    557:        case oNoHostAuthenticationForLocalhost:
                    558:                intptr = &options->no_host_authentication_for_localhost;
                    559:                goto parse_flag;
                    560:
1.17      markus    561:        case oNumberOfPasswordPrompts:
                    562:                intptr = &options->number_of_password_prompts;
                    563:                goto parse_int;
                    564:
                    565:        case oCompressionLevel:
                    566:                intptr = &options->compression_level;
                    567:                goto parse_int;
                    568:
1.105     markus    569:        case oRekeyLimit:
                    570:                arg = strdelim(&s);
                    571:                if (!arg || *arg == '\0')
1.198     dtucker   572:                        fatal("%.200s line %d: Missing argument.", filename,
                    573:                            linenum);
                    574:                if (strcmp(arg, "default") == 0) {
                    575:                        val64 = 0;
                    576:                } else {
1.200     dtucker   577:                        if (scan_scaled(arg, &val64) == -1)
                    578:                                fatal("%.200s line %d: Bad number '%s': %s",
                    579:                                    filename, linenum, arg, strerror(errno));
                    580:                        /* check for too-large or too-small limits */
                    581:                        if (val64 > UINT_MAX)
1.198     dtucker   582:                                fatal("%.200s line %d: RekeyLimit too large",
                    583:                                    filename, linenum);
                    584:                        if (val64 != 0 && val64 < 16)
                    585:                                fatal("%.200s line %d: RekeyLimit too small",
                    586:                                    filename, linenum);
1.105     markus    587:                }
1.165     djm       588:                if (*activep && options->rekey_limit == -1)
                    589:                        options->rekey_limit = (u_int32_t)val64;
1.198     dtucker   590:                if (s != NULL) { /* optional rekey interval present */
                    591:                        if (strcmp(s, "none") == 0) {
                    592:                                (void)strdelim(&s);     /* discard */
                    593:                                break;
                    594:                        }
                    595:                        intptr = &options->rekey_interval;
                    596:                        goto parse_time;
                    597:                }
1.105     markus    598:                break;
                    599:
1.17      markus    600:        case oIdentityFile:
1.42      provos    601:                arg = strdelim(&s);
1.40      ho        602:                if (!arg || *arg == '\0')
1.17      markus    603:                        fatal("%.200s line %d: Missing argument.", filename, linenum);
                    604:                if (*activep) {
1.50      markus    605:                        intptr = &options->num_identity_files;
1.27      markus    606:                        if (*intptr >= SSH_MAX_IDENTITY_FILES)
1.17      markus    607:                                fatal("%.200s line %d: Too many identity files specified (max %d).",
1.93      deraadt   608:                                    filename, linenum, SSH_MAX_IDENTITY_FILES);
1.196     dtucker   609:                        add_identity_file(options, NULL, arg, userconfig);
1.17      markus    610:                }
                    611:                break;
                    612:
1.34      markus    613:        case oXAuthLocation:
                    614:                charptr=&options->xauth_location;
                    615:                goto parse_string;
                    616:
1.17      markus    617:        case oUser:
                    618:                charptr = &options->user;
                    619: parse_string:
1.42      provos    620:                arg = strdelim(&s);
1.40      ho        621:                if (!arg || *arg == '\0')
1.193     djm       622:                        fatal("%.200s line %d: Missing argument.",
                    623:                            filename, linenum);
1.17      markus    624:                if (*activep && *charptr == NULL)
1.38      provos    625:                        *charptr = xstrdup(arg);
1.17      markus    626:                break;
                    627:
                    628:        case oGlobalKnownHostsFile:
1.193     djm       629:                cpptr = (char **)&options->system_hostfiles;
                    630:                uintptr = &options->num_system_hostfiles;
                    631:                max_entries = SSH_MAX_HOSTS_FILES;
                    632: parse_char_array:
                    633:                if (*activep && *uintptr == 0) {
                    634:                        while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
                    635:                                if ((*uintptr) >= max_entries)
                    636:                                        fatal("%s line %d: "
                    637:                                            "too many authorized keys files.",
                    638:                                            filename, linenum);
                    639:                                cpptr[(*uintptr)++] = xstrdup(arg);
                    640:                        }
                    641:                }
                    642:                return 0;
1.17      markus    643:
                    644:        case oUserKnownHostsFile:
1.193     djm       645:                cpptr = (char **)&options->user_hostfiles;
                    646:                uintptr = &options->num_user_hostfiles;
                    647:                max_entries = SSH_MAX_HOSTS_FILES;
                    648:                goto parse_char_array;
1.27      markus    649:
1.17      markus    650:        case oHostName:
                    651:                charptr = &options->hostname;
                    652:                goto parse_string;
                    653:
1.52      markus    654:        case oHostKeyAlias:
                    655:                charptr = &options->host_key_alias;
                    656:                goto parse_string;
                    657:
1.67      markus    658:        case oPreferredAuthentications:
                    659:                charptr = &options->preferred_authentications;
                    660:                goto parse_string;
                    661:
1.77      markus    662:        case oBindAddress:
                    663:                charptr = &options->bind_address;
                    664:                goto parse_string;
                    665:
1.183     markus    666:        case oPKCS11Provider:
                    667:                charptr = &options->pkcs11_provider;
1.86      markus    668:                goto parse_string;
1.85      jakob     669:
1.17      markus    670:        case oProxyCommand:
1.144     reyk      671:                charptr = &options->proxy_command;
                    672: parse_command:
1.113     markus    673:                if (s == NULL)
                    674:                        fatal("%.200s line %d: Missing argument.", filename, linenum);
1.102     markus    675:                len = strspn(s, WHITESPACE "=");
1.17      markus    676:                if (*activep && *charptr == NULL)
1.102     markus    677:                        *charptr = xstrdup(s + len);
1.17      markus    678:                return 0;
                    679:
                    680:        case oPort:
                    681:                intptr = &options->port;
                    682: parse_int:
1.42      provos    683:                arg = strdelim(&s);
1.40      ho        684:                if (!arg || *arg == '\0')
1.17      markus    685:                        fatal("%.200s line %d: Missing argument.", filename, linenum);
1.38      provos    686:                if (arg[0] < '0' || arg[0] > '9')
1.17      markus    687:                        fatal("%.200s line %d: Bad number.", filename, linenum);
1.21      markus    688:
                    689:                /* Octal, decimal, or hex format? */
1.38      provos    690:                value = strtol(arg, &endofnumber, 0);
                    691:                if (arg == endofnumber)
1.21      markus    692:                        fatal("%.200s line %d: Bad number.", filename, linenum);
1.17      markus    693:                if (*activep && *intptr == -1)
                    694:                        *intptr = value;
                    695:                break;
                    696:
                    697:        case oConnectionAttempts:
                    698:                intptr = &options->connection_attempts;
                    699:                goto parse_int;
                    700:
                    701:        case oCipher:
                    702:                intptr = &options->cipher;
1.42      provos    703:                arg = strdelim(&s);
1.40      ho        704:                if (!arg || *arg == '\0')
1.32      markus    705:                        fatal("%.200s line %d: Missing argument.", filename, linenum);
1.38      provos    706:                value = cipher_number(arg);
1.17      markus    707:                if (value == -1)
                    708:                        fatal("%.200s line %d: Bad cipher '%s'.",
1.93      deraadt   709:                            filename, linenum, arg ? arg : "<NONE>");
1.17      markus    710:                if (*activep && *intptr == -1)
                    711:                        *intptr = value;
                    712:                break;
                    713:
1.25      markus    714:        case oCiphers:
1.42      provos    715:                arg = strdelim(&s);
1.40      ho        716:                if (!arg || *arg == '\0')
1.32      markus    717:                        fatal("%.200s line %d: Missing argument.", filename, linenum);
1.38      provos    718:                if (!ciphers_valid(arg))
1.31      markus    719:                        fatal("%.200s line %d: Bad SSH2 cipher spec '%s'.",
1.93      deraadt   720:                            filename, linenum, arg ? arg : "<NONE>");
1.25      markus    721:                if (*activep && options->ciphers == NULL)
1.38      provos    722:                        options->ciphers = xstrdup(arg);
1.25      markus    723:                break;
                    724:
1.62      markus    725:        case oMacs:
                    726:                arg = strdelim(&s);
                    727:                if (!arg || *arg == '\0')
                    728:                        fatal("%.200s line %d: Missing argument.", filename, linenum);
                    729:                if (!mac_valid(arg))
                    730:                        fatal("%.200s line %d: Bad SSH2 Mac spec '%s'.",
1.93      deraadt   731:                            filename, linenum, arg ? arg : "<NONE>");
1.62      markus    732:                if (*activep && options->macs == NULL)
                    733:                        options->macs = xstrdup(arg);
                    734:                break;
                    735:
1.189     djm       736:        case oKexAlgorithms:
                    737:                arg = strdelim(&s);
                    738:                if (!arg || *arg == '\0')
                    739:                        fatal("%.200s line %d: Missing argument.",
                    740:                            filename, linenum);
                    741:                if (!kex_names_valid(arg))
                    742:                        fatal("%.200s line %d: Bad SSH2 KexAlgorithms '%s'.",
                    743:                            filename, linenum, arg ? arg : "<NONE>");
                    744:                if (*activep && options->kex_algorithms == NULL)
                    745:                        options->kex_algorithms = xstrdup(arg);
                    746:                break;
                    747:
1.76      markus    748:        case oHostKeyAlgorithms:
                    749:                arg = strdelim(&s);
                    750:                if (!arg || *arg == '\0')
                    751:                        fatal("%.200s line %d: Missing argument.", filename, linenum);
                    752:                if (!key_names_valid2(arg))
                    753:                        fatal("%.200s line %d: Bad protocol 2 host key algorithms '%s'.",
1.93      deraadt   754:                            filename, linenum, arg ? arg : "<NONE>");
1.76      markus    755:                if (*activep && options->hostkeyalgorithms == NULL)
                    756:                        options->hostkeyalgorithms = xstrdup(arg);
                    757:                break;
                    758:
1.25      markus    759:        case oProtocol:
                    760:                intptr = &options->protocol;
1.42      provos    761:                arg = strdelim(&s);
1.40      ho        762:                if (!arg || *arg == '\0')
1.32      markus    763:                        fatal("%.200s line %d: Missing argument.", filename, linenum);
1.38      provos    764:                value = proto_spec(arg);
1.25      markus    765:                if (value == SSH_PROTO_UNKNOWN)
                    766:                        fatal("%.200s line %d: Bad protocol spec '%s'.",
1.93      deraadt   767:                            filename, linenum, arg ? arg : "<NONE>");
1.25      markus    768:                if (*activep && *intptr == SSH_PROTO_UNKNOWN)
                    769:                        *intptr = value;
                    770:                break;
                    771:
1.17      markus    772:        case oLogLevel:
1.164     dtucker   773:                log_level_ptr = &options->log_level;
1.42      provos    774:                arg = strdelim(&s);
1.38      provos    775:                value = log_level_number(arg);
1.95      markus    776:                if (value == SYSLOG_LEVEL_NOT_SET)
1.64      millert   777:                        fatal("%.200s line %d: unsupported log level '%s'",
1.93      deraadt   778:                            filename, linenum, arg ? arg : "<NONE>");
1.164     dtucker   779:                if (*activep && *log_level_ptr == SYSLOG_LEVEL_NOT_SET)
                    780:                        *log_level_ptr = (LogLevel) value;
1.17      markus    781:                break;
                    782:
1.88      stevesk   783:        case oLocalForward:
1.17      markus    784:        case oRemoteForward:
1.168     stevesk   785:        case oDynamicForward:
1.42      provos    786:                arg = strdelim(&s);
1.135     djm       787:                if (arg == NULL || *arg == '\0')
1.88      stevesk   788:                        fatal("%.200s line %d: Missing port argument.",
                    789:                            filename, linenum);
1.135     djm       790:
1.168     stevesk   791:                if (opcode == oLocalForward ||
                    792:                    opcode == oRemoteForward) {
                    793:                        arg2 = strdelim(&s);
                    794:                        if (arg2 == NULL || *arg2 == '\0')
                    795:                                fatal("%.200s line %d: Missing target argument.",
                    796:                                    filename, linenum);
1.135     djm       797:
1.168     stevesk   798:                        /* construct a string for parse_forward */
                    799:                        snprintf(fwdarg, sizeof(fwdarg), "%s:%s", arg, arg2);
                    800:                } else if (opcode == oDynamicForward) {
                    801:                        strlcpy(fwdarg, arg, sizeof(fwdarg));
                    802:                }
                    803:
                    804:                if (parse_forward(&fwd, fwdarg,
1.176     djm       805:                    opcode == oDynamicForward ? 1 : 0,
                    806:                    opcode == oRemoteForward ? 1 : 0) == 0)
1.88      stevesk   807:                        fatal("%.200s line %d: Bad forwarding specification.",
                    808:                            filename, linenum);
1.135     djm       809:
1.88      stevesk   810:                if (*activep) {
1.168     stevesk   811:                        if (opcode == oLocalForward ||
                    812:                            opcode == oDynamicForward)
1.135     djm       813:                                add_local_forward(options, &fwd);
1.88      stevesk   814:                        else if (opcode == oRemoteForward)
1.135     djm       815:                                add_remote_forward(options, &fwd);
1.88      stevesk   816:                }
1.203   ! dtucker   817:                free(fwd.connect_host);
        !           818:                free(fwd.listen_host);
1.17      markus    819:                break;
1.71      markus    820:
1.90      stevesk   821:        case oClearAllForwardings:
                    822:                intptr = &options->clear_forwardings;
                    823:                goto parse_flag;
                    824:
1.17      markus    825:        case oHost:
                    826:                *activep = 0;
1.191     djm       827:                arg2 = NULL;
                    828:                while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
                    829:                        negated = *arg == '!';
                    830:                        if (negated)
                    831:                                arg++;
1.38      provos    832:                        if (match_pattern(host, arg)) {
1.191     djm       833:                                if (negated) {
                    834:                                        debug("%.200s line %d: Skipping Host "
                    835:                                            "block because of negated match "
                    836:                                            "for %.100s", filename, linenum,
                    837:                                            arg);
                    838:                                        *activep = 0;
                    839:                                        break;
                    840:                                }
                    841:                                if (!*activep)
                    842:                                        arg2 = arg; /* logged below */
1.17      markus    843:                                *activep = 1;
                    844:                        }
1.191     djm       845:                }
                    846:                if (*activep)
                    847:                        debug("%.200s line %d: Applying options for %.100s",
                    848:                            filename, linenum, arg2);
1.42      provos    849:                /* Avoid garbage check below, as strdelim is done. */
1.17      markus    850:                return 0;
                    851:
                    852:        case oEscapeChar:
                    853:                intptr = &options->escape_char;
1.42      provos    854:                arg = strdelim(&s);
1.40      ho        855:                if (!arg || *arg == '\0')
1.17      markus    856:                        fatal("%.200s line %d: Missing argument.", filename, linenum);
1.38      provos    857:                if (arg[0] == '^' && arg[2] == 0 &&
1.51      markus    858:                    (u_char) arg[1] >= 64 && (u_char) arg[1] < 128)
                    859:                        value = (u_char) arg[1] & 31;
1.38      provos    860:                else if (strlen(arg) == 1)
1.51      markus    861:                        value = (u_char) arg[0];
1.38      provos    862:                else if (strcmp(arg, "none") == 0)
1.79      stevesk   863:                        value = SSH_ESCAPECHAR_NONE;
1.17      markus    864:                else {
                    865:                        fatal("%.200s line %d: Bad escape character.",
1.93      deraadt   866:                            filename, linenum);
1.17      markus    867:                        /* NOTREACHED */
                    868:                        value = 0;      /* Avoid compiler warning. */
                    869:                }
                    870:                if (*activep && *intptr == -1)
                    871:                        *intptr = value;
1.112     djm       872:                break;
                    873:
                    874:        case oAddressFamily:
                    875:                arg = strdelim(&s);
1.140     markus    876:                if (!arg || *arg == '\0')
                    877:                        fatal("%s line %d: missing address family.",
                    878:                            filename, linenum);
1.114     djm       879:                intptr = &options->address_family;
1.112     djm       880:                if (strcasecmp(arg, "inet") == 0)
1.114     djm       881:                        value = AF_INET;
1.112     djm       882:                else if (strcasecmp(arg, "inet6") == 0)
1.114     djm       883:                        value = AF_INET6;
1.112     djm       884:                else if (strcasecmp(arg, "any") == 0)
1.114     djm       885:                        value = AF_UNSPEC;
1.112     djm       886:                else
                    887:                        fatal("Unsupported AddressFamily \"%s\"", arg);
1.114     djm       888:                if (*activep && *intptr == -1)
                    889:                        *intptr = value;
1.17      markus    890:                break;
                    891:
1.101     markus    892:        case oEnableSSHKeysign:
                    893:                intptr = &options->enable_ssh_keysign;
                    894:                goto parse_flag;
                    895:
1.128     markus    896:        case oIdentitiesOnly:
                    897:                intptr = &options->identities_only;
                    898:                goto parse_flag;
                    899:
1.127     markus    900:        case oServerAliveInterval:
                    901:                intptr = &options->server_alive_interval;
                    902:                goto parse_time;
                    903:
                    904:        case oServerAliveCountMax:
                    905:                intptr = &options->server_alive_count_max;
                    906:                goto parse_int;
                    907:
1.130     djm       908:        case oSendEnv:
                    909:                while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
                    910:                        if (strchr(arg, '=') != NULL)
                    911:                                fatal("%s line %d: Invalid environment name.",
                    912:                                    filename, linenum);
1.137     djm       913:                        if (!*activep)
                    914:                                continue;
1.130     djm       915:                        if (options->num_send_env >= MAX_SEND_ENV)
                    916:                                fatal("%s line %d: too many send env.",
                    917:                                    filename, linenum);
                    918:                        options->send_env[options->num_send_env++] =
                    919:                            xstrdup(arg);
                    920:                }
                    921:                break;
                    922:
1.132     djm       923:        case oControlPath:
                    924:                charptr = &options->control_path;
                    925:                goto parse_string;
                    926:
                    927:        case oControlMaster:
                    928:                intptr = &options->control_master;
1.141     djm       929:                arg = strdelim(&s);
                    930:                if (!arg || *arg == '\0')
                    931:                        fatal("%.200s line %d: Missing ControlMaster argument.",
                    932:                            filename, linenum);
                    933:                value = 0;      /* To avoid compiler warning... */
                    934:                if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
                    935:                        value = SSHCTL_MASTER_YES;
                    936:                else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
                    937:                        value = SSHCTL_MASTER_NO;
                    938:                else if (strcmp(arg, "auto") == 0)
                    939:                        value = SSHCTL_MASTER_AUTO;
                    940:                else if (strcmp(arg, "ask") == 0)
                    941:                        value = SSHCTL_MASTER_ASK;
                    942:                else if (strcmp(arg, "autoask") == 0)
                    943:                        value = SSHCTL_MASTER_AUTO_ASK;
                    944:                else
                    945:                        fatal("%.200s line %d: Bad ControlMaster argument.",
                    946:                            filename, linenum);
                    947:                if (*activep && *intptr == -1)
                    948:                        *intptr = value;
                    949:                break;
1.132     djm       950:
1.187     djm       951:        case oControlPersist:
                    952:                /* no/false/yes/true, or a time spec */
                    953:                intptr = &options->control_persist;
                    954:                arg = strdelim(&s);
                    955:                if (!arg || *arg == '\0')
                    956:                        fatal("%.200s line %d: Missing ControlPersist"
                    957:                            " argument.", filename, linenum);
                    958:                value = 0;
                    959:                value2 = 0;     /* timeout */
                    960:                if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
                    961:                        value = 0;
                    962:                else if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
                    963:                        value = 1;
                    964:                else if ((value2 = convtime(arg)) >= 0)
                    965:                        value = 1;
                    966:                else
                    967:                        fatal("%.200s line %d: Bad ControlPersist argument.",
                    968:                            filename, linenum);
                    969:                if (*activep && *intptr == -1) {
                    970:                        *intptr = value;
                    971:                        options->control_persist_timeout = value2;
                    972:                }
                    973:                break;
                    974:
1.136     djm       975:        case oHashKnownHosts:
                    976:                intptr = &options->hash_known_hosts;
                    977:                goto parse_flag;
                    978:
1.144     reyk      979:        case oTunnel:
                    980:                intptr = &options->tun_open;
1.145     reyk      981:                arg = strdelim(&s);
                    982:                if (!arg || *arg == '\0')
                    983:                        fatal("%s line %d: Missing yes/point-to-point/"
                    984:                            "ethernet/no argument.", filename, linenum);
                    985:                value = 0;      /* silence compiler */
                    986:                if (strcasecmp(arg, "ethernet") == 0)
                    987:                        value = SSH_TUNMODE_ETHERNET;
                    988:                else if (strcasecmp(arg, "point-to-point") == 0)
                    989:                        value = SSH_TUNMODE_POINTOPOINT;
                    990:                else if (strcasecmp(arg, "yes") == 0)
                    991:                        value = SSH_TUNMODE_DEFAULT;
                    992:                else if (strcasecmp(arg, "no") == 0)
                    993:                        value = SSH_TUNMODE_NO;
                    994:                else
                    995:                        fatal("%s line %d: Bad yes/point-to-point/ethernet/"
                    996:                            "no argument: %s", filename, linenum, arg);
                    997:                if (*activep)
                    998:                        *intptr = value;
                    999:                break;
1.144     reyk     1000:
                   1001:        case oTunnelDevice:
                   1002:                arg = strdelim(&s);
                   1003:                if (!arg || *arg == '\0')
                   1004:                        fatal("%.200s line %d: Missing argument.", filename, linenum);
                   1005:                value = a2tun(arg, &value2);
1.145     reyk     1006:                if (value == SSH_TUNID_ERR)
1.144     reyk     1007:                        fatal("%.200s line %d: Bad tun device.", filename, linenum);
                   1008:                if (*activep) {
                   1009:                        options->tun_local = value;
                   1010:                        options->tun_remote = value2;
                   1011:                }
                   1012:                break;
                   1013:
                   1014:        case oLocalCommand:
                   1015:                charptr = &options->local_command;
                   1016:                goto parse_command;
                   1017:
                   1018:        case oPermitLocalCommand:
                   1019:                intptr = &options->permit_local_command;
                   1020:                goto parse_flag;
                   1021:
1.167     grunk    1022:        case oVisualHostKey:
                   1023:                intptr = &options->visual_host_key;
                   1024:                goto parse_flag;
                   1025:
1.190     djm      1026:        case oIPQoS:
                   1027:                arg = strdelim(&s);
                   1028:                if ((value = parse_ipqos(arg)) == -1)
                   1029:                        fatal("%s line %d: Bad IPQoS value: %s",
                   1030:                            filename, linenum, arg);
                   1031:                arg = strdelim(&s);
                   1032:                if (arg == NULL)
                   1033:                        value2 = value;
                   1034:                else if ((value2 = parse_ipqos(arg)) == -1)
                   1035:                        fatal("%s line %d: Bad IPQoS value: %s",
                   1036:                            filename, linenum, arg);
                   1037:                if (*activep) {
                   1038:                        options->ip_qos_interactive = value;
                   1039:                        options->ip_qos_bulk = value2;
                   1040:                }
                   1041:                break;
                   1042:
1.177     andreas  1043:        case oUseRoaming:
                   1044:                intptr = &options->use_roaming;
                   1045:                goto parse_flag;
                   1046:
1.192     djm      1047:        case oRequestTTY:
                   1048:                arg = strdelim(&s);
                   1049:                if (!arg || *arg == '\0')
                   1050:                        fatal("%s line %d: missing argument.",
                   1051:                            filename, linenum);
                   1052:                intptr = &options->request_tty;
                   1053:                if (strcasecmp(arg, "yes") == 0)
                   1054:                        value = REQUEST_TTY_YES;
                   1055:                else if (strcasecmp(arg, "no") == 0)
                   1056:                        value = REQUEST_TTY_NO;
                   1057:                else if (strcasecmp(arg, "force") == 0)
                   1058:                        value = REQUEST_TTY_FORCE;
                   1059:                else if (strcasecmp(arg, "auto") == 0)
                   1060:                        value = REQUEST_TTY_AUTO;
                   1061:                else
                   1062:                        fatal("Unsupported RequestTTY \"%s\"", arg);
                   1063:                if (*activep && *intptr == -1)
                   1064:                        *intptr = value;
                   1065:                break;
                   1066:
1.199     djm      1067:        case oIgnoreUnknown:
                   1068:                charptr = &options->ignored_unknown;
                   1069:                goto parse_string;
                   1070:
1.96      markus   1071:        case oDeprecated:
1.98      markus   1072:                debug("%s line %d: Deprecated option \"%s\"",
1.96      markus   1073:                    filename, linenum, keyword);
1.98      markus   1074:                return 0;
1.96      markus   1075:
1.110     jakob    1076:        case oUnsupported:
                   1077:                error("%s line %d: Unsupported option \"%s\"",
                   1078:                    filename, linenum, keyword);
                   1079:                return 0;
                   1080:
1.17      markus   1081:        default:
                   1082:                fatal("process_config_line: Unimplemented opcode %d", opcode);
                   1083:        }
                   1084:
                   1085:        /* Check that there is no garbage at end of line. */
1.57      djm      1086:        if ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1.39      ho       1087:                fatal("%.200s line %d: garbage at end of line; \"%.200s\".",
1.142     djm      1088:                    filename, linenum, arg);
1.39      ho       1089:        }
1.17      markus   1090:        return 0;
1.1       deraadt  1091: }
                   1092:
                   1093:
1.19      markus   1094: /*
                   1095:  * Reads the config file and modifies the options accordingly.  Options
                   1096:  * should already be initialized before this call.  This never returns if
1.89      stevesk  1097:  * there is an error.  If the file does not exist, this returns 0.
1.19      markus   1098:  */
1.1       deraadt  1099:
1.89      stevesk  1100: int
1.134     deraadt  1101: read_config_file(const char *filename, const char *host, Options *options,
1.196     dtucker  1102:     int flags)
1.1       deraadt  1103: {
1.17      markus   1104:        FILE *f;
                   1105:        char line[1024];
                   1106:        int active, linenum;
                   1107:        int bad_options = 0;
                   1108:
1.129     djm      1109:        if ((f = fopen(filename, "r")) == NULL)
1.89      stevesk  1110:                return 0;
1.129     djm      1111:
1.196     dtucker  1112:        if (flags & SSHCONF_CHECKPERM) {
1.129     djm      1113:                struct stat sb;
1.134     deraadt  1114:
1.131     dtucker  1115:                if (fstat(fileno(f), &sb) == -1)
1.129     djm      1116:                        fatal("fstat %s: %s", filename, strerror(errno));
                   1117:                if (((sb.st_uid != 0 && sb.st_uid != getuid()) ||
1.131     dtucker  1118:                    (sb.st_mode & 022) != 0))
1.129     djm      1119:                        fatal("Bad owner or permissions on %s", filename);
                   1120:        }
1.17      markus   1121:
                   1122:        debug("Reading configuration data %.200s", filename);
                   1123:
1.19      markus   1124:        /*
                   1125:         * Mark that we are now processing the options.  This flag is turned
                   1126:         * on/off by Host specifications.
                   1127:         */
1.17      markus   1128:        active = 1;
                   1129:        linenum = 0;
                   1130:        while (fgets(line, sizeof(line), f)) {
                   1131:                /* Update line number counter. */
                   1132:                linenum++;
1.196     dtucker  1133:                if (process_config_line(options, host, line, filename, linenum,
                   1134:                    &active, flags & SSHCONF_USERCONF) != 0)
1.17      markus   1135:                        bad_options++;
                   1136:        }
                   1137:        fclose(f);
                   1138:        if (bad_options > 0)
1.64      millert  1139:                fatal("%s: terminating, %d bad configuration options",
1.93      deraadt  1140:                    filename, bad_options);
1.89      stevesk  1141:        return 1;
1.1       deraadt  1142: }
                   1143:
1.19      markus   1144: /*
                   1145:  * Initializes options to special values that indicate that they have not yet
                   1146:  * been set.  Read_config_file will only set options with this value. Options
                   1147:  * are processed in the following order: command line, user config file,
                   1148:  * system config file.  Last, fill_default_options is called.
                   1149:  */
1.1       deraadt  1150:
1.26      markus   1151: void
1.17      markus   1152: initialize_options(Options * options)
1.1       deraadt  1153: {
1.17      markus   1154:        memset(options, 'X', sizeof(*options));
                   1155:        options->forward_agent = -1;
                   1156:        options->forward_x11 = -1;
1.123     markus   1157:        options->forward_x11_trusted = -1;
1.186     djm      1158:        options->forward_x11_timeout = -1;
1.153     markus   1159:        options->exit_on_forward_failure = -1;
1.34      markus   1160:        options->xauth_location = NULL;
1.17      markus   1161:        options->gateway_ports = -1;
                   1162:        options->use_privileged_port = -1;
                   1163:        options->rsa_authentication = -1;
1.50      markus   1164:        options->pubkey_authentication = -1;
1.78      markus   1165:        options->challenge_response_authentication = -1;
1.118     markus   1166:        options->gss_authentication = -1;
                   1167:        options->gss_deleg_creds = -1;
1.17      markus   1168:        options->password_authentication = -1;
1.48      markus   1169:        options->kbd_interactive_authentication = -1;
                   1170:        options->kbd_interactive_devices = NULL;
1.17      markus   1171:        options->rhosts_rsa_authentication = -1;
1.72      markus   1172:        options->hostbased_authentication = -1;
1.17      markus   1173:        options->batch_mode = -1;
                   1174:        options->check_host_ip = -1;
                   1175:        options->strict_host_key_checking = -1;
                   1176:        options->compression = -1;
1.126     markus   1177:        options->tcp_keep_alive = -1;
1.17      markus   1178:        options->compression_level = -1;
                   1179:        options->port = -1;
1.114     djm      1180:        options->address_family = -1;
1.17      markus   1181:        options->connection_attempts = -1;
1.111     djm      1182:        options->connection_timeout = -1;
1.17      markus   1183:        options->number_of_password_prompts = -1;
                   1184:        options->cipher = -1;
1.25      markus   1185:        options->ciphers = NULL;
1.62      markus   1186:        options->macs = NULL;
1.189     djm      1187:        options->kex_algorithms = NULL;
1.76      markus   1188:        options->hostkeyalgorithms = NULL;
1.25      markus   1189:        options->protocol = SSH_PROTO_UNKNOWN;
1.17      markus   1190:        options->num_identity_files = 0;
                   1191:        options->hostname = NULL;
1.52      markus   1192:        options->host_key_alias = NULL;
1.17      markus   1193:        options->proxy_command = NULL;
                   1194:        options->user = NULL;
                   1195:        options->escape_char = -1;
1.193     djm      1196:        options->num_system_hostfiles = 0;
                   1197:        options->num_user_hostfiles = 0;
1.185     djm      1198:        options->local_forwards = NULL;
1.17      markus   1199:        options->num_local_forwards = 0;
1.185     djm      1200:        options->remote_forwards = NULL;
1.17      markus   1201:        options->num_remote_forwards = 0;
1.90      stevesk  1202:        options->clear_forwardings = -1;
1.95      markus   1203:        options->log_level = SYSLOG_LEVEL_NOT_SET;
1.67      markus   1204:        options->preferred_authentications = NULL;
1.77      markus   1205:        options->bind_address = NULL;
1.183     markus   1206:        options->pkcs11_provider = NULL;
1.101     markus   1207:        options->enable_ssh_keysign = - 1;
1.91      markus   1208:        options->no_host_authentication_for_localhost = - 1;
1.128     markus   1209:        options->identities_only = - 1;
1.105     markus   1210:        options->rekey_limit = - 1;
1.198     dtucker  1211:        options->rekey_interval = -1;
1.107     jakob    1212:        options->verify_host_key_dns = -1;
1.127     markus   1213:        options->server_alive_interval = -1;
                   1214:        options->server_alive_count_max = -1;
1.130     djm      1215:        options->num_send_env = 0;
1.132     djm      1216:        options->control_path = NULL;
                   1217:        options->control_master = -1;
1.187     djm      1218:        options->control_persist = -1;
                   1219:        options->control_persist_timeout = 0;
1.136     djm      1220:        options->hash_known_hosts = -1;
1.144     reyk     1221:        options->tun_open = -1;
                   1222:        options->tun_local = -1;
                   1223:        options->tun_remote = -1;
                   1224:        options->local_command = NULL;
                   1225:        options->permit_local_command = -1;
1.177     andreas  1226:        options->use_roaming = -1;
1.167     grunk    1227:        options->visual_host_key = -1;
1.171     djm      1228:        options->zero_knowledge_password_authentication = -1;
1.190     djm      1229:        options->ip_qos_interactive = -1;
                   1230:        options->ip_qos_bulk = -1;
1.192     djm      1231:        options->request_tty = -1;
1.199     djm      1232:        options->ignored_unknown = NULL;
1.1       deraadt  1233: }
                   1234:
1.19      markus   1235: /*
                   1236:  * Called after processing other sources of option data, this fills those
                   1237:  * options for which no value has been specified with their default values.
                   1238:  */
1.1       deraadt  1239:
1.26      markus   1240: void
1.17      markus   1241: fill_default_options(Options * options)
1.1       deraadt  1242: {
1.17      markus   1243:        if (options->forward_agent == -1)
1.33      markus   1244:                options->forward_agent = 0;
1.17      markus   1245:        if (options->forward_x11 == -1)
1.23      markus   1246:                options->forward_x11 = 0;
1.123     markus   1247:        if (options->forward_x11_trusted == -1)
                   1248:                options->forward_x11_trusted = 0;
1.186     djm      1249:        if (options->forward_x11_timeout == -1)
                   1250:                options->forward_x11_timeout = 1200;
1.153     markus   1251:        if (options->exit_on_forward_failure == -1)
                   1252:                options->exit_on_forward_failure = 0;
1.34      markus   1253:        if (options->xauth_location == NULL)
1.80      markus   1254:                options->xauth_location = _PATH_XAUTH;
1.17      markus   1255:        if (options->gateway_ports == -1)
                   1256:                options->gateway_ports = 0;
                   1257:        if (options->use_privileged_port == -1)
1.65      markus   1258:                options->use_privileged_port = 0;
1.17      markus   1259:        if (options->rsa_authentication == -1)
                   1260:                options->rsa_authentication = 1;
1.50      markus   1261:        if (options->pubkey_authentication == -1)
                   1262:                options->pubkey_authentication = 1;
1.78      markus   1263:        if (options->challenge_response_authentication == -1)
1.83      markus   1264:                options->challenge_response_authentication = 1;
1.118     markus   1265:        if (options->gss_authentication == -1)
1.122     markus   1266:                options->gss_authentication = 0;
1.118     markus   1267:        if (options->gss_deleg_creds == -1)
                   1268:                options->gss_deleg_creds = 0;
1.17      markus   1269:        if (options->password_authentication == -1)
                   1270:                options->password_authentication = 1;
1.48      markus   1271:        if (options->kbd_interactive_authentication == -1)
1.59      markus   1272:                options->kbd_interactive_authentication = 1;
1.17      markus   1273:        if (options->rhosts_rsa_authentication == -1)
1.99      stevesk  1274:                options->rhosts_rsa_authentication = 0;
1.72      markus   1275:        if (options->hostbased_authentication == -1)
                   1276:                options->hostbased_authentication = 0;
1.17      markus   1277:        if (options->batch_mode == -1)
                   1278:                options->batch_mode = 0;
                   1279:        if (options->check_host_ip == -1)
                   1280:                options->check_host_ip = 1;
                   1281:        if (options->strict_host_key_checking == -1)
                   1282:                options->strict_host_key_checking = 2;  /* 2 is default */
                   1283:        if (options->compression == -1)
                   1284:                options->compression = 0;
1.126     markus   1285:        if (options->tcp_keep_alive == -1)
                   1286:                options->tcp_keep_alive = 1;
1.17      markus   1287:        if (options->compression_level == -1)
                   1288:                options->compression_level = 6;
                   1289:        if (options->port == -1)
                   1290:                options->port = 0;      /* Filled in ssh_connect. */
1.114     djm      1291:        if (options->address_family == -1)
                   1292:                options->address_family = AF_UNSPEC;
1.17      markus   1293:        if (options->connection_attempts == -1)
1.84      markus   1294:                options->connection_attempts = 1;
1.17      markus   1295:        if (options->number_of_password_prompts == -1)
                   1296:                options->number_of_password_prompts = 3;
                   1297:        /* Selected in ssh_login(). */
                   1298:        if (options->cipher == -1)
                   1299:                options->cipher = SSH_CIPHER_NOT_SET;
1.31      markus   1300:        /* options->ciphers, default set in myproposals.h */
1.62      markus   1301:        /* options->macs, default set in myproposals.h */
1.189     djm      1302:        /* options->kex_algorithms, default set in myproposals.h */
1.76      markus   1303:        /* options->hostkeyalgorithms, default set in myproposals.h */
1.25      markus   1304:        if (options->protocol == SSH_PROTO_UNKNOWN)
1.178     markus   1305:                options->protocol = SSH_PROTO_2;
1.17      markus   1306:        if (options->num_identity_files == 0) {
1.50      markus   1307:                if (options->protocol & SSH_PROTO_1) {
1.195     dtucker  1308:                        add_identity_file(options, "~/",
                   1309:                            _PATH_SSH_CLIENT_IDENTITY, 0);
1.50      markus   1310:                }
                   1311:                if (options->protocol & SSH_PROTO_2) {
1.195     dtucker  1312:                        add_identity_file(options, "~/",
                   1313:                            _PATH_SSH_CLIENT_ID_RSA, 0);
                   1314:                        add_identity_file(options, "~/",
                   1315:                            _PATH_SSH_CLIENT_ID_DSA, 0);
                   1316:                        add_identity_file(options, "~/",
                   1317:                            _PATH_SSH_CLIENT_ID_ECDSA, 0);
1.50      markus   1318:                }
1.27      markus   1319:        }
1.17      markus   1320:        if (options->escape_char == -1)
                   1321:                options->escape_char = '~';
1.193     djm      1322:        if (options->num_system_hostfiles == 0) {
                   1323:                options->system_hostfiles[options->num_system_hostfiles++] =
                   1324:                    xstrdup(_PATH_SSH_SYSTEM_HOSTFILE);
                   1325:                options->system_hostfiles[options->num_system_hostfiles++] =
                   1326:                    xstrdup(_PATH_SSH_SYSTEM_HOSTFILE2);
                   1327:        }
                   1328:        if (options->num_user_hostfiles == 0) {
                   1329:                options->user_hostfiles[options->num_user_hostfiles++] =
                   1330:                    xstrdup(_PATH_SSH_USER_HOSTFILE);
                   1331:                options->user_hostfiles[options->num_user_hostfiles++] =
                   1332:                    xstrdup(_PATH_SSH_USER_HOSTFILE2);
                   1333:        }
1.95      markus   1334:        if (options->log_level == SYSLOG_LEVEL_NOT_SET)
1.54      markus   1335:                options->log_level = SYSLOG_LEVEL_INFO;
1.90      stevesk  1336:        if (options->clear_forwardings == 1)
                   1337:                clear_forwardings(options);
1.91      markus   1338:        if (options->no_host_authentication_for_localhost == - 1)
                   1339:                options->no_host_authentication_for_localhost = 0;
1.128     markus   1340:        if (options->identities_only == -1)
                   1341:                options->identities_only = 0;
1.101     markus   1342:        if (options->enable_ssh_keysign == -1)
                   1343:                options->enable_ssh_keysign = 0;
1.105     markus   1344:        if (options->rekey_limit == -1)
                   1345:                options->rekey_limit = 0;
1.198     dtucker  1346:        if (options->rekey_interval == -1)
                   1347:                options->rekey_interval = 0;
1.107     jakob    1348:        if (options->verify_host_key_dns == -1)
                   1349:                options->verify_host_key_dns = 0;
1.127     markus   1350:        if (options->server_alive_interval == -1)
                   1351:                options->server_alive_interval = 0;
                   1352:        if (options->server_alive_count_max == -1)
                   1353:                options->server_alive_count_max = 3;
1.132     djm      1354:        if (options->control_master == -1)
                   1355:                options->control_master = 0;
1.187     djm      1356:        if (options->control_persist == -1) {
                   1357:                options->control_persist = 0;
                   1358:                options->control_persist_timeout = 0;
                   1359:        }
1.136     djm      1360:        if (options->hash_known_hosts == -1)
                   1361:                options->hash_known_hosts = 0;
1.144     reyk     1362:        if (options->tun_open == -1)
1.145     reyk     1363:                options->tun_open = SSH_TUNMODE_NO;
                   1364:        if (options->tun_local == -1)
                   1365:                options->tun_local = SSH_TUNID_ANY;
                   1366:        if (options->tun_remote == -1)
                   1367:                options->tun_remote = SSH_TUNID_ANY;
1.144     reyk     1368:        if (options->permit_local_command == -1)
                   1369:                options->permit_local_command = 0;
1.177     andreas  1370:        if (options->use_roaming == -1)
                   1371:                options->use_roaming = 1;
1.167     grunk    1372:        if (options->visual_host_key == -1)
                   1373:                options->visual_host_key = 0;
1.171     djm      1374:        if (options->zero_knowledge_password_authentication == -1)
                   1375:                options->zero_knowledge_password_authentication = 0;
1.190     djm      1376:        if (options->ip_qos_interactive == -1)
                   1377:                options->ip_qos_interactive = IPTOS_LOWDELAY;
                   1378:        if (options->ip_qos_bulk == -1)
                   1379:                options->ip_qos_bulk = IPTOS_THROUGHPUT;
1.192     djm      1380:        if (options->request_tty == -1)
                   1381:                options->request_tty = REQUEST_TTY_AUTO;
1.144     reyk     1382:        /* options->local_command should not be set by default */
1.17      markus   1383:        /* options->proxy_command should not be set by default */
                   1384:        /* options->user will be set in the main program if appropriate */
                   1385:        /* options->hostname will be set in the main program if appropriate */
1.52      markus   1386:        /* options->host_key_alias should not be set by default */
1.67      markus   1387:        /* options->preferred_authentications will be set in ssh */
1.135     djm      1388: }
                   1389:
                   1390: /*
                   1391:  * parse_forward
                   1392:  * parses a string containing a port forwarding specification of the form:
1.168     stevesk  1393:  *   dynamicfwd == 0
1.135     djm      1394:  *     [listenhost:]listenport:connecthost:connectport
1.168     stevesk  1395:  *   dynamicfwd == 1
                   1396:  *     [listenhost:]listenport
1.135     djm      1397:  * returns number of arguments parsed or zero on error
                   1398:  */
                   1399: int
1.176     djm      1400: parse_forward(Forward *fwd, const char *fwdspec, int dynamicfwd, int remotefwd)
1.135     djm      1401: {
                   1402:        int i;
                   1403:        char *p, *cp, *fwdarg[4];
                   1404:
                   1405:        memset(fwd, '\0', sizeof(*fwd));
                   1406:
                   1407:        cp = p = xstrdup(fwdspec);
                   1408:
                   1409:        /* skip leading spaces */
1.162     tedu     1410:        while (isspace(*cp))
1.135     djm      1411:                cp++;
                   1412:
                   1413:        for (i = 0; i < 4; ++i)
                   1414:                if ((fwdarg[i] = hpdelim(&cp)) == NULL)
                   1415:                        break;
                   1416:
1.170     stevesk  1417:        /* Check for trailing garbage */
1.135     djm      1418:        if (cp != NULL)
                   1419:                i = 0;  /* failure */
                   1420:
                   1421:        switch (i) {
1.168     stevesk  1422:        case 1:
                   1423:                fwd->listen_host = NULL;
                   1424:                fwd->listen_port = a2port(fwdarg[0]);
                   1425:                fwd->connect_host = xstrdup("socks");
                   1426:                break;
                   1427:
                   1428:        case 2:
                   1429:                fwd->listen_host = xstrdup(cleanhostname(fwdarg[0]));
                   1430:                fwd->listen_port = a2port(fwdarg[1]);
                   1431:                fwd->connect_host = xstrdup("socks");
                   1432:                break;
                   1433:
1.135     djm      1434:        case 3:
                   1435:                fwd->listen_host = NULL;
                   1436:                fwd->listen_port = a2port(fwdarg[0]);
                   1437:                fwd->connect_host = xstrdup(cleanhostname(fwdarg[1]));
                   1438:                fwd->connect_port = a2port(fwdarg[2]);
                   1439:                break;
                   1440:
                   1441:        case 4:
                   1442:                fwd->listen_host = xstrdup(cleanhostname(fwdarg[0]));
                   1443:                fwd->listen_port = a2port(fwdarg[1]);
                   1444:                fwd->connect_host = xstrdup(cleanhostname(fwdarg[2]));
                   1445:                fwd->connect_port = a2port(fwdarg[3]);
                   1446:                break;
                   1447:        default:
                   1448:                i = 0; /* failure */
                   1449:        }
                   1450:
1.202     djm      1451:        free(p);
1.135     djm      1452:
1.168     stevesk  1453:        if (dynamicfwd) {
                   1454:                if (!(i == 1 || i == 2))
                   1455:                        goto fail_free;
                   1456:        } else {
                   1457:                if (!(i == 3 || i == 4))
                   1458:                        goto fail_free;
1.175     djm      1459:                if (fwd->connect_port <= 0)
1.168     stevesk  1460:                        goto fail_free;
                   1461:        }
                   1462:
1.176     djm      1463:        if (fwd->listen_port < 0 || (!remotefwd && fwd->listen_port == 0))
1.135     djm      1464:                goto fail_free;
                   1465:
                   1466:        if (fwd->connect_host != NULL &&
                   1467:            strlen(fwd->connect_host) >= NI_MAXHOST)
                   1468:                goto fail_free;
1.176     djm      1469:        if (fwd->listen_host != NULL &&
                   1470:            strlen(fwd->listen_host) >= NI_MAXHOST)
                   1471:                goto fail_free;
                   1472:
1.135     djm      1473:
                   1474:        return (i);
                   1475:
                   1476:  fail_free:
1.202     djm      1477:        free(fwd->connect_host);
                   1478:        fwd->connect_host = NULL;
                   1479:        free(fwd->listen_host);
                   1480:        fwd->listen_host = NULL;
1.135     djm      1481:        return (0);
1.1       deraadt  1482: }