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

1.1       deraadt     1: /*
1.18      deraadt     2:  * Author: Tatu Ylonen <ylo@cs.hut.fi>
                      3:  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
                      4:  *                    All rights reserved
                      5:  * Functions for reading the configuration files.
1.26      markus      6:  *
1.46      deraadt     7:  * As far as I am concerned, the code I have written for this software
                      8:  * can be used freely for any purpose.  Any derived versions of this
                      9:  * software must be clearly marked as such, and if the derived work is
                     10:  * incompatible with the protocol description in the RFC file, it must be
                     11:  * called by a name other than "ssh" or "Secure Shell".
1.18      deraadt    12:  */
1.1       deraadt    13:
                     14: #include "includes.h"
1.129   ! djm        15: RCSID("$OpenBSD: readconf.c,v 1.128 2004/03/05 10:53:58 markus Exp $");
1.1       deraadt    16:
                     17: #include "ssh.h"
                     18: #include "xmalloc.h"
1.25      markus     19: #include "compat.h"
1.58      markus     20: #include "cipher.h"
1.55      markus     21: #include "pathnames.h"
1.58      markus     22: #include "log.h"
                     23: #include "readconf.h"
                     24: #include "match.h"
                     25: #include "misc.h"
1.62      markus     26: #include "kex.h"
                     27: #include "mac.h"
1.1       deraadt    28:
                     29: /* Format of the configuration file:
                     30:
                     31:    # Configuration data is parsed as follows:
                     32:    #  1. command line options
                     33:    #  2. user-specific file
                     34:    #  3. system-wide file
                     35:    # Any configuration value is only changed the first time it is set.
                     36:    # Thus, host-specific definitions should be at the beginning of the
                     37:    # configuration file, and defaults at the end.
                     38:
                     39:    # Host-specific declarations.  These may override anything above.  A single
                     40:    # host may match multiple declarations; these are processed in the order
                     41:    # that they are given in.
                     42:
                     43:    Host *.ngs.fi ngs.fi
1.96      markus     44:      User foo
1.1       deraadt    45:
                     46:    Host fake.com
                     47:      HostName another.host.name.real.org
                     48:      User blaah
                     49:      Port 34289
                     50:      ForwardX11 no
                     51:      ForwardAgent no
                     52:
                     53:    Host books.com
                     54:      RemoteForward 9999 shadows.cs.hut.fi:9999
                     55:      Cipher 3des
                     56:
                     57:    Host fascist.blob.com
                     58:      Port 23123
                     59:      User tylonen
                     60:      PasswordAuthentication no
                     61:
                     62:    Host puukko.hut.fi
                     63:      User t35124p
                     64:      ProxyCommand ssh-proxy %h %p
                     65:
                     66:    Host *.fr
1.96      markus     67:      PublicKeyAuthentication no
1.1       deraadt    68:
                     69:    Host *.su
                     70:      Cipher none
                     71:      PasswordAuthentication no
                     72:
                     73:    # Defaults for various options
                     74:    Host *
                     75:      ForwardAgent no
1.50      markus     76:      ForwardX11 no
1.1       deraadt    77:      PasswordAuthentication yes
                     78:      RSAAuthentication yes
                     79:      RhostsRSAAuthentication yes
                     80:      StrictHostKeyChecking yes
1.126     markus     81:      TcpKeepAlive no
1.1       deraadt    82:      IdentityFile ~/.ssh/identity
                     83:      Port 22
                     84:      EscapeChar ~
                     85:
                     86: */
                     87:
                     88: /* Keyword tokens. */
                     89:
1.17      markus     90: typedef enum {
                     91:        oBadOption,
1.123     markus     92:        oForwardAgent, oForwardX11, oForwardX11Trusted, oGatewayPorts,
1.100     deraadt    93:        oPasswordAuthentication, oRSAAuthentication,
1.59      markus     94:        oChallengeResponseAuthentication, oXAuthLocation,
1.17      markus     95:        oIdentityFile, oHostName, oPort, oCipher, oRemoteForward, oLocalForward,
                     96:        oUser, oHost, oEscapeChar, oRhostsRSAAuthentication, oProxyCommand,
                     97:        oGlobalKnownHostsFile, oUserKnownHostsFile, oConnectionAttempts,
                     98:        oBatchMode, oCheckHostIP, oStrictHostKeyChecking, oCompression,
1.126     markus     99:        oCompressionLevel, oTCPKeepAlive, oNumberOfPasswordPrompts,
1.62      markus    100:        oUsePrivilegedPort, oLogLevel, oCiphers, oProtocol, oMacs,
1.50      markus    101:        oGlobalKnownHostsFile2, oUserKnownHostsFile2, oPubkeyAuthentication,
1.67      markus    102:        oKbdInteractiveAuthentication, oKbdInteractiveDevices, oHostKeyAlias,
1.76      markus    103:        oDynamicForward, oPreferredAuthentications, oHostbasedAuthentication,
1.90      stevesk   104:        oHostKeyAlgorithms, oBindAddress, oSmartcardDevice,
1.96      markus    105:        oClearAllForwardings, oNoHostAuthenticationForLocalhost,
1.111     djm       106:        oEnableSSHKeysign, oRekeyLimit, oVerifyHostKeyDNS, oConnectTimeout,
1.118     markus    107:        oAddressFamily, oGssAuthentication, oGssDelegateCreds,
1.128     markus    108:        oServerAliveInterval, oServerAliveCountMax, oIdentitiesOnly,
1.110     jakob     109:        oDeprecated, oUnsupported
1.1       deraadt   110: } OpCodes;
                    111:
                    112: /* Textual representations of the tokens. */
                    113:
1.17      markus    114: static struct {
                    115:        const char *name;
                    116:        OpCodes opcode;
                    117: } keywords[] = {
                    118:        { "forwardagent", oForwardAgent },
                    119:        { "forwardx11", oForwardX11 },
1.123     markus    120:        { "forwardx11trusted", oForwardX11Trusted },
1.34      markus    121:        { "xauthlocation", oXAuthLocation },
1.17      markus    122:        { "gatewayports", oGatewayPorts },
                    123:        { "useprivilegedport", oUsePrivilegedPort },
1.116     markus    124:        { "rhostsauthentication", oDeprecated },
1.17      markus    125:        { "passwordauthentication", oPasswordAuthentication },
1.48      markus    126:        { "kbdinteractiveauthentication", oKbdInteractiveAuthentication },
                    127:        { "kbdinteractivedevices", oKbdInteractiveDevices },
1.17      markus    128:        { "rsaauthentication", oRSAAuthentication },
1.50      markus    129:        { "pubkeyauthentication", oPubkeyAuthentication },
1.59      markus    130:        { "dsaauthentication", oPubkeyAuthentication },             /* alias */
1.72      markus    131:        { "rhostsrsaauthentication", oRhostsRSAAuthentication },
1.73      markus    132:        { "hostbasedauthentication", oHostbasedAuthentication },
1.59      markus    133:        { "challengeresponseauthentication", oChallengeResponseAuthentication },
                    134:        { "skeyauthentication", oChallengeResponseAuthentication }, /* alias */
                    135:        { "tisauthentication", oChallengeResponseAuthentication },  /* alias */
1.110     jakob     136:        { "kerberosauthentication", oUnsupported },
                    137:        { "kerberostgtpassing", oUnsupported },
                    138:        { "afstokenpassing", oUnsupported },
1.118     markus    139: #if defined(GSSAPI)
                    140:        { "gssapiauthentication", oGssAuthentication },
                    141:        { "gssapidelegatecredentials", oGssDelegateCreds },
                    142: #else
                    143:        { "gssapiauthentication", oUnsupported },
                    144:        { "gssapidelegatecredentials", oUnsupported },
                    145: #endif
1.96      markus    146:        { "fallbacktorsh", oDeprecated },
                    147:        { "usersh", oDeprecated },
1.17      markus    148:        { "identityfile", oIdentityFile },
1.50      markus    149:        { "identityfile2", oIdentityFile },                     /* alias */
1.128     markus    150:        { "identitiesonly", oIdentitiesOnly },
1.17      markus    151:        { "hostname", oHostName },
1.52      markus    152:        { "hostkeyalias", oHostKeyAlias },
1.17      markus    153:        { "proxycommand", oProxyCommand },
                    154:        { "port", oPort },
                    155:        { "cipher", oCipher },
1.25      markus    156:        { "ciphers", oCiphers },
1.62      markus    157:        { "macs", oMacs },
1.25      markus    158:        { "protocol", oProtocol },
1.17      markus    159:        { "remoteforward", oRemoteForward },
                    160:        { "localforward", oLocalForward },
                    161:        { "user", oUser },
                    162:        { "host", oHost },
                    163:        { "escapechar", oEscapeChar },
                    164:        { "globalknownhostsfile", oGlobalKnownHostsFile },
1.81      markus    165:        { "userknownhostsfile", oUserKnownHostsFile },          /* obsolete */
1.27      markus    166:        { "globalknownhostsfile2", oGlobalKnownHostsFile2 },
1.81      markus    167:        { "userknownhostsfile2", oUserKnownHostsFile2 },        /* obsolete */
1.17      markus    168:        { "connectionattempts", oConnectionAttempts },
                    169:        { "batchmode", oBatchMode },
                    170:        { "checkhostip", oCheckHostIP },
                    171:        { "stricthostkeychecking", oStrictHostKeyChecking },
                    172:        { "compression", oCompression },
                    173:        { "compressionlevel", oCompressionLevel },
1.126     markus    174:        { "tcpkeepalive", oTCPKeepAlive },
                    175:        { "keepalive", oTCPKeepAlive },                         /* obsolete */
1.17      markus    176:        { "numberofpasswordprompts", oNumberOfPasswordPrompts },
                    177:        { "loglevel", oLogLevel },
1.71      markus    178:        { "dynamicforward", oDynamicForward },
1.67      markus    179:        { "preferredauthentications", oPreferredAuthentications },
1.76      markus    180:        { "hostkeyalgorithms", oHostKeyAlgorithms },
1.77      markus    181:        { "bindaddress", oBindAddress },
1.110     jakob     182: #ifdef SMARTCARD
1.85      jakob     183:        { "smartcarddevice", oSmartcardDevice },
1.110     jakob     184: #else
                    185:        { "smartcarddevice", oUnsupported },
                    186: #endif
1.93      deraadt   187:        { "clearallforwardings", oClearAllForwardings },
1.101     markus    188:        { "enablesshkeysign", oEnableSSHKeysign },
1.107     jakob     189:        { "verifyhostkeydns", oVerifyHostKeyDNS },
1.93      deraadt   190:        { "nohostauthenticationforlocalhost", oNoHostAuthenticationForLocalhost },
1.105     markus    191:        { "rekeylimit", oRekeyLimit },
1.111     djm       192:        { "connecttimeout", oConnectTimeout },
1.112     djm       193:        { "addressfamily", oAddressFamily },
1.127     markus    194:        { "serveraliveinterval", oServerAliveInterval },
                    195:        { "serveralivecountmax", oServerAliveCountMax },
1.92      stevesk   196:        { NULL, oBadOption }
1.13      markus    197: };
                    198:
1.19      markus    199: /*
                    200:  * Adds a local TCP/IP port forward to options.  Never returns if there is an
                    201:  * error.
                    202:  */
1.1       deraadt   203:
1.26      markus    204: void
1.22      markus    205: add_local_forward(Options *options, u_short port, const char *host,
                    206:                  u_short host_port)
1.1       deraadt   207: {
1.17      markus    208:        Forward *fwd;
                    209:        extern uid_t original_real_uid;
                    210:        if (port < IPPORT_RESERVED && original_real_uid != 0)
1.64      millert   211:                fatal("Privileged ports can only be forwarded by root.");
1.17      markus    212:        if (options->num_local_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION)
                    213:                fatal("Too many local forwards (max %d).", SSH_MAX_FORWARDS_PER_DIRECTION);
                    214:        fwd = &options->local_forwards[options->num_local_forwards++];
                    215:        fwd->port = port;
                    216:        fwd->host = xstrdup(host);
                    217:        fwd->host_port = host_port;
1.1       deraadt   218: }
                    219:
1.19      markus    220: /*
                    221:  * Adds a remote TCP/IP port forward to options.  Never returns if there is
                    222:  * an error.
                    223:  */
1.1       deraadt   224:
1.26      markus    225: void
1.22      markus    226: add_remote_forward(Options *options, u_short port, const char *host,
                    227:                   u_short host_port)
1.1       deraadt   228: {
1.17      markus    229:        Forward *fwd;
                    230:        if (options->num_remote_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION)
                    231:                fatal("Too many remote forwards (max %d).",
1.93      deraadt   232:                    SSH_MAX_FORWARDS_PER_DIRECTION);
1.17      markus    233:        fwd = &options->remote_forwards[options->num_remote_forwards++];
                    234:        fwd->port = port;
                    235:        fwd->host = xstrdup(host);
                    236:        fwd->host_port = host_port;
1.1       deraadt   237: }
                    238:
1.90      stevesk   239: static void
                    240: clear_forwardings(Options *options)
                    241: {
                    242:        int i;
                    243:
                    244:        for (i = 0; i < options->num_local_forwards; i++)
                    245:                xfree(options->local_forwards[i].host);
                    246:        options->num_local_forwards = 0;
                    247:        for (i = 0; i < options->num_remote_forwards; i++)
                    248:                xfree(options->remote_forwards[i].host);
                    249:        options->num_remote_forwards = 0;
                    250: }
                    251:
1.19      markus    252: /*
1.70      stevesk   253:  * Returns the number of the token pointed to by cp or oBadOption.
1.19      markus    254:  */
1.1       deraadt   255:
1.26      markus    256: static OpCodes
1.17      markus    257: parse_token(const char *cp, const char *filename, int linenum)
1.1       deraadt   258: {
1.51      markus    259:        u_int i;
1.1       deraadt   260:
1.17      markus    261:        for (i = 0; keywords[i].name; i++)
1.20      markus    262:                if (strcasecmp(cp, keywords[i].name) == 0)
1.17      markus    263:                        return keywords[i].opcode;
                    264:
1.75      stevesk   265:        error("%s: line %d: Bad configuration option: %s",
                    266:            filename, linenum, cp);
1.17      markus    267:        return oBadOption;
1.1       deraadt   268: }
                    269:
1.19      markus    270: /*
                    271:  * Processes a single option line as used in the configuration files. This
                    272:  * only sets those values that have not already been set.
                    273:  */
1.102     markus    274: #define WHITESPACE " \t\r\n"
1.1       deraadt   275:
1.14      markus    276: int
                    277: process_config_line(Options *options, const char *host,
1.17      markus    278:                    char *line, const char *filename, int linenum,
                    279:                    int *activep)
1.1       deraadt   280: {
1.102     markus    281:        char buf[256], *s, **charptr, *endofnumber, *keyword, *arg;
1.22      markus    282:        int opcode, *intptr, value;
1.102     markus    283:        size_t len;
1.22      markus    284:        u_short fwd_port, fwd_host_port;
1.88      stevesk   285:        char sfwd_host_port[6];
1.106     djm       286:
                    287:        /* Strip trailing whitespace */
                    288:        for(len = strlen(line) - 1; len > 0; len--) {
                    289:                if (strchr(WHITESPACE, line[len]) == NULL)
                    290:                        break;
                    291:                line[len] = '\0';
                    292:        }
1.1       deraadt   293:
1.42      provos    294:        s = line;
                    295:        /* Get the keyword. (Each line is supposed to begin with a keyword). */
                    296:        keyword = strdelim(&s);
                    297:        /* Ignore leading whitespace. */
                    298:        if (*keyword == '\0')
1.43      markus    299:                keyword = strdelim(&s);
1.56      deraadt   300:        if (keyword == NULL || !*keyword || *keyword == '\n' || *keyword == '#')
1.17      markus    301:                return 0;
                    302:
1.38      provos    303:        opcode = parse_token(keyword, filename, linenum);
1.17      markus    304:
                    305:        switch (opcode) {
                    306:        case oBadOption:
1.19      markus    307:                /* don't panic, but count bad options */
                    308:                return -1;
1.17      markus    309:                /* NOTREACHED */
1.111     djm       310:        case oConnectTimeout:
                    311:                intptr = &options->connection_timeout;
1.127     markus    312: parse_time:
1.111     djm       313:                arg = strdelim(&s);
                    314:                if (!arg || *arg == '\0')
                    315:                        fatal("%s line %d: missing time value.",
                    316:                            filename, linenum);
                    317:                if ((value = convtime(arg)) == -1)
                    318:                        fatal("%s line %d: invalid time value.",
                    319:                            filename, linenum);
                    320:                if (*intptr == -1)
                    321:                        *intptr = value;
                    322:                break;
                    323:
1.17      markus    324:        case oForwardAgent:
                    325:                intptr = &options->forward_agent;
                    326: parse_flag:
1.42      provos    327:                arg = strdelim(&s);
1.40      ho        328:                if (!arg || *arg == '\0')
1.17      markus    329:                        fatal("%.200s line %d: Missing yes/no argument.", filename, linenum);
                    330:                value = 0;      /* To avoid compiler warning... */
1.38      provos    331:                if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
1.17      markus    332:                        value = 1;
1.38      provos    333:                else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
1.17      markus    334:                        value = 0;
                    335:                else
                    336:                        fatal("%.200s line %d: Bad yes/no argument.", filename, linenum);
                    337:                if (*activep && *intptr == -1)
                    338:                        *intptr = value;
                    339:                break;
                    340:
                    341:        case oForwardX11:
                    342:                intptr = &options->forward_x11;
                    343:                goto parse_flag;
                    344:
1.123     markus    345:        case oForwardX11Trusted:
                    346:                intptr = &options->forward_x11_trusted;
                    347:                goto parse_flag;
                    348:
1.17      markus    349:        case oGatewayPorts:
                    350:                intptr = &options->gateway_ports;
                    351:                goto parse_flag;
                    352:
                    353:        case oUsePrivilegedPort:
                    354:                intptr = &options->use_privileged_port;
                    355:                goto parse_flag;
                    356:
                    357:        case oPasswordAuthentication:
                    358:                intptr = &options->password_authentication;
                    359:                goto parse_flag;
                    360:
1.48      markus    361:        case oKbdInteractiveAuthentication:
                    362:                intptr = &options->kbd_interactive_authentication;
                    363:                goto parse_flag;
                    364:
                    365:        case oKbdInteractiveDevices:
                    366:                charptr = &options->kbd_interactive_devices;
                    367:                goto parse_string;
                    368:
1.50      markus    369:        case oPubkeyAuthentication:
                    370:                intptr = &options->pubkey_authentication;
1.30      markus    371:                goto parse_flag;
                    372:
1.17      markus    373:        case oRSAAuthentication:
                    374:                intptr = &options->rsa_authentication;
                    375:                goto parse_flag;
                    376:
                    377:        case oRhostsRSAAuthentication:
                    378:                intptr = &options->rhosts_rsa_authentication;
                    379:                goto parse_flag;
                    380:
1.72      markus    381:        case oHostbasedAuthentication:
                    382:                intptr = &options->hostbased_authentication;
                    383:                goto parse_flag;
                    384:
1.59      markus    385:        case oChallengeResponseAuthentication:
1.78      markus    386:                intptr = &options->challenge_response_authentication;
1.17      markus    387:                goto parse_flag;
1.108     jakob     388:
1.118     markus    389:        case oGssAuthentication:
                    390:                intptr = &options->gss_authentication;
                    391:                goto parse_flag;
                    392:
                    393:        case oGssDelegateCreds:
                    394:                intptr = &options->gss_deleg_creds;
                    395:                goto parse_flag;
                    396:
1.17      markus    397:        case oBatchMode:
                    398:                intptr = &options->batch_mode;
                    399:                goto parse_flag;
                    400:
                    401:        case oCheckHostIP:
                    402:                intptr = &options->check_host_ip;
                    403:                goto parse_flag;
                    404:
1.107     jakob     405:        case oVerifyHostKeyDNS:
                    406:                intptr = &options->verify_host_key_dns;
1.125     jakob     407:                goto parse_yesnoask;
1.107     jakob     408:
1.17      markus    409:        case oStrictHostKeyChecking:
                    410:                intptr = &options->strict_host_key_checking;
1.125     jakob     411: parse_yesnoask:
1.42      provos    412:                arg = strdelim(&s);
1.40      ho        413:                if (!arg || *arg == '\0')
1.60      stevesk   414:                        fatal("%.200s line %d: Missing yes/no/ask argument.",
1.93      deraadt   415:                            filename, linenum);
1.17      markus    416:                value = 0;      /* To avoid compiler warning... */
1.38      provos    417:                if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
1.17      markus    418:                        value = 1;
1.38      provos    419:                else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
1.17      markus    420:                        value = 0;
1.38      provos    421:                else if (strcmp(arg, "ask") == 0)
1.17      markus    422:                        value = 2;
                    423:                else
                    424:                        fatal("%.200s line %d: Bad yes/no/ask argument.", filename, linenum);
                    425:                if (*activep && *intptr == -1)
                    426:                        *intptr = value;
                    427:                break;
                    428:
                    429:        case oCompression:
                    430:                intptr = &options->compression;
                    431:                goto parse_flag;
                    432:
1.126     markus    433:        case oTCPKeepAlive:
                    434:                intptr = &options->tcp_keep_alive;
1.17      markus    435:                goto parse_flag;
                    436:
1.91      markus    437:        case oNoHostAuthenticationForLocalhost:
                    438:                intptr = &options->no_host_authentication_for_localhost;
                    439:                goto parse_flag;
                    440:
1.17      markus    441:        case oNumberOfPasswordPrompts:
                    442:                intptr = &options->number_of_password_prompts;
                    443:                goto parse_int;
                    444:
                    445:        case oCompressionLevel:
                    446:                intptr = &options->compression_level;
                    447:                goto parse_int;
                    448:
1.105     markus    449:        case oRekeyLimit:
                    450:                intptr = &options->rekey_limit;
                    451:                arg = strdelim(&s);
                    452:                if (!arg || *arg == '\0')
                    453:                        fatal("%.200s line %d: Missing argument.", filename, linenum);
                    454:                if (arg[0] < '0' || arg[0] > '9')
                    455:                        fatal("%.200s line %d: Bad number.", filename, linenum);
                    456:                value = strtol(arg, &endofnumber, 10);
                    457:                if (arg == endofnumber)
                    458:                        fatal("%.200s line %d: Bad number.", filename, linenum);
                    459:                switch (toupper(*endofnumber)) {
                    460:                case 'K':
                    461:                        value *= 1<<10;
                    462:                        break;
                    463:                case 'M':
                    464:                        value *= 1<<20;
                    465:                        break;
                    466:                case 'G':
                    467:                        value *= 1<<30;
                    468:                        break;
                    469:                }
                    470:                if (*activep && *intptr == -1)
                    471:                        *intptr = value;
                    472:                break;
                    473:
1.17      markus    474:        case oIdentityFile:
1.42      provos    475:                arg = strdelim(&s);
1.40      ho        476:                if (!arg || *arg == '\0')
1.17      markus    477:                        fatal("%.200s line %d: Missing argument.", filename, linenum);
                    478:                if (*activep) {
1.50      markus    479:                        intptr = &options->num_identity_files;
1.27      markus    480:                        if (*intptr >= SSH_MAX_IDENTITY_FILES)
1.17      markus    481:                                fatal("%.200s line %d: Too many identity files specified (max %d).",
1.93      deraadt   482:                                    filename, linenum, SSH_MAX_IDENTITY_FILES);
1.50      markus    483:                        charptr =  &options->identity_files[*intptr];
1.38      provos    484:                        *charptr = xstrdup(arg);
1.27      markus    485:                        *intptr = *intptr + 1;
1.17      markus    486:                }
                    487:                break;
                    488:
1.34      markus    489:        case oXAuthLocation:
                    490:                charptr=&options->xauth_location;
                    491:                goto parse_string;
                    492:
1.17      markus    493:        case oUser:
                    494:                charptr = &options->user;
                    495: parse_string:
1.42      provos    496:                arg = strdelim(&s);
1.40      ho        497:                if (!arg || *arg == '\0')
1.17      markus    498:                        fatal("%.200s line %d: Missing argument.", filename, linenum);
                    499:                if (*activep && *charptr == NULL)
1.38      provos    500:                        *charptr = xstrdup(arg);
1.17      markus    501:                break;
                    502:
                    503:        case oGlobalKnownHostsFile:
                    504:                charptr = &options->system_hostfile;
                    505:                goto parse_string;
                    506:
                    507:        case oUserKnownHostsFile:
                    508:                charptr = &options->user_hostfile;
                    509:                goto parse_string;
                    510:
1.27      markus    511:        case oGlobalKnownHostsFile2:
                    512:                charptr = &options->system_hostfile2;
                    513:                goto parse_string;
                    514:
                    515:        case oUserKnownHostsFile2:
                    516:                charptr = &options->user_hostfile2;
                    517:                goto parse_string;
                    518:
1.17      markus    519:        case oHostName:
                    520:                charptr = &options->hostname;
                    521:                goto parse_string;
                    522:
1.52      markus    523:        case oHostKeyAlias:
                    524:                charptr = &options->host_key_alias;
                    525:                goto parse_string;
                    526:
1.67      markus    527:        case oPreferredAuthentications:
                    528:                charptr = &options->preferred_authentications;
                    529:                goto parse_string;
                    530:
1.77      markus    531:        case oBindAddress:
                    532:                charptr = &options->bind_address;
                    533:                goto parse_string;
                    534:
1.85      jakob     535:        case oSmartcardDevice:
1.86      markus    536:                charptr = &options->smartcard_device;
                    537:                goto parse_string;
1.85      jakob     538:
1.17      markus    539:        case oProxyCommand:
1.113     markus    540:                if (s == NULL)
                    541:                        fatal("%.200s line %d: Missing argument.", filename, linenum);
1.17      markus    542:                charptr = &options->proxy_command;
1.102     markus    543:                len = strspn(s, WHITESPACE "=");
1.17      markus    544:                if (*activep && *charptr == NULL)
1.102     markus    545:                        *charptr = xstrdup(s + len);
1.17      markus    546:                return 0;
                    547:
                    548:        case oPort:
                    549:                intptr = &options->port;
                    550: parse_int:
1.42      provos    551:                arg = strdelim(&s);
1.40      ho        552:                if (!arg || *arg == '\0')
1.17      markus    553:                        fatal("%.200s line %d: Missing argument.", filename, linenum);
1.38      provos    554:                if (arg[0] < '0' || arg[0] > '9')
1.17      markus    555:                        fatal("%.200s line %d: Bad number.", filename, linenum);
1.21      markus    556:
                    557:                /* Octal, decimal, or hex format? */
1.38      provos    558:                value = strtol(arg, &endofnumber, 0);
                    559:                if (arg == endofnumber)
1.21      markus    560:                        fatal("%.200s line %d: Bad number.", filename, linenum);
1.17      markus    561:                if (*activep && *intptr == -1)
                    562:                        *intptr = value;
                    563:                break;
                    564:
                    565:        case oConnectionAttempts:
                    566:                intptr = &options->connection_attempts;
                    567:                goto parse_int;
                    568:
                    569:        case oCipher:
                    570:                intptr = &options->cipher;
1.42      provos    571:                arg = strdelim(&s);
1.40      ho        572:                if (!arg || *arg == '\0')
1.32      markus    573:                        fatal("%.200s line %d: Missing argument.", filename, linenum);
1.38      provos    574:                value = cipher_number(arg);
1.17      markus    575:                if (value == -1)
                    576:                        fatal("%.200s line %d: Bad cipher '%s'.",
1.93      deraadt   577:                            filename, linenum, arg ? arg : "<NONE>");
1.17      markus    578:                if (*activep && *intptr == -1)
                    579:                        *intptr = value;
                    580:                break;
                    581:
1.25      markus    582:        case oCiphers:
1.42      provos    583:                arg = strdelim(&s);
1.40      ho        584:                if (!arg || *arg == '\0')
1.32      markus    585:                        fatal("%.200s line %d: Missing argument.", filename, linenum);
1.38      provos    586:                if (!ciphers_valid(arg))
1.31      markus    587:                        fatal("%.200s line %d: Bad SSH2 cipher spec '%s'.",
1.93      deraadt   588:                            filename, linenum, arg ? arg : "<NONE>");
1.25      markus    589:                if (*activep && options->ciphers == NULL)
1.38      provos    590:                        options->ciphers = xstrdup(arg);
1.25      markus    591:                break;
                    592:
1.62      markus    593:        case oMacs:
                    594:                arg = strdelim(&s);
                    595:                if (!arg || *arg == '\0')
                    596:                        fatal("%.200s line %d: Missing argument.", filename, linenum);
                    597:                if (!mac_valid(arg))
                    598:                        fatal("%.200s line %d: Bad SSH2 Mac spec '%s'.",
1.93      deraadt   599:                            filename, linenum, arg ? arg : "<NONE>");
1.62      markus    600:                if (*activep && options->macs == NULL)
                    601:                        options->macs = xstrdup(arg);
                    602:                break;
                    603:
1.76      markus    604:        case oHostKeyAlgorithms:
                    605:                arg = strdelim(&s);
                    606:                if (!arg || *arg == '\0')
                    607:                        fatal("%.200s line %d: Missing argument.", filename, linenum);
                    608:                if (!key_names_valid2(arg))
                    609:                        fatal("%.200s line %d: Bad protocol 2 host key algorithms '%s'.",
1.93      deraadt   610:                            filename, linenum, arg ? arg : "<NONE>");
1.76      markus    611:                if (*activep && options->hostkeyalgorithms == NULL)
                    612:                        options->hostkeyalgorithms = xstrdup(arg);
                    613:                break;
                    614:
1.25      markus    615:        case oProtocol:
                    616:                intptr = &options->protocol;
1.42      provos    617:                arg = strdelim(&s);
1.40      ho        618:                if (!arg || *arg == '\0')
1.32      markus    619:                        fatal("%.200s line %d: Missing argument.", filename, linenum);
1.38      provos    620:                value = proto_spec(arg);
1.25      markus    621:                if (value == SSH_PROTO_UNKNOWN)
                    622:                        fatal("%.200s line %d: Bad protocol spec '%s'.",
1.93      deraadt   623:                            filename, linenum, arg ? arg : "<NONE>");
1.25      markus    624:                if (*activep && *intptr == SSH_PROTO_UNKNOWN)
                    625:                        *intptr = value;
                    626:                break;
                    627:
1.17      markus    628:        case oLogLevel:
                    629:                intptr = (int *) &options->log_level;
1.42      provos    630:                arg = strdelim(&s);
1.38      provos    631:                value = log_level_number(arg);
1.95      markus    632:                if (value == SYSLOG_LEVEL_NOT_SET)
1.64      millert   633:                        fatal("%.200s line %d: unsupported log level '%s'",
1.93      deraadt   634:                            filename, linenum, arg ? arg : "<NONE>");
1.95      markus    635:                if (*activep && (LogLevel) *intptr == SYSLOG_LEVEL_NOT_SET)
1.17      markus    636:                        *intptr = (LogLevel) value;
                    637:                break;
                    638:
1.88      stevesk   639:        case oLocalForward:
1.17      markus    640:        case oRemoteForward:
1.42      provos    641:                arg = strdelim(&s);
1.40      ho        642:                if (!arg || *arg == '\0')
1.88      stevesk   643:                        fatal("%.200s line %d: Missing port argument.",
                    644:                            filename, linenum);
                    645:                if ((fwd_port = a2port(arg)) == 0)
                    646:                        fatal("%.200s line %d: Bad listen port.",
                    647:                            filename, linenum);
1.42      provos    648:                arg = strdelim(&s);
1.40      ho        649:                if (!arg || *arg == '\0')
1.17      markus    650:                        fatal("%.200s line %d: Missing second argument.",
1.88      stevesk   651:                            filename, linenum);
                    652:                if (sscanf(arg, "%255[^:]:%5[0-9]", buf, sfwd_host_port) != 2 &&
                    653:                    sscanf(arg, "%255[^/]/%5[0-9]", buf, sfwd_host_port) != 2)
                    654:                        fatal("%.200s line %d: Bad forwarding specification.",
                    655:                            filename, linenum);
                    656:                if ((fwd_host_port = a2port(sfwd_host_port)) == 0)
                    657:                        fatal("%.200s line %d: Bad forwarding port.",
                    658:                            filename, linenum);
                    659:                if (*activep) {
                    660:                        if (opcode == oLocalForward)
                    661:                                add_local_forward(options, fwd_port, buf,
                    662:                                    fwd_host_port);
                    663:                        else if (opcode == oRemoteForward)
                    664:                                add_remote_forward(options, fwd_port, buf,
                    665:                                    fwd_host_port);
                    666:                }
1.17      markus    667:                break;
1.71      markus    668:
                    669:        case oDynamicForward:
                    670:                arg = strdelim(&s);
                    671:                if (!arg || *arg == '\0')
                    672:                        fatal("%.200s line %d: Missing port argument.",
                    673:                            filename, linenum);
1.74      stevesk   674:                fwd_port = a2port(arg);
                    675:                if (fwd_port == 0)
1.71      markus    676:                        fatal("%.200s line %d: Badly formatted port number.",
                    677:                            filename, linenum);
1.87      markus    678:                if (*activep)
1.117     markus    679:                        add_local_forward(options, fwd_port, "socks", 0);
1.72      markus    680:                break;
1.17      markus    681:
1.90      stevesk   682:        case oClearAllForwardings:
                    683:                intptr = &options->clear_forwardings;
                    684:                goto parse_flag;
                    685:
1.17      markus    686:        case oHost:
                    687:                *activep = 0;
1.42      provos    688:                while ((arg = strdelim(&s)) != NULL && *arg != '\0')
1.38      provos    689:                        if (match_pattern(host, arg)) {
                    690:                                debug("Applying options for %.100s", arg);
1.17      markus    691:                                *activep = 1;
                    692:                                break;
                    693:                        }
1.42      provos    694:                /* Avoid garbage check below, as strdelim is done. */
1.17      markus    695:                return 0;
                    696:
                    697:        case oEscapeChar:
                    698:                intptr = &options->escape_char;
1.42      provos    699:                arg = strdelim(&s);
1.40      ho        700:                if (!arg || *arg == '\0')
1.17      markus    701:                        fatal("%.200s line %d: Missing argument.", filename, linenum);
1.38      provos    702:                if (arg[0] == '^' && arg[2] == 0 &&
1.51      markus    703:                    (u_char) arg[1] >= 64 && (u_char) arg[1] < 128)
                    704:                        value = (u_char) arg[1] & 31;
1.38      provos    705:                else if (strlen(arg) == 1)
1.51      markus    706:                        value = (u_char) arg[0];
1.38      provos    707:                else if (strcmp(arg, "none") == 0)
1.79      stevesk   708:                        value = SSH_ESCAPECHAR_NONE;
1.17      markus    709:                else {
                    710:                        fatal("%.200s line %d: Bad escape character.",
1.93      deraadt   711:                            filename, linenum);
1.17      markus    712:                        /* NOTREACHED */
                    713:                        value = 0;      /* Avoid compiler warning. */
                    714:                }
                    715:                if (*activep && *intptr == -1)
                    716:                        *intptr = value;
1.112     djm       717:                break;
                    718:
                    719:        case oAddressFamily:
                    720:                arg = strdelim(&s);
1.114     djm       721:                intptr = &options->address_family;
1.112     djm       722:                if (strcasecmp(arg, "inet") == 0)
1.114     djm       723:                        value = AF_INET;
1.112     djm       724:                else if (strcasecmp(arg, "inet6") == 0)
1.114     djm       725:                        value = AF_INET6;
1.112     djm       726:                else if (strcasecmp(arg, "any") == 0)
1.114     djm       727:                        value = AF_UNSPEC;
1.112     djm       728:                else
                    729:                        fatal("Unsupported AddressFamily \"%s\"", arg);
1.114     djm       730:                if (*activep && *intptr == -1)
                    731:                        *intptr = value;
1.17      markus    732:                break;
                    733:
1.101     markus    734:        case oEnableSSHKeysign:
                    735:                intptr = &options->enable_ssh_keysign;
                    736:                goto parse_flag;
                    737:
1.128     markus    738:        case oIdentitiesOnly:
                    739:                intptr = &options->identities_only;
                    740:                goto parse_flag;
                    741:
1.127     markus    742:        case oServerAliveInterval:
                    743:                intptr = &options->server_alive_interval;
                    744:                goto parse_time;
                    745:
                    746:        case oServerAliveCountMax:
                    747:                intptr = &options->server_alive_count_max;
                    748:                goto parse_int;
                    749:
1.96      markus    750:        case oDeprecated:
1.98      markus    751:                debug("%s line %d: Deprecated option \"%s\"",
1.96      markus    752:                    filename, linenum, keyword);
1.98      markus    753:                return 0;
1.96      markus    754:
1.110     jakob     755:        case oUnsupported:
                    756:                error("%s line %d: Unsupported option \"%s\"",
                    757:                    filename, linenum, keyword);
                    758:                return 0;
                    759:
1.17      markus    760:        default:
                    761:                fatal("process_config_line: Unimplemented opcode %d", opcode);
                    762:        }
                    763:
                    764:        /* Check that there is no garbage at end of line. */
1.57      djm       765:        if ((arg = strdelim(&s)) != NULL && *arg != '\0') {
1.39      ho        766:                fatal("%.200s line %d: garbage at end of line; \"%.200s\".",
1.93      deraadt   767:                     filename, linenum, arg);
1.39      ho        768:        }
1.17      markus    769:        return 0;
1.1       deraadt   770: }
                    771:
                    772:
1.19      markus    773: /*
                    774:  * Reads the config file and modifies the options accordingly.  Options
                    775:  * should already be initialized before this call.  This never returns if
1.89      stevesk   776:  * there is an error.  If the file does not exist, this returns 0.
1.19      markus    777:  */
1.1       deraadt   778:
1.89      stevesk   779: int
1.129   ! djm       780: read_config_file(const char *filename, const char *host, Options *options,
        !           781:     int checkperm)
1.1       deraadt   782: {
1.17      markus    783:        FILE *f;
                    784:        char line[1024];
                    785:        int active, linenum;
                    786:        int bad_options = 0;
                    787:
                    788:        /* Open the file. */
1.129   ! djm       789:        if ((f = fopen(filename, "r")) == NULL)
1.89      stevesk   790:                return 0;
1.129   ! djm       791:
        !           792:        if (checkperm) {
        !           793:                struct stat sb;
        !           794:
        !           795:                if (fstat(fileno(f), &sb) == -1) {
        !           796:                        fatal("fstat %s: %s", filename, strerror(errno));
        !           797:                        fclose(f);
        !           798:                        return (0);
        !           799:                }
        !           800:                if (((sb.st_uid != 0 && sb.st_uid != getuid()) ||
        !           801:                    (sb.st_mode & 022) != 0)) {
        !           802:                        fatal("Bad owner or permissions on %s", filename);
        !           803:                        return 0;
        !           804:                }
        !           805:        }
1.17      markus    806:
                    807:        debug("Reading configuration data %.200s", filename);
                    808:
1.19      markus    809:        /*
                    810:         * Mark that we are now processing the options.  This flag is turned
                    811:         * on/off by Host specifications.
                    812:         */
1.17      markus    813:        active = 1;
                    814:        linenum = 0;
                    815:        while (fgets(line, sizeof(line), f)) {
                    816:                /* Update line number counter. */
                    817:                linenum++;
                    818:                if (process_config_line(options, host, line, filename, linenum, &active) != 0)
                    819:                        bad_options++;
                    820:        }
                    821:        fclose(f);
                    822:        if (bad_options > 0)
1.64      millert   823:                fatal("%s: terminating, %d bad configuration options",
1.93      deraadt   824:                    filename, bad_options);
1.89      stevesk   825:        return 1;
1.1       deraadt   826: }
                    827:
1.19      markus    828: /*
                    829:  * Initializes options to special values that indicate that they have not yet
                    830:  * been set.  Read_config_file will only set options with this value. Options
                    831:  * are processed in the following order: command line, user config file,
                    832:  * system config file.  Last, fill_default_options is called.
                    833:  */
1.1       deraadt   834:
1.26      markus    835: void
1.17      markus    836: initialize_options(Options * options)
1.1       deraadt   837: {
1.17      markus    838:        memset(options, 'X', sizeof(*options));
                    839:        options->forward_agent = -1;
                    840:        options->forward_x11 = -1;
1.123     markus    841:        options->forward_x11_trusted = -1;
1.34      markus    842:        options->xauth_location = NULL;
1.17      markus    843:        options->gateway_ports = -1;
                    844:        options->use_privileged_port = -1;
                    845:        options->rsa_authentication = -1;
1.50      markus    846:        options->pubkey_authentication = -1;
1.78      markus    847:        options->challenge_response_authentication = -1;
1.118     markus    848:        options->gss_authentication = -1;
                    849:        options->gss_deleg_creds = -1;
1.17      markus    850:        options->password_authentication = -1;
1.48      markus    851:        options->kbd_interactive_authentication = -1;
                    852:        options->kbd_interactive_devices = NULL;
1.17      markus    853:        options->rhosts_rsa_authentication = -1;
1.72      markus    854:        options->hostbased_authentication = -1;
1.17      markus    855:        options->batch_mode = -1;
                    856:        options->check_host_ip = -1;
                    857:        options->strict_host_key_checking = -1;
                    858:        options->compression = -1;
1.126     markus    859:        options->tcp_keep_alive = -1;
1.17      markus    860:        options->compression_level = -1;
                    861:        options->port = -1;
1.114     djm       862:        options->address_family = -1;
1.17      markus    863:        options->connection_attempts = -1;
1.111     djm       864:        options->connection_timeout = -1;
1.17      markus    865:        options->number_of_password_prompts = -1;
                    866:        options->cipher = -1;
1.25      markus    867:        options->ciphers = NULL;
1.62      markus    868:        options->macs = NULL;
1.76      markus    869:        options->hostkeyalgorithms = NULL;
1.25      markus    870:        options->protocol = SSH_PROTO_UNKNOWN;
1.17      markus    871:        options->num_identity_files = 0;
                    872:        options->hostname = NULL;
1.52      markus    873:        options->host_key_alias = NULL;
1.17      markus    874:        options->proxy_command = NULL;
                    875:        options->user = NULL;
                    876:        options->escape_char = -1;
                    877:        options->system_hostfile = NULL;
                    878:        options->user_hostfile = NULL;
1.27      markus    879:        options->system_hostfile2 = NULL;
                    880:        options->user_hostfile2 = NULL;
1.17      markus    881:        options->num_local_forwards = 0;
                    882:        options->num_remote_forwards = 0;
1.90      stevesk   883:        options->clear_forwardings = -1;
1.95      markus    884:        options->log_level = SYSLOG_LEVEL_NOT_SET;
1.67      markus    885:        options->preferred_authentications = NULL;
1.77      markus    886:        options->bind_address = NULL;
1.86      markus    887:        options->smartcard_device = NULL;
1.101     markus    888:        options->enable_ssh_keysign = - 1;
1.91      markus    889:        options->no_host_authentication_for_localhost = - 1;
1.128     markus    890:        options->identities_only = - 1;
1.105     markus    891:        options->rekey_limit = - 1;
1.107     jakob     892:        options->verify_host_key_dns = -1;
1.127     markus    893:        options->server_alive_interval = -1;
                    894:        options->server_alive_count_max = -1;
1.1       deraadt   895: }
                    896:
1.19      markus    897: /*
                    898:  * Called after processing other sources of option data, this fills those
                    899:  * options for which no value has been specified with their default values.
                    900:  */
1.1       deraadt   901:
1.26      markus    902: void
1.17      markus    903: fill_default_options(Options * options)
1.1       deraadt   904: {
1.61      deraadt   905:        int len;
                    906:
1.17      markus    907:        if (options->forward_agent == -1)
1.33      markus    908:                options->forward_agent = 0;
1.17      markus    909:        if (options->forward_x11 == -1)
1.23      markus    910:                options->forward_x11 = 0;
1.123     markus    911:        if (options->forward_x11_trusted == -1)
                    912:                options->forward_x11_trusted = 0;
1.34      markus    913:        if (options->xauth_location == NULL)
1.80      markus    914:                options->xauth_location = _PATH_XAUTH;
1.17      markus    915:        if (options->gateway_ports == -1)
                    916:                options->gateway_ports = 0;
                    917:        if (options->use_privileged_port == -1)
1.65      markus    918:                options->use_privileged_port = 0;
1.17      markus    919:        if (options->rsa_authentication == -1)
                    920:                options->rsa_authentication = 1;
1.50      markus    921:        if (options->pubkey_authentication == -1)
                    922:                options->pubkey_authentication = 1;
1.78      markus    923:        if (options->challenge_response_authentication == -1)
1.83      markus    924:                options->challenge_response_authentication = 1;
1.118     markus    925:        if (options->gss_authentication == -1)
1.122     markus    926:                options->gss_authentication = 0;
1.118     markus    927:        if (options->gss_deleg_creds == -1)
                    928:                options->gss_deleg_creds = 0;
1.17      markus    929:        if (options->password_authentication == -1)
                    930:                options->password_authentication = 1;
1.48      markus    931:        if (options->kbd_interactive_authentication == -1)
1.59      markus    932:                options->kbd_interactive_authentication = 1;
1.17      markus    933:        if (options->rhosts_rsa_authentication == -1)
1.99      stevesk   934:                options->rhosts_rsa_authentication = 0;
1.72      markus    935:        if (options->hostbased_authentication == -1)
                    936:                options->hostbased_authentication = 0;
1.17      markus    937:        if (options->batch_mode == -1)
                    938:                options->batch_mode = 0;
                    939:        if (options->check_host_ip == -1)
                    940:                options->check_host_ip = 1;
                    941:        if (options->strict_host_key_checking == -1)
                    942:                options->strict_host_key_checking = 2;  /* 2 is default */
                    943:        if (options->compression == -1)
                    944:                options->compression = 0;
1.126     markus    945:        if (options->tcp_keep_alive == -1)
                    946:                options->tcp_keep_alive = 1;
1.17      markus    947:        if (options->compression_level == -1)
                    948:                options->compression_level = 6;
                    949:        if (options->port == -1)
                    950:                options->port = 0;      /* Filled in ssh_connect. */
1.114     djm       951:        if (options->address_family == -1)
                    952:                options->address_family = AF_UNSPEC;
1.17      markus    953:        if (options->connection_attempts == -1)
1.84      markus    954:                options->connection_attempts = 1;
1.17      markus    955:        if (options->number_of_password_prompts == -1)
                    956:                options->number_of_password_prompts = 3;
                    957:        /* Selected in ssh_login(). */
                    958:        if (options->cipher == -1)
                    959:                options->cipher = SSH_CIPHER_NOT_SET;
1.31      markus    960:        /* options->ciphers, default set in myproposals.h */
1.62      markus    961:        /* options->macs, default set in myproposals.h */
1.76      markus    962:        /* options->hostkeyalgorithms, default set in myproposals.h */
1.25      markus    963:        if (options->protocol == SSH_PROTO_UNKNOWN)
1.69      markus    964:                options->protocol = SSH_PROTO_1|SSH_PROTO_2;
1.17      markus    965:        if (options->num_identity_files == 0) {
1.50      markus    966:                if (options->protocol & SSH_PROTO_1) {
1.61      deraadt   967:                        len = 2 + strlen(_PATH_SSH_CLIENT_IDENTITY) + 1;
1.50      markus    968:                        options->identity_files[options->num_identity_files] =
1.61      deraadt   969:                            xmalloc(len);
                    970:                        snprintf(options->identity_files[options->num_identity_files++],
                    971:                            len, "~/%.100s", _PATH_SSH_CLIENT_IDENTITY);
1.50      markus    972:                }
                    973:                if (options->protocol & SSH_PROTO_2) {
1.63      deraadt   974:                        len = 2 + strlen(_PATH_SSH_CLIENT_ID_RSA) + 1;
                    975:                        options->identity_files[options->num_identity_files] =
                    976:                            xmalloc(len);
                    977:                        snprintf(options->identity_files[options->num_identity_files++],
                    978:                            len, "~/%.100s", _PATH_SSH_CLIENT_ID_RSA);
                    979:
1.61      deraadt   980:                        len = 2 + strlen(_PATH_SSH_CLIENT_ID_DSA) + 1;
1.50      markus    981:                        options->identity_files[options->num_identity_files] =
1.61      deraadt   982:                            xmalloc(len);
                    983:                        snprintf(options->identity_files[options->num_identity_files++],
                    984:                            len, "~/%.100s", _PATH_SSH_CLIENT_ID_DSA);
1.50      markus    985:                }
1.27      markus    986:        }
1.17      markus    987:        if (options->escape_char == -1)
                    988:                options->escape_char = '~';
                    989:        if (options->system_hostfile == NULL)
1.55      markus    990:                options->system_hostfile = _PATH_SSH_SYSTEM_HOSTFILE;
1.17      markus    991:        if (options->user_hostfile == NULL)
1.55      markus    992:                options->user_hostfile = _PATH_SSH_USER_HOSTFILE;
1.27      markus    993:        if (options->system_hostfile2 == NULL)
1.55      markus    994:                options->system_hostfile2 = _PATH_SSH_SYSTEM_HOSTFILE2;
1.27      markus    995:        if (options->user_hostfile2 == NULL)
1.55      markus    996:                options->user_hostfile2 = _PATH_SSH_USER_HOSTFILE2;
1.95      markus    997:        if (options->log_level == SYSLOG_LEVEL_NOT_SET)
1.54      markus    998:                options->log_level = SYSLOG_LEVEL_INFO;
1.90      stevesk   999:        if (options->clear_forwardings == 1)
                   1000:                clear_forwardings(options);
1.91      markus   1001:        if (options->no_host_authentication_for_localhost == - 1)
                   1002:                options->no_host_authentication_for_localhost = 0;
1.128     markus   1003:        if (options->identities_only == -1)
                   1004:                options->identities_only = 0;
1.101     markus   1005:        if (options->enable_ssh_keysign == -1)
                   1006:                options->enable_ssh_keysign = 0;
1.105     markus   1007:        if (options->rekey_limit == -1)
                   1008:                options->rekey_limit = 0;
1.107     jakob    1009:        if (options->verify_host_key_dns == -1)
                   1010:                options->verify_host_key_dns = 0;
1.127     markus   1011:        if (options->server_alive_interval == -1)
                   1012:                options->server_alive_interval = 0;
                   1013:        if (options->server_alive_count_max == -1)
                   1014:                options->server_alive_count_max = 3;
1.17      markus   1015:        /* options->proxy_command should not be set by default */
                   1016:        /* options->user will be set in the main program if appropriate */
                   1017:        /* options->hostname will be set in the main program if appropriate */
1.52      markus   1018:        /* options->host_key_alias should not be set by default */
1.67      markus   1019:        /* options->preferred_authentications will be set in ssh */
1.1       deraadt  1020: }