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