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

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