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