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

1.226     dtucker     1:
1.324   ! djm         2: /* $OpenBSD: servconf.c,v 1.323 2018/02/09 02:37:36 dtucker Exp $ */
1.1       deraadt     3: /*
1.26      deraadt     4:  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
                      5:  *                    All rights reserved
1.34      markus      6:  *
1.51      deraadt     7:  * As far as I am concerned, the code I have written for this software
                      8:  * can be used freely for any purpose.  Any derived versions of this
                      9:  * software must be clearly marked as such, and if the derived work is
                     10:  * incompatible with the protocol description in the RFC file, it must be
                     11:  * called by a name other than "ssh" or "Secure Shell".
1.26      deraadt    12:  */
1.1       deraadt    13:
1.152     stevesk    14: #include <sys/types.h>
                     15: #include <sys/socket.h>
1.179     djm        16: #include <sys/queue.h>
1.315     djm        17: #include <sys/sysctl.h>
1.154     stevesk    18:
1.213     djm        19: #include <netinet/in.h>
                     20: #include <netinet/ip.h>
1.315     djm        21: #include <net/route.h>
1.213     djm        22:
1.235     dtucker    23: #include <ctype.h>
1.154     stevesk    24: #include <netdb.h>
1.165     dtucker    25: #include <pwd.h>
1.162     stevesk    26: #include <stdio.h>
1.161     stevesk    27: #include <stdlib.h>
1.160     stevesk    28: #include <string.h>
1.164     deraadt    29: #include <signal.h>
1.155     stevesk    30: #include <unistd.h>
1.259     deraadt    31: #include <limits.h>
1.164     deraadt    32: #include <stdarg.h>
1.182     dtucker    33: #include <errno.h>
1.236     dtucker    34: #include <util.h>
1.1       deraadt    35:
1.164     deraadt    36: #include "xmalloc.h"
1.1       deraadt    37: #include "ssh.h"
1.62      markus     38: #include "log.h"
1.164     deraadt    39: #include "buffer.h"
1.251     millert    40: #include "misc.h"
1.1       deraadt    41: #include "servconf.h"
1.33      markus     42: #include "compat.h"
1.60      markus     43: #include "pathnames.h"
1.62      markus     44: #include "cipher.h"
1.164     deraadt    45: #include "key.h"
1.66      markus     46: #include "kex.h"
                     47: #include "mac.h"
1.153     dtucker    48: #include "match.h"
1.156     dtucker    49: #include "channels.h"
1.165     dtucker    50: #include "groupaccess.h"
1.226     dtucker    51: #include "canohost.h"
                     52: #include "packet.h"
1.232     djm        53: #include "hostfile.h"
                     54: #include "auth.h"
1.252     djm        55: #include "myproposal.h"
1.256     djm        56: #include "digest.h"
1.1       deraadt    57:
1.315     djm        58: static void add_listen_addr(ServerOptions *, const char *,
                     59:     const char *, int);
                     60: static void add_one_listen_addr(ServerOptions *, const char *,
                     61:     const char *, int);
1.29      markus     62:
1.102     provos     63: /* Use of privilege separation or not */
                     64: extern int use_privsep;
1.153     dtucker    65: extern Buffer cfg;
1.62      markus     66:
1.1       deraadt    67: /* Initializes the server options to their default values. */
                     68:
1.34      markus     69: void
1.25      markus     70: initialize_server_options(ServerOptions *options)
1.1       deraadt    71: {
1.25      markus     72:        memset(options, 0, sizeof(*options));
1.29      markus     73:        options->num_ports = 0;
                     74:        options->ports_from_cmdline = 0;
1.266     dtucker    75:        options->queued_listen_addrs = NULL;
                     76:        options->num_queued_listens = 0;
1.29      markus     77:        options->listen_addrs = NULL;
1.315     djm        78:        options->num_listen_addrs = 0;
1.138     djm        79:        options->address_family = -1;
1.316     djm        80:        options->routing_domain = NULL;
1.54      markus     81:        options->num_host_key_files = 0;
1.203     djm        82:        options->num_host_cert_files = 0;
1.240     markus     83:        options->host_key_agent = NULL;
1.36      markus     84:        options->pid_file = NULL;
1.25      markus     85:        options->login_grace_time = -1;
1.279     chris      86:        options->permit_root_login = PERMIT_NOT_SET;
1.25      markus     87:        options->ignore_rhosts = -1;
                     88:        options->ignore_user_known_hosts = -1;
                     89:        options->print_motd = -1;
1.72      stevesk    90:        options->print_lastlog = -1;
1.25      markus     91:        options->x11_forwarding = -1;
                     92:        options->x11_display_offset = -1;
1.99      stevesk    93:        options->x11_use_localhost = -1;
1.244     djm        94:        options->permit_tty = -1;
1.250     djm        95:        options->permit_user_rc = -1;
1.42      markus     96:        options->xauth_location = NULL;
1.25      markus     97:        options->strict_modes = -1;
1.129     markus     98:        options->tcp_keep_alive = -1;
1.101     markus     99:        options->log_facility = SYSLOG_FACILITY_NOT_SET;
                    100:        options->log_level = SYSLOG_LEVEL_NOT_SET;
1.75      markus    101:        options->hostbased_authentication = -1;
                    102:        options->hostbased_uses_name_from_packet_only = -1;
1.258     djm       103:        options->hostbased_key_types = NULL;
1.276     markus    104:        options->hostkeyalgorithms = NULL;
1.54      markus    105:        options->pubkey_authentication = -1;
1.258     djm       106:        options->pubkey_key_types = NULL;
1.25      markus    107:        options->kerberos_authentication = -1;
                    108:        options->kerberos_or_local_passwd = -1;
                    109:        options->kerberos_ticket_cleanup = -1;
1.130     jakob     110:        options->kerberos_get_afs_token = -1;
1.125     markus    111:        options->gss_authentication=-1;
                    112:        options->gss_cleanup_creds = -1;
1.271     djm       113:        options->gss_strict_acceptor = -1;
1.25      markus    114:        options->password_authentication = -1;
1.52      markus    115:        options->kbd_interactive_authentication = -1;
1.80      markus    116:        options->challenge_response_authentication = -1;
1.25      markus    117:        options->permit_empty_passwd = -1;
1.113     markus    118:        options->permit_user_env = -1;
1.111     markus    119:        options->compression = -1;
1.235     dtucker   120:        options->rekey_limit = -1;
                    121:        options->rekey_interval = -1;
1.53      markus    122:        options->allow_tcp_forwarding = -1;
1.251     millert   123:        options->allow_streamlocal_forwarding = -1;
1.178     pyr       124:        options->allow_agent_forwarding = -1;
1.25      markus    125:        options->num_allow_users = 0;
                    126:        options->num_deny_users = 0;
                    127:        options->num_allow_groups = 0;
                    128:        options->num_deny_groups = 0;
1.33      markus    129:        options->ciphers = NULL;
1.66      markus    130:        options->macs = NULL;
1.211     djm       131:        options->kex_algorithms = NULL;
1.251     millert   132:        options->fwd_opts.gateway_ports = -1;
                    133:        options->fwd_opts.streamlocal_bind_mask = (mode_t)-1;
                    134:        options->fwd_opts.streamlocal_bind_unlink = -1;
1.43      jakob     135:        options->num_subsystems = 0;
1.50      markus    136:        options->max_startups_begin = -1;
                    137:        options->max_startups_rate = -1;
1.46      markus    138:        options->max_startups = -1;
1.133     dtucker   139:        options->max_authtries = -1;
1.180     djm       140:        options->max_sessions = -1;
1.57      markus    141:        options->banner = NULL;
1.122     markus    142:        options->use_dns = -1;
1.77      beck      143:        options->client_alive_interval = -1;
                    144:        options->client_alive_count_max = -1;
1.219     djm       145:        options->num_authkeys_files = 0;
1.131     djm       146:        options->num_accept_env = 0;
1.145     reyk      147:        options->permit_tun = -1;
1.310     djm       148:        options->permitted_opens = NULL;
1.158     dtucker   149:        options->adm_forced_command = NULL;
1.176     djm       150:        options->chroot_directory = NULL;
1.231     djm       151:        options->authorized_keys_command = NULL;
                    152:        options->authorized_keys_command_user = NULL;
1.204     djm       153:        options->revoked_keys_file = NULL;
                    154:        options->trusted_user_ca_keys = NULL;
1.208     djm       155:        options->authorized_principals_file = NULL;
1.270     djm       156:        options->authorized_principals_command = NULL;
                    157:        options->authorized_principals_command_user = NULL;
1.213     djm       158:        options->ip_qos_interactive = -1;
                    159:        options->ip_qos_bulk = -1;
1.225     djm       160:        options->version_addendum = NULL;
1.256     djm       161:        options->fingerprint_hash = -1;
1.301     djm       162:        options->disable_forwarding = -1;
1.309     djm       163:        options->expose_userauth_info = -1;
1.1       deraadt   164: }
                    165:
1.257     djm       166: /* Returns 1 if a string option is unset or set to "none" or 0 otherwise. */
                    167: static int
                    168: option_clear_or_none(const char *o)
                    169: {
                    170:        return o == NULL || strcasecmp(o, "none") == 0;
                    171: }
                    172:
1.282     djm       173: static void
                    174: assemble_algorithms(ServerOptions *o)
                    175: {
                    176:        if (kex_assemble_names(KEX_SERVER_ENCRYPT, &o->ciphers) != 0 ||
                    177:            kex_assemble_names(KEX_SERVER_MAC, &o->macs) != 0 ||
                    178:            kex_assemble_names(KEX_SERVER_KEX, &o->kex_algorithms) != 0 ||
                    179:            kex_assemble_names(KEX_DEFAULT_PK_ALG,
                    180:            &o->hostkeyalgorithms) != 0 ||
                    181:            kex_assemble_names(KEX_DEFAULT_PK_ALG,
                    182:            &o->hostbased_key_types) != 0 ||
                    183:            kex_assemble_names(KEX_DEFAULT_PK_ALG, &o->pubkey_key_types) != 0)
                    184:                fatal("kex_assemble_names failed");
                    185: }
                    186:
1.314     djm       187: static void
                    188: array_append(const char *file, const int line, const char *directive,
                    189:     char ***array, u_int *lp, const char *s)
                    190: {
                    191:
                    192:        if (*lp >= INT_MAX)
                    193:                fatal("%s line %d: Too many %s entries", file, line, directive);
                    194:
                    195:        *array = xrecallocarray(*array, *lp, *lp + 1, sizeof(**array));
                    196:        (*array)[*lp] = xstrdup(s);
                    197:        (*lp)++;
                    198: }
                    199:
                    200: void
                    201: servconf_add_hostkey(const char *file, const int line,
                    202:     ServerOptions *options, const char *path)
                    203: {
                    204:        char *apath = derelativise_path(path);
                    205:
                    206:        array_append(file, line, "HostKey",
                    207:            &options->host_key_files, &options->num_host_key_files, apath);
                    208:        free(apath);
                    209: }
                    210:
                    211: void
                    212: servconf_add_hostcert(const char *file, const int line,
                    213:     ServerOptions *options, const char *path)
                    214: {
                    215:        char *apath = derelativise_path(path);
                    216:
                    217:        array_append(file, line, "HostCertificate",
                    218:            &options->host_cert_files, &options->num_host_cert_files, apath);
                    219:        free(apath);
                    220: }
                    221:
1.34      markus    222: void
1.25      markus    223: fill_default_server_options(ServerOptions *options)
1.1       deraadt   224: {
1.314     djm       225:        u_int i;
1.257     djm       226:
1.54      markus    227:        if (options->num_host_key_files == 0) {
1.293     naddy     228:                /* fill default hostkeys */
1.314     djm       229:                servconf_add_hostkey("[default]", 0, options,
                    230:                    _PATH_HOST_RSA_KEY_FILE);
                    231:                servconf_add_hostkey("[default]", 0, options,
                    232:                    _PATH_HOST_ECDSA_KEY_FILE);
                    233:                servconf_add_hostkey("[default]", 0, options,
                    234:                    _PATH_HOST_ED25519_KEY_FILE);
1.54      markus    235:        }
1.203     djm       236:        /* No certificates by default */
1.29      markus    237:        if (options->num_ports == 0)
                    238:                options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
1.266     dtucker   239:        if (options->address_family == -1)
                    240:                options->address_family = AF_UNSPEC;
1.29      markus    241:        if (options->listen_addrs == NULL)
1.315     djm       242:                add_listen_addr(options, NULL, NULL, 0);
1.36      markus    243:        if (options->pid_file == NULL)
1.257     djm       244:                options->pid_file = xstrdup(_PATH_SSH_DAEMON_PID_FILE);
1.25      markus    245:        if (options->login_grace_time == -1)
1.115     stevesk   246:                options->login_grace_time = 120;
1.67      markus    247:        if (options->permit_root_login == PERMIT_NOT_SET)
1.279     chris     248:                options->permit_root_login = PERMIT_NO_PASSWD;
1.25      markus    249:        if (options->ignore_rhosts == -1)
1.30      markus    250:                options->ignore_rhosts = 1;
1.25      markus    251:        if (options->ignore_user_known_hosts == -1)
                    252:                options->ignore_user_known_hosts = 0;
                    253:        if (options->print_motd == -1)
                    254:                options->print_motd = 1;
1.72      stevesk   255:        if (options->print_lastlog == -1)
                    256:                options->print_lastlog = 1;
1.25      markus    257:        if (options->x11_forwarding == -1)
1.30      markus    258:                options->x11_forwarding = 0;
1.25      markus    259:        if (options->x11_display_offset == -1)
1.30      markus    260:                options->x11_display_offset = 10;
1.99      stevesk   261:        if (options->x11_use_localhost == -1)
                    262:                options->x11_use_localhost = 1;
1.42      markus    263:        if (options->xauth_location == NULL)
1.257     djm       264:                options->xauth_location = xstrdup(_PATH_XAUTH);
1.244     djm       265:        if (options->permit_tty == -1)
                    266:                options->permit_tty = 1;
1.250     djm       267:        if (options->permit_user_rc == -1)
                    268:                options->permit_user_rc = 1;
1.25      markus    269:        if (options->strict_modes == -1)
                    270:                options->strict_modes = 1;
1.129     markus    271:        if (options->tcp_keep_alive == -1)
                    272:                options->tcp_keep_alive = 1;
1.101     markus    273:        if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
1.25      markus    274:                options->log_facility = SYSLOG_FACILITY_AUTH;
1.101     markus    275:        if (options->log_level == SYSLOG_LEVEL_NOT_SET)
1.58      markus    276:                options->log_level = SYSLOG_LEVEL_INFO;
1.75      markus    277:        if (options->hostbased_authentication == -1)
                    278:                options->hostbased_authentication = 0;
                    279:        if (options->hostbased_uses_name_from_packet_only == -1)
                    280:                options->hostbased_uses_name_from_packet_only = 0;
1.54      markus    281:        if (options->pubkey_authentication == -1)
                    282:                options->pubkey_authentication = 1;
1.25      markus    283:        if (options->kerberos_authentication == -1)
1.107     markus    284:                options->kerberos_authentication = 0;
1.25      markus    285:        if (options->kerberos_or_local_passwd == -1)
                    286:                options->kerberos_or_local_passwd = 1;
                    287:        if (options->kerberos_ticket_cleanup == -1)
                    288:                options->kerberos_ticket_cleanup = 1;
1.130     jakob     289:        if (options->kerberos_get_afs_token == -1)
                    290:                options->kerberos_get_afs_token = 0;
1.125     markus    291:        if (options->gss_authentication == -1)
                    292:                options->gss_authentication = 0;
                    293:        if (options->gss_cleanup_creds == -1)
                    294:                options->gss_cleanup_creds = 1;
1.271     djm       295:        if (options->gss_strict_acceptor == -1)
1.302     djm       296:                options->gss_strict_acceptor = 1;
1.25      markus    297:        if (options->password_authentication == -1)
                    298:                options->password_authentication = 1;
1.52      markus    299:        if (options->kbd_interactive_authentication == -1)
                    300:                options->kbd_interactive_authentication = 0;
1.80      markus    301:        if (options->challenge_response_authentication == -1)
                    302:                options->challenge_response_authentication = 1;
1.25      markus    303:        if (options->permit_empty_passwd == -1)
1.30      markus    304:                options->permit_empty_passwd = 0;
1.113     markus    305:        if (options->permit_user_env == -1)
                    306:                options->permit_user_env = 0;
1.111     markus    307:        if (options->compression == -1)
1.143     markus    308:                options->compression = COMP_DELAYED;
1.235     dtucker   309:        if (options->rekey_limit == -1)
                    310:                options->rekey_limit = 0;
                    311:        if (options->rekey_interval == -1)
                    312:                options->rekey_interval = 0;
1.53      markus    313:        if (options->allow_tcp_forwarding == -1)
1.233     djm       314:                options->allow_tcp_forwarding = FORWARD_ALLOW;
1.251     millert   315:        if (options->allow_streamlocal_forwarding == -1)
                    316:                options->allow_streamlocal_forwarding = FORWARD_ALLOW;
1.178     pyr       317:        if (options->allow_agent_forwarding == -1)
                    318:                options->allow_agent_forwarding = 1;
1.251     millert   319:        if (options->fwd_opts.gateway_ports == -1)
                    320:                options->fwd_opts.gateway_ports = 0;
1.46      markus    321:        if (options->max_startups == -1)
1.234     dtucker   322:                options->max_startups = 100;
1.50      markus    323:        if (options->max_startups_rate == -1)
1.234     dtucker   324:                options->max_startups_rate = 30;                /* 30% */
1.50      markus    325:        if (options->max_startups_begin == -1)
1.234     dtucker   326:                options->max_startups_begin = 10;
1.133     dtucker   327:        if (options->max_authtries == -1)
                    328:                options->max_authtries = DEFAULT_AUTH_FAIL_MAX;
1.180     djm       329:        if (options->max_sessions == -1)
                    330:                options->max_sessions = DEFAULT_SESSIONS_MAX;
1.122     markus    331:        if (options->use_dns == -1)
1.260     deraadt   332:                options->use_dns = 0;
1.77      beck      333:        if (options->client_alive_interval == -1)
1.95      deraadt   334:                options->client_alive_interval = 0;
1.77      beck      335:        if (options->client_alive_count_max == -1)
                    336:                options->client_alive_count_max = 3;
1.219     djm       337:        if (options->num_authkeys_files == 0) {
1.314     djm       338:                array_append("[default]", 0, "AuthorizedKeysFiles",
                    339:                    &options->authorized_keys_files,
                    340:                    &options->num_authkeys_files,
                    341:                    _PATH_SSH_USER_PERMITTED_KEYS);
                    342:                array_append("[default]", 0, "AuthorizedKeysFiles",
                    343:                    &options->authorized_keys_files,
                    344:                    &options->num_authkeys_files,
                    345:                    _PATH_SSH_USER_PERMITTED_KEYS2);
1.219     djm       346:        }
1.145     reyk      347:        if (options->permit_tun == -1)
1.146     reyk      348:                options->permit_tun = SSH_TUNMODE_NO;
1.213     djm       349:        if (options->ip_qos_interactive == -1)
                    350:                options->ip_qos_interactive = IPTOS_LOWDELAY;
                    351:        if (options->ip_qos_bulk == -1)
                    352:                options->ip_qos_bulk = IPTOS_THROUGHPUT;
1.225     djm       353:        if (options->version_addendum == NULL)
                    354:                options->version_addendum = xstrdup("");
1.251     millert   355:        if (options->fwd_opts.streamlocal_bind_mask == (mode_t)-1)
                    356:                options->fwd_opts.streamlocal_bind_mask = 0177;
                    357:        if (options->fwd_opts.streamlocal_bind_unlink == -1)
                    358:                options->fwd_opts.streamlocal_bind_unlink = 0;
1.256     djm       359:        if (options->fingerprint_hash == -1)
                    360:                options->fingerprint_hash = SSH_FP_HASH_DEFAULT;
1.301     djm       361:        if (options->disable_forwarding == -1)
                    362:                options->disable_forwarding = 0;
1.309     djm       363:        if (options->expose_userauth_info == -1)
                    364:                options->expose_userauth_info = 0;
1.277     djm       365:
1.282     djm       366:        assemble_algorithms(options);
1.277     djm       367:
1.285     djm       368:        /* Turn privilege separation and sandboxing on by default */
1.102     provos    369:        if (use_privsep == -1)
1.285     djm       370:                use_privsep = PRIVSEP_ON;
1.257     djm       371:
                    372: #define CLEAR_ON_NONE(v) \
                    373:        do { \
                    374:                if (option_clear_or_none(v)) { \
                    375:                        free(v); \
                    376:                        v = NULL; \
                    377:                } \
                    378:        } while(0)
                    379:        CLEAR_ON_NONE(options->pid_file);
                    380:        CLEAR_ON_NONE(options->xauth_location);
                    381:        CLEAR_ON_NONE(options->banner);
                    382:        CLEAR_ON_NONE(options->trusted_user_ca_keys);
                    383:        CLEAR_ON_NONE(options->revoked_keys_file);
1.267     djm       384:        CLEAR_ON_NONE(options->authorized_principals_file);
1.283     djm       385:        CLEAR_ON_NONE(options->adm_forced_command);
                    386:        CLEAR_ON_NONE(options->chroot_directory);
1.316     djm       387:        CLEAR_ON_NONE(options->routing_domain);
1.257     djm       388:        for (i = 0; i < options->num_host_key_files; i++)
                    389:                CLEAR_ON_NONE(options->host_key_files[i]);
                    390:        for (i = 0; i < options->num_host_cert_files; i++)
                    391:                CLEAR_ON_NONE(options->host_cert_files[i]);
                    392: #undef CLEAR_ON_NONE
1.291     djm       393:
                    394:        /* Similar handling for AuthenticationMethods=any */
                    395:        if (options->num_auth_methods == 1 &&
                    396:            strcmp(options->auth_methods[0], "any") == 0) {
                    397:                free(options->auth_methods[0]);
                    398:                options->auth_methods[0] = NULL;
                    399:                options->num_auth_methods = 0;
                    400:        }
                    401:
1.1       deraadt   402: }
                    403:
                    404: /* Keyword tokens. */
1.25      markus    405: typedef enum {
                    406:        sBadOption,             /* == unknown option */
1.293     naddy     407:        sPort, sHostKeyFile, sLoginGraceTime,
                    408:        sPermitRootLogin, sLogFacility, sLogLevel,
1.25      markus    409:        sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
1.323     dtucker   410:        sKerberosGetAFSToken, sChallengeResponseAuthentication,
1.138     djm       411:        sPasswordAuthentication, sKbdInteractiveAuthentication,
                    412:        sListenAddress, sAddressFamily,
1.72      stevesk   413:        sPrintMotd, sPrintLastLog, sIgnoreRhosts,
1.99      stevesk   414:        sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
1.244     djm       415:        sPermitTTY, sStrictModes, sEmptyPasswd, sTCPKeepAlive,
1.294     djm       416:        sPermitUserEnvironment, sAllowTcpForwarding, sCompression,
1.235     dtucker   417:        sRekeyLimit, sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
1.293     naddy     418:        sIgnoreUserKnownHosts, sCiphers, sMacs, sPidFile,
1.258     djm       419:        sGatewayPorts, sPubkeyAuthentication, sPubkeyAcceptedKeyTypes,
                    420:        sXAuthLocation, sSubsystem, sMaxStartups, sMaxAuthTries, sMaxSessions,
1.122     markus    421:        sBanner, sUseDNS, sHostbasedAuthentication,
1.258     djm       422:        sHostbasedUsesNameFromPacketOnly, sHostbasedAcceptedKeyTypes,
1.276     markus    423:        sHostKeyAlgorithms,
1.258     djm       424:        sClientAliveInterval, sClientAliveCountMax, sAuthorizedKeysFile,
1.271     djm       425:        sGssAuthentication, sGssCleanupCreds, sGssStrictAcceptor,
                    426:        sAcceptEnv, sPermitTunnel,
1.176     djm       427:        sMatch, sPermitOpen, sForceCommand, sChrootDirectory,
1.200     dtucker   428:        sUsePrivilegeSeparation, sAllowAgentForwarding,
1.249     djm       429:        sHostCertificate,
1.208     djm       430:        sRevokedKeys, sTrustedUserCAKeys, sAuthorizedPrincipalsFile,
1.270     djm       431:        sAuthorizedPrincipalsCommand, sAuthorizedPrincipalsCommandUser,
1.225     djm       432:        sKexAlgorithms, sIPQoS, sVersionAddendum,
1.231     djm       433:        sAuthorizedKeysCommand, sAuthorizedKeysCommandUser,
1.250     djm       434:        sAuthenticationMethods, sHostKeyAgent, sPermitUserRC,
1.251     millert   435:        sStreamLocalBindMask, sStreamLocalBindUnlink,
1.301     djm       436:        sAllowStreamLocalForwarding, sFingerprintHash, sDisableForwarding,
1.316     djm       437:        sExposeAuthInfo, sRDomain,
1.295     djm       438:        sDeprecated, sIgnore, sUnsupported
1.1       deraadt   439: } ServerOpCodes;
                    440:
1.153     dtucker   441: #define SSHCFG_GLOBAL  0x01    /* allowed in main section of sshd_config */
                    442: #define SSHCFG_MATCH   0x02    /* allowed inside a Match section */
                    443: #define SSHCFG_ALL     (SSHCFG_GLOBAL|SSHCFG_MATCH)
                    444:
1.1       deraadt   445: /* Textual representation of the tokens. */
1.25      markus    446: static struct {
                    447:        const char *name;
                    448:        ServerOpCodes opcode;
1.153     dtucker   449:        u_int flags;
1.25      markus    450: } keywords[] = {
1.153     dtucker   451:        { "port", sPort, SSHCFG_GLOBAL },
                    452:        { "hostkey", sHostKeyFile, SSHCFG_GLOBAL },
                    453:        { "hostdsakey", sHostKeyFile, SSHCFG_GLOBAL },          /* alias */
1.240     markus    454:        { "hostkeyagent", sHostKeyAgent, SSHCFG_GLOBAL },
1.153     dtucker   455:        { "pidfile", sPidFile, SSHCFG_GLOBAL },
1.293     naddy     456:        { "serverkeybits", sDeprecated, SSHCFG_GLOBAL },
1.153     dtucker   457:        { "logingracetime", sLoginGraceTime, SSHCFG_GLOBAL },
1.293     naddy     458:        { "keyregenerationinterval", sDeprecated, SSHCFG_GLOBAL },
1.175     dtucker   459:        { "permitrootlogin", sPermitRootLogin, SSHCFG_ALL },
1.153     dtucker   460:        { "syslogfacility", sLogFacility, SSHCFG_GLOBAL },
1.308     djm       461:        { "loglevel", sLogLevel, SSHCFG_ALL },
1.153     dtucker   462:        { "rhostsauthentication", sDeprecated, SSHCFG_GLOBAL },
1.293     naddy     463:        { "rhostsrsaauthentication", sDeprecated, SSHCFG_ALL },
1.168     dtucker   464:        { "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_ALL },
1.209     djm       465:        { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly, SSHCFG_ALL },
1.258     djm       466:        { "hostbasedacceptedkeytypes", sHostbasedAcceptedKeyTypes, SSHCFG_ALL },
1.276     markus    467:        { "hostkeyalgorithms", sHostKeyAlgorithms, SSHCFG_GLOBAL },
1.293     naddy     468:        { "rsaauthentication", sDeprecated, SSHCFG_ALL },
1.168     dtucker   469:        { "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_ALL },
1.258     djm       470:        { "pubkeyacceptedkeytypes", sPubkeyAcceptedKeyTypes, SSHCFG_ALL },
1.153     dtucker   471:        { "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL }, /* alias */
1.123     markus    472: #ifdef KRB5
1.168     dtucker   473:        { "kerberosauthentication", sKerberosAuthentication, SSHCFG_ALL },
1.153     dtucker   474:        { "kerberosorlocalpasswd", sKerberosOrLocalPasswd, SSHCFG_GLOBAL },
                    475:        { "kerberosticketcleanup", sKerberosTicketCleanup, SSHCFG_GLOBAL },
                    476:        { "kerberosgetafstoken", sKerberosGetAFSToken, SSHCFG_GLOBAL },
1.121     jakob     477: #else
1.168     dtucker   478:        { "kerberosauthentication", sUnsupported, SSHCFG_ALL },
1.153     dtucker   479:        { "kerberosorlocalpasswd", sUnsupported, SSHCFG_GLOBAL },
                    480:        { "kerberosticketcleanup", sUnsupported, SSHCFG_GLOBAL },
                    481:        { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
1.126     markus    482: #endif
1.153     dtucker   483:        { "kerberostgtpassing", sUnsupported, SSHCFG_GLOBAL },
                    484:        { "afstokenpassing", sUnsupported, SSHCFG_GLOBAL },
1.125     markus    485: #ifdef GSSAPI
1.168     dtucker   486:        { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
1.153     dtucker   487:        { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
1.271     djm       488:        { "gssapistrictacceptorcheck", sGssStrictAcceptor, SSHCFG_GLOBAL },
1.125     markus    489: #else
1.168     dtucker   490:        { "gssapiauthentication", sUnsupported, SSHCFG_ALL },
1.153     dtucker   491:        { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
1.271     djm       492:        { "gssapistrictacceptorcheck", sUnsupported, SSHCFG_GLOBAL },
1.125     markus    493: #endif
1.168     dtucker   494:        { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
                    495:        { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
1.170     dtucker   496:        { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
1.153     dtucker   497:        { "skeyauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, /* alias */
                    498:        { "checkmail", sDeprecated, SSHCFG_GLOBAL },
                    499:        { "listenaddress", sListenAddress, SSHCFG_GLOBAL },
                    500:        { "addressfamily", sAddressFamily, SSHCFG_GLOBAL },
                    501:        { "printmotd", sPrintMotd, SSHCFG_GLOBAL },
                    502:        { "printlastlog", sPrintLastLog, SSHCFG_GLOBAL },
                    503:        { "ignorerhosts", sIgnoreRhosts, SSHCFG_GLOBAL },
                    504:        { "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL },
1.157     dtucker   505:        { "x11forwarding", sX11Forwarding, SSHCFG_ALL },
                    506:        { "x11displayoffset", sX11DisplayOffset, SSHCFG_ALL },
                    507:        { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
1.153     dtucker   508:        { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
                    509:        { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
1.188     djm       510:        { "permitemptypasswords", sEmptyPasswd, SSHCFG_ALL },
1.153     dtucker   511:        { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
1.294     djm       512:        { "uselogin", sDeprecated, SSHCFG_GLOBAL },
1.153     dtucker   513:        { "compression", sCompression, SSHCFG_GLOBAL },
1.235     dtucker   514:        { "rekeylimit", sRekeyLimit, SSHCFG_ALL },
1.153     dtucker   515:        { "tcpkeepalive", sTCPKeepAlive, SSHCFG_GLOBAL },
                    516:        { "keepalive", sTCPKeepAlive, SSHCFG_GLOBAL },  /* obsolete alias */
                    517:        { "allowtcpforwarding", sAllowTcpForwarding, SSHCFG_ALL },
1.178     pyr       518:        { "allowagentforwarding", sAllowAgentForwarding, SSHCFG_ALL },
1.227     markus    519:        { "allowusers", sAllowUsers, SSHCFG_ALL },
                    520:        { "denyusers", sDenyUsers, SSHCFG_ALL },
                    521:        { "allowgroups", sAllowGroups, SSHCFG_ALL },
                    522:        { "denygroups", sDenyGroups, SSHCFG_ALL },
1.153     dtucker   523:        { "ciphers", sCiphers, SSHCFG_GLOBAL },
                    524:        { "macs", sMacs, SSHCFG_GLOBAL },
1.295     djm       525:        { "protocol", sIgnore, SSHCFG_GLOBAL },
1.153     dtucker   526:        { "gatewayports", sGatewayPorts, SSHCFG_ALL },
                    527:        { "subsystem", sSubsystem, SSHCFG_GLOBAL },
                    528:        { "maxstartups", sMaxStartups, SSHCFG_GLOBAL },
1.184     dtucker   529:        { "maxauthtries", sMaxAuthTries, SSHCFG_ALL },
1.180     djm       530:        { "maxsessions", sMaxSessions, SSHCFG_ALL },
1.168     dtucker   531:        { "banner", sBanner, SSHCFG_ALL },
1.153     dtucker   532:        { "usedns", sUseDNS, SSHCFG_GLOBAL },
                    533:        { "verifyreversemapping", sDeprecated, SSHCFG_GLOBAL },
                    534:        { "reversemappingcheck", sDeprecated, SSHCFG_GLOBAL },
1.300     markus    535:        { "clientaliveinterval", sClientAliveInterval, SSHCFG_ALL },
                    536:        { "clientalivecountmax", sClientAliveCountMax, SSHCFG_ALL },
1.209     djm       537:        { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_ALL },
1.219     djm       538:        { "authorizedkeysfile2", sDeprecated, SSHCFG_ALL },
1.306     djm       539:        { "useprivilegeseparation", sDeprecated, SSHCFG_GLOBAL},
1.227     markus    540:        { "acceptenv", sAcceptEnv, SSHCFG_ALL },
1.209     djm       541:        { "permittunnel", sPermitTunnel, SSHCFG_ALL },
1.244     djm       542:        { "permittty", sPermitTTY, SSHCFG_ALL },
1.250     djm       543:        { "permituserrc", sPermitUserRC, SSHCFG_ALL },
1.153     dtucker   544:        { "match", sMatch, SSHCFG_ALL },
1.156     dtucker   545:        { "permitopen", sPermitOpen, SSHCFG_ALL },
1.158     dtucker   546:        { "forcecommand", sForceCommand, SSHCFG_ALL },
1.176     djm       547:        { "chrootdirectory", sChrootDirectory, SSHCFG_ALL },
1.203     djm       548:        { "hostcertificate", sHostCertificate, SSHCFG_GLOBAL },
1.204     djm       549:        { "revokedkeys", sRevokedKeys, SSHCFG_ALL },
                    550:        { "trustedusercakeys", sTrustedUserCAKeys, SSHCFG_ALL },
1.209     djm       551:        { "authorizedprincipalsfile", sAuthorizedPrincipalsFile, SSHCFG_ALL },
1.211     djm       552:        { "kexalgorithms", sKexAlgorithms, SSHCFG_GLOBAL },
1.213     djm       553:        { "ipqos", sIPQoS, SSHCFG_ALL },
1.231     djm       554:        { "authorizedkeyscommand", sAuthorizedKeysCommand, SSHCFG_ALL },
                    555:        { "authorizedkeyscommanduser", sAuthorizedKeysCommandUser, SSHCFG_ALL },
1.270     djm       556:        { "authorizedprincipalscommand", sAuthorizedPrincipalsCommand, SSHCFG_ALL },
                    557:        { "authorizedprincipalscommanduser", sAuthorizedPrincipalsCommandUser, SSHCFG_ALL },
1.225     djm       558:        { "versionaddendum", sVersionAddendum, SSHCFG_GLOBAL },
1.232     djm       559:        { "authenticationmethods", sAuthenticationMethods, SSHCFG_ALL },
1.251     millert   560:        { "streamlocalbindmask", sStreamLocalBindMask, SSHCFG_ALL },
                    561:        { "streamlocalbindunlink", sStreamLocalBindUnlink, SSHCFG_ALL },
                    562:        { "allowstreamlocalforwarding", sAllowStreamLocalForwarding, SSHCFG_ALL },
1.256     djm       563:        { "fingerprinthash", sFingerprintHash, SSHCFG_GLOBAL },
1.301     djm       564:        { "disableforwarding", sDisableForwarding, SSHCFG_ALL },
1.309     djm       565:        { "exposeauthinfo", sExposeAuthInfo, SSHCFG_ALL },
1.316     djm       566:        { "rdomain", sRDomain, SSHCFG_ALL },
1.153     dtucker   567:        { NULL, sBadOption, 0 }
1.1       deraadt   568: };
                    569:
1.182     dtucker   570: static struct {
                    571:        int val;
                    572:        char *text;
                    573: } tunmode_desc[] = {
                    574:        { SSH_TUNMODE_NO, "no" },
                    575:        { SSH_TUNMODE_POINTOPOINT, "point-to-point" },
                    576:        { SSH_TUNMODE_ETHERNET, "ethernet" },
                    577:        { SSH_TUNMODE_YES, "yes" },
                    578:        { -1, NULL }
                    579: };
                    580:
1.27      markus    581: /*
1.73      stevesk   582:  * Returns the number of the token pointed to by cp or sBadOption.
1.27      markus    583:  */
1.1       deraadt   584:
1.34      markus    585: static ServerOpCodes
1.25      markus    586: parse_token(const char *cp, const char *filename,
1.153     dtucker   587:            int linenum, u_int *flags)
1.1       deraadt   588: {
1.55      markus    589:        u_int i;
1.1       deraadt   590:
1.25      markus    591:        for (i = 0; keywords[i].name; i++)
1.153     dtucker   592:                if (strcasecmp(cp, keywords[i].name) == 0) {
                    593:                        *flags = keywords[i].flags;
1.25      markus    594:                        return keywords[i].opcode;
1.153     dtucker   595:                }
1.25      markus    596:
1.78      stevesk   597:        error("%s: line %d: Bad configuration option: %s",
                    598:            filename, linenum, cp);
1.25      markus    599:        return sBadOption;
1.1       deraadt   600: }
                    601:
1.202     djm       602: char *
                    603: derelativise_path(const char *path)
                    604: {
1.259     deraadt   605:        char *expanded, *ret, cwd[PATH_MAX];
1.202     djm       606:
1.257     djm       607:        if (strcasecmp(path, "none") == 0)
                    608:                return xstrdup("none");
1.202     djm       609:        expanded = tilde_expand_filename(path, getuid());
                    610:        if (*expanded == '/')
                    611:                return expanded;
1.207     djm       612:        if (getcwd(cwd, sizeof(cwd)) == NULL)
1.202     djm       613:                fatal("%s: getcwd: %s", __func__, strerror(errno));
                    614:        xasprintf(&ret, "%s/%s", cwd, expanded);
1.239     djm       615:        free(expanded);
1.202     djm       616:        return ret;
                    617: }
                    618:
1.84      itojun    619: static void
1.315     djm       620: add_listen_addr(ServerOptions *options, const char *addr,
                    621:     const char *rdomain, int port)
1.74      stevesk   622: {
1.142     djm       623:        u_int i;
1.74      stevesk   624:
1.315     djm       625:        if (port > 0)
                    626:                add_one_listen_addr(options, addr, rdomain, port);
                    627:        else {
                    628:                for (i = 0; i < options->num_ports; i++) {
                    629:                        add_one_listen_addr(options, addr, rdomain,
                    630:                            options->ports[i]);
                    631:                }
                    632:        }
1.74      stevesk   633: }
                    634:
1.84      itojun    635: static void
1.315     djm       636: add_one_listen_addr(ServerOptions *options, const char *addr,
                    637:     const char *rdomain, int port)
1.29      markus    638: {
                    639:        struct addrinfo hints, *ai, *aitop;
                    640:        char strport[NI_MAXSERV];
                    641:        int gaierr;
1.315     djm       642:        u_int i;
                    643:
                    644:        /* Find listen_addrs entry for this rdomain */
                    645:        for (i = 0; i < options->num_listen_addrs; i++) {
                    646:                if (rdomain == NULL && options->listen_addrs[i].rdomain == NULL)
                    647:                        break;
                    648:                if (rdomain == NULL || options->listen_addrs[i].rdomain == NULL)
                    649:                        continue;
                    650:                if (strcmp(rdomain, options->listen_addrs[i].rdomain) == 0)
                    651:                        break;
                    652:        }
                    653:        if (i >= options->num_listen_addrs) {
                    654:                /* No entry for this rdomain; allocate one */
                    655:                if (i >= INT_MAX)
                    656:                        fatal("%s: too many listen addresses", __func__);
                    657:                options->listen_addrs = xrecallocarray(options->listen_addrs,
                    658:                    options->num_listen_addrs, options->num_listen_addrs + 1,
                    659:                    sizeof(*options->listen_addrs));
                    660:                i = options->num_listen_addrs++;
                    661:                if (rdomain != NULL)
                    662:                        options->listen_addrs[i].rdomain = xstrdup(rdomain);
                    663:        }
                    664:        /* options->listen_addrs[i] points to the addresses for this rdomain */
1.29      markus    665:
1.74      stevesk   666:        memset(&hints, 0, sizeof(hints));
1.138     djm       667:        hints.ai_family = options->address_family;
1.74      stevesk   668:        hints.ai_socktype = SOCK_STREAM;
                    669:        hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
1.194     djm       670:        snprintf(strport, sizeof strport, "%d", port);
1.74      stevesk   671:        if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
                    672:                fatal("bad addr or host: %s (%s)",
                    673:                    addr ? addr : "<NULL>",
1.173     dtucker   674:                    ssh_gai_strerror(gaierr));
1.74      stevesk   675:        for (ai = aitop; ai->ai_next; ai = ai->ai_next)
                    676:                ;
1.315     djm       677:        ai->ai_next = options->listen_addrs[i].addrs;
                    678:        options->listen_addrs[i].addrs = aitop;
                    679: }
                    680:
                    681: /* Returns nonzero if the routing domain name is valid */
                    682: static int
                    683: valid_rdomain(const char *name)
                    684: {
                    685:        const char *errstr;
                    686:        long long num;
                    687:        struct rt_tableinfo info;
                    688:        int mib[6];
                    689:        size_t miblen = sizeof(mib);
                    690:
                    691:        if (name == NULL)
                    692:                return 1;
                    693:
                    694:        num = strtonum(name, 0, 255, &errstr);
                    695:        if (errstr != NULL)
                    696:                return 0;
                    697:
                    698:        /* Check whether the table actually exists */
                    699:        memset(mib, 0, sizeof(mib));
                    700:        mib[0] = CTL_NET;
                    701:        mib[1] = PF_ROUTE;
                    702:        mib[4] = NET_RT_TABLE;
                    703:        mib[5] = (int)num;
                    704:        if (sysctl(mib, 6, &info, &miblen, NULL, 0) == -1)
                    705:                return 0;
                    706:
                    707:        return 1;
1.29      markus    708: }
                    709:
1.266     dtucker   710: /*
                    711:  * Queue a ListenAddress to be processed once we have all of the Ports
                    712:  * and AddressFamily options.
                    713:  */
                    714: static void
1.315     djm       715: queue_listen_addr(ServerOptions *options, const char *addr,
                    716:     const char *rdomain, int port)
1.266     dtucker   717: {
1.315     djm       718:        struct queued_listenaddr *qla;
                    719:
                    720:        options->queued_listen_addrs = xrecallocarray(
                    721:            options->queued_listen_addrs,
                    722:            options->num_queued_listens, options->num_queued_listens + 1,
                    723:            sizeof(*options->queued_listen_addrs));
                    724:        qla = &options->queued_listen_addrs[options->num_queued_listens++];
                    725:        qla->addr = xstrdup(addr);
                    726:        qla->port = port;
                    727:        qla->rdomain = rdomain == NULL ? NULL : xstrdup(rdomain);
1.266     dtucker   728: }
                    729:
                    730: /*
                    731:  * Process queued (text) ListenAddress entries.
                    732:  */
                    733: static void
                    734: process_queued_listen_addrs(ServerOptions *options)
                    735: {
                    736:        u_int i;
1.315     djm       737:        struct queued_listenaddr *qla;
1.266     dtucker   738:
                    739:        if (options->num_ports == 0)
                    740:                options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
                    741:        if (options->address_family == -1)
                    742:                options->address_family = AF_UNSPEC;
                    743:
                    744:        for (i = 0; i < options->num_queued_listens; i++) {
1.315     djm       745:                qla = &options->queued_listen_addrs[i];
                    746:                add_listen_addr(options, qla->addr, qla->rdomain, qla->port);
                    747:                free(qla->addr);
                    748:                free(qla->rdomain);
1.266     dtucker   749:        }
                    750:        free(options->queued_listen_addrs);
                    751:        options->queued_listen_addrs = NULL;
                    752:        options->num_queued_listens = 0;
                    753: }
                    754:
1.310     djm       755: /*
                    756:  * Inform channels layer of permitopen options from configuration.
                    757:  */
                    758: void
                    759: process_permitopen(struct ssh *ssh, ServerOptions *options)
                    760: {
                    761:        u_int i;
                    762:        int port;
                    763:        char *host, *arg, *oarg;
                    764:
                    765:        channel_clear_adm_permitted_opens(ssh);
                    766:        if (options->num_permitted_opens == 0)
                    767:                return; /* permit any */
                    768:
                    769:        /* handle keywords: "any" / "none" */
                    770:        if (options->num_permitted_opens == 1 &&
                    771:            strcmp(options->permitted_opens[0], "any") == 0)
                    772:                return;
                    773:        if (options->num_permitted_opens == 1 &&
                    774:            strcmp(options->permitted_opens[0], "none") == 0) {
                    775:                channel_disable_adm_local_opens(ssh);
                    776:                return;
                    777:        }
                    778:        /* Otherwise treat it as a list of permitted host:port */
                    779:        for (i = 0; i < options->num_permitted_opens; i++) {
                    780:                oarg = arg = xstrdup(options->permitted_opens[i]);
                    781:                host = hpdelim(&arg);
                    782:                if (host == NULL)
                    783:                        fatal("%s: missing host in PermitOpen", __func__);
                    784:                host = cleanhostname(host);
                    785:                if (arg == NULL || ((port = permitopen_port(arg)) < 0))
                    786:                        fatal("%s: bad port number in PermitOpen", __func__);
                    787:                /* Send it to channels layer */
                    788:                channel_add_adm_permitted_opens(ssh, host, port);
                    789:                free(oarg);
                    790:        }
                    791: }
                    792:
1.226     dtucker   793: struct connection_info *
                    794: get_connection_info(int populate, int use_dns)
                    795: {
1.286     djm       796:        struct ssh *ssh = active_state; /* XXX */
1.226     dtucker   797:        static struct connection_info ci;
                    798:
                    799:        if (!populate)
                    800:                return &ci;
1.286     djm       801:        ci.host = auth_get_canonical_hostname(ssh, use_dns);
                    802:        ci.address = ssh_remote_ipaddr(ssh);
                    803:        ci.laddress = ssh_local_ipaddr(ssh);
                    804:        ci.lport = ssh_local_port(ssh);
1.317     djm       805:        ci.rdomain = ssh_packet_rdomain_in(ssh);
1.226     dtucker   806:        return &ci;
                    807: }
                    808:
1.153     dtucker   809: /*
                    810:  * The strategy for the Match blocks is that the config file is parsed twice.
                    811:  *
                    812:  * The first time is at startup.  activep is initialized to 1 and the
                    813:  * directives in the global context are processed and acted on.  Hitting a
                    814:  * Match directive unsets activep and the directives inside the block are
                    815:  * checked for syntax only.
                    816:  *
                    817:  * The second time is after a connection has been established but before
                    818:  * authentication.  activep is initialized to 2 and global config directives
                    819:  * are ignored since they have already been processed.  If the criteria in a
                    820:  * Match block is met, activep is set and the subsequent directives
                    821:  * processed and actioned until EOF or another Match block unsets it.  Any
                    822:  * options set are copied into the main server config.
                    823:  *
                    824:  * Potential additions/improvements:
1.295     djm       825:  *  - Add Match support for pre-kex directives, eg. Ciphers.
1.153     dtucker   826:  *
                    827:  *  - Add a Tag directive (idea from David Leonard) ala pf, eg:
                    828:  *     Match Address 192.168.0.*
                    829:  *             Tag trusted
                    830:  *     Match Group wheel
                    831:  *             Tag trusted
                    832:  *     Match Tag trusted
                    833:  *             AllowTcpForwarding yes
                    834:  *             GatewayPorts clientspecified
                    835:  *             [...]
                    836:  *
                    837:  *  - Add a PermittedChannelRequests directive
                    838:  *     Match Group shell
                    839:  *             PermittedChannelRequests session,forwarded-tcpip
                    840:  */
                    841:
                    842: static int
1.165     dtucker   843: match_cfg_line_group(const char *grps, int line, const char *user)
                    844: {
                    845:        int result = 0;
                    846:        struct passwd *pw;
                    847:
                    848:        if (user == NULL)
                    849:                goto out;
                    850:
                    851:        if ((pw = getpwnam(user)) == NULL) {
                    852:                debug("Can't match group at line %d because user %.100s does "
                    853:                    "not exist", line, user);
                    854:        } else if (ga_init(pw->pw_name, pw->pw_gid) == 0) {
                    855:                debug("Can't Match group because user %.100s not in any group "
                    856:                    "at line %d", user, line);
1.186     djm       857:        } else if (ga_match_pattern_list(grps) != 1) {
                    858:                debug("user %.100s does not match group list %.100s at line %d",
                    859:                    user, grps, line);
1.165     dtucker   860:        } else {
1.186     djm       861:                debug("user %.100s matched group list %.100s at line %d", user,
                    862:                    grps, line);
1.165     dtucker   863:                result = 1;
                    864:        }
                    865: out:
                    866:        ga_free();
                    867:        return result;
                    868: }
                    869:
1.319     dtucker   870: static void
                    871: match_test_missing_fatal(const char *criteria, const char *attrib)
                    872: {
                    873:        fatal("'Match %s' in configuration but '%s' not in connection "
                    874:            "test specification.", criteria, attrib);
                    875: }
                    876:
1.226     dtucker   877: /*
1.230     dtucker   878:  * All of the attributes on a single Match line are ANDed together, so we need
1.242     dtucker   879:  * to check every attribute and set the result to zero if any attribute does
1.230     dtucker   880:  * not match.
1.226     dtucker   881:  */
1.165     dtucker   882: static int
1.226     dtucker   883: match_cfg_line(char **condition, int line, struct connection_info *ci)
1.153     dtucker   884: {
1.243     dtucker   885:        int result = 1, attributes = 0, port;
1.153     dtucker   886:        char *arg, *attrib, *cp = *condition;
                    887:
1.226     dtucker   888:        if (ci == NULL)
1.153     dtucker   889:                debug3("checking syntax for 'Match %s'", cp);
                    890:        else
1.226     dtucker   891:                debug3("checking match for '%s' user %s host %s addr %s "
                    892:                    "laddr %s lport %d", cp, ci->user ? ci->user : "(null)",
                    893:                    ci->host ? ci->host : "(null)",
                    894:                    ci->address ? ci->address : "(null)",
                    895:                    ci->laddress ? ci->laddress : "(null)", ci->lport);
1.153     dtucker   896:
                    897:        while ((attrib = strdelim(&cp)) && *attrib != '\0') {
1.243     dtucker   898:                attributes++;
                    899:                if (strcasecmp(attrib, "all") == 0) {
                    900:                        if (attributes != 1 ||
                    901:                            ((arg = strdelim(&cp)) != NULL && *arg != '\0')) {
                    902:                                error("'all' cannot be combined with other "
                    903:                                    "Match attributes");
                    904:                                return -1;
                    905:                        }
                    906:                        *condition = cp;
                    907:                        return 1;
                    908:                }
1.153     dtucker   909:                if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
                    910:                        error("Missing Match criteria for %s", attrib);
                    911:                        return -1;
                    912:                }
                    913:                if (strcasecmp(attrib, "user") == 0) {
1.319     dtucker   914:                        if (ci == NULL) {
1.153     dtucker   915:                                result = 0;
                    916:                                continue;
                    917:                        }
1.319     dtucker   918:                        if (ci->user == NULL)
                    919:                                match_test_missing_fatal("User", "user");
1.269     djm       920:                        if (match_pattern_list(ci->user, arg, 0) != 1)
1.153     dtucker   921:                                result = 0;
                    922:                        else
                    923:                                debug("user %.100s matched 'User %.100s' at "
1.226     dtucker   924:                                    "line %d", ci->user, arg, line);
1.165     dtucker   925:                } else if (strcasecmp(attrib, "group") == 0) {
1.319     dtucker   926:                        if (ci == NULL) {
1.226     dtucker   927:                                result = 0;
                    928:                                continue;
                    929:                        }
1.319     dtucker   930:                        if (ci->user == NULL)
                    931:                                match_test_missing_fatal("Group", "user");
1.226     dtucker   932:                        switch (match_cfg_line_group(arg, line, ci->user)) {
1.165     dtucker   933:                        case -1:
                    934:                                return -1;
                    935:                        case 0:
                    936:                                result = 0;
                    937:                        }
1.153     dtucker   938:                } else if (strcasecmp(attrib, "host") == 0) {
1.319     dtucker   939:                        if (ci == NULL) {
1.153     dtucker   940:                                result = 0;
                    941:                                continue;
                    942:                        }
1.319     dtucker   943:                        if (ci->host == NULL)
                    944:                                match_test_missing_fatal("Host", "host");
1.269     djm       945:                        if (match_hostname(ci->host, arg) != 1)
1.153     dtucker   946:                                result = 0;
                    947:                        else
                    948:                                debug("connection from %.100s matched 'Host "
1.226     dtucker   949:                                    "%.100s' at line %d", ci->host, arg, line);
1.153     dtucker   950:                } else if (strcasecmp(attrib, "address") == 0) {
1.319     dtucker   951:                        if (ci == NULL) {
1.226     dtucker   952:                                result = 0;
                    953:                                continue;
                    954:                        }
1.319     dtucker   955:                        if (ci->address == NULL)
                    956:                                match_test_missing_fatal("Address", "addr");
1.226     dtucker   957:                        switch (addr_match_list(ci->address, arg)) {
1.181     djm       958:                        case 1:
                    959:                                debug("connection from %.100s matched 'Address "
1.226     dtucker   960:                                    "%.100s' at line %d", ci->address, arg, line);
1.181     djm       961:                                break;
                    962:                        case 0:
1.183     djm       963:                        case -1:
1.153     dtucker   964:                                result = 0;
1.181     djm       965:                                break;
1.183     djm       966:                        case -2:
1.181     djm       967:                                return -1;
1.153     dtucker   968:                        }
1.226     dtucker   969:                } else if (strcasecmp(attrib, "localaddress") == 0){
1.319     dtucker   970:                        if (ci == NULL) {
1.226     dtucker   971:                                result = 0;
                    972:                                continue;
                    973:                        }
1.319     dtucker   974:                        if (ci->laddress == NULL)
                    975:                                match_test_missing_fatal("LocalAddress",
                    976:                                    "laddr");
1.226     dtucker   977:                        switch (addr_match_list(ci->laddress, arg)) {
                    978:                        case 1:
                    979:                                debug("connection from %.100s matched "
                    980:                                    "'LocalAddress %.100s' at line %d",
                    981:                                    ci->laddress, arg, line);
                    982:                                break;
                    983:                        case 0:
                    984:                        case -1:
                    985:                                result = 0;
                    986:                                break;
                    987:                        case -2:
                    988:                                return -1;
                    989:                        }
                    990:                } else if (strcasecmp(attrib, "localport") == 0) {
                    991:                        if ((port = a2port(arg)) == -1) {
                    992:                                error("Invalid LocalPort '%s' on Match line",
                    993:                                    arg);
                    994:                                return -1;
                    995:                        }
1.319     dtucker   996:                        if (ci == NULL) {
1.226     dtucker   997:                                result = 0;
                    998:                                continue;
                    999:                        }
1.319     dtucker  1000:                        if (ci->lport == 0)
                   1001:                                match_test_missing_fatal("LocalPort", "lport");
1.226     dtucker  1002:                        /* TODO support port lists */
                   1003:                        if (port == ci->lport)
                   1004:                                debug("connection from %.100s matched "
                   1005:                                    "'LocalPort %d' at line %d",
                   1006:                                    ci->laddress, port, line);
                   1007:                        else
                   1008:                                result = 0;
1.317     djm      1009:                } else if (strcasecmp(attrib, "rdomain") == 0) {
                   1010:                        if (ci == NULL || ci->rdomain == NULL) {
                   1011:                                result = 0;
                   1012:                                continue;
                   1013:                        }
                   1014:                        if (match_pattern_list(ci->rdomain, arg, 0) != 1)
                   1015:                                result = 0;
                   1016:                        else
                   1017:                                debug("user %.100s matched 'RDomain %.100s' at "
                   1018:                                    "line %d", ci->rdomain, arg, line);
1.153     dtucker  1019:                } else {
                   1020:                        error("Unsupported Match attribute %s", attrib);
                   1021:                        return -1;
                   1022:                }
1.243     dtucker  1023:        }
                   1024:        if (attributes == 0) {
                   1025:                error("One or more attributes required for Match");
                   1026:                return -1;
1.153     dtucker  1027:        }
1.226     dtucker  1028:        if (ci != NULL)
1.153     dtucker  1029:                debug3("match %sfound", result ? "" : "not ");
                   1030:        *condition = cp;
                   1031:        return result;
                   1032: }
                   1033:
1.158     dtucker  1034: #define WHITESPACE " \t\r\n"
                   1035:
1.220     djm      1036: /* Multistate option parsing */
                   1037: struct multistate {
                   1038:        char *key;
                   1039:        int value;
                   1040: };
1.320     djm      1041: static const struct multistate multistate_flag[] = {
                   1042:        { "yes",                        1 },
                   1043:        { "no",                         0 },
                   1044:        { NULL, -1 }
                   1045: };
1.220     djm      1046: static const struct multistate multistate_addressfamily[] = {
                   1047:        { "inet",                       AF_INET },
                   1048:        { "inet6",                      AF_INET6 },
                   1049:        { "any",                        AF_UNSPEC },
                   1050:        { NULL, -1 }
                   1051: };
                   1052: static const struct multistate multistate_permitrootlogin[] = {
                   1053:        { "without-password",           PERMIT_NO_PASSWD },
1.280     deraadt  1054:        { "prohibit-password",          PERMIT_NO_PASSWD },
1.220     djm      1055:        { "forced-commands-only",       PERMIT_FORCED_ONLY },
                   1056:        { "yes",                        PERMIT_YES },
                   1057:        { "no",                         PERMIT_NO },
                   1058:        { NULL, -1 }
                   1059: };
                   1060: static const struct multistate multistate_compression[] = {
1.297     djm      1061:        { "yes",                        COMP_DELAYED },
1.220     djm      1062:        { "delayed",                    COMP_DELAYED },
                   1063:        { "no",                         COMP_NONE },
                   1064:        { NULL, -1 }
                   1065: };
                   1066: static const struct multistate multistate_gatewayports[] = {
                   1067:        { "clientspecified",            2 },
                   1068:        { "yes",                        1 },
                   1069:        { "no",                         0 },
1.222     djm      1070:        { NULL, -1 }
                   1071: };
1.233     djm      1072: static const struct multistate multistate_tcpfwd[] = {
                   1073:        { "yes",                        FORWARD_ALLOW },
                   1074:        { "all",                        FORWARD_ALLOW },
                   1075:        { "no",                         FORWARD_DENY },
                   1076:        { "remote",                     FORWARD_REMOTE },
                   1077:        { "local",                      FORWARD_LOCAL },
                   1078:        { NULL, -1 }
                   1079: };
1.220     djm      1080:
1.94      markus   1081: int
                   1082: process_server_config_line(ServerOptions *options, char *line,
1.226     dtucker  1083:     const char *filename, int linenum, int *activep,
                   1084:     struct connection_info *connectinfo)
1.1       deraadt  1085: {
1.310     djm      1086:        char *cp, **charptr, *arg, *arg2, *p;
1.237     dtucker  1087:        int cmdline = 0, *intptr, value, value2, n, port;
1.174     dtucker  1088:        SyslogFacility *log_facility_ptr;
                   1089:        LogLevel *log_level_ptr;
1.25      markus   1090:        ServerOpCodes opcode;
1.153     dtucker  1091:        u_int i, flags = 0;
1.151     djm      1092:        size_t len;
1.237     dtucker  1093:        long long val64;
1.220     djm      1094:        const struct multistate *multistate_ptr;
1.322     dtucker  1095:        const char *errstr;
1.303     djm      1096:
                   1097:        /* Strip trailing whitespace. Allow \f (form feed) at EOL only */
                   1098:        if ((len = strlen(line)) == 0)
                   1099:                return 0;
                   1100:        for (len--; len > 0; len--) {
                   1101:                if (strchr(WHITESPACE "\f", line[len]) == NULL)
                   1102:                        break;
                   1103:                line[len] = '\0';
                   1104:        }
1.25      markus   1105:
1.94      markus   1106:        cp = line;
1.148     dtucker  1107:        if ((arg = strdelim(&cp)) == NULL)
1.147     djm      1108:                return 0;
1.94      markus   1109:        /* Ignore leading whitespace */
                   1110:        if (*arg == '\0')
                   1111:                arg = strdelim(&cp);
                   1112:        if (!arg || !*arg || *arg == '#')
                   1113:                return 0;
                   1114:        intptr = NULL;
                   1115:        charptr = NULL;
1.153     dtucker  1116:        opcode = parse_token(arg, filename, linenum, &flags);
                   1117:
                   1118:        if (activep == NULL) { /* We are processing a command line directive */
                   1119:                cmdline = 1;
                   1120:                activep = &cmdline;
                   1121:        }
                   1122:        if (*activep && opcode != sMatch)
                   1123:                debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
                   1124:        if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
1.226     dtucker  1125:                if (connectinfo == NULL) {
1.153     dtucker  1126:                        fatal("%s line %d: Directive '%s' is not allowed "
                   1127:                            "within a Match block", filename, linenum, arg);
                   1128:                } else { /* this is a directive we have already processed */
                   1129:                        while (arg)
                   1130:                                arg = strdelim(&cp);
                   1131:                        return 0;
                   1132:                }
                   1133:        }
                   1134:
1.94      markus   1135:        switch (opcode) {
                   1136:        case sBadOption:
                   1137:                return -1;
                   1138:        case sPort:
                   1139:                /* ignore ports from configfile if cmdline specifies ports */
                   1140:                if (options->ports_from_cmdline)
                   1141:                        return 0;
                   1142:                if (options->num_ports >= MAX_PORTS)
                   1143:                        fatal("%s line %d: too many ports.",
                   1144:                            filename, linenum);
1.48      provos   1145:                arg = strdelim(&cp);
1.94      markus   1146:                if (!arg || *arg == '\0')
                   1147:                        fatal("%s line %d: missing port number.",
                   1148:                            filename, linenum);
                   1149:                options->ports[options->num_ports++] = a2port(arg);
1.194     djm      1150:                if (options->ports[options->num_ports-1] <= 0)
1.94      markus   1151:                        fatal("%s line %d: Badly formatted port number.",
                   1152:                            filename, linenum);
                   1153:                break;
1.29      markus   1154:
1.94      markus   1155:        case sLoginGraceTime:
                   1156:                intptr = &options->login_grace_time;
1.180     djm      1157:  parse_time:
1.94      markus   1158:                arg = strdelim(&cp);
                   1159:                if (!arg || *arg == '\0')
                   1160:                        fatal("%s line %d: missing time value.",
                   1161:                            filename, linenum);
                   1162:                if ((value = convtime(arg)) == -1)
                   1163:                        fatal("%s line %d: invalid time value.",
                   1164:                            filename, linenum);
1.268     djm      1165:                if (*activep && *intptr == -1)
1.94      markus   1166:                        *intptr = value;
                   1167:                break;
                   1168:
                   1169:        case sListenAddress:
                   1170:                arg = strdelim(&cp);
1.139     djm      1171:                if (arg == NULL || *arg == '\0')
                   1172:                        fatal("%s line %d: missing address",
1.94      markus   1173:                            filename, linenum);
1.144     dtucker  1174:                /* check for bare IPv6 address: no "[]" and 2 or more ":" */
                   1175:                if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
                   1176:                    && strchr(p+1, ':') != NULL) {
1.315     djm      1177:                        port = 0;
                   1178:                        p = arg;
                   1179:                } else {
                   1180:                        p = hpdelim(&arg);
                   1181:                        if (p == NULL)
                   1182:                                fatal("%s line %d: bad address:port usage",
                   1183:                                    filename, linenum);
                   1184:                        p = cleanhostname(p);
                   1185:                        if (arg == NULL)
                   1186:                                port = 0;
                   1187:                        else if ((port = a2port(arg)) <= 0)
                   1188:                                fatal("%s line %d: bad port number",
                   1189:                                    filename, linenum);
                   1190:                }
                   1191:                /* Optional routing table */
                   1192:                arg2 = NULL;
                   1193:                if ((arg = strdelim(&cp)) != NULL) {
                   1194:                        if (strcmp(arg, "rdomain") != 0 ||
                   1195:                            (arg2 = strdelim(&cp)) == NULL)
                   1196:                                fatal("%s line %d: bad ListenAddress syntax",
                   1197:                                    filename, linenum);
                   1198:                        if (!valid_rdomain(arg2))
                   1199:                                fatal("%s line %d: bad routing domain",
                   1200:                                    filename, linenum);
1.144     dtucker  1201:                }
1.139     djm      1202:
1.315     djm      1203:                queue_listen_addr(options, p, arg2, port);
1.25      markus   1204:
1.138     djm      1205:                break;
                   1206:
                   1207:        case sAddressFamily:
1.220     djm      1208:                intptr = &options->address_family;
                   1209:                multistate_ptr = multistate_addressfamily;
                   1210:  parse_multistate:
1.138     djm      1211:                arg = strdelim(&cp);
1.141     markus   1212:                if (!arg || *arg == '\0')
1.220     djm      1213:                        fatal("%s line %d: missing argument.",
1.141     markus   1214:                            filename, linenum);
1.220     djm      1215:                value = -1;
                   1216:                for (i = 0; multistate_ptr[i].key != NULL; i++) {
                   1217:                        if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
                   1218:                                value = multistate_ptr[i].value;
                   1219:                                break;
                   1220:                        }
                   1221:                }
                   1222:                if (value == -1)
                   1223:                        fatal("%s line %d: unsupported option \"%s\".",
1.138     djm      1224:                            filename, linenum, arg);
1.220     djm      1225:                if (*activep && *intptr == -1)
1.138     djm      1226:                        *intptr = value;
1.94      markus   1227:                break;
                   1228:
                   1229:        case sHostKeyFile:
                   1230:                arg = strdelim(&cp);
                   1231:                if (!arg || *arg == '\0')
                   1232:                        fatal("%s line %d: missing file name.",
                   1233:                            filename, linenum);
1.314     djm      1234:                if (*activep)
                   1235:                        servconf_add_hostkey(filename, linenum, options, arg);
1.94      markus   1236:                break;
1.76      stevesk  1237:
1.240     markus   1238:        case sHostKeyAgent:
                   1239:                charptr = &options->host_key_agent;
                   1240:                arg = strdelim(&cp);
                   1241:                if (!arg || *arg == '\0')
                   1242:                        fatal("%s line %d: missing socket name.",
                   1243:                            filename, linenum);
                   1244:                if (*activep && *charptr == NULL)
                   1245:                        *charptr = !strcmp(arg, SSH_AUTHSOCKET_ENV_NAME) ?
                   1246:                            xstrdup(arg) : derelativise_path(arg);
                   1247:                break;
                   1248:
1.203     djm      1249:        case sHostCertificate:
1.314     djm      1250:                arg = strdelim(&cp);
                   1251:                if (!arg || *arg == '\0')
                   1252:                        fatal("%s line %d: missing file name.",
                   1253:                            filename, linenum);
                   1254:                if (*activep)
                   1255:                        servconf_add_hostcert(filename, linenum, options, arg);
                   1256:                break;
1.203     djm      1257:
1.94      markus   1258:        case sPidFile:
                   1259:                charptr = &options->pid_file;
1.314     djm      1260:  parse_filename:
                   1261:                arg = strdelim(&cp);
                   1262:                if (!arg || *arg == '\0')
                   1263:                        fatal("%s line %d: missing file name.",
                   1264:                            filename, linenum);
                   1265:                if (*activep && *charptr == NULL) {
                   1266:                        *charptr = derelativise_path(arg);
                   1267:                        /* increase optional counter */
                   1268:                        if (intptr != NULL)
                   1269:                                *intptr = *intptr + 1;
                   1270:                }
                   1271:                break;
1.25      markus   1272:
1.94      markus   1273:        case sPermitRootLogin:
                   1274:                intptr = &options->permit_root_login;
1.220     djm      1275:                multistate_ptr = multistate_permitrootlogin;
                   1276:                goto parse_multistate;
1.36      markus   1277:
1.94      markus   1278:        case sIgnoreRhosts:
                   1279:                intptr = &options->ignore_rhosts;
1.180     djm      1280:  parse_flag:
1.320     djm      1281:                multistate_ptr = multistate_flag;
                   1282:                goto parse_multistate;
1.94      markus   1283:
                   1284:        case sIgnoreUserKnownHosts:
                   1285:                intptr = &options->ignore_user_known_hosts;
                   1286:                goto parse_flag;
                   1287:
                   1288:        case sHostbasedAuthentication:
                   1289:                intptr = &options->hostbased_authentication;
                   1290:                goto parse_flag;
                   1291:
                   1292:        case sHostbasedUsesNameFromPacketOnly:
                   1293:                intptr = &options->hostbased_uses_name_from_packet_only;
                   1294:                goto parse_flag;
                   1295:
1.258     djm      1296:        case sHostbasedAcceptedKeyTypes:
                   1297:                charptr = &options->hostbased_key_types;
                   1298:  parse_keytypes:
                   1299:                arg = strdelim(&cp);
                   1300:                if (!arg || *arg == '\0')
                   1301:                        fatal("%s line %d: Missing argument.",
                   1302:                            filename, linenum);
1.304     djm      1303:                if (*arg != '-' &&
                   1304:                    !sshkey_names_valid2(*arg == '+' ? arg + 1 : arg, 1))
1.258     djm      1305:                        fatal("%s line %d: Bad key types '%s'.",
                   1306:                            filename, linenum, arg ? arg : "<NONE>");
                   1307:                if (*activep && *charptr == NULL)
                   1308:                        *charptr = xstrdup(arg);
                   1309:                break;
                   1310:
1.276     markus   1311:        case sHostKeyAlgorithms:
                   1312:                charptr = &options->hostkeyalgorithms;
                   1313:                goto parse_keytypes;
                   1314:
1.94      markus   1315:        case sPubkeyAuthentication:
                   1316:                intptr = &options->pubkey_authentication;
                   1317:                goto parse_flag;
1.119     jakob    1318:
1.258     djm      1319:        case sPubkeyAcceptedKeyTypes:
                   1320:                charptr = &options->pubkey_key_types;
                   1321:                goto parse_keytypes;
                   1322:
1.94      markus   1323:        case sKerberosAuthentication:
                   1324:                intptr = &options->kerberos_authentication;
                   1325:                goto parse_flag;
                   1326:
                   1327:        case sKerberosOrLocalPasswd:
                   1328:                intptr = &options->kerberos_or_local_passwd;
                   1329:                goto parse_flag;
                   1330:
                   1331:        case sKerberosTicketCleanup:
                   1332:                intptr = &options->kerberos_ticket_cleanup;
1.130     jakob    1333:                goto parse_flag;
                   1334:
                   1335:        case sKerberosGetAFSToken:
                   1336:                intptr = &options->kerberos_get_afs_token;
1.125     markus   1337:                goto parse_flag;
                   1338:
                   1339:        case sGssAuthentication:
                   1340:                intptr = &options->gss_authentication;
                   1341:                goto parse_flag;
                   1342:
                   1343:        case sGssCleanupCreds:
                   1344:                intptr = &options->gss_cleanup_creds;
1.271     djm      1345:                goto parse_flag;
                   1346:
                   1347:        case sGssStrictAcceptor:
                   1348:                intptr = &options->gss_strict_acceptor;
1.94      markus   1349:                goto parse_flag;
                   1350:
                   1351:        case sPasswordAuthentication:
                   1352:                intptr = &options->password_authentication;
                   1353:                goto parse_flag;
                   1354:
                   1355:        case sKbdInteractiveAuthentication:
                   1356:                intptr = &options->kbd_interactive_authentication;
                   1357:                goto parse_flag;
                   1358:
                   1359:        case sChallengeResponseAuthentication:
                   1360:                intptr = &options->challenge_response_authentication;
                   1361:                goto parse_flag;
                   1362:
                   1363:        case sPrintMotd:
                   1364:                intptr = &options->print_motd;
                   1365:                goto parse_flag;
                   1366:
                   1367:        case sPrintLastLog:
                   1368:                intptr = &options->print_lastlog;
                   1369:                goto parse_flag;
                   1370:
                   1371:        case sX11Forwarding:
                   1372:                intptr = &options->x11_forwarding;
                   1373:                goto parse_flag;
                   1374:
                   1375:        case sX11DisplayOffset:
                   1376:                intptr = &options->x11_display_offset;
1.293     naddy    1377:  parse_int:
                   1378:                arg = strdelim(&cp);
1.322     dtucker  1379:                if ((errstr = atoi_err(arg, &value)) != NULL)
                   1380:                        fatal("%s line %d: integer value %s.",
                   1381:                            filename, linenum, errstr);
1.293     naddy    1382:                if (*activep && *intptr == -1)
                   1383:                        *intptr = value;
                   1384:                break;
1.99      stevesk  1385:
                   1386:        case sX11UseLocalhost:
                   1387:                intptr = &options->x11_use_localhost;
                   1388:                goto parse_flag;
1.94      markus   1389:
                   1390:        case sXAuthLocation:
                   1391:                charptr = &options->xauth_location;
                   1392:                goto parse_filename;
                   1393:
1.244     djm      1394:        case sPermitTTY:
                   1395:                intptr = &options->permit_tty;
                   1396:                goto parse_flag;
                   1397:
1.250     djm      1398:        case sPermitUserRC:
                   1399:                intptr = &options->permit_user_rc;
                   1400:                goto parse_flag;
                   1401:
1.94      markus   1402:        case sStrictModes:
                   1403:                intptr = &options->strict_modes;
                   1404:                goto parse_flag;
                   1405:
1.129     markus   1406:        case sTCPKeepAlive:
                   1407:                intptr = &options->tcp_keep_alive;
1.94      markus   1408:                goto parse_flag;
                   1409:
                   1410:        case sEmptyPasswd:
                   1411:                intptr = &options->permit_empty_passwd;
1.113     markus   1412:                goto parse_flag;
                   1413:
                   1414:        case sPermitUserEnvironment:
                   1415:                intptr = &options->permit_user_env;
1.94      markus   1416:                goto parse_flag;
                   1417:
1.111     markus   1418:        case sCompression:
                   1419:                intptr = &options->compression;
1.220     djm      1420:                multistate_ptr = multistate_compression;
                   1421:                goto parse_multistate;
1.94      markus   1422:
1.235     dtucker  1423:        case sRekeyLimit:
                   1424:                arg = strdelim(&cp);
                   1425:                if (!arg || *arg == '\0')
                   1426:                        fatal("%.200s line %d: Missing argument.", filename,
                   1427:                            linenum);
                   1428:                if (strcmp(arg, "default") == 0) {
                   1429:                        val64 = 0;
                   1430:                } else {
1.236     dtucker  1431:                        if (scan_scaled(arg, &val64) == -1)
                   1432:                                fatal("%.200s line %d: Bad number '%s': %s",
                   1433:                                    filename, linenum, arg, strerror(errno));
1.235     dtucker  1434:                        if (val64 != 0 && val64 < 16)
                   1435:                                fatal("%.200s line %d: RekeyLimit too small",
                   1436:                                    filename, linenum);
                   1437:                }
                   1438:                if (*activep && options->rekey_limit == -1)
1.284     dtucker  1439:                        options->rekey_limit = val64;
1.235     dtucker  1440:                if (cp != NULL) { /* optional rekey interval present */
                   1441:                        if (strcmp(cp, "none") == 0) {
                   1442:                                (void)strdelim(&cp);    /* discard */
                   1443:                                break;
                   1444:                        }
                   1445:                        intptr = &options->rekey_interval;
                   1446:                        goto parse_time;
                   1447:                }
                   1448:                break;
                   1449:
1.94      markus   1450:        case sGatewayPorts:
1.251     millert  1451:                intptr = &options->fwd_opts.gateway_ports;
1.220     djm      1452:                multistate_ptr = multistate_gatewayports;
                   1453:                goto parse_multistate;
1.25      markus   1454:
1.122     markus   1455:        case sUseDNS:
                   1456:                intptr = &options->use_dns;
1.94      markus   1457:                goto parse_flag;
1.53      markus   1458:
1.94      markus   1459:        case sLogFacility:
1.174     dtucker  1460:                log_facility_ptr = &options->log_facility;
1.94      markus   1461:                arg = strdelim(&cp);
                   1462:                value = log_facility_number(arg);
1.101     markus   1463:                if (value == SYSLOG_FACILITY_NOT_SET)
1.94      markus   1464:                        fatal("%.200s line %d: unsupported log facility '%s'",
                   1465:                            filename, linenum, arg ? arg : "<NONE>");
1.174     dtucker  1466:                if (*log_facility_ptr == -1)
                   1467:                        *log_facility_ptr = (SyslogFacility) value;
1.94      markus   1468:                break;
1.25      markus   1469:
1.94      markus   1470:        case sLogLevel:
1.174     dtucker  1471:                log_level_ptr = &options->log_level;
1.94      markus   1472:                arg = strdelim(&cp);
                   1473:                value = log_level_number(arg);
1.101     markus   1474:                if (value == SYSLOG_LEVEL_NOT_SET)
1.94      markus   1475:                        fatal("%.200s line %d: unsupported log level '%s'",
                   1476:                            filename, linenum, arg ? arg : "<NONE>");
1.308     djm      1477:                if (*activep && *log_level_ptr == -1)
1.174     dtucker  1478:                        *log_level_ptr = (LogLevel) value;
1.94      markus   1479:                break;
                   1480:
                   1481:        case sAllowTcpForwarding:
                   1482:                intptr = &options->allow_tcp_forwarding;
1.233     djm      1483:                multistate_ptr = multistate_tcpfwd;
                   1484:                goto parse_multistate;
1.102     provos   1485:
1.251     millert  1486:        case sAllowStreamLocalForwarding:
                   1487:                intptr = &options->allow_streamlocal_forwarding;
                   1488:                multistate_ptr = multistate_tcpfwd;
                   1489:                goto parse_multistate;
                   1490:
1.178     pyr      1491:        case sAllowAgentForwarding:
                   1492:                intptr = &options->allow_agent_forwarding;
                   1493:                goto parse_flag;
                   1494:
1.301     djm      1495:        case sDisableForwarding:
                   1496:                intptr = &options->disable_forwarding;
                   1497:                goto parse_flag;
                   1498:
1.94      markus   1499:        case sAllowUsers:
                   1500:                while ((arg = strdelim(&cp)) && *arg != '\0') {
1.299     djm      1501:                        if (match_user(NULL, NULL, NULL, arg) == -1)
                   1502:                                fatal("%s line %d: invalid AllowUsers pattern: "
                   1503:                                    "\"%.100s\"", filename, linenum, arg);
1.227     markus   1504:                        if (!*activep)
                   1505:                                continue;
1.314     djm      1506:                        array_append(filename, linenum, "AllowUsers",
                   1507:                            &options->allow_users, &options->num_allow_users,
                   1508:                            arg);
1.94      markus   1509:                }
                   1510:                break;
1.25      markus   1511:
1.94      markus   1512:        case sDenyUsers:
                   1513:                while ((arg = strdelim(&cp)) && *arg != '\0') {
1.299     djm      1514:                        if (match_user(NULL, NULL, NULL, arg) == -1)
                   1515:                                fatal("%s line %d: invalid DenyUsers pattern: "
                   1516:                                    "\"%.100s\"", filename, linenum, arg);
1.227     markus   1517:                        if (!*activep)
                   1518:                                continue;
1.314     djm      1519:                        array_append(filename, linenum, "DenyUsers",
                   1520:                            &options->deny_users, &options->num_deny_users,
                   1521:                            arg);
1.94      markus   1522:                }
                   1523:                break;
1.25      markus   1524:
1.94      markus   1525:        case sAllowGroups:
                   1526:                while ((arg = strdelim(&cp)) && *arg != '\0') {
1.227     markus   1527:                        if (!*activep)
                   1528:                                continue;
1.314     djm      1529:                        array_append(filename, linenum, "AllowGroups",
                   1530:                            &options->allow_groups, &options->num_allow_groups,
                   1531:                            arg);
1.94      markus   1532:                }
                   1533:                break;
1.33      markus   1534:
1.94      markus   1535:        case sDenyGroups:
                   1536:                while ((arg = strdelim(&cp)) && *arg != '\0') {
1.227     markus   1537:                        if (!*activep)
                   1538:                                continue;
1.314     djm      1539:                        array_append(filename, linenum, "DenyGroups",
                   1540:                            &options->deny_groups, &options->num_deny_groups,
                   1541:                            arg);
1.94      markus   1542:                }
                   1543:                break;
1.66      markus   1544:
1.94      markus   1545:        case sCiphers:
                   1546:                arg = strdelim(&cp);
                   1547:                if (!arg || *arg == '\0')
                   1548:                        fatal("%s line %d: Missing argument.", filename, linenum);
1.304     djm      1549:                if (*arg != '-' && !ciphers_valid(*arg == '+' ? arg + 1 : arg))
1.94      markus   1550:                        fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
                   1551:                            filename, linenum, arg ? arg : "<NONE>");
                   1552:                if (options->ciphers == NULL)
                   1553:                        options->ciphers = xstrdup(arg);
                   1554:                break;
1.33      markus   1555:
1.94      markus   1556:        case sMacs:
                   1557:                arg = strdelim(&cp);
                   1558:                if (!arg || *arg == '\0')
                   1559:                        fatal("%s line %d: Missing argument.", filename, linenum);
1.304     djm      1560:                if (*arg != '-' && !mac_valid(*arg == '+' ? arg + 1 : arg))
1.94      markus   1561:                        fatal("%s line %d: Bad SSH2 mac spec '%s'.",
                   1562:                            filename, linenum, arg ? arg : "<NONE>");
                   1563:                if (options->macs == NULL)
                   1564:                        options->macs = xstrdup(arg);
1.211     djm      1565:                break;
                   1566:
                   1567:        case sKexAlgorithms:
                   1568:                arg = strdelim(&cp);
                   1569:                if (!arg || *arg == '\0')
                   1570:                        fatal("%s line %d: Missing argument.",
                   1571:                            filename, linenum);
1.304     djm      1572:                if (*arg != '-' &&
                   1573:                    !kex_names_valid(*arg == '+' ? arg + 1 : arg))
1.211     djm      1574:                        fatal("%s line %d: Bad SSH2 KexAlgorithms '%s'.",
                   1575:                            filename, linenum, arg ? arg : "<NONE>");
                   1576:                if (options->kex_algorithms == NULL)
                   1577:                        options->kex_algorithms = xstrdup(arg);
1.94      markus   1578:                break;
1.43      jakob    1579:
1.94      markus   1580:        case sSubsystem:
                   1581:                if (options->num_subsystems >= MAX_SUBSYSTEMS) {
                   1582:                        fatal("%s line %d: too many subsystems defined.",
1.95      deraadt  1583:                            filename, linenum);
1.94      markus   1584:                }
                   1585:                arg = strdelim(&cp);
                   1586:                if (!arg || *arg == '\0')
                   1587:                        fatal("%s line %d: Missing subsystem name.",
1.95      deraadt  1588:                            filename, linenum);
1.153     dtucker  1589:                if (!*activep) {
                   1590:                        arg = strdelim(&cp);
                   1591:                        break;
                   1592:                }
1.94      markus   1593:                for (i = 0; i < options->num_subsystems; i++)
                   1594:                        if (strcmp(arg, options->subsystem_name[i]) == 0)
                   1595:                                fatal("%s line %d: Subsystem '%s' already defined.",
1.95      deraadt  1596:                                    filename, linenum, arg);
1.94      markus   1597:                options->subsystem_name[options->num_subsystems] = xstrdup(arg);
                   1598:                arg = strdelim(&cp);
                   1599:                if (!arg || *arg == '\0')
                   1600:                        fatal("%s line %d: Missing subsystem command.",
1.95      deraadt  1601:                            filename, linenum);
1.94      markus   1602:                options->subsystem_command[options->num_subsystems] = xstrdup(arg);
1.151     djm      1603:
                   1604:                /* Collect arguments (separate to executable) */
                   1605:                p = xstrdup(arg);
                   1606:                len = strlen(p) + 1;
                   1607:                while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
                   1608:                        len += 1 + strlen(arg);
1.264     deraadt  1609:                        p = xreallocarray(p, 1, len);
1.151     djm      1610:                        strlcat(p, " ", len);
                   1611:                        strlcat(p, arg, len);
                   1612:                }
                   1613:                options->subsystem_args[options->num_subsystems] = p;
1.94      markus   1614:                options->num_subsystems++;
                   1615:                break;
1.46      markus   1616:
1.94      markus   1617:        case sMaxStartups:
                   1618:                arg = strdelim(&cp);
                   1619:                if (!arg || *arg == '\0')
                   1620:                        fatal("%s line %d: Missing MaxStartups spec.",
1.95      deraadt  1621:                            filename, linenum);
1.94      markus   1622:                if ((n = sscanf(arg, "%d:%d:%d",
                   1623:                    &options->max_startups_begin,
                   1624:                    &options->max_startups_rate,
                   1625:                    &options->max_startups)) == 3) {
                   1626:                        if (options->max_startups_begin >
                   1627:                            options->max_startups ||
                   1628:                            options->max_startups_rate > 100 ||
                   1629:                            options->max_startups_rate < 1)
1.50      markus   1630:                                fatal("%s line %d: Illegal MaxStartups spec.",
1.87      stevesk  1631:                                    filename, linenum);
1.94      markus   1632:                } else if (n != 1)
                   1633:                        fatal("%s line %d: Illegal MaxStartups spec.",
                   1634:                            filename, linenum);
                   1635:                else
                   1636:                        options->max_startups = options->max_startups_begin;
                   1637:                break;
1.133     dtucker  1638:
                   1639:        case sMaxAuthTries:
                   1640:                intptr = &options->max_authtries;
                   1641:                goto parse_int;
1.94      markus   1642:
1.180     djm      1643:        case sMaxSessions:
                   1644:                intptr = &options->max_sessions;
                   1645:                goto parse_int;
                   1646:
1.94      markus   1647:        case sBanner:
                   1648:                charptr = &options->banner;
                   1649:                goto parse_filename;
1.176     djm      1650:
1.94      markus   1651:        /*
                   1652:         * These options can contain %X options expanded at
                   1653:         * connect time, so that you can specify paths like:
                   1654:         *
                   1655:         * AuthorizedKeysFile   /etc/ssh_keys/%u
                   1656:         */
                   1657:        case sAuthorizedKeysFile:
1.219     djm      1658:                if (*activep && options->num_authkeys_files == 0) {
                   1659:                        while ((arg = strdelim(&cp)) && *arg != '\0') {
1.314     djm      1660:                                arg = tilde_expand_filename(arg, getuid());
                   1661:                                array_append(filename, linenum,
                   1662:                                    "AuthorizedKeysFile",
                   1663:                                    &options->authorized_keys_files,
                   1664:                                    &options->num_authkeys_files, arg);
                   1665:                                free(arg);
1.219     djm      1666:                        }
                   1667:                }
                   1668:                return 0;
                   1669:
1.208     djm      1670:        case sAuthorizedPrincipalsFile:
                   1671:                charptr = &options->authorized_principals_file;
1.205     djm      1672:                arg = strdelim(&cp);
                   1673:                if (!arg || *arg == '\0')
                   1674:                        fatal("%s line %d: missing file name.",
                   1675:                            filename, linenum);
                   1676:                if (*activep && *charptr == NULL) {
1.206     markus   1677:                        *charptr = tilde_expand_filename(arg, getuid());
1.205     djm      1678:                        /* increase optional counter */
                   1679:                        if (intptr != NULL)
                   1680:                                *intptr = *intptr + 1;
                   1681:                }
                   1682:                break;
1.94      markus   1683:
                   1684:        case sClientAliveInterval:
                   1685:                intptr = &options->client_alive_interval;
                   1686:                goto parse_time;
                   1687:
                   1688:        case sClientAliveCountMax:
                   1689:                intptr = &options->client_alive_count_max;
                   1690:                goto parse_int;
1.131     djm      1691:
                   1692:        case sAcceptEnv:
                   1693:                while ((arg = strdelim(&cp)) && *arg != '\0') {
                   1694:                        if (strchr(arg, '=') != NULL)
                   1695:                                fatal("%s line %d: Invalid environment name.",
                   1696:                                    filename, linenum);
1.153     dtucker  1697:                        if (!*activep)
1.227     markus   1698:                                continue;
1.314     djm      1699:                        array_append(filename, linenum, "AcceptEnv",
                   1700:                            &options->accept_env, &options->num_accept_env,
                   1701:                            arg);
1.131     djm      1702:                }
                   1703:                break;
1.145     reyk     1704:
                   1705:        case sPermitTunnel:
                   1706:                intptr = &options->permit_tun;
1.146     reyk     1707:                arg = strdelim(&cp);
                   1708:                if (!arg || *arg == '\0')
                   1709:                        fatal("%s line %d: Missing yes/point-to-point/"
                   1710:                            "ethernet/no argument.", filename, linenum);
1.182     dtucker  1711:                value = -1;
                   1712:                for (i = 0; tunmode_desc[i].val != -1; i++)
                   1713:                        if (strcmp(tunmode_desc[i].text, arg) == 0) {
                   1714:                                value = tunmode_desc[i].val;
                   1715:                                break;
                   1716:                        }
                   1717:                if (value == -1)
1.146     reyk     1718:                        fatal("%s line %d: Bad yes/point-to-point/ethernet/"
                   1719:                            "no argument: %s", filename, linenum, arg);
1.268     djm      1720:                if (*activep && *intptr == -1)
1.146     reyk     1721:                        *intptr = value;
                   1722:                break;
1.94      markus   1723:
1.153     dtucker  1724:        case sMatch:
                   1725:                if (cmdline)
                   1726:                        fatal("Match directive not supported as a command-line "
                   1727:                           "option");
1.226     dtucker  1728:                value = match_cfg_line(&cp, linenum, connectinfo);
1.153     dtucker  1729:                if (value < 0)
                   1730:                        fatal("%s line %d: Bad Match condition", filename,
                   1731:                            linenum);
                   1732:                *activep = value;
1.156     dtucker  1733:                break;
                   1734:
                   1735:        case sPermitOpen:
                   1736:                arg = strdelim(&cp);
                   1737:                if (!arg || *arg == '\0')
                   1738:                        fatal("%s line %d: missing PermitOpen specification",
                   1739:                            filename, linenum);
1.313     djm      1740:                value = options->num_permitted_opens;   /* modified later */
1.310     djm      1741:                if (strcmp(arg, "any") == 0 || strcmp(arg, "none") == 0) {
1.313     djm      1742:                        if (*activep && value == 0) {
1.224     dtucker  1743:                                options->num_permitted_opens = 1;
1.310     djm      1744:                                options->permitted_opens = xcalloc(1,
                   1745:                                    sizeof(*options->permitted_opens));
                   1746:                                options->permitted_opens[0] = xstrdup(arg);
1.311     dtucker  1747:                        }
1.156     dtucker  1748:                        break;
                   1749:                }
1.159     dtucker  1750:                for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
1.310     djm      1751:                        arg2 = xstrdup(arg);
1.159     dtucker  1752:                        p = hpdelim(&arg);
                   1753:                        if (p == NULL)
                   1754:                                fatal("%s line %d: missing host in PermitOpen",
                   1755:                                    filename, linenum);
                   1756:                        p = cleanhostname(p);
1.223     dtucker  1757:                        if (arg == NULL || ((port = permitopen_port(arg)) < 0))
1.159     dtucker  1758:                                fatal("%s line %d: bad port number in "
                   1759:                                    "PermitOpen", filename, linenum);
1.313     djm      1760:                        if (*activep && value == 0) {
1.314     djm      1761:                                array_append(filename, linenum,
                   1762:                                    "PermitOpen",
                   1763:                                    &options->permitted_opens,
                   1764:                                    &options->num_permitted_opens, arg2);
                   1765:                        }
                   1766:                        free(arg2);
1.159     dtucker  1767:                }
1.153     dtucker  1768:                break;
                   1769:
1.158     dtucker  1770:        case sForceCommand:
1.262     dtucker  1771:                if (cp == NULL || *cp == '\0')
1.158     dtucker  1772:                        fatal("%.200s line %d: Missing argument.", filename,
                   1773:                            linenum);
                   1774:                len = strspn(cp, WHITESPACE);
                   1775:                if (*activep && options->adm_forced_command == NULL)
                   1776:                        options->adm_forced_command = xstrdup(cp + len);
                   1777:                return 0;
                   1778:
1.176     djm      1779:        case sChrootDirectory:
                   1780:                charptr = &options->chroot_directory;
1.177     djm      1781:
                   1782:                arg = strdelim(&cp);
                   1783:                if (!arg || *arg == '\0')
                   1784:                        fatal("%s line %d: missing file name.",
                   1785:                            filename, linenum);
                   1786:                if (*activep && *charptr == NULL)
                   1787:                        *charptr = xstrdup(arg);
                   1788:                break;
1.176     djm      1789:
1.204     djm      1790:        case sTrustedUserCAKeys:
                   1791:                charptr = &options->trusted_user_ca_keys;
                   1792:                goto parse_filename;
                   1793:
                   1794:        case sRevokedKeys:
                   1795:                charptr = &options->revoked_keys_file;
                   1796:                goto parse_filename;
                   1797:
1.213     djm      1798:        case sIPQoS:
                   1799:                arg = strdelim(&cp);
                   1800:                if ((value = parse_ipqos(arg)) == -1)
                   1801:                        fatal("%s line %d: Bad IPQoS value: %s",
                   1802:                            filename, linenum, arg);
                   1803:                arg = strdelim(&cp);
                   1804:                if (arg == NULL)
                   1805:                        value2 = value;
                   1806:                else if ((value2 = parse_ipqos(arg)) == -1)
                   1807:                        fatal("%s line %d: Bad IPQoS value: %s",
                   1808:                            filename, linenum, arg);
                   1809:                if (*activep) {
                   1810:                        options->ip_qos_interactive = value;
                   1811:                        options->ip_qos_bulk = value2;
                   1812:                }
                   1813:                break;
                   1814:
1.225     djm      1815:        case sVersionAddendum:
1.262     dtucker  1816:                if (cp == NULL || *cp == '\0')
1.225     djm      1817:                        fatal("%.200s line %d: Missing argument.", filename,
                   1818:                            linenum);
                   1819:                len = strspn(cp, WHITESPACE);
                   1820:                if (*activep && options->version_addendum == NULL) {
                   1821:                        if (strcasecmp(cp + len, "none") == 0)
                   1822:                                options->version_addendum = xstrdup("");
                   1823:                        else if (strchr(cp + len, '\r') != NULL)
                   1824:                                fatal("%.200s line %d: Invalid argument",
                   1825:                                    filename, linenum);
                   1826:                        else
                   1827:                                options->version_addendum = xstrdup(cp + len);
                   1828:                }
                   1829:                return 0;
                   1830:
1.231     djm      1831:        case sAuthorizedKeysCommand:
1.255     jsg      1832:                if (cp == NULL)
                   1833:                        fatal("%.200s line %d: Missing argument.", filename,
                   1834:                            linenum);
1.231     djm      1835:                len = strspn(cp, WHITESPACE);
                   1836:                if (*activep && options->authorized_keys_command == NULL) {
                   1837:                        if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
                   1838:                                fatal("%.200s line %d: AuthorizedKeysCommand "
                   1839:                                    "must be an absolute path",
                   1840:                                    filename, linenum);
                   1841:                        options->authorized_keys_command = xstrdup(cp + len);
                   1842:                }
                   1843:                return 0;
                   1844:
                   1845:        case sAuthorizedKeysCommandUser:
                   1846:                charptr = &options->authorized_keys_command_user;
                   1847:
                   1848:                arg = strdelim(&cp);
1.255     jsg      1849:                if (!arg || *arg == '\0')
                   1850:                        fatal("%s line %d: missing AuthorizedKeysCommandUser "
                   1851:                            "argument.", filename, linenum);
1.231     djm      1852:                if (*activep && *charptr == NULL)
                   1853:                        *charptr = xstrdup(arg);
                   1854:                break;
                   1855:
1.270     djm      1856:        case sAuthorizedPrincipalsCommand:
                   1857:                if (cp == NULL)
                   1858:                        fatal("%.200s line %d: Missing argument.", filename,
                   1859:                            linenum);
                   1860:                len = strspn(cp, WHITESPACE);
                   1861:                if (*activep &&
                   1862:                    options->authorized_principals_command == NULL) {
                   1863:                        if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
                   1864:                                fatal("%.200s line %d: "
                   1865:                                    "AuthorizedPrincipalsCommand must be "
                   1866:                                    "an absolute path", filename, linenum);
                   1867:                        options->authorized_principals_command =
                   1868:                            xstrdup(cp + len);
                   1869:                }
                   1870:                return 0;
                   1871:
                   1872:        case sAuthorizedPrincipalsCommandUser:
                   1873:                charptr = &options->authorized_principals_command_user;
                   1874:
                   1875:                arg = strdelim(&cp);
                   1876:                if (!arg || *arg == '\0')
                   1877:                        fatal("%s line %d: missing "
                   1878:                            "AuthorizedPrincipalsCommandUser argument.",
                   1879:                            filename, linenum);
                   1880:                if (*activep && *charptr == NULL)
                   1881:                        *charptr = xstrdup(arg);
                   1882:                break;
                   1883:
1.232     djm      1884:        case sAuthenticationMethods:
1.268     djm      1885:                if (options->num_auth_methods == 0) {
1.291     djm      1886:                        value = 0; /* seen "any" pseudo-method */
1.292     djm      1887:                        value2 = 0; /* sucessfully parsed any method */
1.232     djm      1888:                        while ((arg = strdelim(&cp)) && *arg != '\0') {
1.291     djm      1889:                                if (strcmp(arg, "any") == 0) {
                   1890:                                        if (options->num_auth_methods > 0) {
                   1891:                                                fatal("%s line %d: \"any\" "
                   1892:                                                    "must appear alone in "
                   1893:                                                    "AuthenticationMethods",
                   1894:                                                    filename, linenum);
                   1895:                                        }
                   1896:                                        value = 1;
                   1897:                                } else if (value) {
                   1898:                                        fatal("%s line %d: \"any\" must appear "
                   1899:                                            "alone in AuthenticationMethods",
                   1900:                                            filename, linenum);
                   1901:                                } else if (auth2_methods_valid(arg, 0) != 0) {
1.232     djm      1902:                                        fatal("%s line %d: invalid "
                   1903:                                            "authentication method list.",
                   1904:                                            filename, linenum);
1.291     djm      1905:                                }
1.292     djm      1906:                                value2 = 1;
1.268     djm      1907:                                if (!*activep)
                   1908:                                        continue;
1.314     djm      1909:                                array_append(filename, linenum,
                   1910:                                    "AuthenticationMethods",
                   1911:                                    &options->auth_methods,
                   1912:                                    &options->num_auth_methods, arg);
1.232     djm      1913:                        }
1.292     djm      1914:                        if (value2 == 0) {
1.291     djm      1915:                                fatal("%s line %d: no AuthenticationMethods "
                   1916:                                    "specified", filename, linenum);
                   1917:                        }
1.232     djm      1918:                }
                   1919:                return 0;
                   1920:
1.251     millert  1921:        case sStreamLocalBindMask:
                   1922:                arg = strdelim(&cp);
                   1923:                if (!arg || *arg == '\0')
1.268     djm      1924:                        fatal("%s line %d: missing StreamLocalBindMask "
                   1925:                            "argument.", filename, linenum);
1.251     millert  1926:                /* Parse mode in octal format */
                   1927:                value = strtol(arg, &p, 8);
                   1928:                if (arg == p || value < 0 || value > 0777)
                   1929:                        fatal("%s line %d: Bad mask.", filename, linenum);
1.268     djm      1930:                if (*activep)
                   1931:                        options->fwd_opts.streamlocal_bind_mask = (mode_t)value;
1.251     millert  1932:                break;
                   1933:
                   1934:        case sStreamLocalBindUnlink:
                   1935:                intptr = &options->fwd_opts.streamlocal_bind_unlink;
                   1936:                goto parse_flag;
                   1937:
1.256     djm      1938:        case sFingerprintHash:
                   1939:                arg = strdelim(&cp);
                   1940:                if (!arg || *arg == '\0')
                   1941:                        fatal("%.200s line %d: Missing argument.",
                   1942:                            filename, linenum);
                   1943:                if ((value = ssh_digest_alg_by_name(arg)) == -1)
                   1944:                        fatal("%.200s line %d: Invalid hash algorithm \"%s\".",
                   1945:                            filename, linenum, arg);
                   1946:                if (*activep)
                   1947:                        options->fingerprint_hash = value;
                   1948:                break;
                   1949:
1.309     djm      1950:        case sExposeAuthInfo:
                   1951:                intptr = &options->expose_userauth_info;
                   1952:                goto parse_flag;
                   1953:
1.316     djm      1954:        case sRDomain:
                   1955:                charptr = &options->routing_domain;
                   1956:                arg = strdelim(&cp);
                   1957:                if (!arg || *arg == '\0')
                   1958:                        fatal("%.200s line %d: Missing argument.",
                   1959:                            filename, linenum);
                   1960:                if (strcasecmp(arg, "none") != 0 && strcmp(arg, "%D") != 0 &&
                   1961:                    !valid_rdomain(arg))
                   1962:                        fatal("%s line %d: bad routing domain",
                   1963:                            filename, linenum);
                   1964:                if (*activep && *charptr == NULL)
                   1965:                        *charptr = xstrdup(arg);
1.321     dtucker  1966:                break;
1.316     djm      1967:
1.94      markus   1968:        case sDeprecated:
1.295     djm      1969:        case sIgnore:
1.121     jakob    1970:        case sUnsupported:
1.295     djm      1971:                do_log2(opcode == sIgnore ?
                   1972:                    SYSLOG_LEVEL_DEBUG2 : SYSLOG_LEVEL_INFO,
                   1973:                    "%s line %d: %s option %s", filename, linenum,
                   1974:                    opcode == sUnsupported ? "Unsupported" : "Deprecated", arg);
1.94      markus   1975:                while (arg)
                   1976:                    arg = strdelim(&cp);
                   1977:                break;
                   1978:
                   1979:        default:
                   1980:                fatal("%s line %d: Missing handler for opcode %s (%d)",
                   1981:                    filename, linenum, arg, opcode);
                   1982:        }
                   1983:        if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
                   1984:                fatal("%s line %d: garbage at end of line; \"%.200s\".",
                   1985:                    filename, linenum, arg);
                   1986:        return 0;
                   1987: }
                   1988:
                   1989: /* Reads the server configuration file. */
1.25      markus   1990:
1.94      markus   1991: void
1.134     djm      1992: load_server_config(const char *filename, Buffer *conf)
1.94      markus   1993: {
1.229     dtucker  1994:        char line[4096], *cp;
1.94      markus   1995:        FILE *f;
1.229     dtucker  1996:        int lineno = 0;
1.81      stevesk  1997:
1.134     djm      1998:        debug2("%s: filename %s", __func__, filename);
                   1999:        if ((f = fopen(filename, "r")) == NULL) {
1.94      markus   2000:                perror(filename);
                   2001:                exit(1);
                   2002:        }
1.134     djm      2003:        buffer_clear(conf);
                   2004:        while (fgets(line, sizeof(line), f)) {
1.229     dtucker  2005:                lineno++;
                   2006:                if (strlen(line) == sizeof(line) - 1)
                   2007:                        fatal("%s line %d too long", filename, lineno);
1.134     djm      2008:                /*
                   2009:                 * Trim out comments and strip whitespace
1.135     deraadt  2010:                 * NB - preserve newlines, they are needed to reproduce
1.134     djm      2011:                 * line numbers later for error messages
                   2012:                 */
                   2013:                if ((cp = strchr(line, '#')) != NULL)
                   2014:                        memcpy(cp, "\n", 2);
                   2015:                cp = line + strspn(line, " \t\r");
                   2016:
                   2017:                buffer_append(conf, cp, strlen(cp));
                   2018:        }
                   2019:        buffer_append(conf, "\0", 1);
                   2020:        fclose(f);
                   2021:        debug2("%s: done config len = %d", __func__, buffer_len(conf));
                   2022: }
                   2023:
                   2024: void
1.226     dtucker  2025: parse_server_match_config(ServerOptions *options,
                   2026:    struct connection_info *connectinfo)
1.153     dtucker  2027: {
                   2028:        ServerOptions mo;
                   2029:
                   2030:        initialize_server_options(&mo);
1.226     dtucker  2031:        parse_server_config(&mo, "reprocess config", &cfg, connectinfo);
1.168     dtucker  2032:        copy_set_server_options(options, &mo, 0);
1.153     dtucker  2033: }
                   2034:
1.226     dtucker  2035: int parse_server_match_testspec(struct connection_info *ci, char *spec)
                   2036: {
                   2037:        char *p;
                   2038:
                   2039:        while ((p = strsep(&spec, ",")) && *p != '\0') {
                   2040:                if (strncmp(p, "addr=", 5) == 0) {
                   2041:                        ci->address = xstrdup(p + 5);
                   2042:                } else if (strncmp(p, "host=", 5) == 0) {
                   2043:                        ci->host = xstrdup(p + 5);
                   2044:                } else if (strncmp(p, "user=", 5) == 0) {
                   2045:                        ci->user = xstrdup(p + 5);
                   2046:                } else if (strncmp(p, "laddr=", 6) == 0) {
                   2047:                        ci->laddress = xstrdup(p + 6);
1.317     djm      2048:                } else if (strncmp(p, "rdomain=", 8) == 0) {
                   2049:                        ci->rdomain = xstrdup(p + 8);
1.226     dtucker  2050:                } else if (strncmp(p, "lport=", 6) == 0) {
                   2051:                        ci->lport = a2port(p + 6);
                   2052:                        if (ci->lport == -1) {
                   2053:                                fprintf(stderr, "Invalid port '%s' in test mode"
                   2054:                                   " specification %s\n", p+6, p);
                   2055:                                return -1;
                   2056:                        }
                   2057:                } else {
                   2058:                        fprintf(stderr, "Invalid test mode specification %s\n",
                   2059:                           p);
                   2060:                        return -1;
                   2061:                }
                   2062:        }
                   2063:        return 0;
                   2064: }
                   2065:
1.168     dtucker  2066: /*
                   2067:  * Copy any supported values that are set.
                   2068:  *
1.195     jj       2069:  * If the preauth flag is set, we do not bother copying the string or
1.168     dtucker  2070:  * array values that are not used pre-authentication, because any that we
                   2071:  * do use must be explictly sent in mm_getpwnamallow().
                   2072:  */
1.153     dtucker  2073: void
1.168     dtucker  2074: copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
1.153     dtucker  2075: {
1.247     djm      2076: #define M_CP_INTOPT(n) do {\
                   2077:        if (src->n != -1) \
                   2078:                dst->n = src->n; \
                   2079: } while (0)
                   2080:
1.168     dtucker  2081:        M_CP_INTOPT(password_authentication);
                   2082:        M_CP_INTOPT(gss_authentication);
                   2083:        M_CP_INTOPT(pubkey_authentication);
                   2084:        M_CP_INTOPT(kerberos_authentication);
                   2085:        M_CP_INTOPT(hostbased_authentication);
1.209     djm      2086:        M_CP_INTOPT(hostbased_uses_name_from_packet_only);
1.168     dtucker  2087:        M_CP_INTOPT(kbd_interactive_authentication);
1.175     dtucker  2088:        M_CP_INTOPT(permit_root_login);
1.188     djm      2089:        M_CP_INTOPT(permit_empty_passwd);
1.168     dtucker  2090:
                   2091:        M_CP_INTOPT(allow_tcp_forwarding);
1.251     millert  2092:        M_CP_INTOPT(allow_streamlocal_forwarding);
1.178     pyr      2093:        M_CP_INTOPT(allow_agent_forwarding);
1.301     djm      2094:        M_CP_INTOPT(disable_forwarding);
1.309     djm      2095:        M_CP_INTOPT(expose_userauth_info);
1.209     djm      2096:        M_CP_INTOPT(permit_tun);
1.251     millert  2097:        M_CP_INTOPT(fwd_opts.gateway_ports);
1.289     djm      2098:        M_CP_INTOPT(fwd_opts.streamlocal_bind_unlink);
1.168     dtucker  2099:        M_CP_INTOPT(x11_display_offset);
                   2100:        M_CP_INTOPT(x11_forwarding);
                   2101:        M_CP_INTOPT(x11_use_localhost);
1.244     djm      2102:        M_CP_INTOPT(permit_tty);
1.250     djm      2103:        M_CP_INTOPT(permit_user_rc);
1.180     djm      2104:        M_CP_INTOPT(max_sessions);
1.184     dtucker  2105:        M_CP_INTOPT(max_authtries);
1.300     markus   2106:        M_CP_INTOPT(client_alive_count_max);
                   2107:        M_CP_INTOPT(client_alive_interval);
1.213     djm      2108:        M_CP_INTOPT(ip_qos_interactive);
                   2109:        M_CP_INTOPT(ip_qos_bulk);
1.235     dtucker  2110:        M_CP_INTOPT(rekey_limit);
                   2111:        M_CP_INTOPT(rekey_interval);
1.308     djm      2112:        M_CP_INTOPT(log_level);
1.289     djm      2113:
                   2114:        /*
                   2115:         * The bind_mask is a mode_t that may be unsigned, so we can't use
                   2116:         * M_CP_INTOPT - it does a signed comparison that causes compiler
                   2117:         * warnings.
                   2118:         */
1.290     dtucker  2119:        if (src->fwd_opts.streamlocal_bind_mask != (mode_t)-1) {
1.289     djm      2120:                dst->fwd_opts.streamlocal_bind_mask =
                   2121:                    src->fwd_opts.streamlocal_bind_mask;
                   2122:        }
1.247     djm      2123:
                   2124:        /* M_CP_STROPT and M_CP_STRARRAYOPT should not appear before here */
                   2125: #define M_CP_STROPT(n) do {\
                   2126:        if (src->n != NULL && dst->n != src->n) { \
                   2127:                free(dst->n); \
                   2128:                dst->n = src->n; \
                   2129:        } \
                   2130: } while(0)
1.314     djm      2131: #define M_CP_STRARRAYOPT(s, num_s) do {\
                   2132:        u_int i; \
                   2133:        if (src->num_s != 0) { \
                   2134:                for (i = 0; i < dst->num_s; i++) \
                   2135:                        free(dst->s[i]); \
                   2136:                free(dst->s); \
                   2137:                dst->s = xcalloc(src->num_s, sizeof(*dst->s)); \
                   2138:                for (i = 0; i < src->num_s; i++) \
                   2139:                        dst->s[i] = xstrdup(src->s[i]); \
                   2140:                dst->num_s = src->num_s; \
1.312     djm      2141:        } \
                   2142: } while(0)
1.168     dtucker  2143:
1.218     djm      2144:        /* See comment in servconf.h */
                   2145:        COPY_MATCH_STRING_OPTS();
1.282     djm      2146:
                   2147:        /* Arguments that accept '+...' need to be expanded */
                   2148:        assemble_algorithms(dst);
1.216     djm      2149:
1.217     dtucker  2150:        /*
                   2151:         * The only things that should be below this point are string options
                   2152:         * which are only used after authentication.
                   2153:         */
1.168     dtucker  2154:        if (preauth)
                   2155:                return;
1.219     djm      2156:
1.283     djm      2157:        /* These options may be "none" to clear a global setting */
1.168     dtucker  2158:        M_CP_STROPT(adm_forced_command);
1.283     djm      2159:        if (option_clear_or_none(dst->adm_forced_command)) {
                   2160:                free(dst->adm_forced_command);
                   2161:                dst->adm_forced_command = NULL;
                   2162:        }
1.176     djm      2163:        M_CP_STROPT(chroot_directory);
1.283     djm      2164:        if (option_clear_or_none(dst->chroot_directory)) {
                   2165:                free(dst->chroot_directory);
                   2166:                dst->chroot_directory = NULL;
                   2167:        }
1.153     dtucker  2168: }
1.168     dtucker  2169:
                   2170: #undef M_CP_INTOPT
                   2171: #undef M_CP_STROPT
1.219     djm      2172: #undef M_CP_STRARRAYOPT
1.153     dtucker  2173:
                   2174: void
                   2175: parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
1.226     dtucker  2176:     struct connection_info *connectinfo)
1.134     djm      2177: {
1.153     dtucker  2178:        int active, linenum, bad_options = 0;
1.136     dtucker  2179:        char *cp, *obuf, *cbuf;
1.134     djm      2180:
                   2181:        debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
                   2182:
1.287     djm      2183:        if ((obuf = cbuf = sshbuf_dup_string(conf)) == NULL)
                   2184:                fatal("%s: sshbuf_dup_string failed", __func__);
1.226     dtucker  2185:        active = connectinfo ? 0 : 1;
1.137     dtucker  2186:        linenum = 1;
1.140     deraadt  2187:        while ((cp = strsep(&cbuf, "\n")) != NULL) {
1.134     djm      2188:                if (process_server_config_line(options, cp, filename,
1.226     dtucker  2189:                    linenum++, &active, connectinfo) != 0)
1.94      markus   2190:                        bad_options++;
1.1       deraadt  2191:        }
1.239     djm      2192:        free(obuf);
1.78      stevesk  2193:        if (bad_options > 0)
                   2194:                fatal("%s: terminating, %d bad configuration options",
                   2195:                    filename, bad_options);
1.266     dtucker  2196:        process_queued_listen_addrs(options);
1.182     dtucker  2197: }
                   2198:
                   2199: static const char *
1.221     djm      2200: fmt_multistate_int(int val, const struct multistate *m)
                   2201: {
                   2202:        u_int i;
                   2203:
                   2204:        for (i = 0; m[i].key != NULL; i++) {
                   2205:                if (m[i].value == val)
                   2206:                        return m[i].key;
                   2207:        }
                   2208:        return "UNKNOWN";
                   2209: }
                   2210:
                   2211: static const char *
1.182     dtucker  2212: fmt_intarg(ServerOpCodes code, int val)
                   2213: {
1.221     djm      2214:        if (val == -1)
                   2215:                return "unset";
                   2216:        switch (code) {
                   2217:        case sAddressFamily:
                   2218:                return fmt_multistate_int(val, multistate_addressfamily);
                   2219:        case sPermitRootLogin:
                   2220:                return fmt_multistate_int(val, multistate_permitrootlogin);
                   2221:        case sGatewayPorts:
                   2222:                return fmt_multistate_int(val, multistate_gatewayports);
                   2223:        case sCompression:
                   2224:                return fmt_multistate_int(val, multistate_compression);
1.233     djm      2225:        case sAllowTcpForwarding:
                   2226:                return fmt_multistate_int(val, multistate_tcpfwd);
1.251     millert  2227:        case sAllowStreamLocalForwarding:
                   2228:                return fmt_multistate_int(val, multistate_tcpfwd);
1.256     djm      2229:        case sFingerprintHash:
                   2230:                return ssh_digest_alg_name(val);
1.221     djm      2231:        default:
                   2232:                switch (val) {
                   2233:                case 0:
                   2234:                        return "no";
                   2235:                case 1:
                   2236:                        return "yes";
                   2237:                default:
                   2238:                        return "UNKNOWN";
                   2239:                }
1.182     dtucker  2240:        }
                   2241: }
                   2242:
                   2243: static const char *
                   2244: lookup_opcode_name(ServerOpCodes code)
                   2245: {
                   2246:        u_int i;
                   2247:
                   2248:        for (i = 0; keywords[i].name != NULL; i++)
                   2249:                if (keywords[i].opcode == code)
                   2250:                        return(keywords[i].name);
                   2251:        return "UNKNOWN";
                   2252: }
                   2253:
                   2254: static void
                   2255: dump_cfg_int(ServerOpCodes code, int val)
                   2256: {
                   2257:        printf("%s %d\n", lookup_opcode_name(code), val);
                   2258: }
                   2259:
                   2260: static void
1.263     dtucker  2261: dump_cfg_oct(ServerOpCodes code, int val)
                   2262: {
                   2263:        printf("%s 0%o\n", lookup_opcode_name(code), val);
                   2264: }
                   2265:
                   2266: static void
1.182     dtucker  2267: dump_cfg_fmtint(ServerOpCodes code, int val)
                   2268: {
                   2269:        printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
                   2270: }
                   2271:
                   2272: static void
                   2273: dump_cfg_string(ServerOpCodes code, const char *val)
                   2274: {
1.257     djm      2275:        printf("%s %s\n", lookup_opcode_name(code),
                   2276:            val == NULL ? "none" : val);
1.182     dtucker  2277: }
                   2278:
                   2279: static void
                   2280: dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
                   2281: {
                   2282:        u_int i;
                   2283:
                   2284:        for (i = 0; i < count; i++)
1.219     djm      2285:                printf("%s %s\n", lookup_opcode_name(code), vals[i]);
                   2286: }
                   2287:
                   2288: static void
                   2289: dump_cfg_strarray_oneline(ServerOpCodes code, u_int count, char **vals)
                   2290: {
                   2291:        u_int i;
                   2292:
1.291     djm      2293:        if (count <= 0 && code != sAuthenticationMethods)
1.261     dtucker  2294:                return;
1.219     djm      2295:        printf("%s", lookup_opcode_name(code));
                   2296:        for (i = 0; i < count; i++)
                   2297:                printf(" %s",  vals[i]);
1.291     djm      2298:        if (code == sAuthenticationMethods && count == 0)
                   2299:                printf(" any");
1.219     djm      2300:        printf("\n");
1.182     dtucker  2301: }
                   2302:
1.315     djm      2303: static char *
                   2304: format_listen_addrs(struct listenaddr *la)
1.182     dtucker  2305: {
1.315     djm      2306:        int r;
1.182     dtucker  2307:        struct addrinfo *ai;
1.315     djm      2308:        char addr[NI_MAXHOST], port[NI_MAXSERV];
1.263     dtucker  2309:        char *laddr1 = xstrdup(""), *laddr2 = NULL;
1.182     dtucker  2310:
1.263     dtucker  2311:        /*
                   2312:         * ListenAddress must be after Port.  add_one_listen_addr pushes
                   2313:         * addresses onto a stack, so to maintain ordering we need to
                   2314:         * print these in reverse order.
                   2315:         */
1.315     djm      2316:        for (ai = la->addrs; ai; ai = ai->ai_next) {
                   2317:                if ((r = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
1.182     dtucker  2318:                    sizeof(addr), port, sizeof(port),
                   2319:                    NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
1.315     djm      2320:                        error("getnameinfo: %.100s", ssh_gai_strerror(r));
                   2321:                        continue;
                   2322:                }
                   2323:                laddr2 = laddr1;
                   2324:                if (ai->ai_family == AF_INET6) {
                   2325:                        xasprintf(&laddr1, "listenaddress [%s]:%s%s%s\n%s",
                   2326:                            addr, port,
                   2327:                            la->rdomain == NULL ? "" : " rdomain ",
                   2328:                            la->rdomain == NULL ? "" : la->rdomain,
                   2329:                            laddr2);
1.182     dtucker  2330:                } else {
1.315     djm      2331:                        xasprintf(&laddr1, "listenaddress %s:%s%s%s\n%s",
                   2332:                            addr, port,
                   2333:                            la->rdomain == NULL ? "" : " rdomain ",
                   2334:                            la->rdomain == NULL ? "" : la->rdomain,
                   2335:                            laddr2);
1.182     dtucker  2336:                }
1.315     djm      2337:                free(laddr2);
                   2338:        }
                   2339:        return laddr1;
                   2340: }
                   2341:
                   2342: void
                   2343: dump_config(ServerOptions *o)
                   2344: {
                   2345:        char *s;
                   2346:        u_int i;
                   2347:
                   2348:        /* these are usually at the top of the config */
                   2349:        for (i = 0; i < o->num_ports; i++)
                   2350:                printf("port %d\n", o->ports[i]);
                   2351:        dump_cfg_fmtint(sAddressFamily, o->address_family);
                   2352:
                   2353:        for (i = 0; i < o->num_listen_addrs; i++) {
                   2354:                s = format_listen_addrs(&o->listen_addrs[i]);
                   2355:                printf("%s", s);
                   2356:                free(s);
1.182     dtucker  2357:        }
                   2358:
                   2359:        /* integer arguments */
                   2360:        dump_cfg_int(sLoginGraceTime, o->login_grace_time);
                   2361:        dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
                   2362:        dump_cfg_int(sMaxAuthTries, o->max_authtries);
1.189     djm      2363:        dump_cfg_int(sMaxSessions, o->max_sessions);
1.182     dtucker  2364:        dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
                   2365:        dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
1.263     dtucker  2366:        dump_cfg_oct(sStreamLocalBindMask, o->fwd_opts.streamlocal_bind_mask);
1.182     dtucker  2367:
                   2368:        /* formatted integer arguments */
                   2369:        dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
                   2370:        dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
                   2371:        dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
                   2372:        dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
                   2373:        dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
                   2374:            o->hostbased_uses_name_from_packet_only);
                   2375:        dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
1.187     djm      2376: #ifdef KRB5
1.182     dtucker  2377:        dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
                   2378:        dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
                   2379:        dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
                   2380:        dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
1.187     djm      2381: #endif
                   2382: #ifdef GSSAPI
1.182     dtucker  2383:        dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
                   2384:        dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
1.187     djm      2385: #endif
1.182     dtucker  2386:        dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
                   2387:        dump_cfg_fmtint(sKbdInteractiveAuthentication,
                   2388:            o->kbd_interactive_authentication);
                   2389:        dump_cfg_fmtint(sChallengeResponseAuthentication,
                   2390:            o->challenge_response_authentication);
                   2391:        dump_cfg_fmtint(sPrintMotd, o->print_motd);
                   2392:        dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
                   2393:        dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
                   2394:        dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
1.244     djm      2395:        dump_cfg_fmtint(sPermitTTY, o->permit_tty);
1.250     djm      2396:        dump_cfg_fmtint(sPermitUserRC, o->permit_user_rc);
1.182     dtucker  2397:        dump_cfg_fmtint(sStrictModes, o->strict_modes);
                   2398:        dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
                   2399:        dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
                   2400:        dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
                   2401:        dump_cfg_fmtint(sCompression, o->compression);
1.251     millert  2402:        dump_cfg_fmtint(sGatewayPorts, o->fwd_opts.gateway_ports);
1.182     dtucker  2403:        dump_cfg_fmtint(sUseDNS, o->use_dns);
                   2404:        dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
1.261     dtucker  2405:        dump_cfg_fmtint(sAllowAgentForwarding, o->allow_agent_forwarding);
1.301     djm      2406:        dump_cfg_fmtint(sDisableForwarding, o->disable_forwarding);
1.251     millert  2407:        dump_cfg_fmtint(sAllowStreamLocalForwarding, o->allow_streamlocal_forwarding);
1.288     djm      2408:        dump_cfg_fmtint(sStreamLocalBindUnlink, o->fwd_opts.streamlocal_bind_unlink);
1.256     djm      2409:        dump_cfg_fmtint(sFingerprintHash, o->fingerprint_hash);
1.309     djm      2410:        dump_cfg_fmtint(sExposeAuthInfo, o->expose_userauth_info);
1.182     dtucker  2411:
                   2412:        /* string arguments */
                   2413:        dump_cfg_string(sPidFile, o->pid_file);
                   2414:        dump_cfg_string(sXAuthLocation, o->xauth_location);
1.252     djm      2415:        dump_cfg_string(sCiphers, o->ciphers ? o->ciphers : KEX_SERVER_ENCRYPT);
                   2416:        dump_cfg_string(sMacs, o->macs ? o->macs : KEX_SERVER_MAC);
1.182     dtucker  2417:        dump_cfg_string(sBanner, o->banner);
                   2418:        dump_cfg_string(sForceCommand, o->adm_forced_command);
1.201     dtucker  2419:        dump_cfg_string(sChrootDirectory, o->chroot_directory);
1.204     djm      2420:        dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
                   2421:        dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
1.208     djm      2422:        dump_cfg_string(sAuthorizedPrincipalsFile,
                   2423:            o->authorized_principals_file);
1.261     dtucker  2424:        dump_cfg_string(sVersionAddendum, *o->version_addendum == '\0'
                   2425:            ? "none" : o->version_addendum);
1.231     djm      2426:        dump_cfg_string(sAuthorizedKeysCommand, o->authorized_keys_command);
                   2427:        dump_cfg_string(sAuthorizedKeysCommandUser, o->authorized_keys_command_user);
1.270     djm      2428:        dump_cfg_string(sAuthorizedPrincipalsCommand, o->authorized_principals_command);
                   2429:        dump_cfg_string(sAuthorizedPrincipalsCommandUser, o->authorized_principals_command_user);
1.240     markus   2430:        dump_cfg_string(sHostKeyAgent, o->host_key_agent);
1.252     djm      2431:        dump_cfg_string(sKexAlgorithms,
1.253     djm      2432:            o->kex_algorithms ? o->kex_algorithms : KEX_SERVER_KEX);
1.258     djm      2433:        dump_cfg_string(sHostbasedAcceptedKeyTypes, o->hostbased_key_types ?
                   2434:            o->hostbased_key_types : KEX_DEFAULT_PK_ALG);
1.276     markus   2435:        dump_cfg_string(sHostKeyAlgorithms, o->hostkeyalgorithms ?
                   2436:            o->hostkeyalgorithms : KEX_DEFAULT_PK_ALG);
1.258     djm      2437:        dump_cfg_string(sPubkeyAcceptedKeyTypes, o->pubkey_key_types ?
                   2438:            o->pubkey_key_types : KEX_DEFAULT_PK_ALG);
1.316     djm      2439:        dump_cfg_string(sRDomain, o->routing_domain);
1.182     dtucker  2440:
                   2441:        /* string arguments requiring a lookup */
                   2442:        dump_cfg_string(sLogLevel, log_level_name(o->log_level));
                   2443:        dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
                   2444:
                   2445:        /* string array arguments */
1.219     djm      2446:        dump_cfg_strarray_oneline(sAuthorizedKeysFile, o->num_authkeys_files,
                   2447:            o->authorized_keys_files);
1.182     dtucker  2448:        dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
                   2449:             o->host_key_files);
1.261     dtucker  2450:        dump_cfg_strarray(sHostCertificate, o->num_host_cert_files,
1.203     djm      2451:             o->host_cert_files);
1.182     dtucker  2452:        dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
                   2453:        dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
                   2454:        dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
                   2455:        dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
                   2456:        dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
1.232     djm      2457:        dump_cfg_strarray_oneline(sAuthenticationMethods,
                   2458:            o->num_auth_methods, o->auth_methods);
1.182     dtucker  2459:
                   2460:        /* other arguments */
                   2461:        for (i = 0; i < o->num_subsystems; i++)
                   2462:                printf("subsystem %s %s\n", o->subsystem_name[i],
                   2463:                    o->subsystem_args[i]);
                   2464:
                   2465:        printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
                   2466:            o->max_startups_rate, o->max_startups);
                   2467:
1.318     djm      2468:        s = NULL;
                   2469:        for (i = 0; tunmode_desc[i].val != -1; i++) {
1.182     dtucker  2470:                if (tunmode_desc[i].val == o->permit_tun) {
                   2471:                        s = tunmode_desc[i].text;
                   2472:                        break;
                   2473:                }
1.318     djm      2474:        }
1.182     dtucker  2475:        dump_cfg_string(sPermitTunnel, s);
1.213     djm      2476:
1.214     stevesk  2477:        printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
                   2478:        printf("%s\n", iptos2str(o->ip_qos_bulk));
1.235     dtucker  2479:
1.284     dtucker  2480:        printf("rekeylimit %llu %d\n", (unsigned long long)o->rekey_limit,
1.241     djm      2481:            o->rekey_interval);
1.182     dtucker  2482:
1.310     djm      2483:        printf("permitopen");
                   2484:        if (o->num_permitted_opens == 0)
                   2485:                printf(" any");
                   2486:        else {
                   2487:                for (i = 0; i < o->num_permitted_opens; i++)
                   2488:                        printf(" %s", o->permitted_opens[i]);
                   2489:        }
                   2490:        printf("\n");
1.1       deraadt  2491: }