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