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

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