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

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