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