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