[BACK]Return to servconf.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / ssh

Annotation of src/usr.bin/ssh/servconf.c, Revision 1.96

1.1       deraadt     1: /*
1.26      deraadt     2:  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
                      3:  *                    All rights reserved
1.34      markus      4:  *
1.51      deraadt     5:  * As far as I am concerned, the code I have written for this software
                      6:  * can be used freely for any purpose.  Any derived versions of this
                      7:  * software must be clearly marked as such, and if the derived work is
                      8:  * incompatible with the protocol description in the RFC file, it must be
                      9:  * called by a name other than "ssh" or "Secure Shell".
1.26      deraadt    10:  */
1.1       deraadt    11:
                     12: #include "includes.h"
1.96    ! stevesk    13: RCSID("$OpenBSD: servconf.c,v 1.95 2001/12/19 07:18:56 deraadt Exp $");
1.62      markus     14:
1.88      itojun     15: #if defined(KRB4) || defined(KRB5)
1.62      markus     16: #include <krb.h>
1.86      dugsong    17: #endif
                     18: #ifdef AFS
                     19: #include <kafs.h>
1.62      markus     20: #endif
1.1       deraadt    21:
                     22: #include "ssh.h"
1.62      markus     23: #include "log.h"
1.1       deraadt    24: #include "servconf.h"
                     25: #include "xmalloc.h"
1.33      markus     26: #include "compat.h"
1.60      markus     27: #include "pathnames.h"
1.62      markus     28: #include "tildexpand.h"
                     29: #include "misc.h"
                     30: #include "cipher.h"
1.66      markus     31: #include "kex.h"
                     32: #include "mac.h"
1.1       deraadt    33:
1.84      itojun     34: static void add_listen_addr(ServerOptions *, char *, u_short);
                     35: static void add_one_listen_addr(ServerOptions *, char *, u_short);
1.29      markus     36:
1.62      markus     37: /* AF_UNSPEC or AF_INET or AF_INET6 */
                     38: extern int IPv4or6;
                     39:
1.1       deraadt    40: /* Initializes the server options to their default values. */
                     41:
1.34      markus     42: void
1.25      markus     43: initialize_server_options(ServerOptions *options)
1.1       deraadt    44: {
1.25      markus     45:        memset(options, 0, sizeof(*options));
1.29      markus     46:        options->num_ports = 0;
                     47:        options->ports_from_cmdline = 0;
                     48:        options->listen_addrs = NULL;
1.54      markus     49:        options->num_host_key_files = 0;
1.36      markus     50:        options->pid_file = NULL;
1.25      markus     51:        options->server_key_bits = -1;
                     52:        options->login_grace_time = -1;
                     53:        options->key_regeneration_time = -1;
1.67      markus     54:        options->permit_root_login = PERMIT_NOT_SET;
1.25      markus     55:        options->ignore_rhosts = -1;
                     56:        options->ignore_user_known_hosts = -1;
                     57:        options->print_motd = -1;
1.72      stevesk    58:        options->print_lastlog = -1;
1.25      markus     59:        options->x11_forwarding = -1;
                     60:        options->x11_display_offset = -1;
1.42      markus     61:        options->xauth_location = NULL;
1.25      markus     62:        options->strict_modes = -1;
                     63:        options->keepalives = -1;
                     64:        options->log_facility = (SyslogFacility) - 1;
                     65:        options->log_level = (LogLevel) - 1;
                     66:        options->rhosts_authentication = -1;
                     67:        options->rhosts_rsa_authentication = -1;
1.75      markus     68:        options->hostbased_authentication = -1;
                     69:        options->hostbased_uses_name_from_packet_only = -1;
1.25      markus     70:        options->rsa_authentication = -1;
1.54      markus     71:        options->pubkey_authentication = -1;
1.85      dugsong    72: #if defined(KRB4) || defined(KRB5)
1.25      markus     73:        options->kerberos_authentication = -1;
                     74:        options->kerberos_or_local_passwd = -1;
                     75:        options->kerberos_ticket_cleanup = -1;
1.1       deraadt    76: #endif
1.85      dugsong    77: #if defined(AFS) || defined(KRB5)
                     78:        options->kerberos_tgt_passing = -1;
                     79: #endif
1.4       dugsong    80: #ifdef AFS
1.25      markus     81:        options->afs_token_passing = -1;
1.1       deraadt    82: #endif
1.25      markus     83:        options->password_authentication = -1;
1.52      markus     84:        options->kbd_interactive_authentication = -1;
1.80      markus     85:        options->challenge_response_authentication = -1;
1.25      markus     86:        options->permit_empty_passwd = -1;
                     87:        options->use_login = -1;
1.53      markus     88:        options->allow_tcp_forwarding = -1;
1.25      markus     89:        options->num_allow_users = 0;
                     90:        options->num_deny_users = 0;
                     91:        options->num_allow_groups = 0;
                     92:        options->num_deny_groups = 0;
1.33      markus     93:        options->ciphers = NULL;
1.66      markus     94:        options->macs = NULL;
1.33      markus     95:        options->protocol = SSH_PROTO_UNKNOWN;
1.38      markus     96:        options->gateway_ports = -1;
1.43      jakob      97:        options->num_subsystems = 0;
1.50      markus     98:        options->max_startups_begin = -1;
                     99:        options->max_startups_rate = -1;
1.46      markus    100:        options->max_startups = -1;
1.57      markus    101:        options->banner = NULL;
1.64      markus    102:        options->reverse_mapping_check = -1;
1.77      beck      103:        options->client_alive_interval = -1;
                    104:        options->client_alive_count_max = -1;
1.82      markus    105:        options->authorized_keys_file = NULL;
                    106:        options->authorized_keys_file2 = NULL;
1.1       deraadt   107: }
                    108:
1.34      markus    109: void
1.25      markus    110: fill_default_server_options(ServerOptions *options)
1.1       deraadt   111: {
1.54      markus    112:        if (options->protocol == SSH_PROTO_UNKNOWN)
                    113:                options->protocol = SSH_PROTO_1|SSH_PROTO_2;
                    114:        if (options->num_host_key_files == 0) {
                    115:                /* fill default hostkeys for protocols */
                    116:                if (options->protocol & SSH_PROTO_1)
1.60      markus    117:                        options->host_key_files[options->num_host_key_files++] = _PATH_HOST_KEY_FILE;
1.54      markus    118:                if (options->protocol & SSH_PROTO_2)
1.60      markus    119:                        options->host_key_files[options->num_host_key_files++] = _PATH_HOST_DSA_KEY_FILE;
1.54      markus    120:        }
1.29      markus    121:        if (options->num_ports == 0)
                    122:                options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
                    123:        if (options->listen_addrs == NULL)
1.76      stevesk   124:                add_listen_addr(options, NULL, 0);
1.36      markus    125:        if (options->pid_file == NULL)
1.60      markus    126:                options->pid_file = _PATH_SSH_DAEMON_PID_FILE;
1.25      markus    127:        if (options->server_key_bits == -1)
                    128:                options->server_key_bits = 768;
                    129:        if (options->login_grace_time == -1)
                    130:                options->login_grace_time = 600;
                    131:        if (options->key_regeneration_time == -1)
                    132:                options->key_regeneration_time = 3600;
1.67      markus    133:        if (options->permit_root_login == PERMIT_NOT_SET)
                    134:                options->permit_root_login = PERMIT_YES;
1.25      markus    135:        if (options->ignore_rhosts == -1)
1.30      markus    136:                options->ignore_rhosts = 1;
1.25      markus    137:        if (options->ignore_user_known_hosts == -1)
                    138:                options->ignore_user_known_hosts = 0;
                    139:        if (options->print_motd == -1)
                    140:                options->print_motd = 1;
1.72      stevesk   141:        if (options->print_lastlog == -1)
                    142:                options->print_lastlog = 1;
1.25      markus    143:        if (options->x11_forwarding == -1)
1.30      markus    144:                options->x11_forwarding = 0;
1.25      markus    145:        if (options->x11_display_offset == -1)
1.30      markus    146:                options->x11_display_offset = 10;
1.42      markus    147:        if (options->xauth_location == NULL)
1.83      markus    148:                options->xauth_location = _PATH_XAUTH;
1.25      markus    149:        if (options->strict_modes == -1)
                    150:                options->strict_modes = 1;
                    151:        if (options->keepalives == -1)
                    152:                options->keepalives = 1;
                    153:        if (options->log_facility == (SyslogFacility) (-1))
                    154:                options->log_facility = SYSLOG_FACILITY_AUTH;
                    155:        if (options->log_level == (LogLevel) (-1))
1.58      markus    156:                options->log_level = SYSLOG_LEVEL_INFO;
1.25      markus    157:        if (options->rhosts_authentication == -1)
                    158:                options->rhosts_authentication = 0;
                    159:        if (options->rhosts_rsa_authentication == -1)
1.30      markus    160:                options->rhosts_rsa_authentication = 0;
1.75      markus    161:        if (options->hostbased_authentication == -1)
                    162:                options->hostbased_authentication = 0;
                    163:        if (options->hostbased_uses_name_from_packet_only == -1)
                    164:                options->hostbased_uses_name_from_packet_only = 0;
1.25      markus    165:        if (options->rsa_authentication == -1)
                    166:                options->rsa_authentication = 1;
1.54      markus    167:        if (options->pubkey_authentication == -1)
                    168:                options->pubkey_authentication = 1;
1.85      dugsong   169: #if defined(KRB4) || defined(KRB5)
1.25      markus    170:        if (options->kerberos_authentication == -1)
                    171:                options->kerberos_authentication = (access(KEYFILE, R_OK) == 0);
                    172:        if (options->kerberos_or_local_passwd == -1)
                    173:                options->kerberos_or_local_passwd = 1;
                    174:        if (options->kerberos_ticket_cleanup == -1)
                    175:                options->kerberos_ticket_cleanup = 1;
1.85      dugsong   176: #endif
                    177: #if defined(AFS) || defined(KRB5)
1.25      markus    178:        if (options->kerberos_tgt_passing == -1)
                    179:                options->kerberos_tgt_passing = 0;
1.85      dugsong   180: #endif
1.95      deraadt   181: #ifdef AFS
1.25      markus    182:        if (options->afs_token_passing == -1)
                    183:                options->afs_token_passing = k_hasafs();
1.85      dugsong   184: #endif
1.25      markus    185:        if (options->password_authentication == -1)
                    186:                options->password_authentication = 1;
1.52      markus    187:        if (options->kbd_interactive_authentication == -1)
                    188:                options->kbd_interactive_authentication = 0;
1.80      markus    189:        if (options->challenge_response_authentication == -1)
                    190:                options->challenge_response_authentication = 1;
1.25      markus    191:        if (options->permit_empty_passwd == -1)
1.30      markus    192:                options->permit_empty_passwd = 0;
1.25      markus    193:        if (options->use_login == -1)
                    194:                options->use_login = 0;
1.53      markus    195:        if (options->allow_tcp_forwarding == -1)
                    196:                options->allow_tcp_forwarding = 1;
1.38      markus    197:        if (options->gateway_ports == -1)
                    198:                options->gateway_ports = 0;
1.46      markus    199:        if (options->max_startups == -1)
                    200:                options->max_startups = 10;
1.50      markus    201:        if (options->max_startups_rate == -1)
                    202:                options->max_startups_rate = 100;               /* 100% */
                    203:        if (options->max_startups_begin == -1)
                    204:                options->max_startups_begin = options->max_startups;
1.64      markus    205:        if (options->reverse_mapping_check == -1)
                    206:                options->reverse_mapping_check = 0;
1.77      beck      207:        if (options->client_alive_interval == -1)
1.95      deraadt   208:                options->client_alive_interval = 0;
1.77      beck      209:        if (options->client_alive_count_max == -1)
                    210:                options->client_alive_count_max = 3;
1.90      markus    211:        if (options->authorized_keys_file2 == NULL) {
                    212:                /* authorized_keys_file2 falls back to authorized_keys_file */
                    213:                if (options->authorized_keys_file != NULL)
                    214:                        options->authorized_keys_file2 = options->authorized_keys_file;
                    215:                else
                    216:                        options->authorized_keys_file2 = _PATH_SSH_USER_PERMITTED_KEYS2;
                    217:        }
                    218:        if (options->authorized_keys_file == NULL)
                    219:                options->authorized_keys_file = _PATH_SSH_USER_PERMITTED_KEYS;
1.1       deraadt   220: }
                    221:
                    222: /* Keyword tokens. */
1.25      markus    223: typedef enum {
                    224:        sBadOption,             /* == unknown option */
                    225:        sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
                    226:        sPermitRootLogin, sLogFacility, sLogLevel,
                    227:        sRhostsAuthentication, sRhostsRSAAuthentication, sRSAAuthentication,
1.85      dugsong   228: #if defined(KRB4) || defined(KRB5)
1.25      markus    229:        sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
1.1       deraadt   230: #endif
1.85      dugsong   231: #if defined(AFS) || defined(KRB5)
                    232:        sKerberosTgtPassing,
                    233: #endif
1.1       deraadt   234: #ifdef AFS
1.85      dugsong   235:        sAFSTokenPassing,
1.1       deraadt   236: #endif
1.63      markus    237:        sChallengeResponseAuthentication,
1.52      markus    238:        sPasswordAuthentication, sKbdInteractiveAuthentication, sListenAddress,
1.72      stevesk   239:        sPrintMotd, sPrintLastLog, sIgnoreRhosts,
                    240:        sX11Forwarding, sX11DisplayOffset,
1.89      jakob     241:        sStrictModes, sEmptyPasswd, sKeepAlives,
1.53      markus    242:        sUseLogin, sAllowTcpForwarding,
                    243:        sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
1.66      markus    244:        sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
1.54      markus    245:        sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem, sMaxStartups,
1.75      markus    246:        sBanner, sReverseMappingCheck, sHostbasedAuthentication,
1.95      deraadt   247:        sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
1.89      jakob     248:        sClientAliveCountMax, sAuthorizedKeysFile, sAuthorizedKeysFile2,
                    249:        sDeprecated
1.1       deraadt   250: } ServerOpCodes;
                    251:
                    252: /* Textual representation of the tokens. */
1.25      markus    253: static struct {
                    254:        const char *name;
                    255:        ServerOpCodes opcode;
                    256: } keywords[] = {
                    257:        { "port", sPort },
                    258:        { "hostkey", sHostKeyFile },
1.54      markus    259:        { "hostdsakey", sHostKeyFile },                                 /* alias */
1.65      stevesk   260:        { "pidfile", sPidFile },
1.25      markus    261:        { "serverkeybits", sServerKeyBits },
                    262:        { "logingracetime", sLoginGraceTime },
                    263:        { "keyregenerationinterval", sKeyRegenerationTime },
                    264:        { "permitrootlogin", sPermitRootLogin },
                    265:        { "syslogfacility", sLogFacility },
                    266:        { "loglevel", sLogLevel },
                    267:        { "rhostsauthentication", sRhostsAuthentication },
                    268:        { "rhostsrsaauthentication", sRhostsRSAAuthentication },
1.75      markus    269:        { "hostbasedauthentication", sHostbasedAuthentication },
                    270:        { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly },
1.25      markus    271:        { "rsaauthentication", sRSAAuthentication },
1.54      markus    272:        { "pubkeyauthentication", sPubkeyAuthentication },
                    273:        { "dsaauthentication", sPubkeyAuthentication },                 /* alias */
1.85      dugsong   274: #if defined(KRB4) || defined(KRB5)
1.25      markus    275:        { "kerberosauthentication", sKerberosAuthentication },
                    276:        { "kerberosorlocalpasswd", sKerberosOrLocalPasswd },
                    277:        { "kerberosticketcleanup", sKerberosTicketCleanup },
1.1       deraadt   278: #endif
1.85      dugsong   279: #if defined(AFS) || defined(KRB5)
                    280:        { "kerberostgtpassing", sKerberosTgtPassing },
                    281: #endif
1.4       dugsong   282: #ifdef AFS
1.25      markus    283:        { "afstokenpassing", sAFSTokenPassing },
1.1       deraadt   284: #endif
1.25      markus    285:        { "passwordauthentication", sPasswordAuthentication },
1.52      markus    286:        { "kbdinteractiveauthentication", sKbdInteractiveAuthentication },
1.63      markus    287:        { "challengeresponseauthentication", sChallengeResponseAuthentication },
                    288:        { "skeyauthentication", sChallengeResponseAuthentication }, /* alias */
1.89      jakob     289:        { "checkmail", sDeprecated },
1.25      markus    290:        { "listenaddress", sListenAddress },
                    291:        { "printmotd", sPrintMotd },
1.72      stevesk   292:        { "printlastlog", sPrintLastLog },
1.25      markus    293:        { "ignorerhosts", sIgnoreRhosts },
                    294:        { "ignoreuserknownhosts", sIgnoreUserKnownHosts },
                    295:        { "x11forwarding", sX11Forwarding },
                    296:        { "x11displayoffset", sX11DisplayOffset },
1.42      markus    297:        { "xauthlocation", sXAuthLocation },
1.25      markus    298:        { "strictmodes", sStrictModes },
                    299:        { "permitemptypasswords", sEmptyPasswd },
                    300:        { "uselogin", sUseLogin },
                    301:        { "keepalive", sKeepAlives },
1.53      markus    302:        { "allowtcpforwarding", sAllowTcpForwarding },
1.25      markus    303:        { "allowusers", sAllowUsers },
                    304:        { "denyusers", sDenyUsers },
                    305:        { "allowgroups", sAllowGroups },
                    306:        { "denygroups", sDenyGroups },
1.33      markus    307:        { "ciphers", sCiphers },
1.66      markus    308:        { "macs", sMacs },
1.33      markus    309:        { "protocol", sProtocol },
1.38      markus    310:        { "gatewayports", sGatewayPorts },
1.43      jakob     311:        { "subsystem", sSubsystem },
1.46      markus    312:        { "maxstartups", sMaxStartups },
1.57      markus    313:        { "banner", sBanner },
1.64      markus    314:        { "reversemappingcheck", sReverseMappingCheck },
1.77      beck      315:        { "clientaliveinterval", sClientAliveInterval },
                    316:        { "clientalivecountmax", sClientAliveCountMax },
1.82      markus    317:        { "authorizedkeysfile", sAuthorizedKeysFile },
                    318:        { "authorizedkeysfile2", sAuthorizedKeysFile2 },
1.92      stevesk   319:        { NULL, sBadOption }
1.1       deraadt   320: };
                    321:
1.27      markus    322: /*
1.73      stevesk   323:  * Returns the number of the token pointed to by cp or sBadOption.
1.27      markus    324:  */
1.1       deraadt   325:
1.34      markus    326: static ServerOpCodes
1.25      markus    327: parse_token(const char *cp, const char *filename,
                    328:            int linenum)
1.1       deraadt   329: {
1.55      markus    330:        u_int i;
1.1       deraadt   331:
1.25      markus    332:        for (i = 0; keywords[i].name; i++)
1.28      markus    333:                if (strcasecmp(cp, keywords[i].name) == 0)
1.25      markus    334:                        return keywords[i].opcode;
                    335:
1.78      stevesk   336:        error("%s: line %d: Bad configuration option: %s",
                    337:            filename, linenum, cp);
1.25      markus    338:        return sBadOption;
1.1       deraadt   339: }
                    340:
1.84      itojun    341: static void
1.76      stevesk   342: add_listen_addr(ServerOptions *options, char *addr, u_short port)
1.74      stevesk   343: {
                    344:        int i;
                    345:
                    346:        if (options->num_ports == 0)
                    347:                options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
1.76      stevesk   348:        if (port == 0)
1.74      stevesk   349:                for (i = 0; i < options->num_ports; i++)
                    350:                        add_one_listen_addr(options, addr, options->ports[i]);
                    351:        else
1.76      stevesk   352:                add_one_listen_addr(options, addr, port);
1.74      stevesk   353: }
                    354:
1.84      itojun    355: static void
1.74      stevesk   356: add_one_listen_addr(ServerOptions *options, char *addr, u_short port)
1.29      markus    357: {
                    358:        struct addrinfo hints, *ai, *aitop;
                    359:        char strport[NI_MAXSERV];
                    360:        int gaierr;
                    361:
1.74      stevesk   362:        memset(&hints, 0, sizeof(hints));
                    363:        hints.ai_family = IPv4or6;
                    364:        hints.ai_socktype = SOCK_STREAM;
                    365:        hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
                    366:        snprintf(strport, sizeof strport, "%d", port);
                    367:        if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
                    368:                fatal("bad addr or host: %s (%s)",
                    369:                    addr ? addr : "<NULL>",
                    370:                    gai_strerror(gaierr));
                    371:        for (ai = aitop; ai->ai_next; ai = ai->ai_next)
                    372:                ;
                    373:        ai->ai_next = options->listen_addrs;
                    374:        options->listen_addrs = aitop;
1.29      markus    375: }
                    376:
1.94      markus    377: int
                    378: process_server_config_line(ServerOptions *options, char *line,
                    379:     const char *filename, int linenum)
1.1       deraadt   380: {
1.74      stevesk   381:        char *cp, **charptr, *arg, *p;
1.94      markus    382:        int *intptr, value;
1.25      markus    383:        ServerOpCodes opcode;
1.87      stevesk   384:        int i, n;
1.25      markus    385:
1.94      markus    386:        cp = line;
                    387:        arg = strdelim(&cp);
                    388:        /* Ignore leading whitespace */
                    389:        if (*arg == '\0')
                    390:                arg = strdelim(&cp);
                    391:        if (!arg || !*arg || *arg == '#')
                    392:                return 0;
                    393:        intptr = NULL;
                    394:        charptr = NULL;
                    395:        opcode = parse_token(arg, filename, linenum);
                    396:        switch (opcode) {
                    397:        case sBadOption:
                    398:                return -1;
                    399:        case sPort:
                    400:                /* ignore ports from configfile if cmdline specifies ports */
                    401:                if (options->ports_from_cmdline)
                    402:                        return 0;
                    403:                if (options->listen_addrs != NULL)
                    404:                        fatal("%s line %d: ports must be specified before "
                    405:                            "ListenAdress.", filename, linenum);
                    406:                if (options->num_ports >= MAX_PORTS)
                    407:                        fatal("%s line %d: too many ports.",
                    408:                            filename, linenum);
1.48      provos    409:                arg = strdelim(&cp);
1.94      markus    410:                if (!arg || *arg == '\0')
                    411:                        fatal("%s line %d: missing port number.",
                    412:                            filename, linenum);
                    413:                options->ports[options->num_ports++] = a2port(arg);
                    414:                if (options->ports[options->num_ports-1] == 0)
                    415:                        fatal("%s line %d: Badly formatted port number.",
                    416:                            filename, linenum);
                    417:                break;
1.29      markus    418:
1.94      markus    419:        case sServerKeyBits:
                    420:                intptr = &options->server_key_bits;
1.25      markus    421: parse_int:
1.94      markus    422:                arg = strdelim(&cp);
                    423:                if (!arg || *arg == '\0')
                    424:                        fatal("%s line %d: missing integer value.",
                    425:                            filename, linenum);
                    426:                value = atoi(arg);
                    427:                if (*intptr == -1)
                    428:                        *intptr = value;
                    429:                break;
1.25      markus    430:
1.94      markus    431:        case sLoginGraceTime:
                    432:                intptr = &options->login_grace_time;
1.81      stevesk   433: parse_time:
1.94      markus    434:                arg = strdelim(&cp);
                    435:                if (!arg || *arg == '\0')
                    436:                        fatal("%s line %d: missing time value.",
                    437:                            filename, linenum);
                    438:                if ((value = convtime(arg)) == -1)
                    439:                        fatal("%s line %d: invalid time value.",
                    440:                            filename, linenum);
                    441:                if (*intptr == -1)
                    442:                        *intptr = value;
                    443:                break;
                    444:
                    445:        case sKeyRegenerationTime:
                    446:                intptr = &options->key_regeneration_time;
                    447:                goto parse_time;
                    448:
                    449:        case sListenAddress:
                    450:                arg = strdelim(&cp);
                    451:                if (!arg || *arg == '\0' || strncmp(arg, "[]", 2) == 0)
                    452:                        fatal("%s line %d: missing inet addr.",
                    453:                            filename, linenum);
                    454:                if (*arg == '[') {
                    455:                        if ((p = strchr(arg, ']')) == NULL)
                    456:                                fatal("%s line %d: bad ipv6 inet addr usage.",
                    457:                                    filename, linenum);
                    458:                        arg++;
                    459:                        memmove(p, p+1, strlen(p+1)+1);
                    460:                } else if (((p = strchr(arg, ':')) == NULL) ||
                    461:                            (strchr(p+1, ':') != NULL)) {
                    462:                        add_listen_addr(options, arg, 0);
1.81      stevesk   463:                        break;
1.94      markus    464:                }
                    465:                if (*p == ':') {
                    466:                        u_short port;
1.25      markus    467:
1.94      markus    468:                        p++;
                    469:                        if (*p == '\0')
                    470:                                fatal("%s line %d: bad inet addr:port usage.",
                    471:                                    filename, linenum);
                    472:                        else {
                    473:                                *(p-1) = '\0';
                    474:                                if ((port = a2port(p)) == 0)
                    475:                                        fatal("%s line %d: bad port number.",
1.74      stevesk   476:                                            filename, linenum);
1.94      markus    477:                                add_listen_addr(options, arg, port);
1.74      stevesk   478:                        }
1.94      markus    479:                } else if (*p == '\0')
                    480:                        add_listen_addr(options, arg, 0);
                    481:                else
                    482:                        fatal("%s line %d: bad inet addr usage.",
                    483:                            filename, linenum);
                    484:                break;
                    485:
                    486:        case sHostKeyFile:
                    487:                intptr = &options->num_host_key_files;
                    488:                if (*intptr >= MAX_HOSTKEYS)
                    489:                        fatal("%s line %d: too many host keys specified (max %d).",
                    490:                            filename, linenum, MAX_HOSTKEYS);
                    491:                charptr = &options->host_key_files[*intptr];
                    492: parse_filename:
                    493:                arg = strdelim(&cp);
                    494:                if (!arg || *arg == '\0')
                    495:                        fatal("%s line %d: missing file name.",
                    496:                            filename, linenum);
                    497:                if (*charptr == NULL) {
                    498:                        *charptr = tilde_expand_filename(arg, getuid());
                    499:                        /* increase optional counter */
                    500:                        if (intptr != NULL)
                    501:                                *intptr = *intptr + 1;
                    502:                }
                    503:                break;
1.76      stevesk   504:
1.94      markus    505:        case sPidFile:
                    506:                charptr = &options->pid_file;
                    507:                goto parse_filename;
1.25      markus    508:
1.94      markus    509:        case sPermitRootLogin:
                    510:                intptr = &options->permit_root_login;
                    511:                arg = strdelim(&cp);
                    512:                if (!arg || *arg == '\0')
                    513:                        fatal("%s line %d: missing yes/"
                    514:                            "without-password/forced-commands-only/no "
                    515:                            "argument.", filename, linenum);
                    516:                value = 0;      /* silence compiler */
                    517:                if (strcmp(arg, "without-password") == 0)
                    518:                        value = PERMIT_NO_PASSWD;
                    519:                else if (strcmp(arg, "forced-commands-only") == 0)
                    520:                        value = PERMIT_FORCED_ONLY;
                    521:                else if (strcmp(arg, "yes") == 0)
                    522:                        value = PERMIT_YES;
                    523:                else if (strcmp(arg, "no") == 0)
                    524:                        value = PERMIT_NO;
                    525:                else
                    526:                        fatal("%s line %d: Bad yes/"
                    527:                            "without-password/forced-commands-only/no "
                    528:                            "argument: %s", filename, linenum, arg);
                    529:                if (*intptr == -1)
                    530:                        *intptr = value;
                    531:                break;
1.36      markus    532:
1.94      markus    533:        case sIgnoreRhosts:
                    534:                intptr = &options->ignore_rhosts;
1.25      markus    535: parse_flag:
1.94      markus    536:                arg = strdelim(&cp);
                    537:                if (!arg || *arg == '\0')
                    538:                        fatal("%s line %d: missing yes/no argument.",
                    539:                            filename, linenum);
                    540:                value = 0;      /* silence compiler */
                    541:                if (strcmp(arg, "yes") == 0)
                    542:                        value = 1;
                    543:                else if (strcmp(arg, "no") == 0)
                    544:                        value = 0;
                    545:                else
                    546:                        fatal("%s line %d: Bad yes/no argument: %s",
                    547:                                filename, linenum, arg);
                    548:                if (*intptr == -1)
                    549:                        *intptr = value;
                    550:                break;
                    551:
                    552:        case sIgnoreUserKnownHosts:
                    553:                intptr = &options->ignore_user_known_hosts;
                    554:                goto parse_flag;
                    555:
                    556:        case sRhostsAuthentication:
                    557:                intptr = &options->rhosts_authentication;
                    558:                goto parse_flag;
                    559:
                    560:        case sRhostsRSAAuthentication:
                    561:                intptr = &options->rhosts_rsa_authentication;
                    562:                goto parse_flag;
                    563:
                    564:        case sHostbasedAuthentication:
                    565:                intptr = &options->hostbased_authentication;
                    566:                goto parse_flag;
                    567:
                    568:        case sHostbasedUsesNameFromPacketOnly:
                    569:                intptr = &options->hostbased_uses_name_from_packet_only;
                    570:                goto parse_flag;
                    571:
                    572:        case sRSAAuthentication:
                    573:                intptr = &options->rsa_authentication;
                    574:                goto parse_flag;
                    575:
                    576:        case sPubkeyAuthentication:
                    577:                intptr = &options->pubkey_authentication;
                    578:                goto parse_flag;
1.85      dugsong   579: #if defined(KRB4) || defined(KRB5)
1.94      markus    580:        case sKerberosAuthentication:
                    581:                intptr = &options->kerberos_authentication;
                    582:                goto parse_flag;
                    583:
                    584:        case sKerberosOrLocalPasswd:
                    585:                intptr = &options->kerberos_or_local_passwd;
                    586:                goto parse_flag;
                    587:
                    588:        case sKerberosTicketCleanup:
                    589:                intptr = &options->kerberos_ticket_cleanup;
                    590:                goto parse_flag;
1.1       deraadt   591: #endif
1.85      dugsong   592: #if defined(AFS) || defined(KRB5)
1.94      markus    593:        case sKerberosTgtPassing:
                    594:                intptr = &options->kerberos_tgt_passing;
                    595:                goto parse_flag;
1.85      dugsong   596: #endif
                    597: #ifdef AFS
1.94      markus    598:        case sAFSTokenPassing:
                    599:                intptr = &options->afs_token_passing;
                    600:                goto parse_flag;
                    601: #endif
                    602:
                    603:        case sPasswordAuthentication:
                    604:                intptr = &options->password_authentication;
                    605:                goto parse_flag;
                    606:
                    607:        case sKbdInteractiveAuthentication:
                    608:                intptr = &options->kbd_interactive_authentication;
                    609:                goto parse_flag;
                    610:
                    611:        case sChallengeResponseAuthentication:
                    612:                intptr = &options->challenge_response_authentication;
                    613:                goto parse_flag;
                    614:
                    615:        case sPrintMotd:
                    616:                intptr = &options->print_motd;
                    617:                goto parse_flag;
                    618:
                    619:        case sPrintLastLog:
                    620:                intptr = &options->print_lastlog;
                    621:                goto parse_flag;
                    622:
                    623:        case sX11Forwarding:
                    624:                intptr = &options->x11_forwarding;
                    625:                goto parse_flag;
                    626:
                    627:        case sX11DisplayOffset:
                    628:                intptr = &options->x11_display_offset;
                    629:                goto parse_int;
                    630:
                    631:        case sXAuthLocation:
                    632:                charptr = &options->xauth_location;
                    633:                goto parse_filename;
                    634:
                    635:        case sStrictModes:
                    636:                intptr = &options->strict_modes;
                    637:                goto parse_flag;
                    638:
                    639:        case sKeepAlives:
                    640:                intptr = &options->keepalives;
                    641:                goto parse_flag;
                    642:
                    643:        case sEmptyPasswd:
                    644:                intptr = &options->permit_empty_passwd;
                    645:                goto parse_flag;
                    646:
                    647:        case sUseLogin:
                    648:                intptr = &options->use_login;
                    649:                goto parse_flag;
                    650:
                    651:        case sGatewayPorts:
                    652:                intptr = &options->gateway_ports;
                    653:                goto parse_flag;
1.25      markus    654:
1.94      markus    655:        case sReverseMappingCheck:
                    656:                intptr = &options->reverse_mapping_check;
                    657:                goto parse_flag;
1.53      markus    658:
1.94      markus    659:        case sLogFacility:
                    660:                intptr = (int *) &options->log_facility;
                    661:                arg = strdelim(&cp);
                    662:                value = log_facility_number(arg);
                    663:                if (value == (SyslogFacility) - 1)
                    664:                        fatal("%.200s line %d: unsupported log facility '%s'",
                    665:                            filename, linenum, arg ? arg : "<NONE>");
                    666:                if (*intptr == -1)
                    667:                        *intptr = (SyslogFacility) value;
                    668:                break;
1.25      markus    669:
1.94      markus    670:        case sLogLevel:
                    671:                intptr = (int *) &options->log_level;
                    672:                arg = strdelim(&cp);
                    673:                value = log_level_number(arg);
                    674:                if (value == (LogLevel) - 1)
                    675:                        fatal("%.200s line %d: unsupported log level '%s'",
                    676:                            filename, linenum, arg ? arg : "<NONE>");
                    677:                if (*intptr == -1)
                    678:                        *intptr = (LogLevel) value;
                    679:                break;
                    680:
                    681:        case sAllowTcpForwarding:
                    682:                intptr = &options->allow_tcp_forwarding;
                    683:                goto parse_flag;
                    684:
                    685:        case sAllowUsers:
                    686:                while ((arg = strdelim(&cp)) && *arg != '\0') {
                    687:                        if (options->num_allow_users >= MAX_ALLOW_USERS)
                    688:                                fatal("%s line %d: too many allow users.",
                    689:                                    filename, linenum);
                    690:                        options->allow_users[options->num_allow_users++] = xstrdup(arg);
                    691:                }
                    692:                break;
1.25      markus    693:
1.94      markus    694:        case sDenyUsers:
                    695:                while ((arg = strdelim(&cp)) && *arg != '\0') {
                    696:                        if (options->num_deny_users >= MAX_DENY_USERS)
                    697:                                fatal( "%s line %d: too many deny users.",
                    698:                                    filename, linenum);
                    699:                        options->deny_users[options->num_deny_users++] = xstrdup(arg);
                    700:                }
                    701:                break;
1.25      markus    702:
1.94      markus    703:        case sAllowGroups:
                    704:                while ((arg = strdelim(&cp)) && *arg != '\0') {
                    705:                        if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
                    706:                                fatal("%s line %d: too many allow groups.",
                    707:                                    filename, linenum);
                    708:                        options->allow_groups[options->num_allow_groups++] = xstrdup(arg);
                    709:                }
                    710:                break;
1.33      markus    711:
1.94      markus    712:        case sDenyGroups:
                    713:                while ((arg = strdelim(&cp)) && *arg != '\0') {
                    714:                        if (options->num_deny_groups >= MAX_DENY_GROUPS)
                    715:                                fatal("%s line %d: too many deny groups.",
                    716:                                    filename, linenum);
                    717:                        options->deny_groups[options->num_deny_groups++] = xstrdup(arg);
                    718:                }
                    719:                break;
1.66      markus    720:
1.94      markus    721:        case sCiphers:
                    722:                arg = strdelim(&cp);
                    723:                if (!arg || *arg == '\0')
                    724:                        fatal("%s line %d: Missing argument.", filename, linenum);
                    725:                if (!ciphers_valid(arg))
                    726:                        fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
                    727:                            filename, linenum, arg ? arg : "<NONE>");
                    728:                if (options->ciphers == NULL)
                    729:                        options->ciphers = xstrdup(arg);
                    730:                break;
1.33      markus    731:
1.94      markus    732:        case sMacs:
                    733:                arg = strdelim(&cp);
                    734:                if (!arg || *arg == '\0')
                    735:                        fatal("%s line %d: Missing argument.", filename, linenum);
                    736:                if (!mac_valid(arg))
                    737:                        fatal("%s line %d: Bad SSH2 mac spec '%s'.",
                    738:                            filename, linenum, arg ? arg : "<NONE>");
                    739:                if (options->macs == NULL)
                    740:                        options->macs = xstrdup(arg);
                    741:                break;
1.43      jakob     742:
1.94      markus    743:        case sProtocol:
                    744:                intptr = &options->protocol;
                    745:                arg = strdelim(&cp);
                    746:                if (!arg || *arg == '\0')
                    747:                        fatal("%s line %d: Missing argument.", filename, linenum);
                    748:                value = proto_spec(arg);
                    749:                if (value == SSH_PROTO_UNKNOWN)
                    750:                        fatal("%s line %d: Bad protocol spec '%s'.",
1.95      deraadt   751:                            filename, linenum, arg ? arg : "<NONE>");
1.94      markus    752:                if (*intptr == SSH_PROTO_UNKNOWN)
                    753:                        *intptr = value;
                    754:                break;
                    755:
                    756:        case sSubsystem:
                    757:                if (options->num_subsystems >= MAX_SUBSYSTEMS) {
                    758:                        fatal("%s line %d: too many subsystems defined.",
1.95      deraadt   759:                            filename, linenum);
1.94      markus    760:                }
                    761:                arg = strdelim(&cp);
                    762:                if (!arg || *arg == '\0')
                    763:                        fatal("%s line %d: Missing subsystem name.",
1.95      deraadt   764:                            filename, linenum);
1.94      markus    765:                for (i = 0; i < options->num_subsystems; i++)
                    766:                        if (strcmp(arg, options->subsystem_name[i]) == 0)
                    767:                                fatal("%s line %d: Subsystem '%s' already defined.",
1.95      deraadt   768:                                    filename, linenum, arg);
1.94      markus    769:                options->subsystem_name[options->num_subsystems] = xstrdup(arg);
                    770:                arg = strdelim(&cp);
                    771:                if (!arg || *arg == '\0')
                    772:                        fatal("%s line %d: Missing subsystem command.",
1.95      deraadt   773:                            filename, linenum);
1.94      markus    774:                options->subsystem_command[options->num_subsystems] = xstrdup(arg);
                    775:                options->num_subsystems++;
                    776:                break;
1.46      markus    777:
1.94      markus    778:        case sMaxStartups:
                    779:                arg = strdelim(&cp);
                    780:                if (!arg || *arg == '\0')
                    781:                        fatal("%s line %d: Missing MaxStartups spec.",
1.95      deraadt   782:                            filename, linenum);
1.94      markus    783:                if ((n = sscanf(arg, "%d:%d:%d",
                    784:                    &options->max_startups_begin,
                    785:                    &options->max_startups_rate,
                    786:                    &options->max_startups)) == 3) {
                    787:                        if (options->max_startups_begin >
                    788:                            options->max_startups ||
                    789:                            options->max_startups_rate > 100 ||
                    790:                            options->max_startups_rate < 1)
1.50      markus    791:                                fatal("%s line %d: Illegal MaxStartups spec.",
1.87      stevesk   792:                                    filename, linenum);
1.94      markus    793:                } else if (n != 1)
                    794:                        fatal("%s line %d: Illegal MaxStartups spec.",
                    795:                            filename, linenum);
                    796:                else
                    797:                        options->max_startups = options->max_startups_begin;
                    798:                break;
                    799:
                    800:        case sBanner:
                    801:                charptr = &options->banner;
                    802:                goto parse_filename;
                    803:        /*
                    804:         * These options can contain %X options expanded at
                    805:         * connect time, so that you can specify paths like:
                    806:         *
                    807:         * AuthorizedKeysFile   /etc/ssh_keys/%u
                    808:         */
                    809:        case sAuthorizedKeysFile:
                    810:        case sAuthorizedKeysFile2:
                    811:                charptr = (opcode == sAuthorizedKeysFile ) ?
                    812:                    &options->authorized_keys_file :
                    813:                    &options->authorized_keys_file2;
                    814:                goto parse_filename;
                    815:
                    816:        case sClientAliveInterval:
                    817:                intptr = &options->client_alive_interval;
                    818:                goto parse_time;
                    819:
                    820:        case sClientAliveCountMax:
                    821:                intptr = &options->client_alive_count_max;
                    822:                goto parse_int;
                    823:
                    824:        case sDeprecated:
                    825:                log("%s line %d: Deprecated option %s",
                    826:                    filename, linenum, arg);
                    827:                while (arg)
                    828:                    arg = strdelim(&cp);
                    829:                break;
                    830:
                    831:        default:
                    832:                fatal("%s line %d: Missing handler for opcode %s (%d)",
                    833:                    filename, linenum, arg, opcode);
                    834:        }
                    835:        if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
                    836:                fatal("%s line %d: garbage at end of line; \"%.200s\".",
                    837:                    filename, linenum, arg);
                    838:        return 0;
                    839: }
                    840:
                    841: /* Reads the server configuration file. */
1.25      markus    842:
1.94      markus    843: void
                    844: read_server_config(ServerOptions *options, const char *filename)
                    845: {
                    846:        FILE *f;
                    847:        char line[1024];
                    848:        int linenum;
                    849:        int bad_options = 0;
1.81      stevesk   850:
1.94      markus    851:        f = fopen(filename, "r");
                    852:        if (!f) {
                    853:                perror(filename);
                    854:                exit(1);
                    855:        }
                    856:        linenum = 0;
                    857:        while (fgets(line, sizeof(line), f)) {
                    858:                /* Update line number counter. */
                    859:                linenum++;
                    860:                if (process_server_config_line(options, line, filename, linenum) != 0)
                    861:                        bad_options++;
1.1       deraadt   862:        }
1.25      markus    863:        fclose(f);
1.78      stevesk   864:        if (bad_options > 0)
                    865:                fatal("%s: terminating, %d bad configuration options",
                    866:                    filename, bad_options);
1.1       deraadt   867: }