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