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