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

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