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

1.1       deraadt     1: /*
                      2:
                      3: readconf.c
                      4:
                      5: Author: Tatu Ylonen <ylo@cs.hut.fi>
                      6:
                      7: Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
                      8:                    All rights reserved
                      9:
                     10: Created: Sat Apr 22 00:03:10 1995 ylo
                     11:
                     12: Functions for reading the configuration files.
                     13:
                     14: */
                     15:
                     16: #include "includes.h"
1.16    ! markus     17: RCSID("$Id: readconf.c,v 1.15 1999/11/19 16:04:17 markus Exp $");
1.1       deraadt    18:
                     19: #include "ssh.h"
                     20: #include "cipher.h"
                     21: #include "readconf.h"
                     22: #include "xmalloc.h"
                     23:
                     24: /* Format of the configuration file:
                     25:
                     26:    # Configuration data is parsed as follows:
                     27:    #  1. command line options
                     28:    #  2. user-specific file
                     29:    #  3. system-wide file
                     30:    # Any configuration value is only changed the first time it is set.
                     31:    # Thus, host-specific definitions should be at the beginning of the
                     32:    # configuration file, and defaults at the end.
                     33:
                     34:    # Host-specific declarations.  These may override anything above.  A single
                     35:    # host may match multiple declarations; these are processed in the order
                     36:    # that they are given in.
                     37:
                     38:    Host *.ngs.fi ngs.fi
                     39:      FallBackToRsh no
                     40:
                     41:    Host fake.com
                     42:      HostName another.host.name.real.org
                     43:      User blaah
                     44:      Port 34289
                     45:      ForwardX11 no
                     46:      ForwardAgent no
                     47:
                     48:    Host books.com
                     49:      RemoteForward 9999 shadows.cs.hut.fi:9999
                     50:      Cipher 3des
                     51:
                     52:    Host fascist.blob.com
                     53:      Port 23123
                     54:      User tylonen
                     55:      RhostsAuthentication no
                     56:      PasswordAuthentication no
                     57:
                     58:    Host puukko.hut.fi
                     59:      User t35124p
                     60:      ProxyCommand ssh-proxy %h %p
                     61:
                     62:    Host *.fr
                     63:      UseRsh yes
                     64:
                     65:    Host *.su
                     66:      Cipher none
                     67:      PasswordAuthentication no
                     68:
                     69:    # Defaults for various options
                     70:    Host *
                     71:      ForwardAgent no
                     72:      ForwardX11 yes
                     73:      RhostsAuthentication yes
                     74:      PasswordAuthentication yes
                     75:      RSAAuthentication yes
                     76:      RhostsRSAAuthentication yes
                     77:      FallBackToRsh no
                     78:      UseRsh no
                     79:      StrictHostKeyChecking yes
                     80:      KeepAlives no
                     81:      IdentityFile ~/.ssh/identity
                     82:      Port 22
                     83:      EscapeChar ~
                     84:
                     85: */
                     86:
                     87: /* Keyword tokens. */
                     88:
                     89: typedef enum
                     90: {
1.14      markus     91:   oBadOption,
1.3       deraadt    92:   oForwardAgent, oForwardX11, oGatewayPorts, oRhostsAuthentication,
1.1       deraadt    93:   oPasswordAuthentication, oRSAAuthentication, oFallBackToRsh, oUseRsh,
1.16    ! markus     94:   oSkeyAuthentication,
1.1       deraadt    95: #ifdef KRB4
                     96:   oKerberosAuthentication,
                     97: #endif /* KRB4 */
                     98: #ifdef AFS
1.5       dugsong    99:   oKerberosTgtPassing, oAFSTokenPassing,
1.1       deraadt   100: #endif
                    101:   oIdentityFile, oHostName, oPort, oCipher, oRemoteForward, oLocalForward,
                    102:   oUser, oHost, oEscapeChar, oRhostsRSAAuthentication, oProxyCommand,
                    103:   oGlobalKnownHostsFile, oUserKnownHostsFile, oConnectionAttempts,
1.8       provos    104:   oBatchMode, oCheckHostIP, oStrictHostKeyChecking, oCompression,
1.11      markus    105:   oCompressionLevel, oKeepAlives, oNumberOfPasswordPrompts, oTISAuthentication,
1.13      markus    106:   oUsePrivilegedPort, oLogLevel
1.1       deraadt   107: } OpCodes;
                    108:
                    109: /* Textual representations of the tokens. */
                    110:
                    111: static struct
                    112: {
                    113:   const char *name;
                    114:   OpCodes opcode;
                    115: } keywords[] =
                    116: {
                    117:   { "forwardagent", oForwardAgent },
                    118:   { "forwardx11", oForwardX11 },
1.3       deraadt   119:   { "gatewayports", oGatewayPorts },
1.12      markus    120:   { "useprivilegedport", oUsePrivilegedPort },
1.1       deraadt   121:   { "rhostsauthentication", oRhostsAuthentication },
                    122:   { "passwordauthentication", oPasswordAuthentication },
                    123:   { "rsaauthentication", oRSAAuthentication },
1.16    ! markus    124:   { "skeyauthentication", oSkeyAuthentication },
1.1       deraadt   125: #ifdef KRB4
                    126:   { "kerberosauthentication", oKerberosAuthentication },
                    127: #endif /* KRB4 */
1.5       dugsong   128: #ifdef AFS
1.1       deraadt   129:   { "kerberostgtpassing", oKerberosTgtPassing },
                    130:   { "afstokenpassing", oAFSTokenPassing },
                    131: #endif
                    132:   { "fallbacktorsh", oFallBackToRsh },
                    133:   { "usersh", oUseRsh },
                    134:   { "identityfile", oIdentityFile },
                    135:   { "hostname", oHostName },
                    136:   { "proxycommand", oProxyCommand },
                    137:   { "port", oPort },
                    138:   { "cipher", oCipher },
                    139:   { "remoteforward", oRemoteForward },
                    140:   { "localforward", oLocalForward },
                    141:   { "user", oUser },
                    142:   { "host", oHost },
                    143:   { "escapechar", oEscapeChar },
                    144:   { "rhostsrsaauthentication", oRhostsRSAAuthentication },
                    145:   { "globalknownhostsfile", oGlobalKnownHostsFile },
                    146:   { "userknownhostsfile", oUserKnownHostsFile },
                    147:   { "connectionattempts", oConnectionAttempts },
                    148:   { "batchmode", oBatchMode },
1.8       provos    149:   { "checkhostip", oCheckHostIP },
1.1       deraadt   150:   { "stricthostkeychecking", oStrictHostKeyChecking },
                    151:   { "compression", oCompression },
                    152:   { "compressionlevel", oCompressionLevel },
                    153:   { "keepalive", oKeepAlives },
1.10      dugsong   154:   { "numberofpasswordprompts", oNumberOfPasswordPrompts },
1.1       deraadt   155:   { "tisauthentication", oTISAuthentication },
1.13      markus    156:   { "loglevel", oLogLevel },
                    157:   { NULL, 0 }
                    158: };
                    159:
1.1       deraadt   160: /* Characters considered whitespace in strtok calls. */
                    161: #define WHITESPACE " \t\r\n"
                    162:
                    163:
                    164: /* Adds a local TCP/IP port forward to options.  Never returns if there
                    165:    is an error. */
                    166:
                    167: void add_local_forward(Options *options, int port, const char *host,
                    168:                       int host_port)
                    169: {
                    170:   Forward *fwd;
1.4       deraadt   171:   extern uid_t original_real_uid;
                    172:   if ((port & 0xffff) != port)
                    173:     fatal("Requested forwarding of nonexistent port %d.", port);
1.7       deraadt   174:   if (port < IPPORT_RESERVED && original_real_uid != 0)
1.4       deraadt   175:     fatal("Privileged ports can only be forwarded by root.\n");
1.1       deraadt   176:   if (options->num_local_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION)
                    177:     fatal("Too many local forwards (max %d).", SSH_MAX_FORWARDS_PER_DIRECTION);
                    178:   fwd = &options->local_forwards[options->num_local_forwards++];
                    179:   fwd->port = port;
                    180:   fwd->host = xstrdup(host);
                    181:   fwd->host_port = host_port;
                    182: }
                    183:
                    184: /* Adds a remote TCP/IP port forward to options.  Never returns if there
                    185:    is an error. */
                    186:
                    187: void add_remote_forward(Options *options, int port, const char *host,
                    188:                       int host_port)
                    189: {
                    190:   Forward *fwd;
                    191:   if (options->num_remote_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION)
                    192:     fatal("Too many remote forwards (max %d).",
                    193:          SSH_MAX_FORWARDS_PER_DIRECTION);
                    194:   fwd = &options->remote_forwards[options->num_remote_forwards++];
                    195:   fwd->port = port;
                    196:   fwd->host = xstrdup(host);
                    197:   fwd->host_port = host_port;
                    198: }
                    199:
                    200: /* Returns the number of the token pointed to by cp of length len.
                    201:    Never returns if the token is not known. */
                    202:
                    203: static OpCodes parse_token(const char *cp, const char *filename, int linenum)
                    204: {
                    205:   unsigned int i;
                    206:
                    207:   for (i = 0; keywords[i].name; i++)
                    208:     if (strcmp(cp, keywords[i].name) == 0)
                    209:       return keywords[i].opcode;
                    210:
1.14      markus    211:   fprintf(stderr, "%s: line %d: Bad configuration option: %s\n",
                    212:          filename, linenum, cp);
                    213:   return oBadOption;
1.1       deraadt   214: }
                    215:
                    216: /* Processes a single option line as used in the configuration files.
                    217:    This only sets those values that have not already been set. */
                    218:
1.14      markus    219: int
                    220: process_config_line(Options *options, const char *host,
1.1       deraadt   221:                         char *line, const char *filename, int linenum,
                    222:                         int *activep)
                    223: {
                    224:   char buf[256], *cp, *string, **charptr;
1.15      markus    225:   int opcode, *intptr, value, fwd_port, fwd_host_port;
1.1       deraadt   226:
                    227:   /* Skip leading whitespace. */
                    228:   cp = line + strspn(line, WHITESPACE);
                    229:   if (!*cp || *cp == '\n' || *cp == '#')
1.14      markus    230:     return 0;
1.1       deraadt   231:
                    232:   /* Get the keyword. (Each line is supposed to begin with a keyword). */
                    233:   cp = strtok(cp, WHITESPACE);
                    234:   {
                    235:     char *t = cp;
                    236:     for (; *t != 0; t++)
                    237:       if ('A' <= *t && *t <= 'Z')
                    238:        *t = *t - 'A' + 'a';    /* tolower */
                    239:
                    240:   }
                    241:   opcode = parse_token(cp, filename, linenum);
                    242:
                    243:   switch (opcode)
                    244:     {
1.14      markus    245:     case oBadOption:
                    246:       return -1;               /* don't panic, but count bad options */
                    247:       /*NOTREACHED*/
1.1       deraadt   248:     case oForwardAgent:
                    249:       intptr = &options->forward_agent;
                    250:     parse_flag:
                    251:       cp = strtok(NULL, WHITESPACE);
                    252:       if (!cp)
                    253:        fatal("%.200s line %d: Missing yes/no argument.", filename, linenum);
                    254:       value = 0; /* To avoid compiler warning... */
                    255:       if (strcmp(cp, "yes") == 0 || strcmp(cp, "true") == 0)
                    256:        value = 1;
                    257:       else if (strcmp(cp, "no") == 0 || strcmp(cp, "false") == 0)
                    258:        value = 0;
                    259:       else
                    260:        fatal("%.200s line %d: Bad yes/no argument.", filename, linenum);
                    261:       if (*activep && *intptr == -1)
                    262:        *intptr = value;
                    263:       break;
                    264:
                    265:     case oForwardX11:
                    266:       intptr = &options->forward_x11;
                    267:       goto parse_flag;
1.3       deraadt   268:
                    269:     case oGatewayPorts:
                    270:       intptr = &options->gateway_ports;
                    271:       goto parse_flag;
1.1       deraadt   272:
1.11      markus    273:     case oUsePrivilegedPort:
                    274:       intptr = &options->use_privileged_port;
                    275:       goto parse_flag;
                    276:
1.1       deraadt   277:     case oRhostsAuthentication:
                    278:       intptr = &options->rhosts_authentication;
                    279:       goto parse_flag;
                    280:
                    281:     case oPasswordAuthentication:
                    282:       intptr = &options->password_authentication;
                    283:       goto parse_flag;
                    284:
                    285:     case oRSAAuthentication:
                    286:       intptr = &options->rsa_authentication;
                    287:       goto parse_flag;
                    288:
                    289:     case oRhostsRSAAuthentication:
                    290:       intptr = &options->rhosts_rsa_authentication;
                    291:       goto parse_flag;
                    292:
1.16    ! markus    293:     case oTISAuthentication:
        !           294:       /* fallthrough, there is no difference on the client side */
        !           295:     case oSkeyAuthentication:
        !           296:       intptr = &options->skey_authentication;
        !           297:       goto parse_flag;
        !           298:
1.1       deraadt   299: #ifdef KRB4
                    300:     case oKerberosAuthentication:
                    301:       intptr = &options->kerberos_authentication;
                    302:       goto parse_flag;
                    303: #endif /* KRB4 */
                    304:
1.5       dugsong   305: #ifdef AFS
1.1       deraadt   306:     case oKerberosTgtPassing:
                    307:       intptr = &options->kerberos_tgt_passing;
                    308:       goto parse_flag;
                    309:
                    310:     case oAFSTokenPassing:
                    311:       intptr = &options->afs_token_passing;
                    312:       goto parse_flag;
                    313: #endif
                    314:
                    315:     case oFallBackToRsh:
                    316:       intptr = &options->fallback_to_rsh;
                    317:       goto parse_flag;
                    318:
                    319:     case oUseRsh:
                    320:       intptr = &options->use_rsh;
                    321:       goto parse_flag;
                    322:
                    323:     case oBatchMode:
                    324:       intptr = &options->batch_mode;
1.9       provos    325:       goto parse_flag;
                    326:
                    327:     case oCheckHostIP:
                    328:       intptr = &options->check_host_ip;
1.1       deraadt   329:       goto parse_flag;
                    330:
                    331:     case oStrictHostKeyChecking:
                    332:       intptr = &options->strict_host_key_checking;
                    333:       cp = strtok(NULL, WHITESPACE);
                    334:       if (!cp)
                    335:        fatal("%.200s line %d: Missing yes/no argument.",
                    336:              filename, linenum);
                    337:       value = 0; /* To avoid compiler warning... */
                    338:       if (strcmp(cp, "yes") == 0 || strcmp(cp, "true") == 0)
                    339:        value = 1;
                    340:       else if (strcmp(cp, "no") == 0 || strcmp(cp, "false") == 0)
                    341:        value = 0;
                    342:       else if (strcmp(cp, "ask") == 0)
                    343:        value = 2;
                    344:       else
                    345:        fatal("%.200s line %d: Bad yes/no/ask argument.", filename, linenum);
                    346:       if (*activep && *intptr == -1)
                    347:        *intptr = value;
                    348:       break;
                    349:
                    350:     case oCompression:
                    351:       intptr = &options->compression;
                    352:       goto parse_flag;
                    353:
                    354:     case oKeepAlives:
                    355:       intptr = &options->keepalives;
                    356:       goto parse_flag;
                    357:
1.10      dugsong   358:     case oNumberOfPasswordPrompts:
                    359:       intptr = &options->number_of_password_prompts;
                    360:       goto parse_int;
1.1       deraadt   361:
                    362:     case oCompressionLevel:
                    363:       intptr = &options->compression_level;
                    364:       goto parse_int;
                    365:
                    366:     case oIdentityFile:
                    367:       cp = strtok(NULL, WHITESPACE);
                    368:       if (!cp)
                    369:        fatal("%.200s line %d: Missing argument.", filename, linenum);
                    370:       if (*activep)
                    371:        {
                    372:          if (options->num_identity_files >= SSH_MAX_IDENTITY_FILES)
                    373:            fatal("%.200s line %d: Too many identity files specified (max %d).",
                    374:                  filename, linenum, SSH_MAX_IDENTITY_FILES);
                    375:          options->identity_files[options->num_identity_files++] = xstrdup(cp);
                    376:        }
                    377:       break;
                    378:
                    379:     case oUser:
                    380:       charptr = &options->user;
                    381:     parse_string:
                    382:       cp = strtok(NULL, WHITESPACE);
                    383:       if (!cp)
                    384:        fatal("%.200s line %d: Missing argument.", filename, linenum);
                    385:       if (*activep && *charptr == NULL)
                    386:        *charptr = xstrdup(cp);
                    387:       break;
                    388:
                    389:     case oGlobalKnownHostsFile:
                    390:       charptr = &options->system_hostfile;
                    391:       goto parse_string;
                    392:
                    393:     case oUserKnownHostsFile:
                    394:       charptr = &options->user_hostfile;
                    395:       goto parse_string;
                    396:
                    397:     case oHostName:
                    398:       charptr = &options->hostname;
                    399:       goto parse_string;
                    400:
                    401:     case oProxyCommand:
                    402:       charptr = &options->proxy_command;
                    403:       string = xstrdup("");
                    404:       while ((cp = strtok(NULL, WHITESPACE)) != NULL)
                    405:        {
                    406:          string = xrealloc(string, strlen(string) + strlen(cp) + 2);
                    407:          strcat(string, " ");
                    408:          strcat(string, cp);
                    409:        }
                    410:       if (*activep && *charptr == NULL)
                    411:        *charptr = string;
                    412:       else
                    413:        xfree(string);
1.14      markus    414:       return 0;
1.1       deraadt   415:
                    416:     case oPort:
                    417:       intptr = &options->port;
                    418:     parse_int:
                    419:       cp = strtok(NULL, WHITESPACE);
                    420:       if (!cp)
                    421:        fatal("%.200s line %d: Missing argument.", filename, linenum);
                    422:       if (cp[0] < '0' || cp[0] > '9')
                    423:        fatal("%.200s line %d: Bad number.", filename, linenum);
                    424: #if 0
                    425:       value = atoi(cp);
                    426: #else
                    427:       {
                    428:        char *ptr;
                    429:        value = strtol(cp, &ptr, 0); /* Octal, decimal, or hex format? */
                    430:        if (cp == ptr)
                    431:          fatal("%.200s line %d: Bad number.", filename, linenum);
                    432:       }
                    433: #endif
                    434:       if (*activep && *intptr == -1)
                    435:        *intptr = value;
                    436:       break;
                    437:
                    438:     case oConnectionAttempts:
                    439:       intptr = &options->connection_attempts;
                    440:       goto parse_int;
                    441:
                    442:     case oCipher:
                    443:       intptr = &options->cipher;
                    444:       cp = strtok(NULL, WHITESPACE);
                    445:       value = cipher_number(cp);
                    446:       if (value == -1)
1.15      markus    447:        fatal("%.200s line %d: Bad cipher '%s'.",
                    448:              filename, linenum, cp ? cp : "<NONE>");
1.1       deraadt   449:       if (*activep && *intptr == -1)
                    450:        *intptr = value;
                    451:       break;
1.13      markus    452:
                    453:     case oLogLevel:
1.15      markus    454:       intptr = (int *)&options->log_level;
1.13      markus    455:       cp = strtok(NULL, WHITESPACE);
1.15      markus    456:       value = log_level_number(cp);
                    457:       if (value == (LogLevel)-1)
                    458:         fatal("%.200s line %d: unsupported log level '%s'\n",
                    459:              filename, linenum, cp ? cp : "<NONE>");
                    460:       if (*activep && (LogLevel)*intptr == -1)
                    461:        *intptr = (LogLevel)value;
1.13      markus    462:       break;
1.1       deraadt   463:
                    464:     case oRemoteForward:
                    465:       cp = strtok(NULL, WHITESPACE);
                    466:       if (!cp)
                    467:        fatal("%.200s line %d: Missing argument.", filename, linenum);
                    468:       if (cp[0] < '0' || cp[0] > '9')
                    469:        fatal("%.200s line %d: Badly formatted port number.",
                    470:              filename, linenum);
                    471:       fwd_port = atoi(cp);
                    472:       cp = strtok(NULL, WHITESPACE);
                    473:       if (!cp)
                    474:        fatal("%.200s line %d: Missing second argument.",
                    475:              filename, linenum);
                    476:       if (sscanf(cp, "%255[^:]:%d", buf, &fwd_host_port) != 2)
                    477:        fatal("%.200s line %d: Badly formatted host:port.",
                    478:              filename, linenum);
                    479:       if (*activep)
                    480:        add_remote_forward(options, fwd_port, buf, fwd_host_port);
                    481:       break;
                    482:
                    483:     case oLocalForward:
                    484:       cp = strtok(NULL, WHITESPACE);
                    485:       if (!cp)
                    486:        fatal("%.200s line %d: Missing argument.", filename, linenum);
                    487:       if (cp[0] < '0' || cp[0] > '9')
                    488:        fatal("%.200s line %d: Badly formatted port number.",
                    489:              filename, linenum);
                    490:       fwd_port = atoi(cp);
                    491:       cp = strtok(NULL, WHITESPACE);
                    492:       if (!cp)
                    493:        fatal("%.200s line %d: Missing second argument.",
                    494:              filename, linenum);
                    495:       if (sscanf(cp, "%255[^:]:%d", buf, &fwd_host_port) != 2)
                    496:        fatal("%.200s line %d: Badly formatted host:port.",
                    497:              filename, linenum);
                    498:       if (*activep)
                    499:        add_local_forward(options, fwd_port, buf, fwd_host_port);
                    500:       break;
                    501:
                    502:     case oHost:
                    503:       *activep = 0;
                    504:       while ((cp = strtok(NULL, WHITESPACE)) != NULL)
                    505:        if (match_pattern(host, cp))
                    506:          {
                    507:            debug("Applying options for %.100s", cp);
                    508:            *activep = 1;
                    509:            break;
                    510:          }
                    511:       /* Avoid garbage check below, as strtok already returned NULL. */
1.14      markus    512:       return 0;
1.1       deraadt   513:
                    514:     case oEscapeChar:
                    515:       intptr = &options->escape_char;
                    516:       cp = strtok(NULL, WHITESPACE);
                    517:       if (!cp)
                    518:        fatal("%.200s line %d: Missing argument.", filename, linenum);
                    519:       if (cp[0] == '^' && cp[2] == 0 &&
                    520:          (unsigned char)cp[1] >= 64 && (unsigned char)cp[1] < 128)
                    521:        value = (unsigned char)cp[1] & 31;
                    522:       else
                    523:        if (strlen(cp) == 1)
                    524:          value = (unsigned char)cp[0];
                    525:        else
                    526:          if (strcmp(cp, "none") == 0)
                    527:            value = -2;
                    528:          else
                    529:            {
                    530:              fatal("%.200s line %d: Bad escape character.",
                    531:                    filename, linenum);
                    532:              /*NOTREACHED*/
                    533:              value = 0; /* Avoid compiler warning. */
                    534:            }
                    535:       if (*activep && *intptr == -1)
                    536:        *intptr = value;
                    537:       break;
                    538:
                    539:     default:
1.14      markus    540:       fatal("process_config_line: Unimplemented opcode %d", opcode);
1.1       deraadt   541:     }
                    542:
                    543:   /* Check that there is no garbage at end of line. */
                    544:   if (strtok(NULL, WHITESPACE) != NULL)
                    545:     fatal("%.200s line %d: garbage at end of line.",
                    546:          filename, linenum);
1.14      markus    547:   return 0;
1.1       deraadt   548: }
                    549:
                    550:
                    551: /* Reads the config file and modifies the options accordingly.  Options should
                    552:    already be initialized before this call.  This never returns if there
                    553:    is an error.  If the file does not exist, this returns immediately. */
                    554:
                    555: void read_config_file(const char *filename, const char *host, Options *options)
                    556: {
                    557:   FILE *f;
                    558:   char line[1024];
                    559:   int active, linenum;
1.14      markus    560:   int bad_options = 0;
1.1       deraadt   561:
                    562:   /* Open the file. */
                    563:   f = fopen(filename, "r");
                    564:   if (!f)
                    565:     return;
                    566:
                    567:   debug("Reading configuration data %.200s", filename);
                    568:
                    569:   /* Mark that we are now processing the options.  This flag is turned on/off
                    570:      by Host specifications. */
                    571:   active = 1;
                    572:   linenum = 0;
                    573:   while (fgets(line, sizeof(line), f))
                    574:     {
                    575:       /* Update line number counter. */
                    576:       linenum++;
1.14      markus    577:       if (process_config_line(options, host, line, filename, linenum, &active) != 0)
                    578:        bad_options++;
1.1       deraadt   579:     }
                    580:   fclose(f);
1.14      markus    581:   if (bad_options > 0)
                    582:     fatal("%s: terminating, %d bad configuration options\n",
                    583:           filename, bad_options);
1.1       deraadt   584: }
                    585:
                    586: /* Initializes options to special values that indicate that they have not
                    587:    yet been set.  Read_config_file will only set options with this value.
                    588:    Options are processed in the following order: command line, user config
                    589:    file, system config file.  Last, fill_default_options is called. */
                    590:
                    591: void initialize_options(Options *options)
                    592: {
                    593:   memset(options, 'X', sizeof(*options));
                    594:   options->forward_agent = -1;
                    595:   options->forward_x11 = -1;
1.3       deraadt   596:   options->gateway_ports = -1;
1.11      markus    597:   options->use_privileged_port = -1;
1.1       deraadt   598:   options->rhosts_authentication = -1;
                    599:   options->rsa_authentication = -1;
1.16    ! markus    600:   options->skey_authentication = -1;
1.1       deraadt   601: #ifdef KRB4
                    602:   options->kerberos_authentication = -1;
                    603: #endif
1.5       dugsong   604: #ifdef AFS
1.1       deraadt   605:   options->kerberos_tgt_passing = -1;
                    606:   options->afs_token_passing = -1;
                    607: #endif
                    608:   options->password_authentication = -1;
                    609:   options->rhosts_rsa_authentication = -1;
                    610:   options->fallback_to_rsh = -1;
                    611:   options->use_rsh = -1;
                    612:   options->batch_mode = -1;
1.8       provos    613:   options->check_host_ip = -1;
1.1       deraadt   614:   options->strict_host_key_checking = -1;
                    615:   options->compression = -1;
                    616:   options->keepalives = -1;
                    617:   options->compression_level = -1;
                    618:   options->port = -1;
                    619:   options->connection_attempts = -1;
1.10      dugsong   620:   options->number_of_password_prompts = -1;
1.1       deraadt   621:   options->cipher = -1;
                    622:   options->num_identity_files = 0;
                    623:   options->hostname = NULL;
                    624:   options->proxy_command = NULL;
                    625:   options->user = NULL;
                    626:   options->escape_char = -1;
                    627:   options->system_hostfile = NULL;
                    628:   options->user_hostfile = NULL;
                    629:   options->num_local_forwards = 0;
                    630:   options->num_remote_forwards = 0;
1.13      markus    631:   options->log_level = (LogLevel)-1;
1.1       deraadt   632: }
                    633:
                    634: /* Called after processing other sources of option data, this fills those
                    635:    options for which no value has been specified with their default values. */
                    636:
                    637: void fill_default_options(Options *options)
                    638: {
                    639:   if (options->forward_agent == -1)
                    640:     options->forward_agent = 1;
                    641:   if (options->forward_x11 == -1)
                    642:     options->forward_x11 = 1;
1.3       deraadt   643:   if (options->gateway_ports == -1)
                    644:     options->gateway_ports = 0;
1.11      markus    645:   if (options->use_privileged_port == -1)
                    646:     options->use_privileged_port = 1;
1.1       deraadt   647:   if (options->rhosts_authentication == -1)
                    648:     options->rhosts_authentication = 1;
                    649:   if (options->rsa_authentication == -1)
                    650:     options->rsa_authentication = 1;
1.16    ! markus    651:   if (options->skey_authentication == -1)
        !           652:     options->skey_authentication = 0;
1.1       deraadt   653: #ifdef KRB4
                    654:   if (options->kerberos_authentication == -1)
                    655:     options->kerberos_authentication = 1;
1.5       dugsong   656: #endif /* KRB4 */
                    657: #ifdef AFS
1.1       deraadt   658:   if (options->kerberos_tgt_passing == -1)
                    659:     options->kerberos_tgt_passing = 1;
                    660:   if (options->afs_token_passing == -1)
                    661:     options->afs_token_passing = 1;
1.5       dugsong   662: #endif /* AFS */
1.1       deraadt   663:   if (options->password_authentication == -1)
                    664:     options->password_authentication = 1;
                    665:   if (options->rhosts_rsa_authentication == -1)
                    666:     options->rhosts_rsa_authentication = 1;
                    667:   if (options->fallback_to_rsh == -1)
                    668:     options->fallback_to_rsh = 1;
                    669:   if (options->use_rsh == -1)
                    670:     options->use_rsh = 0;
                    671:   if (options->batch_mode == -1)
                    672:     options->batch_mode = 0;
1.8       provos    673:   if (options->check_host_ip == -1)
                    674:     options->check_host_ip = 1;
1.1       deraadt   675:   if (options->strict_host_key_checking == -1)
                    676:     options->strict_host_key_checking = 2; /* 2 is default */
                    677:   if (options->compression == -1)
                    678:     options->compression = 0;
                    679:   if (options->keepalives == -1)
                    680:     options->keepalives = 1;
                    681:   if (options->compression_level == -1)
                    682:     options->compression_level = 6;
                    683:   if (options->port == -1)
                    684:     options->port = 0; /* Filled in ssh_connect. */
                    685:   if (options->connection_attempts == -1)
                    686:     options->connection_attempts = 4;
1.10      dugsong   687:   if (options->number_of_password_prompts == -1)
                    688:     options->number_of_password_prompts = 3;
1.1       deraadt   689:   if (options->cipher == -1)
                    690:     options->cipher = SSH_CIPHER_NOT_SET; /* Selected in ssh_login(). */
                    691:   if (options->num_identity_files == 0)
                    692:     {
                    693:       options->identity_files[0] =
                    694:        xmalloc(2 + strlen(SSH_CLIENT_IDENTITY) + 1);
                    695:       sprintf(options->identity_files[0], "~/%.100s", SSH_CLIENT_IDENTITY);
                    696:       options->num_identity_files = 1;
                    697:     }
                    698:   if (options->escape_char == -1)
                    699:     options->escape_char = '~';
                    700:   if (options->system_hostfile == NULL)
                    701:     options->system_hostfile = SSH_SYSTEM_HOSTFILE;
                    702:   if (options->user_hostfile == NULL)
                    703:     options->user_hostfile = SSH_USER_HOSTFILE;
1.13      markus    704:   if (options->log_level == (LogLevel)-1)
                    705:     options->log_level = SYSLOG_LEVEL_INFO;
1.1       deraadt   706:   /* options->proxy_command should not be set by default */
                    707:   /* options->user will be set in the main program if appropriate */
                    708:   /* options->hostname will be set in the main program if appropriate */
                    709: }
                    710: