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

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