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