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