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