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