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