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