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

1.226     dtucker     1:
1.248   ! markus      2: /* $OpenBSD: servconf.c,v 1.247 2013/12/05 01:16:41 djm 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.154     stevesk    17:
1.213     djm        18: #include <netinet/in.h>
                     19: #include <netinet/in_systm.h>
                     20: #include <netinet/ip.h>
                     21:
1.235     dtucker    22: #include <ctype.h>
1.154     stevesk    23: #include <netdb.h>
1.165     dtucker    24: #include <pwd.h>
1.162     stevesk    25: #include <stdio.h>
1.161     stevesk    26: #include <stdlib.h>
1.160     stevesk    27: #include <string.h>
1.164     deraadt    28: #include <signal.h>
1.155     stevesk    29: #include <unistd.h>
1.164     deraadt    30: #include <stdarg.h>
1.182     dtucker    31: #include <errno.h>
1.236     dtucker    32: #include <util.h>
1.1       deraadt    33:
1.164     deraadt    34: #include "xmalloc.h"
1.1       deraadt    35: #include "ssh.h"
1.62      markus     36: #include "log.h"
1.164     deraadt    37: #include "buffer.h"
1.1       deraadt    38: #include "servconf.h"
1.33      markus     39: #include "compat.h"
1.60      markus     40: #include "pathnames.h"
1.62      markus     41: #include "misc.h"
                     42: #include "cipher.h"
1.164     deraadt    43: #include "key.h"
1.66      markus     44: #include "kex.h"
                     45: #include "mac.h"
1.153     dtucker    46: #include "match.h"
1.156     dtucker    47: #include "channels.h"
1.165     dtucker    48: #include "groupaccess.h"
1.226     dtucker    49: #include "canohost.h"
                     50: #include "packet.h"
1.232     djm        51: #include "hostfile.h"
                     52: #include "auth.h"
1.1       deraadt    53:
1.194     djm        54: static void add_listen_addr(ServerOptions *, char *, int);
                     55: static void add_one_listen_addr(ServerOptions *, char *, int);
1.29      markus     56:
1.102     provos     57: /* Use of privilege separation or not */
                     58: extern int use_privsep;
1.153     dtucker    59: extern Buffer cfg;
1.62      markus     60:
1.1       deraadt    61: /* Initializes the server options to their default values. */
                     62:
1.34      markus     63: void
1.25      markus     64: initialize_server_options(ServerOptions *options)
1.1       deraadt    65: {
1.25      markus     66:        memset(options, 0, sizeof(*options));
1.29      markus     67:        options->num_ports = 0;
                     68:        options->ports_from_cmdline = 0;
                     69:        options->listen_addrs = NULL;
1.138     djm        70:        options->address_family = -1;
1.54      markus     71:        options->num_host_key_files = 0;
1.203     djm        72:        options->num_host_cert_files = 0;
1.240     markus     73:        options->host_key_agent = NULL;
1.36      markus     74:        options->pid_file = NULL;
1.25      markus     75:        options->server_key_bits = -1;
                     76:        options->login_grace_time = -1;
                     77:        options->key_regeneration_time = -1;
1.67      markus     78:        options->permit_root_login = PERMIT_NOT_SET;
1.25      markus     79:        options->ignore_rhosts = -1;
                     80:        options->ignore_user_known_hosts = -1;
                     81:        options->print_motd = -1;
1.72      stevesk    82:        options->print_lastlog = -1;
1.25      markus     83:        options->x11_forwarding = -1;
                     84:        options->x11_display_offset = -1;
1.99      stevesk    85:        options->x11_use_localhost = -1;
1.244     djm        86:        options->permit_tty = -1;
1.42      markus     87:        options->xauth_location = NULL;
1.25      markus     88:        options->strict_modes = -1;
1.129     markus     89:        options->tcp_keep_alive = -1;
1.101     markus     90:        options->log_facility = SYSLOG_FACILITY_NOT_SET;
                     91:        options->log_level = SYSLOG_LEVEL_NOT_SET;
1.25      markus     92:        options->rhosts_rsa_authentication = -1;
1.75      markus     93:        options->hostbased_authentication = -1;
                     94:        options->hostbased_uses_name_from_packet_only = -1;
1.25      markus     95:        options->rsa_authentication = -1;
1.54      markus     96:        options->pubkey_authentication = -1;
1.25      markus     97:        options->kerberos_authentication = -1;
                     98:        options->kerberos_or_local_passwd = -1;
                     99:        options->kerberos_ticket_cleanup = -1;
1.130     jakob     100:        options->kerberos_get_afs_token = -1;
1.125     markus    101:        options->gss_authentication=-1;
                    102:        options->gss_cleanup_creds = -1;
1.25      markus    103:        options->password_authentication = -1;
1.52      markus    104:        options->kbd_interactive_authentication = -1;
1.80      markus    105:        options->challenge_response_authentication = -1;
1.25      markus    106:        options->permit_empty_passwd = -1;
1.113     markus    107:        options->permit_user_env = -1;
1.25      markus    108:        options->use_login = -1;
1.111     markus    109:        options->compression = -1;
1.235     dtucker   110:        options->rekey_limit = -1;
                    111:        options->rekey_interval = -1;
1.53      markus    112:        options->allow_tcp_forwarding = -1;
1.178     pyr       113:        options->allow_agent_forwarding = -1;
1.25      markus    114:        options->num_allow_users = 0;
                    115:        options->num_deny_users = 0;
                    116:        options->num_allow_groups = 0;
                    117:        options->num_deny_groups = 0;
1.33      markus    118:        options->ciphers = NULL;
1.66      markus    119:        options->macs = NULL;
1.211     djm       120:        options->kex_algorithms = NULL;
1.33      markus    121:        options->protocol = SSH_PROTO_UNKNOWN;
1.38      markus    122:        options->gateway_ports = -1;
1.43      jakob     123:        options->num_subsystems = 0;
1.50      markus    124:        options->max_startups_begin = -1;
                    125:        options->max_startups_rate = -1;
1.46      markus    126:        options->max_startups = -1;
1.133     dtucker   127:        options->max_authtries = -1;
1.180     djm       128:        options->max_sessions = -1;
1.57      markus    129:        options->banner = NULL;
1.122     markus    130:        options->use_dns = -1;
1.77      beck      131:        options->client_alive_interval = -1;
                    132:        options->client_alive_count_max = -1;
1.219     djm       133:        options->num_authkeys_files = 0;
1.131     djm       134:        options->num_accept_env = 0;
1.145     reyk      135:        options->permit_tun = -1;
1.159     dtucker   136:        options->num_permitted_opens = -1;
1.158     dtucker   137:        options->adm_forced_command = NULL;
1.176     djm       138:        options->chroot_directory = NULL;
1.231     djm       139:        options->authorized_keys_command = NULL;
                    140:        options->authorized_keys_command_user = NULL;
1.190     djm       141:        options->zero_knowledge_password_authentication = -1;
1.204     djm       142:        options->revoked_keys_file = NULL;
                    143:        options->trusted_user_ca_keys = NULL;
1.208     djm       144:        options->authorized_principals_file = NULL;
1.213     djm       145:        options->ip_qos_interactive = -1;
                    146:        options->ip_qos_bulk = -1;
1.225     djm       147:        options->version_addendum = NULL;
1.1       deraadt   148: }
                    149:
1.34      markus    150: void
1.25      markus    151: fill_default_server_options(ServerOptions *options)
1.1       deraadt   152: {
1.54      markus    153:        if (options->protocol == SSH_PROTO_UNKNOWN)
1.196     markus    154:                options->protocol = SSH_PROTO_2;
1.54      markus    155:        if (options->num_host_key_files == 0) {
                    156:                /* fill default hostkeys for protocols */
                    157:                if (options->protocol & SSH_PROTO_1)
1.97      stevesk   158:                        options->host_key_files[options->num_host_key_files++] =
                    159:                            _PATH_HOST_KEY_FILE;
                    160:                if (options->protocol & SSH_PROTO_2) {
                    161:                        options->host_key_files[options->num_host_key_files++] =
                    162:                            _PATH_HOST_RSA_KEY_FILE;
                    163:                        options->host_key_files[options->num_host_key_files++] =
                    164:                            _PATH_HOST_DSA_KEY_FILE;
1.210     naddy     165:                        options->host_key_files[options->num_host_key_files++] =
                    166:                            _PATH_HOST_ECDSA_KEY_FILE;
1.248   ! markus    167:                        options->host_key_files[options->num_host_key_files++] =
        !           168:                            _PATH_HOST_ED25519_KEY_FILE;
1.97      stevesk   169:                }
1.54      markus    170:        }
1.203     djm       171:        /* No certificates by default */
1.29      markus    172:        if (options->num_ports == 0)
                    173:                options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
                    174:        if (options->listen_addrs == NULL)
1.76      stevesk   175:                add_listen_addr(options, NULL, 0);
1.36      markus    176:        if (options->pid_file == NULL)
1.60      markus    177:                options->pid_file = _PATH_SSH_DAEMON_PID_FILE;
1.25      markus    178:        if (options->server_key_bits == -1)
1.185     djm       179:                options->server_key_bits = 1024;
1.25      markus    180:        if (options->login_grace_time == -1)
1.115     stevesk   181:                options->login_grace_time = 120;
1.25      markus    182:        if (options->key_regeneration_time == -1)
                    183:                options->key_regeneration_time = 3600;
1.67      markus    184:        if (options->permit_root_login == PERMIT_NOT_SET)
                    185:                options->permit_root_login = PERMIT_YES;
1.25      markus    186:        if (options->ignore_rhosts == -1)
1.30      markus    187:                options->ignore_rhosts = 1;
1.25      markus    188:        if (options->ignore_user_known_hosts == -1)
                    189:                options->ignore_user_known_hosts = 0;
                    190:        if (options->print_motd == -1)
                    191:                options->print_motd = 1;
1.72      stevesk   192:        if (options->print_lastlog == -1)
                    193:                options->print_lastlog = 1;
1.25      markus    194:        if (options->x11_forwarding == -1)
1.30      markus    195:                options->x11_forwarding = 0;
1.25      markus    196:        if (options->x11_display_offset == -1)
1.30      markus    197:                options->x11_display_offset = 10;
1.99      stevesk   198:        if (options->x11_use_localhost == -1)
                    199:                options->x11_use_localhost = 1;
1.42      markus    200:        if (options->xauth_location == NULL)
1.83      markus    201:                options->xauth_location = _PATH_XAUTH;
1.244     djm       202:        if (options->permit_tty == -1)
                    203:                options->permit_tty = 1;
1.25      markus    204:        if (options->strict_modes == -1)
                    205:                options->strict_modes = 1;
1.129     markus    206:        if (options->tcp_keep_alive == -1)
                    207:                options->tcp_keep_alive = 1;
1.101     markus    208:        if (options->log_facility == SYSLOG_FACILITY_NOT_SET)
1.25      markus    209:                options->log_facility = SYSLOG_FACILITY_AUTH;
1.101     markus    210:        if (options->log_level == SYSLOG_LEVEL_NOT_SET)
1.58      markus    211:                options->log_level = SYSLOG_LEVEL_INFO;
1.25      markus    212:        if (options->rhosts_rsa_authentication == -1)
1.30      markus    213:                options->rhosts_rsa_authentication = 0;
1.75      markus    214:        if (options->hostbased_authentication == -1)
                    215:                options->hostbased_authentication = 0;
                    216:        if (options->hostbased_uses_name_from_packet_only == -1)
                    217:                options->hostbased_uses_name_from_packet_only = 0;
1.25      markus    218:        if (options->rsa_authentication == -1)
                    219:                options->rsa_authentication = 1;
1.54      markus    220:        if (options->pubkey_authentication == -1)
                    221:                options->pubkey_authentication = 1;
1.25      markus    222:        if (options->kerberos_authentication == -1)
1.107     markus    223:                options->kerberos_authentication = 0;
1.25      markus    224:        if (options->kerberos_or_local_passwd == -1)
                    225:                options->kerberos_or_local_passwd = 1;
                    226:        if (options->kerberos_ticket_cleanup == -1)
                    227:                options->kerberos_ticket_cleanup = 1;
1.130     jakob     228:        if (options->kerberos_get_afs_token == -1)
                    229:                options->kerberos_get_afs_token = 0;
1.125     markus    230:        if (options->gss_authentication == -1)
                    231:                options->gss_authentication = 0;
                    232:        if (options->gss_cleanup_creds == -1)
                    233:                options->gss_cleanup_creds = 1;
1.25      markus    234:        if (options->password_authentication == -1)
                    235:                options->password_authentication = 1;
1.52      markus    236:        if (options->kbd_interactive_authentication == -1)
                    237:                options->kbd_interactive_authentication = 0;
1.80      markus    238:        if (options->challenge_response_authentication == -1)
                    239:                options->challenge_response_authentication = 1;
1.25      markus    240:        if (options->permit_empty_passwd == -1)
1.30      markus    241:                options->permit_empty_passwd = 0;
1.113     markus    242:        if (options->permit_user_env == -1)
                    243:                options->permit_user_env = 0;
1.25      markus    244:        if (options->use_login == -1)
                    245:                options->use_login = 0;
1.111     markus    246:        if (options->compression == -1)
1.143     markus    247:                options->compression = COMP_DELAYED;
1.235     dtucker   248:        if (options->rekey_limit == -1)
                    249:                options->rekey_limit = 0;
                    250:        if (options->rekey_interval == -1)
                    251:                options->rekey_interval = 0;
1.53      markus    252:        if (options->allow_tcp_forwarding == -1)
1.233     djm       253:                options->allow_tcp_forwarding = FORWARD_ALLOW;
1.178     pyr       254:        if (options->allow_agent_forwarding == -1)
                    255:                options->allow_agent_forwarding = 1;
1.38      markus    256:        if (options->gateway_ports == -1)
                    257:                options->gateway_ports = 0;
1.46      markus    258:        if (options->max_startups == -1)
1.234     dtucker   259:                options->max_startups = 100;
1.50      markus    260:        if (options->max_startups_rate == -1)
1.234     dtucker   261:                options->max_startups_rate = 30;                /* 30% */
1.50      markus    262:        if (options->max_startups_begin == -1)
1.234     dtucker   263:                options->max_startups_begin = 10;
1.133     dtucker   264:        if (options->max_authtries == -1)
                    265:                options->max_authtries = DEFAULT_AUTH_FAIL_MAX;
1.180     djm       266:        if (options->max_sessions == -1)
                    267:                options->max_sessions = DEFAULT_SESSIONS_MAX;
1.122     markus    268:        if (options->use_dns == -1)
                    269:                options->use_dns = 1;
1.77      beck      270:        if (options->client_alive_interval == -1)
1.95      deraadt   271:                options->client_alive_interval = 0;
1.77      beck      272:        if (options->client_alive_count_max == -1)
                    273:                options->client_alive_count_max = 3;
1.219     djm       274:        if (options->num_authkeys_files == 0) {
                    275:                options->authorized_keys_files[options->num_authkeys_files++] =
                    276:                    xstrdup(_PATH_SSH_USER_PERMITTED_KEYS);
                    277:                options->authorized_keys_files[options->num_authkeys_files++] =
                    278:                    xstrdup(_PATH_SSH_USER_PERMITTED_KEYS2);
                    279:        }
1.145     reyk      280:        if (options->permit_tun == -1)
1.146     reyk      281:                options->permit_tun = SSH_TUNMODE_NO;
1.190     djm       282:        if (options->zero_knowledge_password_authentication == -1)
                    283:                options->zero_knowledge_password_authentication = 0;
1.213     djm       284:        if (options->ip_qos_interactive == -1)
                    285:                options->ip_qos_interactive = IPTOS_LOWDELAY;
                    286:        if (options->ip_qos_bulk == -1)
                    287:                options->ip_qos_bulk = IPTOS_THROUGHPUT;
1.225     djm       288:        if (options->version_addendum == NULL)
                    289:                options->version_addendum = xstrdup("");
1.110     markus    290:        /* Turn privilege separation on by default */
1.102     provos    291:        if (use_privsep == -1)
1.228     djm       292:                use_privsep = PRIVSEP_NOSANDBOX;
1.1       deraadt   293: }
                    294:
                    295: /* Keyword tokens. */
1.25      markus    296: typedef enum {
                    297:        sBadOption,             /* == unknown option */
                    298:        sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime,
                    299:        sPermitRootLogin, sLogFacility, sLogLevel,
1.124     markus    300:        sRhostsRSAAuthentication, sRSAAuthentication,
1.25      markus    301:        sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
1.130     jakob     302:        sKerberosGetAFSToken,
1.123     markus    303:        sKerberosTgtPassing, sChallengeResponseAuthentication,
1.138     djm       304:        sPasswordAuthentication, sKbdInteractiveAuthentication,
                    305:        sListenAddress, sAddressFamily,
1.72      stevesk   306:        sPrintMotd, sPrintLastLog, sIgnoreRhosts,
1.99      stevesk   307:        sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
1.244     djm       308:        sPermitTTY, sStrictModes, sEmptyPasswd, sTCPKeepAlive,
1.113     markus    309:        sPermitUserEnvironment, sUseLogin, sAllowTcpForwarding, sCompression,
1.235     dtucker   310:        sRekeyLimit, sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
1.66      markus    311:        sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
1.133     dtucker   312:        sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem,
1.180     djm       313:        sMaxStartups, sMaxAuthTries, sMaxSessions,
1.122     markus    314:        sBanner, sUseDNS, sHostbasedAuthentication,
1.95      deraadt   315:        sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
1.219     djm       316:        sClientAliveCountMax, sAuthorizedKeysFile,
1.145     reyk      317:        sGssAuthentication, sGssCleanupCreds, sAcceptEnv, sPermitTunnel,
1.176     djm       318:        sMatch, sPermitOpen, sForceCommand, sChrootDirectory,
1.200     dtucker   319:        sUsePrivilegeSeparation, sAllowAgentForwarding,
1.203     djm       320:        sZeroKnowledgePasswordAuthentication, sHostCertificate,
1.208     djm       321:        sRevokedKeys, sTrustedUserCAKeys, sAuthorizedPrincipalsFile,
1.225     djm       322:        sKexAlgorithms, sIPQoS, sVersionAddendum,
1.231     djm       323:        sAuthorizedKeysCommand, sAuthorizedKeysCommandUser,
1.240     markus    324:        sAuthenticationMethods, sHostKeyAgent,
1.121     jakob     325:        sDeprecated, sUnsupported
1.1       deraadt   326: } ServerOpCodes;
                    327:
1.153     dtucker   328: #define SSHCFG_GLOBAL  0x01    /* allowed in main section of sshd_config */
                    329: #define SSHCFG_MATCH   0x02    /* allowed inside a Match section */
                    330: #define SSHCFG_ALL     (SSHCFG_GLOBAL|SSHCFG_MATCH)
                    331:
1.1       deraadt   332: /* Textual representation of the tokens. */
1.25      markus    333: static struct {
                    334:        const char *name;
                    335:        ServerOpCodes opcode;
1.153     dtucker   336:        u_int flags;
1.25      markus    337: } keywords[] = {
1.153     dtucker   338:        { "port", sPort, SSHCFG_GLOBAL },
                    339:        { "hostkey", sHostKeyFile, SSHCFG_GLOBAL },
                    340:        { "hostdsakey", sHostKeyFile, SSHCFG_GLOBAL },          /* alias */
1.240     markus    341:        { "hostkeyagent", sHostKeyAgent, SSHCFG_GLOBAL },
1.153     dtucker   342:        { "pidfile", sPidFile, SSHCFG_GLOBAL },
                    343:        { "serverkeybits", sServerKeyBits, SSHCFG_GLOBAL },
                    344:        { "logingracetime", sLoginGraceTime, SSHCFG_GLOBAL },
                    345:        { "keyregenerationinterval", sKeyRegenerationTime, SSHCFG_GLOBAL },
1.175     dtucker   346:        { "permitrootlogin", sPermitRootLogin, SSHCFG_ALL },
1.153     dtucker   347:        { "syslogfacility", sLogFacility, SSHCFG_GLOBAL },
                    348:        { "loglevel", sLogLevel, SSHCFG_GLOBAL },
                    349:        { "rhostsauthentication", sDeprecated, SSHCFG_GLOBAL },
1.168     dtucker   350:        { "rhostsrsaauthentication", sRhostsRSAAuthentication, SSHCFG_ALL },
                    351:        { "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_ALL },
1.209     djm       352:        { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly, SSHCFG_ALL },
1.168     dtucker   353:        { "rsaauthentication", sRSAAuthentication, SSHCFG_ALL },
                    354:        { "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_ALL },
1.153     dtucker   355:        { "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL }, /* alias */
1.123     markus    356: #ifdef KRB5
1.168     dtucker   357:        { "kerberosauthentication", sKerberosAuthentication, SSHCFG_ALL },
1.153     dtucker   358:        { "kerberosorlocalpasswd", sKerberosOrLocalPasswd, SSHCFG_GLOBAL },
                    359:        { "kerberosticketcleanup", sKerberosTicketCleanup, SSHCFG_GLOBAL },
                    360:        { "kerberosgetafstoken", sKerberosGetAFSToken, SSHCFG_GLOBAL },
1.121     jakob     361: #else
1.168     dtucker   362:        { "kerberosauthentication", sUnsupported, SSHCFG_ALL },
1.153     dtucker   363:        { "kerberosorlocalpasswd", sUnsupported, SSHCFG_GLOBAL },
                    364:        { "kerberosticketcleanup", sUnsupported, SSHCFG_GLOBAL },
                    365:        { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
1.126     markus    366: #endif
1.153     dtucker   367:        { "kerberostgtpassing", sUnsupported, SSHCFG_GLOBAL },
                    368:        { "afstokenpassing", sUnsupported, SSHCFG_GLOBAL },
1.125     markus    369: #ifdef GSSAPI
1.168     dtucker   370:        { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
1.153     dtucker   371:        { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
1.125     markus    372: #else
1.168     dtucker   373:        { "gssapiauthentication", sUnsupported, SSHCFG_ALL },
1.153     dtucker   374:        { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
1.125     markus    375: #endif
1.168     dtucker   376:        { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
                    377:        { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
1.170     dtucker   378:        { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
1.153     dtucker   379:        { "skeyauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, /* alias */
1.190     djm       380: #ifdef JPAKE
                    381:        { "zeroknowledgepasswordauthentication", sZeroKnowledgePasswordAuthentication, SSHCFG_ALL },
                    382: #else
                    383:        { "zeroknowledgepasswordauthentication", sUnsupported, SSHCFG_ALL },
                    384: #endif
1.153     dtucker   385:        { "checkmail", sDeprecated, SSHCFG_GLOBAL },
                    386:        { "listenaddress", sListenAddress, SSHCFG_GLOBAL },
                    387:        { "addressfamily", sAddressFamily, SSHCFG_GLOBAL },
                    388:        { "printmotd", sPrintMotd, SSHCFG_GLOBAL },
                    389:        { "printlastlog", sPrintLastLog, SSHCFG_GLOBAL },
                    390:        { "ignorerhosts", sIgnoreRhosts, SSHCFG_GLOBAL },
                    391:        { "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL },
1.157     dtucker   392:        { "x11forwarding", sX11Forwarding, SSHCFG_ALL },
                    393:        { "x11displayoffset", sX11DisplayOffset, SSHCFG_ALL },
                    394:        { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
1.153     dtucker   395:        { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
                    396:        { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
1.188     djm       397:        { "permitemptypasswords", sEmptyPasswd, SSHCFG_ALL },
1.153     dtucker   398:        { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
                    399:        { "uselogin", sUseLogin, SSHCFG_GLOBAL },
                    400:        { "compression", sCompression, SSHCFG_GLOBAL },
1.235     dtucker   401:        { "rekeylimit", sRekeyLimit, SSHCFG_ALL },
1.153     dtucker   402:        { "tcpkeepalive", sTCPKeepAlive, SSHCFG_GLOBAL },
                    403:        { "keepalive", sTCPKeepAlive, SSHCFG_GLOBAL },  /* obsolete alias */
                    404:        { "allowtcpforwarding", sAllowTcpForwarding, SSHCFG_ALL },
1.178     pyr       405:        { "allowagentforwarding", sAllowAgentForwarding, SSHCFG_ALL },
1.227     markus    406:        { "allowusers", sAllowUsers, SSHCFG_ALL },
                    407:        { "denyusers", sDenyUsers, SSHCFG_ALL },
                    408:        { "allowgroups", sAllowGroups, SSHCFG_ALL },
                    409:        { "denygroups", sDenyGroups, SSHCFG_ALL },
1.153     dtucker   410:        { "ciphers", sCiphers, SSHCFG_GLOBAL },
                    411:        { "macs", sMacs, SSHCFG_GLOBAL },
                    412:        { "protocol", sProtocol, SSHCFG_GLOBAL },
                    413:        { "gatewayports", sGatewayPorts, SSHCFG_ALL },
                    414:        { "subsystem", sSubsystem, SSHCFG_GLOBAL },
                    415:        { "maxstartups", sMaxStartups, SSHCFG_GLOBAL },
1.184     dtucker   416:        { "maxauthtries", sMaxAuthTries, SSHCFG_ALL },
1.180     djm       417:        { "maxsessions", sMaxSessions, SSHCFG_ALL },
1.168     dtucker   418:        { "banner", sBanner, SSHCFG_ALL },
1.153     dtucker   419:        { "usedns", sUseDNS, SSHCFG_GLOBAL },
                    420:        { "verifyreversemapping", sDeprecated, SSHCFG_GLOBAL },
                    421:        { "reversemappingcheck", sDeprecated, SSHCFG_GLOBAL },
                    422:        { "clientaliveinterval", sClientAliveInterval, SSHCFG_GLOBAL },
                    423:        { "clientalivecountmax", sClientAliveCountMax, SSHCFG_GLOBAL },
1.209     djm       424:        { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_ALL },
1.219     djm       425:        { "authorizedkeysfile2", sDeprecated, SSHCFG_ALL },
1.153     dtucker   426:        { "useprivilegeseparation", sUsePrivilegeSeparation, SSHCFG_GLOBAL},
1.227     markus    427:        { "acceptenv", sAcceptEnv, SSHCFG_ALL },
1.209     djm       428:        { "permittunnel", sPermitTunnel, SSHCFG_ALL },
1.244     djm       429:        { "permittty", sPermitTTY, SSHCFG_ALL },
1.153     dtucker   430:        { "match", sMatch, SSHCFG_ALL },
1.156     dtucker   431:        { "permitopen", sPermitOpen, SSHCFG_ALL },
1.158     dtucker   432:        { "forcecommand", sForceCommand, SSHCFG_ALL },
1.176     djm       433:        { "chrootdirectory", sChrootDirectory, SSHCFG_ALL },
1.203     djm       434:        { "hostcertificate", sHostCertificate, SSHCFG_GLOBAL },
1.204     djm       435:        { "revokedkeys", sRevokedKeys, SSHCFG_ALL },
                    436:        { "trustedusercakeys", sTrustedUserCAKeys, SSHCFG_ALL },
1.209     djm       437:        { "authorizedprincipalsfile", sAuthorizedPrincipalsFile, SSHCFG_ALL },
1.211     djm       438:        { "kexalgorithms", sKexAlgorithms, SSHCFG_GLOBAL },
1.213     djm       439:        { "ipqos", sIPQoS, SSHCFG_ALL },
1.231     djm       440:        { "authorizedkeyscommand", sAuthorizedKeysCommand, SSHCFG_ALL },
                    441:        { "authorizedkeyscommanduser", sAuthorizedKeysCommandUser, SSHCFG_ALL },
1.225     djm       442:        { "versionaddendum", sVersionAddendum, SSHCFG_GLOBAL },
1.232     djm       443:        { "authenticationmethods", sAuthenticationMethods, SSHCFG_ALL },
1.153     dtucker   444:        { NULL, sBadOption, 0 }
1.1       deraadt   445: };
                    446:
1.182     dtucker   447: static struct {
                    448:        int val;
                    449:        char *text;
                    450: } tunmode_desc[] = {
                    451:        { SSH_TUNMODE_NO, "no" },
                    452:        { SSH_TUNMODE_POINTOPOINT, "point-to-point" },
                    453:        { SSH_TUNMODE_ETHERNET, "ethernet" },
                    454:        { SSH_TUNMODE_YES, "yes" },
                    455:        { -1, NULL }
                    456: };
                    457:
1.27      markus    458: /*
1.73      stevesk   459:  * Returns the number of the token pointed to by cp or sBadOption.
1.27      markus    460:  */
1.1       deraadt   461:
1.34      markus    462: static ServerOpCodes
1.25      markus    463: parse_token(const char *cp, const char *filename,
1.153     dtucker   464:            int linenum, u_int *flags)
1.1       deraadt   465: {
1.55      markus    466:        u_int i;
1.1       deraadt   467:
1.25      markus    468:        for (i = 0; keywords[i].name; i++)
1.153     dtucker   469:                if (strcasecmp(cp, keywords[i].name) == 0) {
                    470:                        *flags = keywords[i].flags;
1.25      markus    471:                        return keywords[i].opcode;
1.153     dtucker   472:                }
1.25      markus    473:
1.78      stevesk   474:        error("%s: line %d: Bad configuration option: %s",
                    475:            filename, linenum, cp);
1.25      markus    476:        return sBadOption;
1.1       deraadt   477: }
                    478:
1.202     djm       479: char *
                    480: derelativise_path(const char *path)
                    481: {
1.207     djm       482:        char *expanded, *ret, cwd[MAXPATHLEN];
1.202     djm       483:
                    484:        expanded = tilde_expand_filename(path, getuid());
                    485:        if (*expanded == '/')
                    486:                return expanded;
1.207     djm       487:        if (getcwd(cwd, sizeof(cwd)) == NULL)
1.202     djm       488:                fatal("%s: getcwd: %s", __func__, strerror(errno));
                    489:        xasprintf(&ret, "%s/%s", cwd, expanded);
1.239     djm       490:        free(expanded);
1.202     djm       491:        return ret;
                    492: }
                    493:
1.84      itojun    494: static void
1.194     djm       495: add_listen_addr(ServerOptions *options, char *addr, int port)
1.74      stevesk   496: {
1.142     djm       497:        u_int i;
1.74      stevesk   498:
                    499:        if (options->num_ports == 0)
                    500:                options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
1.138     djm       501:        if (options->address_family == -1)
                    502:                options->address_family = AF_UNSPEC;
1.76      stevesk   503:        if (port == 0)
1.74      stevesk   504:                for (i = 0; i < options->num_ports; i++)
                    505:                        add_one_listen_addr(options, addr, options->ports[i]);
                    506:        else
1.76      stevesk   507:                add_one_listen_addr(options, addr, port);
1.74      stevesk   508: }
                    509:
1.84      itojun    510: static void
1.194     djm       511: add_one_listen_addr(ServerOptions *options, char *addr, int port)
1.29      markus    512: {
                    513:        struct addrinfo hints, *ai, *aitop;
                    514:        char strport[NI_MAXSERV];
                    515:        int gaierr;
                    516:
1.74      stevesk   517:        memset(&hints, 0, sizeof(hints));
1.138     djm       518:        hints.ai_family = options->address_family;
1.74      stevesk   519:        hints.ai_socktype = SOCK_STREAM;
                    520:        hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
1.194     djm       521:        snprintf(strport, sizeof strport, "%d", port);
1.74      stevesk   522:        if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
                    523:                fatal("bad addr or host: %s (%s)",
                    524:                    addr ? addr : "<NULL>",
1.173     dtucker   525:                    ssh_gai_strerror(gaierr));
1.74      stevesk   526:        for (ai = aitop; ai->ai_next; ai = ai->ai_next)
                    527:                ;
                    528:        ai->ai_next = options->listen_addrs;
                    529:        options->listen_addrs = aitop;
1.29      markus    530: }
                    531:
1.226     dtucker   532: struct connection_info *
                    533: get_connection_info(int populate, int use_dns)
                    534: {
                    535:        static struct connection_info ci;
                    536:
                    537:        if (!populate)
                    538:                return &ci;
                    539:        ci.host = get_canonical_hostname(use_dns);
                    540:        ci.address = get_remote_ipaddr();
                    541:        ci.laddress = get_local_ipaddr(packet_get_connection_in());
                    542:        ci.lport = get_local_port();
                    543:        return &ci;
                    544: }
                    545:
1.153     dtucker   546: /*
                    547:  * The strategy for the Match blocks is that the config file is parsed twice.
                    548:  *
                    549:  * The first time is at startup.  activep is initialized to 1 and the
                    550:  * directives in the global context are processed and acted on.  Hitting a
                    551:  * Match directive unsets activep and the directives inside the block are
                    552:  * checked for syntax only.
                    553:  *
                    554:  * The second time is after a connection has been established but before
                    555:  * authentication.  activep is initialized to 2 and global config directives
                    556:  * are ignored since they have already been processed.  If the criteria in a
                    557:  * Match block is met, activep is set and the subsequent directives
                    558:  * processed and actioned until EOF or another Match block unsets it.  Any
                    559:  * options set are copied into the main server config.
                    560:  *
                    561:  * Potential additions/improvements:
                    562:  *  - Add Match support for pre-kex directives, eg Protocol, Ciphers.
                    563:  *
                    564:  *  - Add a Tag directive (idea from David Leonard) ala pf, eg:
                    565:  *     Match Address 192.168.0.*
                    566:  *             Tag trusted
                    567:  *     Match Group wheel
                    568:  *             Tag trusted
                    569:  *     Match Tag trusted
                    570:  *             AllowTcpForwarding yes
                    571:  *             GatewayPorts clientspecified
                    572:  *             [...]
                    573:  *
                    574:  *  - Add a PermittedChannelRequests directive
                    575:  *     Match Group shell
                    576:  *             PermittedChannelRequests session,forwarded-tcpip
                    577:  */
                    578:
                    579: static int
1.165     dtucker   580: match_cfg_line_group(const char *grps, int line, const char *user)
                    581: {
                    582:        int result = 0;
                    583:        struct passwd *pw;
                    584:
                    585:        if (user == NULL)
                    586:                goto out;
                    587:
                    588:        if ((pw = getpwnam(user)) == NULL) {
                    589:                debug("Can't match group at line %d because user %.100s does "
                    590:                    "not exist", line, user);
                    591:        } else if (ga_init(pw->pw_name, pw->pw_gid) == 0) {
                    592:                debug("Can't Match group because user %.100s not in any group "
                    593:                    "at line %d", user, line);
1.186     djm       594:        } else if (ga_match_pattern_list(grps) != 1) {
                    595:                debug("user %.100s does not match group list %.100s at line %d",
                    596:                    user, grps, line);
1.165     dtucker   597:        } else {
1.186     djm       598:                debug("user %.100s matched group list %.100s at line %d", user,
                    599:                    grps, line);
1.165     dtucker   600:                result = 1;
                    601:        }
                    602: out:
                    603:        ga_free();
                    604:        return result;
                    605: }
                    606:
1.226     dtucker   607: /*
1.230     dtucker   608:  * All of the attributes on a single Match line are ANDed together, so we need
1.242     dtucker   609:  * to check every attribute and set the result to zero if any attribute does
1.230     dtucker   610:  * not match.
1.226     dtucker   611:  */
1.165     dtucker   612: static int
1.226     dtucker   613: match_cfg_line(char **condition, int line, struct connection_info *ci)
1.153     dtucker   614: {
1.243     dtucker   615:        int result = 1, attributes = 0, port;
1.153     dtucker   616:        char *arg, *attrib, *cp = *condition;
                    617:        size_t len;
                    618:
1.226     dtucker   619:        if (ci == NULL)
1.153     dtucker   620:                debug3("checking syntax for 'Match %s'", cp);
                    621:        else
1.226     dtucker   622:                debug3("checking match for '%s' user %s host %s addr %s "
                    623:                    "laddr %s lport %d", cp, ci->user ? ci->user : "(null)",
                    624:                    ci->host ? ci->host : "(null)",
                    625:                    ci->address ? ci->address : "(null)",
                    626:                    ci->laddress ? ci->laddress : "(null)", ci->lport);
1.153     dtucker   627:
                    628:        while ((attrib = strdelim(&cp)) && *attrib != '\0') {
1.243     dtucker   629:                attributes++;
                    630:                if (strcasecmp(attrib, "all") == 0) {
                    631:                        if (attributes != 1 ||
                    632:                            ((arg = strdelim(&cp)) != NULL && *arg != '\0')) {
                    633:                                error("'all' cannot be combined with other "
                    634:                                    "Match attributes");
                    635:                                return -1;
                    636:                        }
                    637:                        *condition = cp;
                    638:                        return 1;
                    639:                }
1.153     dtucker   640:                if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
                    641:                        error("Missing Match criteria for %s", attrib);
                    642:                        return -1;
                    643:                }
                    644:                len = strlen(arg);
                    645:                if (strcasecmp(attrib, "user") == 0) {
1.226     dtucker   646:                        if (ci == NULL || ci->user == NULL) {
1.153     dtucker   647:                                result = 0;
                    648:                                continue;
                    649:                        }
1.226     dtucker   650:                        if (match_pattern_list(ci->user, arg, len, 0) != 1)
1.153     dtucker   651:                                result = 0;
                    652:                        else
                    653:                                debug("user %.100s matched 'User %.100s' at "
1.226     dtucker   654:                                    "line %d", ci->user, arg, line);
1.165     dtucker   655:                } else if (strcasecmp(attrib, "group") == 0) {
1.226     dtucker   656:                        if (ci == NULL || ci->user == NULL) {
                    657:                                result = 0;
                    658:                                continue;
                    659:                        }
                    660:                        switch (match_cfg_line_group(arg, line, ci->user)) {
1.165     dtucker   661:                        case -1:
                    662:                                return -1;
                    663:                        case 0:
                    664:                                result = 0;
                    665:                        }
1.153     dtucker   666:                } else if (strcasecmp(attrib, "host") == 0) {
1.226     dtucker   667:                        if (ci == NULL || ci->host == NULL) {
1.153     dtucker   668:                                result = 0;
                    669:                                continue;
                    670:                        }
1.226     dtucker   671:                        if (match_hostname(ci->host, arg, len) != 1)
1.153     dtucker   672:                                result = 0;
                    673:                        else
                    674:                                debug("connection from %.100s matched 'Host "
1.226     dtucker   675:                                    "%.100s' at line %d", ci->host, arg, line);
1.153     dtucker   676:                } else if (strcasecmp(attrib, "address") == 0) {
1.226     dtucker   677:                        if (ci == NULL || ci->address == NULL) {
                    678:                                result = 0;
                    679:                                continue;
                    680:                        }
                    681:                        switch (addr_match_list(ci->address, arg)) {
1.181     djm       682:                        case 1:
                    683:                                debug("connection from %.100s matched 'Address "
1.226     dtucker   684:                                    "%.100s' at line %d", ci->address, arg, line);
1.181     djm       685:                                break;
                    686:                        case 0:
1.183     djm       687:                        case -1:
1.153     dtucker   688:                                result = 0;
1.181     djm       689:                                break;
1.183     djm       690:                        case -2:
1.181     djm       691:                                return -1;
1.153     dtucker   692:                        }
1.226     dtucker   693:                } else if (strcasecmp(attrib, "localaddress") == 0){
                    694:                        if (ci == NULL || ci->laddress == NULL) {
                    695:                                result = 0;
                    696:                                continue;
                    697:                        }
                    698:                        switch (addr_match_list(ci->laddress, arg)) {
                    699:                        case 1:
                    700:                                debug("connection from %.100s matched "
                    701:                                    "'LocalAddress %.100s' at line %d",
                    702:                                    ci->laddress, arg, line);
                    703:                                break;
                    704:                        case 0:
                    705:                        case -1:
                    706:                                result = 0;
                    707:                                break;
                    708:                        case -2:
                    709:                                return -1;
                    710:                        }
                    711:                } else if (strcasecmp(attrib, "localport") == 0) {
                    712:                        if ((port = a2port(arg)) == -1) {
                    713:                                error("Invalid LocalPort '%s' on Match line",
                    714:                                    arg);
                    715:                                return -1;
                    716:                        }
                    717:                        if (ci == NULL || ci->lport == 0) {
                    718:                                result = 0;
                    719:                                continue;
                    720:                        }
                    721:                        /* TODO support port lists */
                    722:                        if (port == ci->lport)
                    723:                                debug("connection from %.100s matched "
                    724:                                    "'LocalPort %d' at line %d",
                    725:                                    ci->laddress, port, line);
                    726:                        else
                    727:                                result = 0;
1.153     dtucker   728:                } else {
                    729:                        error("Unsupported Match attribute %s", attrib);
                    730:                        return -1;
                    731:                }
1.243     dtucker   732:        }
                    733:        if (attributes == 0) {
                    734:                error("One or more attributes required for Match");
                    735:                return -1;
1.153     dtucker   736:        }
1.226     dtucker   737:        if (ci != NULL)
1.153     dtucker   738:                debug3("match %sfound", result ? "" : "not ");
                    739:        *condition = cp;
                    740:        return result;
                    741: }
                    742:
1.158     dtucker   743: #define WHITESPACE " \t\r\n"
                    744:
1.220     djm       745: /* Multistate option parsing */
                    746: struct multistate {
                    747:        char *key;
                    748:        int value;
                    749: };
                    750: static const struct multistate multistate_addressfamily[] = {
                    751:        { "inet",                       AF_INET },
                    752:        { "inet6",                      AF_INET6 },
                    753:        { "any",                        AF_UNSPEC },
                    754:        { NULL, -1 }
                    755: };
                    756: static const struct multistate multistate_permitrootlogin[] = {
                    757:        { "without-password",           PERMIT_NO_PASSWD },
                    758:        { "forced-commands-only",       PERMIT_FORCED_ONLY },
                    759:        { "yes",                        PERMIT_YES },
                    760:        { "no",                         PERMIT_NO },
                    761:        { NULL, -1 }
                    762: };
                    763: static const struct multistate multistate_compression[] = {
                    764:        { "delayed",                    COMP_DELAYED },
                    765:        { "yes",                        COMP_ZLIB },
                    766:        { "no",                         COMP_NONE },
                    767:        { NULL, -1 }
                    768: };
                    769: static const struct multistate multistate_gatewayports[] = {
                    770:        { "clientspecified",            2 },
                    771:        { "yes",                        1 },
                    772:        { "no",                         0 },
                    773:        { NULL, -1 }
                    774: };
1.222     djm       775: static const struct multistate multistate_privsep[] = {
1.228     djm       776:        { "yes",                        PRIVSEP_NOSANDBOX },
                    777:        { "sandbox",                    PRIVSEP_ON },
                    778:        { "nosandbox",                  PRIVSEP_NOSANDBOX },
1.222     djm       779:        { "no",                         PRIVSEP_OFF },
                    780:        { NULL, -1 }
                    781: };
1.233     djm       782: static const struct multistate multistate_tcpfwd[] = {
                    783:        { "yes",                        FORWARD_ALLOW },
                    784:        { "all",                        FORWARD_ALLOW },
                    785:        { "no",                         FORWARD_DENY },
                    786:        { "remote",                     FORWARD_REMOTE },
                    787:        { "local",                      FORWARD_LOCAL },
                    788:        { NULL, -1 }
                    789: };
1.220     djm       790:
1.94      markus    791: int
                    792: process_server_config_line(ServerOptions *options, char *line,
1.226     dtucker   793:     const char *filename, int linenum, int *activep,
                    794:     struct connection_info *connectinfo)
1.1       deraadt   795: {
1.238     dtucker   796:        char *cp, **charptr, *arg, *p;
1.237     dtucker   797:        int cmdline = 0, *intptr, value, value2, n, port;
1.174     dtucker   798:        SyslogFacility *log_facility_ptr;
                    799:        LogLevel *log_level_ptr;
1.25      markus    800:        ServerOpCodes opcode;
1.153     dtucker   801:        u_int i, flags = 0;
1.151     djm       802:        size_t len;
1.237     dtucker   803:        long long val64;
1.220     djm       804:        const struct multistate *multistate_ptr;
1.25      markus    805:
1.94      markus    806:        cp = line;
1.148     dtucker   807:        if ((arg = strdelim(&cp)) == NULL)
1.147     djm       808:                return 0;
1.94      markus    809:        /* Ignore leading whitespace */
                    810:        if (*arg == '\0')
                    811:                arg = strdelim(&cp);
                    812:        if (!arg || !*arg || *arg == '#')
                    813:                return 0;
                    814:        intptr = NULL;
                    815:        charptr = NULL;
1.153     dtucker   816:        opcode = parse_token(arg, filename, linenum, &flags);
                    817:
                    818:        if (activep == NULL) { /* We are processing a command line directive */
                    819:                cmdline = 1;
                    820:                activep = &cmdline;
                    821:        }
                    822:        if (*activep && opcode != sMatch)
                    823:                debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
                    824:        if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
1.226     dtucker   825:                if (connectinfo == NULL) {
1.153     dtucker   826:                        fatal("%s line %d: Directive '%s' is not allowed "
                    827:                            "within a Match block", filename, linenum, arg);
                    828:                } else { /* this is a directive we have already processed */
                    829:                        while (arg)
                    830:                                arg = strdelim(&cp);
                    831:                        return 0;
                    832:                }
                    833:        }
                    834:
1.94      markus    835:        switch (opcode) {
                    836:        case sBadOption:
                    837:                return -1;
                    838:        case sPort:
                    839:                /* ignore ports from configfile if cmdline specifies ports */
                    840:                if (options->ports_from_cmdline)
                    841:                        return 0;
                    842:                if (options->listen_addrs != NULL)
                    843:                        fatal("%s line %d: ports must be specified before "
1.98      stevesk   844:                            "ListenAddress.", filename, linenum);
1.94      markus    845:                if (options->num_ports >= MAX_PORTS)
                    846:                        fatal("%s line %d: too many ports.",
                    847:                            filename, linenum);
1.48      provos    848:                arg = strdelim(&cp);
1.94      markus    849:                if (!arg || *arg == '\0')
                    850:                        fatal("%s line %d: missing port number.",
                    851:                            filename, linenum);
                    852:                options->ports[options->num_ports++] = a2port(arg);
1.194     djm       853:                if (options->ports[options->num_ports-1] <= 0)
1.94      markus    854:                        fatal("%s line %d: Badly formatted port number.",
                    855:                            filename, linenum);
                    856:                break;
1.29      markus    857:
1.94      markus    858:        case sServerKeyBits:
                    859:                intptr = &options->server_key_bits;
1.180     djm       860:  parse_int:
1.94      markus    861:                arg = strdelim(&cp);
                    862:                if (!arg || *arg == '\0')
                    863:                        fatal("%s line %d: missing integer value.",
                    864:                            filename, linenum);
                    865:                value = atoi(arg);
1.153     dtucker   866:                if (*activep && *intptr == -1)
1.94      markus    867:                        *intptr = value;
                    868:                break;
1.25      markus    869:
1.94      markus    870:        case sLoginGraceTime:
                    871:                intptr = &options->login_grace_time;
1.180     djm       872:  parse_time:
1.94      markus    873:                arg = strdelim(&cp);
                    874:                if (!arg || *arg == '\0')
                    875:                        fatal("%s line %d: missing time value.",
                    876:                            filename, linenum);
                    877:                if ((value = convtime(arg)) == -1)
                    878:                        fatal("%s line %d: invalid time value.",
                    879:                            filename, linenum);
                    880:                if (*intptr == -1)
                    881:                        *intptr = value;
                    882:                break;
                    883:
                    884:        case sKeyRegenerationTime:
                    885:                intptr = &options->key_regeneration_time;
                    886:                goto parse_time;
                    887:
                    888:        case sListenAddress:
                    889:                arg = strdelim(&cp);
1.139     djm       890:                if (arg == NULL || *arg == '\0')
                    891:                        fatal("%s line %d: missing address",
1.94      markus    892:                            filename, linenum);
1.144     dtucker   893:                /* check for bare IPv6 address: no "[]" and 2 or more ":" */
                    894:                if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
                    895:                    && strchr(p+1, ':') != NULL) {
                    896:                        add_listen_addr(options, arg, 0);
                    897:                        break;
                    898:                }
1.139     djm       899:                p = hpdelim(&arg);
                    900:                if (p == NULL)
                    901:                        fatal("%s line %d: bad address:port usage",
                    902:                            filename, linenum);
                    903:                p = cleanhostname(p);
                    904:                if (arg == NULL)
                    905:                        port = 0;
1.194     djm       906:                else if ((port = a2port(arg)) <= 0)
1.139     djm       907:                        fatal("%s line %d: bad port number", filename, linenum);
                    908:
                    909:                add_listen_addr(options, p, port);
1.25      markus    910:
1.138     djm       911:                break;
                    912:
                    913:        case sAddressFamily:
1.220     djm       914:                intptr = &options->address_family;
                    915:                multistate_ptr = multistate_addressfamily;
                    916:                if (options->listen_addrs != NULL)
                    917:                        fatal("%s line %d: address family must be specified "
                    918:                            "before ListenAddress.", filename, linenum);
                    919:  parse_multistate:
1.138     djm       920:                arg = strdelim(&cp);
1.141     markus    921:                if (!arg || *arg == '\0')
1.220     djm       922:                        fatal("%s line %d: missing argument.",
1.141     markus    923:                            filename, linenum);
1.220     djm       924:                value = -1;
                    925:                for (i = 0; multistate_ptr[i].key != NULL; i++) {
                    926:                        if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
                    927:                                value = multistate_ptr[i].value;
                    928:                                break;
                    929:                        }
                    930:                }
                    931:                if (value == -1)
                    932:                        fatal("%s line %d: unsupported option \"%s\".",
1.138     djm       933:                            filename, linenum, arg);
1.220     djm       934:                if (*activep && *intptr == -1)
1.138     djm       935:                        *intptr = value;
1.94      markus    936:                break;
                    937:
                    938:        case sHostKeyFile:
                    939:                intptr = &options->num_host_key_files;
                    940:                if (*intptr >= MAX_HOSTKEYS)
                    941:                        fatal("%s line %d: too many host keys specified (max %d).",
                    942:                            filename, linenum, MAX_HOSTKEYS);
                    943:                charptr = &options->host_key_files[*intptr];
1.180     djm       944:  parse_filename:
1.94      markus    945:                arg = strdelim(&cp);
                    946:                if (!arg || *arg == '\0')
                    947:                        fatal("%s line %d: missing file name.",
                    948:                            filename, linenum);
1.153     dtucker   949:                if (*activep && *charptr == NULL) {
1.202     djm       950:                        *charptr = derelativise_path(arg);
1.94      markus    951:                        /* increase optional counter */
                    952:                        if (intptr != NULL)
                    953:                                *intptr = *intptr + 1;
                    954:                }
                    955:                break;
1.76      stevesk   956:
1.240     markus    957:        case sHostKeyAgent:
                    958:                charptr = &options->host_key_agent;
                    959:                arg = strdelim(&cp);
                    960:                if (!arg || *arg == '\0')
                    961:                        fatal("%s line %d: missing socket name.",
                    962:                            filename, linenum);
                    963:                if (*activep && *charptr == NULL)
                    964:                        *charptr = !strcmp(arg, SSH_AUTHSOCKET_ENV_NAME) ?
                    965:                            xstrdup(arg) : derelativise_path(arg);
                    966:                break;
                    967:
1.203     djm       968:        case sHostCertificate:
                    969:                intptr = &options->num_host_cert_files;
                    970:                if (*intptr >= MAX_HOSTKEYS)
                    971:                        fatal("%s line %d: too many host certificates "
                    972:                            "specified (max %d).", filename, linenum,
                    973:                            MAX_HOSTCERTS);
                    974:                charptr = &options->host_cert_files[*intptr];
                    975:                goto parse_filename;
                    976:                break;
                    977:
1.94      markus    978:        case sPidFile:
                    979:                charptr = &options->pid_file;
                    980:                goto parse_filename;
1.25      markus    981:
1.94      markus    982:        case sPermitRootLogin:
                    983:                intptr = &options->permit_root_login;
1.220     djm       984:                multistate_ptr = multistate_permitrootlogin;
                    985:                goto parse_multistate;
1.36      markus    986:
1.94      markus    987:        case sIgnoreRhosts:
                    988:                intptr = &options->ignore_rhosts;
1.180     djm       989:  parse_flag:
1.94      markus    990:                arg = strdelim(&cp);
                    991:                if (!arg || *arg == '\0')
                    992:                        fatal("%s line %d: missing yes/no argument.",
                    993:                            filename, linenum);
                    994:                value = 0;      /* silence compiler */
                    995:                if (strcmp(arg, "yes") == 0)
                    996:                        value = 1;
                    997:                else if (strcmp(arg, "no") == 0)
                    998:                        value = 0;
                    999:                else
                   1000:                        fatal("%s line %d: Bad yes/no argument: %s",
                   1001:                                filename, linenum, arg);
1.153     dtucker  1002:                if (*activep && *intptr == -1)
1.94      markus   1003:                        *intptr = value;
                   1004:                break;
                   1005:
                   1006:        case sIgnoreUserKnownHosts:
                   1007:                intptr = &options->ignore_user_known_hosts;
                   1008:                goto parse_flag;
                   1009:
                   1010:        case sRhostsRSAAuthentication:
                   1011:                intptr = &options->rhosts_rsa_authentication;
                   1012:                goto parse_flag;
                   1013:
                   1014:        case sHostbasedAuthentication:
                   1015:                intptr = &options->hostbased_authentication;
                   1016:                goto parse_flag;
                   1017:
                   1018:        case sHostbasedUsesNameFromPacketOnly:
                   1019:                intptr = &options->hostbased_uses_name_from_packet_only;
                   1020:                goto parse_flag;
                   1021:
                   1022:        case sRSAAuthentication:
                   1023:                intptr = &options->rsa_authentication;
                   1024:                goto parse_flag;
                   1025:
                   1026:        case sPubkeyAuthentication:
                   1027:                intptr = &options->pubkey_authentication;
                   1028:                goto parse_flag;
1.119     jakob    1029:
1.94      markus   1030:        case sKerberosAuthentication:
                   1031:                intptr = &options->kerberos_authentication;
                   1032:                goto parse_flag;
                   1033:
                   1034:        case sKerberosOrLocalPasswd:
                   1035:                intptr = &options->kerberos_or_local_passwd;
                   1036:                goto parse_flag;
                   1037:
                   1038:        case sKerberosTicketCleanup:
                   1039:                intptr = &options->kerberos_ticket_cleanup;
1.130     jakob    1040:                goto parse_flag;
                   1041:
                   1042:        case sKerberosGetAFSToken:
                   1043:                intptr = &options->kerberos_get_afs_token;
1.125     markus   1044:                goto parse_flag;
                   1045:
                   1046:        case sGssAuthentication:
                   1047:                intptr = &options->gss_authentication;
                   1048:                goto parse_flag;
                   1049:
                   1050:        case sGssCleanupCreds:
                   1051:                intptr = &options->gss_cleanup_creds;
1.94      markus   1052:                goto parse_flag;
                   1053:
                   1054:        case sPasswordAuthentication:
                   1055:                intptr = &options->password_authentication;
                   1056:                goto parse_flag;
                   1057:
1.190     djm      1058:        case sZeroKnowledgePasswordAuthentication:
                   1059:                intptr = &options->zero_knowledge_password_authentication;
                   1060:                goto parse_flag;
                   1061:
1.94      markus   1062:        case sKbdInteractiveAuthentication:
                   1063:                intptr = &options->kbd_interactive_authentication;
                   1064:                goto parse_flag;
                   1065:
                   1066:        case sChallengeResponseAuthentication:
                   1067:                intptr = &options->challenge_response_authentication;
                   1068:                goto parse_flag;
                   1069:
                   1070:        case sPrintMotd:
                   1071:                intptr = &options->print_motd;
                   1072:                goto parse_flag;
                   1073:
                   1074:        case sPrintLastLog:
                   1075:                intptr = &options->print_lastlog;
                   1076:                goto parse_flag;
                   1077:
                   1078:        case sX11Forwarding:
                   1079:                intptr = &options->x11_forwarding;
                   1080:                goto parse_flag;
                   1081:
                   1082:        case sX11DisplayOffset:
                   1083:                intptr = &options->x11_display_offset;
                   1084:                goto parse_int;
1.99      stevesk  1085:
                   1086:        case sX11UseLocalhost:
                   1087:                intptr = &options->x11_use_localhost;
                   1088:                goto parse_flag;
1.94      markus   1089:
                   1090:        case sXAuthLocation:
                   1091:                charptr = &options->xauth_location;
                   1092:                goto parse_filename;
                   1093:
1.244     djm      1094:        case sPermitTTY:
                   1095:                intptr = &options->permit_tty;
                   1096:                goto parse_flag;
                   1097:
1.94      markus   1098:        case sStrictModes:
                   1099:                intptr = &options->strict_modes;
                   1100:                goto parse_flag;
                   1101:
1.129     markus   1102:        case sTCPKeepAlive:
                   1103:                intptr = &options->tcp_keep_alive;
1.94      markus   1104:                goto parse_flag;
                   1105:
                   1106:        case sEmptyPasswd:
                   1107:                intptr = &options->permit_empty_passwd;
1.113     markus   1108:                goto parse_flag;
                   1109:
                   1110:        case sPermitUserEnvironment:
                   1111:                intptr = &options->permit_user_env;
1.94      markus   1112:                goto parse_flag;
                   1113:
                   1114:        case sUseLogin:
                   1115:                intptr = &options->use_login;
1.111     markus   1116:                goto parse_flag;
                   1117:
                   1118:        case sCompression:
                   1119:                intptr = &options->compression;
1.220     djm      1120:                multistate_ptr = multistate_compression;
                   1121:                goto parse_multistate;
1.94      markus   1122:
1.235     dtucker  1123:        case sRekeyLimit:
                   1124:                arg = strdelim(&cp);
                   1125:                if (!arg || *arg == '\0')
                   1126:                        fatal("%.200s line %d: Missing argument.", filename,
                   1127:                            linenum);
                   1128:                if (strcmp(arg, "default") == 0) {
                   1129:                        val64 = 0;
                   1130:                } else {
1.236     dtucker  1131:                        if (scan_scaled(arg, &val64) == -1)
                   1132:                                fatal("%.200s line %d: Bad number '%s': %s",
                   1133:                                    filename, linenum, arg, strerror(errno));
                   1134:                        /* check for too-large or too-small limits */
                   1135:                        if (val64 > UINT_MAX)
1.235     dtucker  1136:                                fatal("%.200s line %d: RekeyLimit too large",
                   1137:                                    filename, linenum);
                   1138:                        if (val64 != 0 && val64 < 16)
                   1139:                                fatal("%.200s line %d: RekeyLimit too small",
                   1140:                                    filename, linenum);
                   1141:                }
                   1142:                if (*activep && options->rekey_limit == -1)
                   1143:                        options->rekey_limit = (u_int32_t)val64;
                   1144:                if (cp != NULL) { /* optional rekey interval present */
                   1145:                        if (strcmp(cp, "none") == 0) {
                   1146:                                (void)strdelim(&cp);    /* discard */
                   1147:                                break;
                   1148:                        }
                   1149:                        intptr = &options->rekey_interval;
                   1150:                        goto parse_time;
                   1151:                }
                   1152:                break;
                   1153:
1.94      markus   1154:        case sGatewayPorts:
                   1155:                intptr = &options->gateway_ports;
1.220     djm      1156:                multistate_ptr = multistate_gatewayports;
                   1157:                goto parse_multistate;
1.25      markus   1158:
1.122     markus   1159:        case sUseDNS:
                   1160:                intptr = &options->use_dns;
1.94      markus   1161:                goto parse_flag;
1.53      markus   1162:
1.94      markus   1163:        case sLogFacility:
1.174     dtucker  1164:                log_facility_ptr = &options->log_facility;
1.94      markus   1165:                arg = strdelim(&cp);
                   1166:                value = log_facility_number(arg);
1.101     markus   1167:                if (value == SYSLOG_FACILITY_NOT_SET)
1.94      markus   1168:                        fatal("%.200s line %d: unsupported log facility '%s'",
                   1169:                            filename, linenum, arg ? arg : "<NONE>");
1.174     dtucker  1170:                if (*log_facility_ptr == -1)
                   1171:                        *log_facility_ptr = (SyslogFacility) value;
1.94      markus   1172:                break;
1.25      markus   1173:
1.94      markus   1174:        case sLogLevel:
1.174     dtucker  1175:                log_level_ptr = &options->log_level;
1.94      markus   1176:                arg = strdelim(&cp);
                   1177:                value = log_level_number(arg);
1.101     markus   1178:                if (value == SYSLOG_LEVEL_NOT_SET)
1.94      markus   1179:                        fatal("%.200s line %d: unsupported log level '%s'",
                   1180:                            filename, linenum, arg ? arg : "<NONE>");
1.174     dtucker  1181:                if (*log_level_ptr == -1)
                   1182:                        *log_level_ptr = (LogLevel) value;
1.94      markus   1183:                break;
                   1184:
                   1185:        case sAllowTcpForwarding:
                   1186:                intptr = &options->allow_tcp_forwarding;
1.233     djm      1187:                multistate_ptr = multistate_tcpfwd;
                   1188:                goto parse_multistate;
1.102     provos   1189:
1.178     pyr      1190:        case sAllowAgentForwarding:
                   1191:                intptr = &options->allow_agent_forwarding;
                   1192:                goto parse_flag;
                   1193:
1.102     provos   1194:        case sUsePrivilegeSeparation:
                   1195:                intptr = &use_privsep;
1.222     djm      1196:                multistate_ptr = multistate_privsep;
                   1197:                goto parse_multistate;
1.94      markus   1198:
                   1199:        case sAllowUsers:
                   1200:                while ((arg = strdelim(&cp)) && *arg != '\0') {
                   1201:                        if (options->num_allow_users >= MAX_ALLOW_USERS)
                   1202:                                fatal("%s line %d: too many allow users.",
                   1203:                                    filename, linenum);
1.227     markus   1204:                        if (!*activep)
                   1205:                                continue;
1.112     deraadt  1206:                        options->allow_users[options->num_allow_users++] =
                   1207:                            xstrdup(arg);
1.94      markus   1208:                }
                   1209:                break;
1.25      markus   1210:
1.94      markus   1211:        case sDenyUsers:
                   1212:                while ((arg = strdelim(&cp)) && *arg != '\0') {
                   1213:                        if (options->num_deny_users >= MAX_DENY_USERS)
1.163     stevesk  1214:                                fatal("%s line %d: too many deny users.",
1.94      markus   1215:                                    filename, linenum);
1.227     markus   1216:                        if (!*activep)
                   1217:                                continue;
1.112     deraadt  1218:                        options->deny_users[options->num_deny_users++] =
                   1219:                            xstrdup(arg);
1.94      markus   1220:                }
                   1221:                break;
1.25      markus   1222:
1.94      markus   1223:        case sAllowGroups:
                   1224:                while ((arg = strdelim(&cp)) && *arg != '\0') {
                   1225:                        if (options->num_allow_groups >= MAX_ALLOW_GROUPS)
                   1226:                                fatal("%s line %d: too many allow groups.",
                   1227:                                    filename, linenum);
1.227     markus   1228:                        if (!*activep)
                   1229:                                continue;
1.112     deraadt  1230:                        options->allow_groups[options->num_allow_groups++] =
                   1231:                            xstrdup(arg);
1.94      markus   1232:                }
                   1233:                break;
1.33      markus   1234:
1.94      markus   1235:        case sDenyGroups:
                   1236:                while ((arg = strdelim(&cp)) && *arg != '\0') {
                   1237:                        if (options->num_deny_groups >= MAX_DENY_GROUPS)
                   1238:                                fatal("%s line %d: too many deny groups.",
                   1239:                                    filename, linenum);
1.227     markus   1240:                        if (!*activep)
                   1241:                                continue;
                   1242:                        options->deny_groups[options->num_deny_groups++] =
                   1243:                            xstrdup(arg);
1.94      markus   1244:                }
                   1245:                break;
1.66      markus   1246:
1.94      markus   1247:        case sCiphers:
                   1248:                arg = strdelim(&cp);
                   1249:                if (!arg || *arg == '\0')
                   1250:                        fatal("%s line %d: Missing argument.", filename, linenum);
                   1251:                if (!ciphers_valid(arg))
                   1252:                        fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
                   1253:                            filename, linenum, arg ? arg : "<NONE>");
                   1254:                if (options->ciphers == NULL)
                   1255:                        options->ciphers = xstrdup(arg);
                   1256:                break;
1.33      markus   1257:
1.94      markus   1258:        case sMacs:
                   1259:                arg = strdelim(&cp);
                   1260:                if (!arg || *arg == '\0')
                   1261:                        fatal("%s line %d: Missing argument.", filename, linenum);
                   1262:                if (!mac_valid(arg))
                   1263:                        fatal("%s line %d: Bad SSH2 mac spec '%s'.",
                   1264:                            filename, linenum, arg ? arg : "<NONE>");
                   1265:                if (options->macs == NULL)
                   1266:                        options->macs = xstrdup(arg);
1.211     djm      1267:                break;
                   1268:
                   1269:        case sKexAlgorithms:
                   1270:                arg = strdelim(&cp);
                   1271:                if (!arg || *arg == '\0')
                   1272:                        fatal("%s line %d: Missing argument.",
                   1273:                            filename, linenum);
                   1274:                if (!kex_names_valid(arg))
                   1275:                        fatal("%s line %d: Bad SSH2 KexAlgorithms '%s'.",
                   1276:                            filename, linenum, arg ? arg : "<NONE>");
                   1277:                if (options->kex_algorithms == NULL)
                   1278:                        options->kex_algorithms = xstrdup(arg);
1.94      markus   1279:                break;
1.43      jakob    1280:
1.94      markus   1281:        case sProtocol:
                   1282:                intptr = &options->protocol;
                   1283:                arg = strdelim(&cp);
                   1284:                if (!arg || *arg == '\0')
                   1285:                        fatal("%s line %d: Missing argument.", filename, linenum);
                   1286:                value = proto_spec(arg);
                   1287:                if (value == SSH_PROTO_UNKNOWN)
                   1288:                        fatal("%s line %d: Bad protocol spec '%s'.",
1.95      deraadt  1289:                            filename, linenum, arg ? arg : "<NONE>");
1.94      markus   1290:                if (*intptr == SSH_PROTO_UNKNOWN)
                   1291:                        *intptr = value;
                   1292:                break;
                   1293:
                   1294:        case sSubsystem:
                   1295:                if (options->num_subsystems >= MAX_SUBSYSTEMS) {
                   1296:                        fatal("%s line %d: too many subsystems defined.",
1.95      deraadt  1297:                            filename, linenum);
1.94      markus   1298:                }
                   1299:                arg = strdelim(&cp);
                   1300:                if (!arg || *arg == '\0')
                   1301:                        fatal("%s line %d: Missing subsystem name.",
1.95      deraadt  1302:                            filename, linenum);
1.153     dtucker  1303:                if (!*activep) {
                   1304:                        arg = strdelim(&cp);
                   1305:                        break;
                   1306:                }
1.94      markus   1307:                for (i = 0; i < options->num_subsystems; i++)
                   1308:                        if (strcmp(arg, options->subsystem_name[i]) == 0)
                   1309:                                fatal("%s line %d: Subsystem '%s' already defined.",
1.95      deraadt  1310:                                    filename, linenum, arg);
1.94      markus   1311:                options->subsystem_name[options->num_subsystems] = xstrdup(arg);
                   1312:                arg = strdelim(&cp);
                   1313:                if (!arg || *arg == '\0')
                   1314:                        fatal("%s line %d: Missing subsystem command.",
1.95      deraadt  1315:                            filename, linenum);
1.94      markus   1316:                options->subsystem_command[options->num_subsystems] = xstrdup(arg);
1.151     djm      1317:
                   1318:                /* Collect arguments (separate to executable) */
                   1319:                p = xstrdup(arg);
                   1320:                len = strlen(p) + 1;
                   1321:                while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
                   1322:                        len += 1 + strlen(arg);
                   1323:                        p = xrealloc(p, 1, len);
                   1324:                        strlcat(p, " ", len);
                   1325:                        strlcat(p, arg, len);
                   1326:                }
                   1327:                options->subsystem_args[options->num_subsystems] = p;
1.94      markus   1328:                options->num_subsystems++;
                   1329:                break;
1.46      markus   1330:
1.94      markus   1331:        case sMaxStartups:
                   1332:                arg = strdelim(&cp);
                   1333:                if (!arg || *arg == '\0')
                   1334:                        fatal("%s line %d: Missing MaxStartups spec.",
1.95      deraadt  1335:                            filename, linenum);
1.94      markus   1336:                if ((n = sscanf(arg, "%d:%d:%d",
                   1337:                    &options->max_startups_begin,
                   1338:                    &options->max_startups_rate,
                   1339:                    &options->max_startups)) == 3) {
                   1340:                        if (options->max_startups_begin >
                   1341:                            options->max_startups ||
                   1342:                            options->max_startups_rate > 100 ||
                   1343:                            options->max_startups_rate < 1)
1.50      markus   1344:                                fatal("%s line %d: Illegal MaxStartups spec.",
1.87      stevesk  1345:                                    filename, linenum);
1.94      markus   1346:                } else if (n != 1)
                   1347:                        fatal("%s line %d: Illegal MaxStartups spec.",
                   1348:                            filename, linenum);
                   1349:                else
                   1350:                        options->max_startups = options->max_startups_begin;
                   1351:                break;
1.133     dtucker  1352:
                   1353:        case sMaxAuthTries:
                   1354:                intptr = &options->max_authtries;
                   1355:                goto parse_int;
1.94      markus   1356:
1.180     djm      1357:        case sMaxSessions:
                   1358:                intptr = &options->max_sessions;
                   1359:                goto parse_int;
                   1360:
1.94      markus   1361:        case sBanner:
                   1362:                charptr = &options->banner;
                   1363:                goto parse_filename;
1.176     djm      1364:
1.94      markus   1365:        /*
                   1366:         * These options can contain %X options expanded at
                   1367:         * connect time, so that you can specify paths like:
                   1368:         *
                   1369:         * AuthorizedKeysFile   /etc/ssh_keys/%u
                   1370:         */
                   1371:        case sAuthorizedKeysFile:
1.219     djm      1372:                if (*activep && options->num_authkeys_files == 0) {
                   1373:                        while ((arg = strdelim(&cp)) && *arg != '\0') {
                   1374:                                if (options->num_authkeys_files >=
                   1375:                                    MAX_AUTHKEYS_FILES)
                   1376:                                        fatal("%s line %d: "
                   1377:                                            "too many authorized keys files.",
                   1378:                                            filename, linenum);
                   1379:                                options->authorized_keys_files[
                   1380:                                    options->num_authkeys_files++] =
                   1381:                                    tilde_expand_filename(arg, getuid());
                   1382:                        }
                   1383:                }
                   1384:                return 0;
                   1385:
1.208     djm      1386:        case sAuthorizedPrincipalsFile:
                   1387:                charptr = &options->authorized_principals_file;
1.205     djm      1388:                arg = strdelim(&cp);
                   1389:                if (!arg || *arg == '\0')
                   1390:                        fatal("%s line %d: missing file name.",
                   1391:                            filename, linenum);
                   1392:                if (*activep && *charptr == NULL) {
1.206     markus   1393:                        *charptr = tilde_expand_filename(arg, getuid());
1.205     djm      1394:                        /* increase optional counter */
                   1395:                        if (intptr != NULL)
                   1396:                                *intptr = *intptr + 1;
                   1397:                }
                   1398:                break;
1.94      markus   1399:
                   1400:        case sClientAliveInterval:
                   1401:                intptr = &options->client_alive_interval;
                   1402:                goto parse_time;
                   1403:
                   1404:        case sClientAliveCountMax:
                   1405:                intptr = &options->client_alive_count_max;
                   1406:                goto parse_int;
1.131     djm      1407:
                   1408:        case sAcceptEnv:
                   1409:                while ((arg = strdelim(&cp)) && *arg != '\0') {
                   1410:                        if (strchr(arg, '=') != NULL)
                   1411:                                fatal("%s line %d: Invalid environment name.",
                   1412:                                    filename, linenum);
                   1413:                        if (options->num_accept_env >= MAX_ACCEPT_ENV)
                   1414:                                fatal("%s line %d: too many allow env.",
                   1415:                                    filename, linenum);
1.153     dtucker  1416:                        if (!*activep)
1.227     markus   1417:                                continue;
1.131     djm      1418:                        options->accept_env[options->num_accept_env++] =
                   1419:                            xstrdup(arg);
                   1420:                }
                   1421:                break;
1.145     reyk     1422:
                   1423:        case sPermitTunnel:
                   1424:                intptr = &options->permit_tun;
1.146     reyk     1425:                arg = strdelim(&cp);
                   1426:                if (!arg || *arg == '\0')
                   1427:                        fatal("%s line %d: Missing yes/point-to-point/"
                   1428:                            "ethernet/no argument.", filename, linenum);
1.182     dtucker  1429:                value = -1;
                   1430:                for (i = 0; tunmode_desc[i].val != -1; i++)
                   1431:                        if (strcmp(tunmode_desc[i].text, arg) == 0) {
                   1432:                                value = tunmode_desc[i].val;
                   1433:                                break;
                   1434:                        }
                   1435:                if (value == -1)
1.146     reyk     1436:                        fatal("%s line %d: Bad yes/point-to-point/ethernet/"
                   1437:                            "no argument: %s", filename, linenum, arg);
                   1438:                if (*intptr == -1)
                   1439:                        *intptr = value;
                   1440:                break;
1.94      markus   1441:
1.153     dtucker  1442:        case sMatch:
                   1443:                if (cmdline)
                   1444:                        fatal("Match directive not supported as a command-line "
                   1445:                           "option");
1.226     dtucker  1446:                value = match_cfg_line(&cp, linenum, connectinfo);
1.153     dtucker  1447:                if (value < 0)
                   1448:                        fatal("%s line %d: Bad Match condition", filename,
                   1449:                            linenum);
                   1450:                *activep = value;
1.156     dtucker  1451:                break;
                   1452:
                   1453:        case sPermitOpen:
                   1454:                arg = strdelim(&cp);
                   1455:                if (!arg || *arg == '\0')
                   1456:                        fatal("%s line %d: missing PermitOpen specification",
                   1457:                            filename, linenum);
1.167     dtucker  1458:                n = options->num_permitted_opens;       /* modified later */
1.156     dtucker  1459:                if (strcmp(arg, "any") == 0) {
1.167     dtucker  1460:                        if (*activep && n == -1) {
1.156     dtucker  1461:                                channel_clear_adm_permitted_opens();
1.159     dtucker  1462:                                options->num_permitted_opens = 0;
1.224     dtucker  1463:                        }
                   1464:                        break;
                   1465:                }
                   1466:                if (strcmp(arg, "none") == 0) {
                   1467:                        if (*activep && n == -1) {
                   1468:                                options->num_permitted_opens = 1;
                   1469:                                channel_disable_adm_local_opens();
1.159     dtucker  1470:                        }
1.156     dtucker  1471:                        break;
                   1472:                }
1.166     dtucker  1473:                if (*activep && n == -1)
                   1474:                        channel_clear_adm_permitted_opens();
1.159     dtucker  1475:                for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
                   1476:                        p = hpdelim(&arg);
                   1477:                        if (p == NULL)
                   1478:                                fatal("%s line %d: missing host in PermitOpen",
                   1479:                                    filename, linenum);
                   1480:                        p = cleanhostname(p);
1.223     dtucker  1481:                        if (arg == NULL || ((port = permitopen_port(arg)) < 0))
1.159     dtucker  1482:                                fatal("%s line %d: bad port number in "
                   1483:                                    "PermitOpen", filename, linenum);
1.166     dtucker  1484:                        if (*activep && n == -1)
1.159     dtucker  1485:                                options->num_permitted_opens =
                   1486:                                    channel_add_adm_permitted_opens(p, port);
                   1487:                }
1.153     dtucker  1488:                break;
                   1489:
1.158     dtucker  1490:        case sForceCommand:
                   1491:                if (cp == NULL)
                   1492:                        fatal("%.200s line %d: Missing argument.", filename,
                   1493:                            linenum);
                   1494:                len = strspn(cp, WHITESPACE);
                   1495:                if (*activep && options->adm_forced_command == NULL)
                   1496:                        options->adm_forced_command = xstrdup(cp + len);
                   1497:                return 0;
                   1498:
1.176     djm      1499:        case sChrootDirectory:
                   1500:                charptr = &options->chroot_directory;
1.177     djm      1501:
                   1502:                arg = strdelim(&cp);
                   1503:                if (!arg || *arg == '\0')
                   1504:                        fatal("%s line %d: missing file name.",
                   1505:                            filename, linenum);
                   1506:                if (*activep && *charptr == NULL)
                   1507:                        *charptr = xstrdup(arg);
                   1508:                break;
1.176     djm      1509:
1.204     djm      1510:        case sTrustedUserCAKeys:
                   1511:                charptr = &options->trusted_user_ca_keys;
                   1512:                goto parse_filename;
                   1513:
                   1514:        case sRevokedKeys:
                   1515:                charptr = &options->revoked_keys_file;
                   1516:                goto parse_filename;
                   1517:
1.213     djm      1518:        case sIPQoS:
                   1519:                arg = strdelim(&cp);
                   1520:                if ((value = parse_ipqos(arg)) == -1)
                   1521:                        fatal("%s line %d: Bad IPQoS value: %s",
                   1522:                            filename, linenum, arg);
                   1523:                arg = strdelim(&cp);
                   1524:                if (arg == NULL)
                   1525:                        value2 = value;
                   1526:                else if ((value2 = parse_ipqos(arg)) == -1)
                   1527:                        fatal("%s line %d: Bad IPQoS value: %s",
                   1528:                            filename, linenum, arg);
                   1529:                if (*activep) {
                   1530:                        options->ip_qos_interactive = value;
                   1531:                        options->ip_qos_bulk = value2;
                   1532:                }
                   1533:                break;
                   1534:
1.225     djm      1535:        case sVersionAddendum:
                   1536:                if (cp == NULL)
                   1537:                        fatal("%.200s line %d: Missing argument.", filename,
                   1538:                            linenum);
                   1539:                len = strspn(cp, WHITESPACE);
                   1540:                if (*activep && options->version_addendum == NULL) {
                   1541:                        if (strcasecmp(cp + len, "none") == 0)
                   1542:                                options->version_addendum = xstrdup("");
                   1543:                        else if (strchr(cp + len, '\r') != NULL)
                   1544:                                fatal("%.200s line %d: Invalid argument",
                   1545:                                    filename, linenum);
                   1546:                        else
                   1547:                                options->version_addendum = xstrdup(cp + len);
                   1548:                }
                   1549:                return 0;
                   1550:
1.231     djm      1551:        case sAuthorizedKeysCommand:
                   1552:                len = strspn(cp, WHITESPACE);
                   1553:                if (*activep && options->authorized_keys_command == NULL) {
                   1554:                        if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
                   1555:                                fatal("%.200s line %d: AuthorizedKeysCommand "
                   1556:                                    "must be an absolute path",
                   1557:                                    filename, linenum);
                   1558:                        options->authorized_keys_command = xstrdup(cp + len);
                   1559:                }
                   1560:                return 0;
                   1561:
                   1562:        case sAuthorizedKeysCommandUser:
                   1563:                charptr = &options->authorized_keys_command_user;
                   1564:
                   1565:                arg = strdelim(&cp);
                   1566:                if (*activep && *charptr == NULL)
                   1567:                        *charptr = xstrdup(arg);
                   1568:                break;
                   1569:
1.232     djm      1570:        case sAuthenticationMethods:
                   1571:                if (*activep && options->num_auth_methods == 0) {
                   1572:                        while ((arg = strdelim(&cp)) && *arg != '\0') {
                   1573:                                if (options->num_auth_methods >=
                   1574:                                    MAX_AUTH_METHODS)
                   1575:                                        fatal("%s line %d: "
                   1576:                                            "too many authentication methods.",
                   1577:                                            filename, linenum);
                   1578:                                if (auth2_methods_valid(arg, 0) != 0)
                   1579:                                        fatal("%s line %d: invalid "
                   1580:                                            "authentication method list.",
                   1581:                                            filename, linenum);
                   1582:                                options->auth_methods[
                   1583:                                    options->num_auth_methods++] = xstrdup(arg);
                   1584:                        }
                   1585:                }
                   1586:                return 0;
                   1587:
1.94      markus   1588:        case sDeprecated:
1.117     itojun   1589:                logit("%s line %d: Deprecated option %s",
1.121     jakob    1590:                    filename, linenum, arg);
                   1591:                while (arg)
                   1592:                    arg = strdelim(&cp);
                   1593:                break;
                   1594:
                   1595:        case sUnsupported:
                   1596:                logit("%s line %d: Unsupported option %s",
1.94      markus   1597:                    filename, linenum, arg);
                   1598:                while (arg)
                   1599:                    arg = strdelim(&cp);
                   1600:                break;
                   1601:
                   1602:        default:
                   1603:                fatal("%s line %d: Missing handler for opcode %s (%d)",
                   1604:                    filename, linenum, arg, opcode);
                   1605:        }
                   1606:        if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
                   1607:                fatal("%s line %d: garbage at end of line; \"%.200s\".",
                   1608:                    filename, linenum, arg);
                   1609:        return 0;
                   1610: }
                   1611:
                   1612: /* Reads the server configuration file. */
1.25      markus   1613:
1.94      markus   1614: void
1.134     djm      1615: load_server_config(const char *filename, Buffer *conf)
1.94      markus   1616: {
1.229     dtucker  1617:        char line[4096], *cp;
1.94      markus   1618:        FILE *f;
1.229     dtucker  1619:        int lineno = 0;
1.81      stevesk  1620:
1.134     djm      1621:        debug2("%s: filename %s", __func__, filename);
                   1622:        if ((f = fopen(filename, "r")) == NULL) {
1.94      markus   1623:                perror(filename);
                   1624:                exit(1);
                   1625:        }
1.134     djm      1626:        buffer_clear(conf);
                   1627:        while (fgets(line, sizeof(line), f)) {
1.229     dtucker  1628:                lineno++;
                   1629:                if (strlen(line) == sizeof(line) - 1)
                   1630:                        fatal("%s line %d too long", filename, lineno);
1.134     djm      1631:                /*
                   1632:                 * Trim out comments and strip whitespace
1.135     deraadt  1633:                 * NB - preserve newlines, they are needed to reproduce
1.134     djm      1634:                 * line numbers later for error messages
                   1635:                 */
                   1636:                if ((cp = strchr(line, '#')) != NULL)
                   1637:                        memcpy(cp, "\n", 2);
                   1638:                cp = line + strspn(line, " \t\r");
                   1639:
                   1640:                buffer_append(conf, cp, strlen(cp));
                   1641:        }
                   1642:        buffer_append(conf, "\0", 1);
                   1643:        fclose(f);
                   1644:        debug2("%s: done config len = %d", __func__, buffer_len(conf));
                   1645: }
                   1646:
                   1647: void
1.226     dtucker  1648: parse_server_match_config(ServerOptions *options,
                   1649:    struct connection_info *connectinfo)
1.153     dtucker  1650: {
                   1651:        ServerOptions mo;
                   1652:
                   1653:        initialize_server_options(&mo);
1.226     dtucker  1654:        parse_server_config(&mo, "reprocess config", &cfg, connectinfo);
1.168     dtucker  1655:        copy_set_server_options(options, &mo, 0);
1.153     dtucker  1656: }
                   1657:
1.226     dtucker  1658: int parse_server_match_testspec(struct connection_info *ci, char *spec)
                   1659: {
                   1660:        char *p;
                   1661:
                   1662:        while ((p = strsep(&spec, ",")) && *p != '\0') {
                   1663:                if (strncmp(p, "addr=", 5) == 0) {
                   1664:                        ci->address = xstrdup(p + 5);
                   1665:                } else if (strncmp(p, "host=", 5) == 0) {
                   1666:                        ci->host = xstrdup(p + 5);
                   1667:                } else if (strncmp(p, "user=", 5) == 0) {
                   1668:                        ci->user = xstrdup(p + 5);
                   1669:                } else if (strncmp(p, "laddr=", 6) == 0) {
                   1670:                        ci->laddress = xstrdup(p + 6);
                   1671:                } else if (strncmp(p, "lport=", 6) == 0) {
                   1672:                        ci->lport = a2port(p + 6);
                   1673:                        if (ci->lport == -1) {
                   1674:                                fprintf(stderr, "Invalid port '%s' in test mode"
                   1675:                                   " specification %s\n", p+6, p);
                   1676:                                return -1;
                   1677:                        }
                   1678:                } else {
                   1679:                        fprintf(stderr, "Invalid test mode specification %s\n",
                   1680:                           p);
                   1681:                        return -1;
                   1682:                }
                   1683:        }
                   1684:        return 0;
                   1685: }
                   1686:
                   1687: /*
                   1688:  * returns 1 for a complete spec, 0 for partial spec and -1 for an
                   1689:  * empty spec.
                   1690:  */
                   1691: int server_match_spec_complete(struct connection_info *ci)
                   1692: {
                   1693:        if (ci->user && ci->host && ci->address)
                   1694:                return 1;       /* complete */
                   1695:        if (!ci->user && !ci->host && !ci->address)
                   1696:                return -1;      /* empty */
                   1697:        return 0;       /* partial */
                   1698: }
                   1699:
1.168     dtucker  1700: /*
                   1701:  * Copy any supported values that are set.
                   1702:  *
1.195     jj       1703:  * If the preauth flag is set, we do not bother copying the string or
1.168     dtucker  1704:  * array values that are not used pre-authentication, because any that we
                   1705:  * do use must be explictly sent in mm_getpwnamallow().
                   1706:  */
1.153     dtucker  1707: void
1.168     dtucker  1708: copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
1.153     dtucker  1709: {
1.247     djm      1710: #define M_CP_INTOPT(n) do {\
                   1711:        if (src->n != -1) \
                   1712:                dst->n = src->n; \
                   1713: } while (0)
                   1714:
1.168     dtucker  1715:        M_CP_INTOPT(password_authentication);
                   1716:        M_CP_INTOPT(gss_authentication);
                   1717:        M_CP_INTOPT(rsa_authentication);
                   1718:        M_CP_INTOPT(pubkey_authentication);
                   1719:        M_CP_INTOPT(kerberos_authentication);
                   1720:        M_CP_INTOPT(hostbased_authentication);
1.209     djm      1721:        M_CP_INTOPT(hostbased_uses_name_from_packet_only);
1.168     dtucker  1722:        M_CP_INTOPT(kbd_interactive_authentication);
1.190     djm      1723:        M_CP_INTOPT(zero_knowledge_password_authentication);
1.175     dtucker  1724:        M_CP_INTOPT(permit_root_login);
1.188     djm      1725:        M_CP_INTOPT(permit_empty_passwd);
1.168     dtucker  1726:
                   1727:        M_CP_INTOPT(allow_tcp_forwarding);
1.178     pyr      1728:        M_CP_INTOPT(allow_agent_forwarding);
1.209     djm      1729:        M_CP_INTOPT(permit_tun);
1.168     dtucker  1730:        M_CP_INTOPT(gateway_ports);
                   1731:        M_CP_INTOPT(x11_display_offset);
                   1732:        M_CP_INTOPT(x11_forwarding);
                   1733:        M_CP_INTOPT(x11_use_localhost);
1.244     djm      1734:        M_CP_INTOPT(permit_tty);
1.180     djm      1735:        M_CP_INTOPT(max_sessions);
1.184     dtucker  1736:        M_CP_INTOPT(max_authtries);
1.213     djm      1737:        M_CP_INTOPT(ip_qos_interactive);
                   1738:        M_CP_INTOPT(ip_qos_bulk);
1.235     dtucker  1739:        M_CP_INTOPT(rekey_limit);
                   1740:        M_CP_INTOPT(rekey_interval);
1.247     djm      1741:
                   1742:        /* M_CP_STROPT and M_CP_STRARRAYOPT should not appear before here */
                   1743: #define M_CP_STROPT(n) do {\
                   1744:        if (src->n != NULL && dst->n != src->n) { \
                   1745:                free(dst->n); \
                   1746:                dst->n = src->n; \
                   1747:        } \
                   1748: } while(0)
                   1749: #define M_CP_STRARRAYOPT(n, num_n) do {\
                   1750:        if (src->num_n != 0) { \
                   1751:                for (dst->num_n = 0; dst->num_n < src->num_n; dst->num_n++) \
                   1752:                        dst->n[dst->num_n] = xstrdup(src->n[dst->num_n]); \
                   1753:        } \
                   1754: } while(0)
1.168     dtucker  1755:
1.218     djm      1756:        /* See comment in servconf.h */
                   1757:        COPY_MATCH_STRING_OPTS();
1.216     djm      1758:
1.217     dtucker  1759:        /*
                   1760:         * The only things that should be below this point are string options
                   1761:         * which are only used after authentication.
                   1762:         */
1.168     dtucker  1763:        if (preauth)
                   1764:                return;
1.219     djm      1765:
1.168     dtucker  1766:        M_CP_STROPT(adm_forced_command);
1.176     djm      1767:        M_CP_STROPT(chroot_directory);
1.153     dtucker  1768: }
1.168     dtucker  1769:
                   1770: #undef M_CP_INTOPT
                   1771: #undef M_CP_STROPT
1.219     djm      1772: #undef M_CP_STRARRAYOPT
1.153     dtucker  1773:
                   1774: void
                   1775: parse_server_config(ServerOptions *options, const char *filename, Buffer *conf,
1.226     dtucker  1776:     struct connection_info *connectinfo)
1.134     djm      1777: {
1.153     dtucker  1778:        int active, linenum, bad_options = 0;
1.136     dtucker  1779:        char *cp, *obuf, *cbuf;
1.134     djm      1780:
                   1781:        debug2("%s: config %s len %d", __func__, filename, buffer_len(conf));
                   1782:
1.136     dtucker  1783:        obuf = cbuf = xstrdup(buffer_ptr(conf));
1.226     dtucker  1784:        active = connectinfo ? 0 : 1;
1.137     dtucker  1785:        linenum = 1;
1.140     deraadt  1786:        while ((cp = strsep(&cbuf, "\n")) != NULL) {
1.134     djm      1787:                if (process_server_config_line(options, cp, filename,
1.226     dtucker  1788:                    linenum++, &active, connectinfo) != 0)
1.94      markus   1789:                        bad_options++;
1.1       deraadt  1790:        }
1.239     djm      1791:        free(obuf);
1.78      stevesk  1792:        if (bad_options > 0)
                   1793:                fatal("%s: terminating, %d bad configuration options",
                   1794:                    filename, bad_options);
1.182     dtucker  1795: }
                   1796:
                   1797: static const char *
1.221     djm      1798: fmt_multistate_int(int val, const struct multistate *m)
                   1799: {
                   1800:        u_int i;
                   1801:
                   1802:        for (i = 0; m[i].key != NULL; i++) {
                   1803:                if (m[i].value == val)
                   1804:                        return m[i].key;
                   1805:        }
                   1806:        return "UNKNOWN";
                   1807: }
                   1808:
                   1809: static const char *
1.182     dtucker  1810: fmt_intarg(ServerOpCodes code, int val)
                   1811: {
1.221     djm      1812:        if (val == -1)
                   1813:                return "unset";
                   1814:        switch (code) {
                   1815:        case sAddressFamily:
                   1816:                return fmt_multistate_int(val, multistate_addressfamily);
                   1817:        case sPermitRootLogin:
                   1818:                return fmt_multistate_int(val, multistate_permitrootlogin);
                   1819:        case sGatewayPorts:
                   1820:                return fmt_multistate_int(val, multistate_gatewayports);
                   1821:        case sCompression:
                   1822:                return fmt_multistate_int(val, multistate_compression);
1.222     djm      1823:        case sUsePrivilegeSeparation:
                   1824:                return fmt_multistate_int(val, multistate_privsep);
1.233     djm      1825:        case sAllowTcpForwarding:
                   1826:                return fmt_multistate_int(val, multistate_tcpfwd);
1.221     djm      1827:        case sProtocol:
1.182     dtucker  1828:                switch (val) {
                   1829:                case SSH_PROTO_1:
                   1830:                        return "1";
                   1831:                case SSH_PROTO_2:
                   1832:                        return "2";
                   1833:                case (SSH_PROTO_1|SSH_PROTO_2):
                   1834:                        return "2,1";
                   1835:                default:
                   1836:                        return "UNKNOWN";
                   1837:                }
1.221     djm      1838:        default:
                   1839:                switch (val) {
                   1840:                case 0:
                   1841:                        return "no";
                   1842:                case 1:
                   1843:                        return "yes";
                   1844:                default:
                   1845:                        return "UNKNOWN";
                   1846:                }
1.182     dtucker  1847:        }
                   1848: }
                   1849:
                   1850: static const char *
                   1851: lookup_opcode_name(ServerOpCodes code)
                   1852: {
                   1853:        u_int i;
                   1854:
                   1855:        for (i = 0; keywords[i].name != NULL; i++)
                   1856:                if (keywords[i].opcode == code)
                   1857:                        return(keywords[i].name);
                   1858:        return "UNKNOWN";
                   1859: }
                   1860:
                   1861: static void
                   1862: dump_cfg_int(ServerOpCodes code, int val)
                   1863: {
                   1864:        printf("%s %d\n", lookup_opcode_name(code), val);
                   1865: }
                   1866:
                   1867: static void
                   1868: dump_cfg_fmtint(ServerOpCodes code, int val)
                   1869: {
                   1870:        printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
                   1871: }
                   1872:
                   1873: static void
                   1874: dump_cfg_string(ServerOpCodes code, const char *val)
                   1875: {
                   1876:        if (val == NULL)
                   1877:                return;
                   1878:        printf("%s %s\n", lookup_opcode_name(code), val);
                   1879: }
                   1880:
                   1881: static void
                   1882: dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
                   1883: {
                   1884:        u_int i;
                   1885:
                   1886:        for (i = 0; i < count; i++)
1.219     djm      1887:                printf("%s %s\n", lookup_opcode_name(code), vals[i]);
                   1888: }
                   1889:
                   1890: static void
                   1891: dump_cfg_strarray_oneline(ServerOpCodes code, u_int count, char **vals)
                   1892: {
                   1893:        u_int i;
                   1894:
                   1895:        printf("%s", lookup_opcode_name(code));
                   1896:        for (i = 0; i < count; i++)
                   1897:                printf(" %s",  vals[i]);
                   1898:        printf("\n");
1.182     dtucker  1899: }
                   1900:
                   1901: void
                   1902: dump_config(ServerOptions *o)
                   1903: {
                   1904:        u_int i;
                   1905:        int ret;
                   1906:        struct addrinfo *ai;
                   1907:        char addr[NI_MAXHOST], port[NI_MAXSERV], *s = NULL;
                   1908:
                   1909:        /* these are usually at the top of the config */
                   1910:        for (i = 0; i < o->num_ports; i++)
                   1911:                printf("port %d\n", o->ports[i]);
                   1912:        dump_cfg_fmtint(sProtocol, o->protocol);
                   1913:        dump_cfg_fmtint(sAddressFamily, o->address_family);
                   1914:
                   1915:        /* ListenAddress must be after Port */
                   1916:        for (ai = o->listen_addrs; ai; ai = ai->ai_next) {
                   1917:                if ((ret = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
                   1918:                    sizeof(addr), port, sizeof(port),
                   1919:                    NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
                   1920:                        error("getnameinfo failed: %.100s",
                   1921:                            (ret != EAI_SYSTEM) ? gai_strerror(ret) :
                   1922:                            strerror(errno));
                   1923:                } else {
                   1924:                        if (ai->ai_family == AF_INET6)
                   1925:                                printf("listenaddress [%s]:%s\n", addr, port);
                   1926:                        else
                   1927:                                printf("listenaddress %s:%s\n", addr, port);
                   1928:                }
                   1929:        }
                   1930:
                   1931:        /* integer arguments */
                   1932:        dump_cfg_int(sServerKeyBits, o->server_key_bits);
                   1933:        dump_cfg_int(sLoginGraceTime, o->login_grace_time);
                   1934:        dump_cfg_int(sKeyRegenerationTime, o->key_regeneration_time);
                   1935:        dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
                   1936:        dump_cfg_int(sMaxAuthTries, o->max_authtries);
1.189     djm      1937:        dump_cfg_int(sMaxSessions, o->max_sessions);
1.182     dtucker  1938:        dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
                   1939:        dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
                   1940:
                   1941:        /* formatted integer arguments */
                   1942:        dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
                   1943:        dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
                   1944:        dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
                   1945:        dump_cfg_fmtint(sRhostsRSAAuthentication, o->rhosts_rsa_authentication);
                   1946:        dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
                   1947:        dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
                   1948:            o->hostbased_uses_name_from_packet_only);
                   1949:        dump_cfg_fmtint(sRSAAuthentication, o->rsa_authentication);
                   1950:        dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
1.187     djm      1951: #ifdef KRB5
1.182     dtucker  1952:        dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
                   1953:        dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
                   1954:        dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
                   1955:        dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
1.187     djm      1956: #endif
                   1957: #ifdef GSSAPI
1.182     dtucker  1958:        dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
                   1959:        dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
1.190     djm      1960: #endif
                   1961: #ifdef JPAKE
                   1962:        dump_cfg_fmtint(sZeroKnowledgePasswordAuthentication,
                   1963:            o->zero_knowledge_password_authentication);
1.187     djm      1964: #endif
1.182     dtucker  1965:        dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
                   1966:        dump_cfg_fmtint(sKbdInteractiveAuthentication,
                   1967:            o->kbd_interactive_authentication);
                   1968:        dump_cfg_fmtint(sChallengeResponseAuthentication,
                   1969:            o->challenge_response_authentication);
                   1970:        dump_cfg_fmtint(sPrintMotd, o->print_motd);
                   1971:        dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
                   1972:        dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
                   1973:        dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
1.244     djm      1974:        dump_cfg_fmtint(sPermitTTY, o->permit_tty);
1.182     dtucker  1975:        dump_cfg_fmtint(sStrictModes, o->strict_modes);
                   1976:        dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
                   1977:        dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
                   1978:        dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
                   1979:        dump_cfg_fmtint(sUseLogin, o->use_login);
                   1980:        dump_cfg_fmtint(sCompression, o->compression);
                   1981:        dump_cfg_fmtint(sGatewayPorts, o->gateway_ports);
                   1982:        dump_cfg_fmtint(sUseDNS, o->use_dns);
                   1983:        dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
                   1984:        dump_cfg_fmtint(sUsePrivilegeSeparation, use_privsep);
                   1985:
                   1986:        /* string arguments */
                   1987:        dump_cfg_string(sPidFile, o->pid_file);
                   1988:        dump_cfg_string(sXAuthLocation, o->xauth_location);
1.245     dtucker  1989:        dump_cfg_string(sCiphers, o->ciphers ? o->ciphers :
1.246     djm      1990:            cipher_alg_list(',', 0));
1.245     dtucker  1991:        dump_cfg_string(sMacs, o->macs ? o->macs : mac_alg_list(','));
1.182     dtucker  1992:        dump_cfg_string(sBanner, o->banner);
                   1993:        dump_cfg_string(sForceCommand, o->adm_forced_command);
1.201     dtucker  1994:        dump_cfg_string(sChrootDirectory, o->chroot_directory);
1.204     djm      1995:        dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
                   1996:        dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
1.208     djm      1997:        dump_cfg_string(sAuthorizedPrincipalsFile,
                   1998:            o->authorized_principals_file);
1.225     djm      1999:        dump_cfg_string(sVersionAddendum, o->version_addendum);
1.231     djm      2000:        dump_cfg_string(sAuthorizedKeysCommand, o->authorized_keys_command);
                   2001:        dump_cfg_string(sAuthorizedKeysCommandUser, o->authorized_keys_command_user);
1.240     markus   2002:        dump_cfg_string(sHostKeyAgent, o->host_key_agent);
1.245     dtucker  2003:        dump_cfg_string(sKexAlgorithms, o->kex_algorithms ? o->kex_algorithms :
                   2004:            kex_alg_list(','));
1.182     dtucker  2005:
                   2006:        /* string arguments requiring a lookup */
                   2007:        dump_cfg_string(sLogLevel, log_level_name(o->log_level));
                   2008:        dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
                   2009:
                   2010:        /* string array arguments */
1.219     djm      2011:        dump_cfg_strarray_oneline(sAuthorizedKeysFile, o->num_authkeys_files,
                   2012:            o->authorized_keys_files);
1.182     dtucker  2013:        dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
                   2014:             o->host_key_files);
1.203     djm      2015:        dump_cfg_strarray(sHostKeyFile, o->num_host_cert_files,
                   2016:             o->host_cert_files);
1.182     dtucker  2017:        dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
                   2018:        dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
                   2019:        dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
                   2020:        dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
                   2021:        dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
1.232     djm      2022:        dump_cfg_strarray_oneline(sAuthenticationMethods,
                   2023:            o->num_auth_methods, o->auth_methods);
1.182     dtucker  2024:
                   2025:        /* other arguments */
                   2026:        for (i = 0; i < o->num_subsystems; i++)
                   2027:                printf("subsystem %s %s\n", o->subsystem_name[i],
                   2028:                    o->subsystem_args[i]);
                   2029:
                   2030:        printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
                   2031:            o->max_startups_rate, o->max_startups);
                   2032:
                   2033:        for (i = 0; tunmode_desc[i].val != -1; i++)
                   2034:                if (tunmode_desc[i].val == o->permit_tun) {
                   2035:                        s = tunmode_desc[i].text;
                   2036:                        break;
                   2037:                }
                   2038:        dump_cfg_string(sPermitTunnel, s);
1.213     djm      2039:
1.214     stevesk  2040:        printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
                   2041:        printf("%s\n", iptos2str(o->ip_qos_bulk));
1.235     dtucker  2042:
1.241     djm      2043:        printf("rekeylimit %lld %d\n", (long long)o->rekey_limit,
                   2044:            o->rekey_interval);
1.182     dtucker  2045:
                   2046:        channel_print_adm_permitted_opens();
1.1       deraadt  2047: }