Annotation of src/usr.bin/ssh/servconf.c, Revision 1.346
1.226 dtucker 1:
1.346 ! djm 2: /* $OpenBSD: servconf.c,v 1.345 2019/01/19 21:31:32 djm Exp $ */
1.1 deraadt 3: /*
1.26 deraadt 4: * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
5: * All rights reserved
1.34 markus 6: *
1.51 deraadt 7: * As far as I am concerned, the code I have written for this software
8: * can be used freely for any purpose. Any derived versions of this
9: * software must be clearly marked as such, and if the derived work is
10: * incompatible with the protocol description in the RFC file, it must be
11: * called by a name other than "ssh" or "Secure Shell".
1.26 deraadt 12: */
1.1 deraadt 13:
1.152 stevesk 14: #include <sys/types.h>
15: #include <sys/socket.h>
1.179 djm 16: #include <sys/queue.h>
1.315 djm 17: #include <sys/sysctl.h>
1.154 stevesk 18:
1.213 djm 19: #include <netinet/in.h>
20: #include <netinet/ip.h>
1.315 djm 21: #include <net/route.h>
1.213 djm 22:
1.235 dtucker 23: #include <ctype.h>
1.154 stevesk 24: #include <netdb.h>
1.165 dtucker 25: #include <pwd.h>
1.162 stevesk 26: #include <stdio.h>
1.161 stevesk 27: #include <stdlib.h>
1.160 stevesk 28: #include <string.h>
1.164 deraadt 29: #include <signal.h>
1.155 stevesk 30: #include <unistd.h>
1.259 deraadt 31: #include <limits.h>
1.164 deraadt 32: #include <stdarg.h>
1.182 dtucker 33: #include <errno.h>
1.236 dtucker 34: #include <util.h>
1.1 deraadt 35:
1.164 deraadt 36: #include "xmalloc.h"
1.1 deraadt 37: #include "ssh.h"
1.62 markus 38: #include "log.h"
1.338 markus 39: #include "sshbuf.h"
1.251 millert 40: #include "misc.h"
1.1 deraadt 41: #include "servconf.h"
1.33 markus 42: #include "compat.h"
1.60 markus 43: #include "pathnames.h"
1.62 markus 44: #include "cipher.h"
1.339 markus 45: #include "sshkey.h"
1.66 markus 46: #include "kex.h"
47: #include "mac.h"
1.153 dtucker 48: #include "match.h"
1.156 dtucker 49: #include "channels.h"
1.165 dtucker 50: #include "groupaccess.h"
1.226 dtucker 51: #include "canohost.h"
52: #include "packet.h"
1.338 markus 53: #include "ssherr.h"
1.232 djm 54: #include "hostfile.h"
55: #include "auth.h"
1.252 djm 56: #include "myproposal.h"
1.256 djm 57: #include "digest.h"
1.345 djm 58:
1.315 djm 59: static void add_listen_addr(ServerOptions *, const char *,
60: const char *, int);
61: static void add_one_listen_addr(ServerOptions *, const char *,
62: const char *, int);
1.29 markus 63:
1.102 provos 64: /* Use of privilege separation or not */
65: extern int use_privsep;
1.338 markus 66: extern struct sshbuf *cfg;
1.62 markus 67:
1.1 deraadt 68: /* Initializes the server options to their default values. */
69:
1.34 markus 70: void
1.25 markus 71: initialize_server_options(ServerOptions *options)
1.1 deraadt 72: {
1.25 markus 73: memset(options, 0, sizeof(*options));
1.29 markus 74: options->num_ports = 0;
75: options->ports_from_cmdline = 0;
1.266 dtucker 76: options->queued_listen_addrs = NULL;
77: options->num_queued_listens = 0;
1.29 markus 78: options->listen_addrs = NULL;
1.315 djm 79: options->num_listen_addrs = 0;
1.138 djm 80: options->address_family = -1;
1.316 djm 81: options->routing_domain = NULL;
1.54 markus 82: options->num_host_key_files = 0;
1.203 djm 83: options->num_host_cert_files = 0;
1.240 markus 84: options->host_key_agent = NULL;
1.36 markus 85: options->pid_file = NULL;
1.25 markus 86: options->login_grace_time = -1;
1.279 chris 87: options->permit_root_login = PERMIT_NOT_SET;
1.25 markus 88: options->ignore_rhosts = -1;
89: options->ignore_user_known_hosts = -1;
90: options->print_motd = -1;
1.72 stevesk 91: options->print_lastlog = -1;
1.25 markus 92: options->x11_forwarding = -1;
93: options->x11_display_offset = -1;
1.99 stevesk 94: options->x11_use_localhost = -1;
1.244 djm 95: options->permit_tty = -1;
1.250 djm 96: options->permit_user_rc = -1;
1.42 markus 97: options->xauth_location = NULL;
1.25 markus 98: options->strict_modes = -1;
1.129 markus 99: options->tcp_keep_alive = -1;
1.101 markus 100: options->log_facility = SYSLOG_FACILITY_NOT_SET;
101: options->log_level = SYSLOG_LEVEL_NOT_SET;
1.75 markus 102: options->hostbased_authentication = -1;
103: options->hostbased_uses_name_from_packet_only = -1;
1.258 djm 104: options->hostbased_key_types = NULL;
1.276 markus 105: options->hostkeyalgorithms = NULL;
1.54 markus 106: options->pubkey_authentication = -1;
1.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: }
443:
1.1 deraadt 444: }
445:
446: /* Keyword tokens. */
1.25 markus 447: typedef enum {
448: sBadOption, /* == unknown option */
1.293 naddy 449: sPort, sHostKeyFile, sLoginGraceTime,
450: sPermitRootLogin, sLogFacility, sLogLevel,
1.25 markus 451: sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup,
1.323 dtucker 452: sKerberosGetAFSToken, sChallengeResponseAuthentication,
1.138 djm 453: sPasswordAuthentication, sKbdInteractiveAuthentication,
454: sListenAddress, sAddressFamily,
1.72 stevesk 455: sPrintMotd, sPrintLastLog, sIgnoreRhosts,
1.99 stevesk 456: sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost,
1.244 djm 457: sPermitTTY, sStrictModes, sEmptyPasswd, sTCPKeepAlive,
1.294 djm 458: sPermitUserEnvironment, sAllowTcpForwarding, sCompression,
1.235 dtucker 459: sRekeyLimit, sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
1.293 naddy 460: sIgnoreUserKnownHosts, sCiphers, sMacs, sPidFile,
1.258 djm 461: sGatewayPorts, sPubkeyAuthentication, sPubkeyAcceptedKeyTypes,
462: sXAuthLocation, sSubsystem, sMaxStartups, sMaxAuthTries, sMaxSessions,
1.122 markus 463: sBanner, sUseDNS, sHostbasedAuthentication,
1.258 djm 464: sHostbasedUsesNameFromPacketOnly, sHostbasedAcceptedKeyTypes,
1.276 markus 465: sHostKeyAlgorithms,
1.258 djm 466: sClientAliveInterval, sClientAliveCountMax, sAuthorizedKeysFile,
1.271 djm 467: sGssAuthentication, sGssCleanupCreds, sGssStrictAcceptor,
1.332 djm 468: sAcceptEnv, sSetEnv, sPermitTunnel,
1.330 djm 469: sMatch, sPermitOpen, sPermitListen, sForceCommand, sChrootDirectory,
1.200 dtucker 470: sUsePrivilegeSeparation, sAllowAgentForwarding,
1.249 djm 471: sHostCertificate,
1.208 djm 472: sRevokedKeys, sTrustedUserCAKeys, sAuthorizedPrincipalsFile,
1.270 djm 473: sAuthorizedPrincipalsCommand, sAuthorizedPrincipalsCommandUser,
1.341 djm 474: sKexAlgorithms, sCASignatureAlgorithms, sIPQoS, sVersionAddendum,
1.231 djm 475: sAuthorizedKeysCommand, sAuthorizedKeysCommandUser,
1.250 djm 476: sAuthenticationMethods, sHostKeyAgent, sPermitUserRC,
1.251 millert 477: sStreamLocalBindMask, sStreamLocalBindUnlink,
1.301 djm 478: sAllowStreamLocalForwarding, sFingerprintHash, sDisableForwarding,
1.316 djm 479: sExposeAuthInfo, sRDomain,
1.295 djm 480: sDeprecated, sIgnore, sUnsupported
1.1 deraadt 481: } ServerOpCodes;
482:
1.153 dtucker 483: #define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */
484: #define SSHCFG_MATCH 0x02 /* allowed inside a Match section */
485: #define SSHCFG_ALL (SSHCFG_GLOBAL|SSHCFG_MATCH)
486:
1.1 deraadt 487: /* Textual representation of the tokens. */
1.25 markus 488: static struct {
489: const char *name;
490: ServerOpCodes opcode;
1.153 dtucker 491: u_int flags;
1.25 markus 492: } keywords[] = {
1.153 dtucker 493: { "port", sPort, SSHCFG_GLOBAL },
494: { "hostkey", sHostKeyFile, SSHCFG_GLOBAL },
495: { "hostdsakey", sHostKeyFile, SSHCFG_GLOBAL }, /* alias */
1.240 markus 496: { "hostkeyagent", sHostKeyAgent, SSHCFG_GLOBAL },
1.153 dtucker 497: { "pidfile", sPidFile, SSHCFG_GLOBAL },
1.293 naddy 498: { "serverkeybits", sDeprecated, SSHCFG_GLOBAL },
1.153 dtucker 499: { "logingracetime", sLoginGraceTime, SSHCFG_GLOBAL },
1.293 naddy 500: { "keyregenerationinterval", sDeprecated, SSHCFG_GLOBAL },
1.175 dtucker 501: { "permitrootlogin", sPermitRootLogin, SSHCFG_ALL },
1.153 dtucker 502: { "syslogfacility", sLogFacility, SSHCFG_GLOBAL },
1.308 djm 503: { "loglevel", sLogLevel, SSHCFG_ALL },
1.153 dtucker 504: { "rhostsauthentication", sDeprecated, SSHCFG_GLOBAL },
1.293 naddy 505: { "rhostsrsaauthentication", sDeprecated, SSHCFG_ALL },
1.168 dtucker 506: { "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_ALL },
1.209 djm 507: { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly, SSHCFG_ALL },
1.258 djm 508: { "hostbasedacceptedkeytypes", sHostbasedAcceptedKeyTypes, SSHCFG_ALL },
1.276 markus 509: { "hostkeyalgorithms", sHostKeyAlgorithms, SSHCFG_GLOBAL },
1.293 naddy 510: { "rsaauthentication", sDeprecated, SSHCFG_ALL },
1.168 dtucker 511: { "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_ALL },
1.258 djm 512: { "pubkeyacceptedkeytypes", sPubkeyAcceptedKeyTypes, SSHCFG_ALL },
1.153 dtucker 513: { "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL }, /* alias */
1.123 markus 514: #ifdef KRB5
1.168 dtucker 515: { "kerberosauthentication", sKerberosAuthentication, SSHCFG_ALL },
1.153 dtucker 516: { "kerberosorlocalpasswd", sKerberosOrLocalPasswd, SSHCFG_GLOBAL },
517: { "kerberosticketcleanup", sKerberosTicketCleanup, SSHCFG_GLOBAL },
518: { "kerberosgetafstoken", sKerberosGetAFSToken, SSHCFG_GLOBAL },
1.121 jakob 519: #else
1.168 dtucker 520: { "kerberosauthentication", sUnsupported, SSHCFG_ALL },
1.153 dtucker 521: { "kerberosorlocalpasswd", sUnsupported, SSHCFG_GLOBAL },
522: { "kerberosticketcleanup", sUnsupported, SSHCFG_GLOBAL },
523: { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL },
1.126 markus 524: #endif
1.153 dtucker 525: { "kerberostgtpassing", sUnsupported, SSHCFG_GLOBAL },
526: { "afstokenpassing", sUnsupported, SSHCFG_GLOBAL },
1.125 markus 527: #ifdef GSSAPI
1.168 dtucker 528: { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
1.153 dtucker 529: { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
1.271 djm 530: { "gssapistrictacceptorcheck", sGssStrictAcceptor, SSHCFG_GLOBAL },
1.125 markus 531: #else
1.168 dtucker 532: { "gssapiauthentication", sUnsupported, SSHCFG_ALL },
1.153 dtucker 533: { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
1.271 djm 534: { "gssapistrictacceptorcheck", sUnsupported, SSHCFG_GLOBAL },
1.125 markus 535: #endif
1.168 dtucker 536: { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
537: { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
1.170 dtucker 538: { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL },
1.153 dtucker 539: { "skeyauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, /* alias */
540: { "checkmail", sDeprecated, SSHCFG_GLOBAL },
541: { "listenaddress", sListenAddress, SSHCFG_GLOBAL },
542: { "addressfamily", sAddressFamily, SSHCFG_GLOBAL },
543: { "printmotd", sPrintMotd, SSHCFG_GLOBAL },
544: { "printlastlog", sPrintLastLog, SSHCFG_GLOBAL },
545: { "ignorerhosts", sIgnoreRhosts, SSHCFG_GLOBAL },
546: { "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL },
1.157 dtucker 547: { "x11forwarding", sX11Forwarding, SSHCFG_ALL },
548: { "x11displayoffset", sX11DisplayOffset, SSHCFG_ALL },
549: { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL },
1.153 dtucker 550: { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL },
551: { "strictmodes", sStrictModes, SSHCFG_GLOBAL },
1.188 djm 552: { "permitemptypasswords", sEmptyPasswd, SSHCFG_ALL },
1.153 dtucker 553: { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL },
1.294 djm 554: { "uselogin", sDeprecated, SSHCFG_GLOBAL },
1.153 dtucker 555: { "compression", sCompression, SSHCFG_GLOBAL },
1.235 dtucker 556: { "rekeylimit", sRekeyLimit, SSHCFG_ALL },
1.153 dtucker 557: { "tcpkeepalive", sTCPKeepAlive, SSHCFG_GLOBAL },
558: { "keepalive", sTCPKeepAlive, SSHCFG_GLOBAL }, /* obsolete alias */
559: { "allowtcpforwarding", sAllowTcpForwarding, SSHCFG_ALL },
1.178 pyr 560: { "allowagentforwarding", sAllowAgentForwarding, SSHCFG_ALL },
1.227 markus 561: { "allowusers", sAllowUsers, SSHCFG_ALL },
562: { "denyusers", sDenyUsers, SSHCFG_ALL },
563: { "allowgroups", sAllowGroups, SSHCFG_ALL },
564: { "denygroups", sDenyGroups, SSHCFG_ALL },
1.153 dtucker 565: { "ciphers", sCiphers, SSHCFG_GLOBAL },
566: { "macs", sMacs, SSHCFG_GLOBAL },
1.295 djm 567: { "protocol", sIgnore, SSHCFG_GLOBAL },
1.153 dtucker 568: { "gatewayports", sGatewayPorts, SSHCFG_ALL },
569: { "subsystem", sSubsystem, SSHCFG_GLOBAL },
570: { "maxstartups", sMaxStartups, SSHCFG_GLOBAL },
1.184 dtucker 571: { "maxauthtries", sMaxAuthTries, SSHCFG_ALL },
1.180 djm 572: { "maxsessions", sMaxSessions, SSHCFG_ALL },
1.168 dtucker 573: { "banner", sBanner, SSHCFG_ALL },
1.153 dtucker 574: { "usedns", sUseDNS, SSHCFG_GLOBAL },
575: { "verifyreversemapping", sDeprecated, SSHCFG_GLOBAL },
576: { "reversemappingcheck", sDeprecated, SSHCFG_GLOBAL },
1.300 markus 577: { "clientaliveinterval", sClientAliveInterval, SSHCFG_ALL },
578: { "clientalivecountmax", sClientAliveCountMax, SSHCFG_ALL },
1.209 djm 579: { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_ALL },
1.219 djm 580: { "authorizedkeysfile2", sDeprecated, SSHCFG_ALL },
1.306 djm 581: { "useprivilegeseparation", sDeprecated, SSHCFG_GLOBAL},
1.227 markus 582: { "acceptenv", sAcceptEnv, SSHCFG_ALL },
1.332 djm 583: { "setenv", sSetEnv, SSHCFG_ALL },
1.209 djm 584: { "permittunnel", sPermitTunnel, SSHCFG_ALL },
1.244 djm 585: { "permittty", sPermitTTY, SSHCFG_ALL },
1.250 djm 586: { "permituserrc", sPermitUserRC, SSHCFG_ALL },
1.153 dtucker 587: { "match", sMatch, SSHCFG_ALL },
1.156 dtucker 588: { "permitopen", sPermitOpen, SSHCFG_ALL },
1.330 djm 589: { "permitlisten", sPermitListen, SSHCFG_ALL },
1.158 dtucker 590: { "forcecommand", sForceCommand, SSHCFG_ALL },
1.176 djm 591: { "chrootdirectory", sChrootDirectory, SSHCFG_ALL },
1.203 djm 592: { "hostcertificate", sHostCertificate, SSHCFG_GLOBAL },
1.204 djm 593: { "revokedkeys", sRevokedKeys, SSHCFG_ALL },
594: { "trustedusercakeys", sTrustedUserCAKeys, SSHCFG_ALL },
1.209 djm 595: { "authorizedprincipalsfile", sAuthorizedPrincipalsFile, SSHCFG_ALL },
1.211 djm 596: { "kexalgorithms", sKexAlgorithms, SSHCFG_GLOBAL },
1.213 djm 597: { "ipqos", sIPQoS, SSHCFG_ALL },
1.231 djm 598: { "authorizedkeyscommand", sAuthorizedKeysCommand, SSHCFG_ALL },
599: { "authorizedkeyscommanduser", sAuthorizedKeysCommandUser, SSHCFG_ALL },
1.270 djm 600: { "authorizedprincipalscommand", sAuthorizedPrincipalsCommand, SSHCFG_ALL },
601: { "authorizedprincipalscommanduser", sAuthorizedPrincipalsCommandUser, SSHCFG_ALL },
1.225 djm 602: { "versionaddendum", sVersionAddendum, SSHCFG_GLOBAL },
1.232 djm 603: { "authenticationmethods", sAuthenticationMethods, SSHCFG_ALL },
1.251 millert 604: { "streamlocalbindmask", sStreamLocalBindMask, SSHCFG_ALL },
605: { "streamlocalbindunlink", sStreamLocalBindUnlink, SSHCFG_ALL },
606: { "allowstreamlocalforwarding", sAllowStreamLocalForwarding, SSHCFG_ALL },
1.256 djm 607: { "fingerprinthash", sFingerprintHash, SSHCFG_GLOBAL },
1.301 djm 608: { "disableforwarding", sDisableForwarding, SSHCFG_ALL },
1.309 djm 609: { "exposeauthinfo", sExposeAuthInfo, SSHCFG_ALL },
1.316 djm 610: { "rdomain", sRDomain, SSHCFG_ALL },
1.342 djm 611: { "casignaturealgorithms", sCASignatureAlgorithms, SSHCFG_ALL },
1.153 dtucker 612: { NULL, sBadOption, 0 }
1.1 deraadt 613: };
614:
1.182 dtucker 615: static struct {
616: int val;
617: char *text;
618: } tunmode_desc[] = {
619: { SSH_TUNMODE_NO, "no" },
620: { SSH_TUNMODE_POINTOPOINT, "point-to-point" },
621: { SSH_TUNMODE_ETHERNET, "ethernet" },
622: { SSH_TUNMODE_YES, "yes" },
623: { -1, NULL }
624: };
625:
1.329 djm 626: /* Returns an opcode name from its number */
627:
628: static const char *
629: lookup_opcode_name(ServerOpCodes code)
630: {
631: u_int i;
632:
633: for (i = 0; keywords[i].name != NULL; i++)
634: if (keywords[i].opcode == code)
635: return(keywords[i].name);
636: return "UNKNOWN";
637: }
638:
639:
1.27 markus 640: /*
1.73 stevesk 641: * Returns the number of the token pointed to by cp or sBadOption.
1.27 markus 642: */
1.1 deraadt 643:
1.34 markus 644: static ServerOpCodes
1.25 markus 645: parse_token(const char *cp, const char *filename,
1.153 dtucker 646: int linenum, u_int *flags)
1.1 deraadt 647: {
1.55 markus 648: u_int i;
1.1 deraadt 649:
1.25 markus 650: for (i = 0; keywords[i].name; i++)
1.153 dtucker 651: if (strcasecmp(cp, keywords[i].name) == 0) {
652: *flags = keywords[i].flags;
1.25 markus 653: return keywords[i].opcode;
1.153 dtucker 654: }
1.25 markus 655:
1.78 stevesk 656: error("%s: line %d: Bad configuration option: %s",
657: filename, linenum, cp);
1.25 markus 658: return sBadOption;
1.1 deraadt 659: }
660:
1.202 djm 661: char *
662: derelativise_path(const char *path)
663: {
1.259 deraadt 664: char *expanded, *ret, cwd[PATH_MAX];
1.202 djm 665:
1.257 djm 666: if (strcasecmp(path, "none") == 0)
667: return xstrdup("none");
1.202 djm 668: expanded = tilde_expand_filename(path, getuid());
1.343 djm 669: if (path_absolute(expanded))
1.202 djm 670: return expanded;
1.207 djm 671: if (getcwd(cwd, sizeof(cwd)) == NULL)
1.202 djm 672: fatal("%s: getcwd: %s", __func__, strerror(errno));
673: xasprintf(&ret, "%s/%s", cwd, expanded);
1.239 djm 674: free(expanded);
1.202 djm 675: return ret;
676: }
677:
1.84 itojun 678: static void
1.315 djm 679: add_listen_addr(ServerOptions *options, const char *addr,
680: const char *rdomain, int port)
1.74 stevesk 681: {
1.142 djm 682: u_int i;
1.74 stevesk 683:
1.315 djm 684: if (port > 0)
685: add_one_listen_addr(options, addr, rdomain, port);
686: else {
687: for (i = 0; i < options->num_ports; i++) {
688: add_one_listen_addr(options, addr, rdomain,
689: options->ports[i]);
690: }
691: }
1.74 stevesk 692: }
693:
1.84 itojun 694: static void
1.315 djm 695: add_one_listen_addr(ServerOptions *options, const char *addr,
696: const char *rdomain, int port)
1.29 markus 697: {
698: struct addrinfo hints, *ai, *aitop;
699: char strport[NI_MAXSERV];
700: int gaierr;
1.315 djm 701: u_int i;
702:
703: /* Find listen_addrs entry for this rdomain */
704: for (i = 0; i < options->num_listen_addrs; i++) {
705: if (rdomain == NULL && options->listen_addrs[i].rdomain == NULL)
706: break;
707: if (rdomain == NULL || options->listen_addrs[i].rdomain == NULL)
708: continue;
709: if (strcmp(rdomain, options->listen_addrs[i].rdomain) == 0)
710: break;
711: }
712: if (i >= options->num_listen_addrs) {
713: /* No entry for this rdomain; allocate one */
714: if (i >= INT_MAX)
715: fatal("%s: too many listen addresses", __func__);
716: options->listen_addrs = xrecallocarray(options->listen_addrs,
717: options->num_listen_addrs, options->num_listen_addrs + 1,
718: sizeof(*options->listen_addrs));
719: i = options->num_listen_addrs++;
720: if (rdomain != NULL)
721: options->listen_addrs[i].rdomain = xstrdup(rdomain);
722: }
723: /* options->listen_addrs[i] points to the addresses for this rdomain */
1.29 markus 724:
1.74 stevesk 725: memset(&hints, 0, sizeof(hints));
1.138 djm 726: hints.ai_family = options->address_family;
1.74 stevesk 727: hints.ai_socktype = SOCK_STREAM;
728: hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0;
1.194 djm 729: snprintf(strport, sizeof strport, "%d", port);
1.74 stevesk 730: if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0)
731: fatal("bad addr or host: %s (%s)",
732: addr ? addr : "<NULL>",
1.173 dtucker 733: ssh_gai_strerror(gaierr));
1.74 stevesk 734: for (ai = aitop; ai->ai_next; ai = ai->ai_next)
735: ;
1.315 djm 736: ai->ai_next = options->listen_addrs[i].addrs;
737: options->listen_addrs[i].addrs = aitop;
738: }
739:
740: /* Returns nonzero if the routing domain name is valid */
741: static int
742: valid_rdomain(const char *name)
743: {
744: const char *errstr;
745: long long num;
746: struct rt_tableinfo info;
747: int mib[6];
748: size_t miblen = sizeof(mib);
749:
750: if (name == NULL)
751: return 1;
752:
753: num = strtonum(name, 0, 255, &errstr);
754: if (errstr != NULL)
755: return 0;
756:
757: /* Check whether the table actually exists */
758: memset(mib, 0, sizeof(mib));
759: mib[0] = CTL_NET;
760: mib[1] = PF_ROUTE;
761: mib[4] = NET_RT_TABLE;
762: mib[5] = (int)num;
763: if (sysctl(mib, 6, &info, &miblen, NULL, 0) == -1)
764: return 0;
765:
766: return 1;
1.29 markus 767: }
768:
1.266 dtucker 769: /*
770: * Queue a ListenAddress to be processed once we have all of the Ports
771: * and AddressFamily options.
772: */
773: static void
1.315 djm 774: queue_listen_addr(ServerOptions *options, const char *addr,
775: const char *rdomain, int port)
1.266 dtucker 776: {
1.315 djm 777: struct queued_listenaddr *qla;
778:
779: options->queued_listen_addrs = xrecallocarray(
780: options->queued_listen_addrs,
781: options->num_queued_listens, options->num_queued_listens + 1,
782: sizeof(*options->queued_listen_addrs));
783: qla = &options->queued_listen_addrs[options->num_queued_listens++];
784: qla->addr = xstrdup(addr);
785: qla->port = port;
786: qla->rdomain = rdomain == NULL ? NULL : xstrdup(rdomain);
1.266 dtucker 787: }
788:
789: /*
790: * Process queued (text) ListenAddress entries.
791: */
792: static void
793: process_queued_listen_addrs(ServerOptions *options)
794: {
795: u_int i;
1.315 djm 796: struct queued_listenaddr *qla;
1.266 dtucker 797:
798: if (options->num_ports == 0)
799: options->ports[options->num_ports++] = SSH_DEFAULT_PORT;
800: if (options->address_family == -1)
801: options->address_family = AF_UNSPEC;
802:
803: for (i = 0; i < options->num_queued_listens; i++) {
1.315 djm 804: qla = &options->queued_listen_addrs[i];
805: add_listen_addr(options, qla->addr, qla->rdomain, qla->port);
806: free(qla->addr);
807: free(qla->rdomain);
1.266 dtucker 808: }
809: free(options->queued_listen_addrs);
810: options->queued_listen_addrs = NULL;
811: options->num_queued_listens = 0;
812: }
813:
1.310 djm 814: /*
1.329 djm 815: * Inform channels layer of permitopen options for a single forwarding
816: * direction (local/remote).
1.310 djm 817: */
1.329 djm 818: static void
819: process_permitopen_list(struct ssh *ssh, ServerOpCodes opcode,
820: char **opens, u_int num_opens)
1.310 djm 821: {
822: u_int i;
823: int port;
824: char *host, *arg, *oarg;
1.329 djm 825: int where = opcode == sPermitOpen ? FORWARD_LOCAL : FORWARD_REMOTE;
826: const char *what = lookup_opcode_name(opcode);
1.310 djm 827:
1.329 djm 828: channel_clear_permission(ssh, FORWARD_ADM, where);
829: if (num_opens == 0)
1.310 djm 830: return; /* permit any */
831:
832: /* handle keywords: "any" / "none" */
1.329 djm 833: if (num_opens == 1 && strcmp(opens[0], "any") == 0)
1.310 djm 834: return;
1.329 djm 835: if (num_opens == 1 && strcmp(opens[0], "none") == 0) {
836: channel_disable_admin(ssh, where);
1.310 djm 837: return;
838: }
839: /* Otherwise treat it as a list of permitted host:port */
1.329 djm 840: for (i = 0; i < num_opens; i++) {
841: oarg = arg = xstrdup(opens[i]);
1.310 djm 842: host = hpdelim(&arg);
843: if (host == NULL)
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.269 djm 994: if (match_pattern_list(ci->user, arg, 0) != 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.329 djm 1160: char *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 {
1254: p = hpdelim(&arg);
1255: if (p == NULL)
1256: fatal("%s line %d: bad address:port usage",
1257: filename, linenum);
1258: p = cleanhostname(p);
1259: if (arg == NULL)
1260: port = 0;
1261: else if ((port = a2port(arg)) <= 0)
1262: fatal("%s line %d: bad port number",
1263: filename, linenum);
1264: }
1265: /* Optional routing table */
1266: arg2 = NULL;
1267: if ((arg = strdelim(&cp)) != NULL) {
1268: if (strcmp(arg, "rdomain") != 0 ||
1269: (arg2 = strdelim(&cp)) == NULL)
1270: fatal("%s line %d: bad ListenAddress syntax",
1271: filename, linenum);
1272: if (!valid_rdomain(arg2))
1273: fatal("%s line %d: bad routing domain",
1274: filename, linenum);
1.144 dtucker 1275: }
1.139 djm 1276:
1.315 djm 1277: queue_listen_addr(options, p, arg2, port);
1.25 markus 1278:
1.138 djm 1279: break;
1280:
1281: case sAddressFamily:
1.220 djm 1282: intptr = &options->address_family;
1283: multistate_ptr = multistate_addressfamily;
1284: parse_multistate:
1.138 djm 1285: arg = strdelim(&cp);
1.141 markus 1286: if (!arg || *arg == '\0')
1.220 djm 1287: fatal("%s line %d: missing argument.",
1.141 markus 1288: filename, linenum);
1.220 djm 1289: value = -1;
1290: for (i = 0; multistate_ptr[i].key != NULL; i++) {
1291: if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
1292: value = multistate_ptr[i].value;
1293: break;
1294: }
1295: }
1296: if (value == -1)
1297: fatal("%s line %d: unsupported option \"%s\".",
1.138 djm 1298: filename, linenum, arg);
1.220 djm 1299: if (*activep && *intptr == -1)
1.138 djm 1300: *intptr = value;
1.94 markus 1301: break;
1302:
1303: case sHostKeyFile:
1304: arg = strdelim(&cp);
1305: if (!arg || *arg == '\0')
1306: fatal("%s line %d: missing file name.",
1307: filename, linenum);
1.344 djm 1308: if (*activep) {
1309: servconf_add_hostkey(filename, linenum,
1310: options, arg, 1);
1311: }
1.94 markus 1312: break;
1.76 stevesk 1313:
1.240 markus 1314: case sHostKeyAgent:
1315: charptr = &options->host_key_agent;
1316: arg = strdelim(&cp);
1317: if (!arg || *arg == '\0')
1318: fatal("%s line %d: missing socket name.",
1319: filename, linenum);
1320: if (*activep && *charptr == NULL)
1321: *charptr = !strcmp(arg, SSH_AUTHSOCKET_ENV_NAME) ?
1322: xstrdup(arg) : derelativise_path(arg);
1323: break;
1324:
1.203 djm 1325: case sHostCertificate:
1.314 djm 1326: arg = strdelim(&cp);
1327: if (!arg || *arg == '\0')
1328: fatal("%s line %d: missing file name.",
1329: filename, linenum);
1330: if (*activep)
1331: servconf_add_hostcert(filename, linenum, options, arg);
1332: break;
1.203 djm 1333:
1.94 markus 1334: case sPidFile:
1335: charptr = &options->pid_file;
1.314 djm 1336: parse_filename:
1337: arg = strdelim(&cp);
1338: if (!arg || *arg == '\0')
1339: fatal("%s line %d: missing file name.",
1340: filename, linenum);
1341: if (*activep && *charptr == NULL) {
1342: *charptr = derelativise_path(arg);
1343: /* increase optional counter */
1344: if (intptr != NULL)
1345: *intptr = *intptr + 1;
1346: }
1347: break;
1.25 markus 1348:
1.94 markus 1349: case sPermitRootLogin:
1350: intptr = &options->permit_root_login;
1.220 djm 1351: multistate_ptr = multistate_permitrootlogin;
1352: goto parse_multistate;
1.36 markus 1353:
1.94 markus 1354: case sIgnoreRhosts:
1355: intptr = &options->ignore_rhosts;
1.180 djm 1356: parse_flag:
1.320 djm 1357: multistate_ptr = multistate_flag;
1358: goto parse_multistate;
1.94 markus 1359:
1360: case sIgnoreUserKnownHosts:
1361: intptr = &options->ignore_user_known_hosts;
1362: goto parse_flag;
1363:
1364: case sHostbasedAuthentication:
1365: intptr = &options->hostbased_authentication;
1366: goto parse_flag;
1367:
1368: case sHostbasedUsesNameFromPacketOnly:
1369: intptr = &options->hostbased_uses_name_from_packet_only;
1370: goto parse_flag;
1371:
1.258 djm 1372: case sHostbasedAcceptedKeyTypes:
1373: charptr = &options->hostbased_key_types;
1374: parse_keytypes:
1375: arg = strdelim(&cp);
1376: if (!arg || *arg == '\0')
1377: fatal("%s line %d: Missing argument.",
1378: filename, linenum);
1.304 djm 1379: if (*arg != '-' &&
1380: !sshkey_names_valid2(*arg == '+' ? arg + 1 : arg, 1))
1.258 djm 1381: fatal("%s line %d: Bad key types '%s'.",
1382: filename, linenum, arg ? arg : "<NONE>");
1383: if (*activep && *charptr == NULL)
1384: *charptr = xstrdup(arg);
1385: break;
1386:
1.276 markus 1387: case sHostKeyAlgorithms:
1388: charptr = &options->hostkeyalgorithms;
1389: goto parse_keytypes;
1390:
1.341 djm 1391: case sCASignatureAlgorithms:
1392: charptr = &options->ca_sign_algorithms;
1393: goto parse_keytypes;
1394:
1.94 markus 1395: case sPubkeyAuthentication:
1396: intptr = &options->pubkey_authentication;
1397: goto parse_flag;
1.119 jakob 1398:
1.258 djm 1399: case sPubkeyAcceptedKeyTypes:
1400: charptr = &options->pubkey_key_types;
1401: goto parse_keytypes;
1402:
1.94 markus 1403: case sKerberosAuthentication:
1404: intptr = &options->kerberos_authentication;
1405: goto parse_flag;
1406:
1407: case sKerberosOrLocalPasswd:
1408: intptr = &options->kerberos_or_local_passwd;
1409: goto parse_flag;
1410:
1411: case sKerberosTicketCleanup:
1412: intptr = &options->kerberos_ticket_cleanup;
1.130 jakob 1413: goto parse_flag;
1414:
1415: case sKerberosGetAFSToken:
1416: intptr = &options->kerberos_get_afs_token;
1.125 markus 1417: goto parse_flag;
1418:
1419: case sGssAuthentication:
1420: intptr = &options->gss_authentication;
1421: goto parse_flag;
1422:
1423: case sGssCleanupCreds:
1424: intptr = &options->gss_cleanup_creds;
1.271 djm 1425: goto parse_flag;
1426:
1427: case sGssStrictAcceptor:
1428: intptr = &options->gss_strict_acceptor;
1.94 markus 1429: goto parse_flag;
1430:
1431: case sPasswordAuthentication:
1432: intptr = &options->password_authentication;
1433: goto parse_flag;
1434:
1435: case sKbdInteractiveAuthentication:
1436: intptr = &options->kbd_interactive_authentication;
1437: goto parse_flag;
1438:
1439: case sChallengeResponseAuthentication:
1440: intptr = &options->challenge_response_authentication;
1441: goto parse_flag;
1442:
1443: case sPrintMotd:
1444: intptr = &options->print_motd;
1445: goto parse_flag;
1446:
1447: case sPrintLastLog:
1448: intptr = &options->print_lastlog;
1449: goto parse_flag;
1450:
1451: case sX11Forwarding:
1452: intptr = &options->x11_forwarding;
1453: goto parse_flag;
1454:
1455: case sX11DisplayOffset:
1456: intptr = &options->x11_display_offset;
1.293 naddy 1457: parse_int:
1458: arg = strdelim(&cp);
1.322 dtucker 1459: if ((errstr = atoi_err(arg, &value)) != NULL)
1460: fatal("%s line %d: integer value %s.",
1461: filename, linenum, errstr);
1.293 naddy 1462: if (*activep && *intptr == -1)
1463: *intptr = value;
1464: break;
1.99 stevesk 1465:
1466: case sX11UseLocalhost:
1467: intptr = &options->x11_use_localhost;
1468: goto parse_flag;
1.94 markus 1469:
1470: case sXAuthLocation:
1471: charptr = &options->xauth_location;
1472: goto parse_filename;
1473:
1.244 djm 1474: case sPermitTTY:
1475: intptr = &options->permit_tty;
1476: goto parse_flag;
1477:
1.250 djm 1478: case sPermitUserRC:
1479: intptr = &options->permit_user_rc;
1480: goto parse_flag;
1481:
1.94 markus 1482: case sStrictModes:
1483: intptr = &options->strict_modes;
1484: goto parse_flag;
1485:
1.129 markus 1486: case sTCPKeepAlive:
1487: intptr = &options->tcp_keep_alive;
1.94 markus 1488: goto parse_flag;
1489:
1490: case sEmptyPasswd:
1491: intptr = &options->permit_empty_passwd;
1.113 markus 1492: goto parse_flag;
1493:
1494: case sPermitUserEnvironment:
1495: intptr = &options->permit_user_env;
1.334 djm 1496: charptr = &options->permit_user_env_whitelist;
1497: arg = strdelim(&cp);
1498: if (!arg || *arg == '\0')
1499: fatal("%s line %d: missing argument.",
1500: filename, linenum);
1501: value = 0;
1502: p = NULL;
1503: if (strcmp(arg, "yes") == 0)
1504: value = 1;
1505: else if (strcmp(arg, "no") == 0)
1506: value = 0;
1507: else {
1508: /* Pattern-list specified */
1509: value = 1;
1510: p = xstrdup(arg);
1511: }
1512: if (*activep && *intptr == -1) {
1513: *intptr = value;
1514: *charptr = p;
1515: p = NULL;
1516: }
1517: free(p);
1518: break;
1.94 markus 1519:
1.111 markus 1520: case sCompression:
1521: intptr = &options->compression;
1.220 djm 1522: multistate_ptr = multistate_compression;
1523: goto parse_multistate;
1.94 markus 1524:
1.235 dtucker 1525: case sRekeyLimit:
1526: arg = strdelim(&cp);
1527: if (!arg || *arg == '\0')
1528: fatal("%.200s line %d: Missing argument.", filename,
1529: linenum);
1530: if (strcmp(arg, "default") == 0) {
1531: val64 = 0;
1532: } else {
1.236 dtucker 1533: if (scan_scaled(arg, &val64) == -1)
1534: fatal("%.200s line %d: Bad number '%s': %s",
1535: filename, linenum, arg, strerror(errno));
1.235 dtucker 1536: if (val64 != 0 && val64 < 16)
1537: fatal("%.200s line %d: RekeyLimit too small",
1538: filename, linenum);
1539: }
1540: if (*activep && options->rekey_limit == -1)
1.284 dtucker 1541: options->rekey_limit = val64;
1.235 dtucker 1542: if (cp != NULL) { /* optional rekey interval present */
1543: if (strcmp(cp, "none") == 0) {
1544: (void)strdelim(&cp); /* discard */
1545: break;
1546: }
1547: intptr = &options->rekey_interval;
1548: goto parse_time;
1549: }
1550: break;
1551:
1.94 markus 1552: case sGatewayPorts:
1.251 millert 1553: intptr = &options->fwd_opts.gateway_ports;
1.220 djm 1554: multistate_ptr = multistate_gatewayports;
1555: goto parse_multistate;
1.25 markus 1556:
1.122 markus 1557: case sUseDNS:
1558: intptr = &options->use_dns;
1.94 markus 1559: goto parse_flag;
1.53 markus 1560:
1.94 markus 1561: case sLogFacility:
1.174 dtucker 1562: log_facility_ptr = &options->log_facility;
1.94 markus 1563: arg = strdelim(&cp);
1564: value = log_facility_number(arg);
1.101 markus 1565: if (value == SYSLOG_FACILITY_NOT_SET)
1.94 markus 1566: fatal("%.200s line %d: unsupported log facility '%s'",
1567: filename, linenum, arg ? arg : "<NONE>");
1.174 dtucker 1568: if (*log_facility_ptr == -1)
1569: *log_facility_ptr = (SyslogFacility) value;
1.94 markus 1570: break;
1.25 markus 1571:
1.94 markus 1572: case sLogLevel:
1.174 dtucker 1573: log_level_ptr = &options->log_level;
1.94 markus 1574: arg = strdelim(&cp);
1575: value = log_level_number(arg);
1.101 markus 1576: if (value == SYSLOG_LEVEL_NOT_SET)
1.94 markus 1577: fatal("%.200s line %d: unsupported log level '%s'",
1578: filename, linenum, arg ? arg : "<NONE>");
1.308 djm 1579: if (*activep && *log_level_ptr == -1)
1.174 dtucker 1580: *log_level_ptr = (LogLevel) value;
1.94 markus 1581: break;
1582:
1583: case sAllowTcpForwarding:
1584: intptr = &options->allow_tcp_forwarding;
1.233 djm 1585: multistate_ptr = multistate_tcpfwd;
1586: goto parse_multistate;
1.102 provos 1587:
1.251 millert 1588: case sAllowStreamLocalForwarding:
1589: intptr = &options->allow_streamlocal_forwarding;
1590: multistate_ptr = multistate_tcpfwd;
1591: goto parse_multistate;
1592:
1.178 pyr 1593: case sAllowAgentForwarding:
1594: intptr = &options->allow_agent_forwarding;
1595: goto parse_flag;
1596:
1.301 djm 1597: case sDisableForwarding:
1598: intptr = &options->disable_forwarding;
1599: goto parse_flag;
1600:
1.94 markus 1601: case sAllowUsers:
1602: while ((arg = strdelim(&cp)) && *arg != '\0') {
1.299 djm 1603: if (match_user(NULL, NULL, NULL, arg) == -1)
1604: fatal("%s line %d: invalid AllowUsers pattern: "
1605: "\"%.100s\"", filename, linenum, arg);
1.227 markus 1606: if (!*activep)
1607: continue;
1.314 djm 1608: array_append(filename, linenum, "AllowUsers",
1609: &options->allow_users, &options->num_allow_users,
1610: arg);
1.94 markus 1611: }
1612: break;
1.25 markus 1613:
1.94 markus 1614: case sDenyUsers:
1615: while ((arg = strdelim(&cp)) && *arg != '\0') {
1.299 djm 1616: if (match_user(NULL, NULL, NULL, arg) == -1)
1617: fatal("%s line %d: invalid DenyUsers pattern: "
1618: "\"%.100s\"", filename, linenum, arg);
1.227 markus 1619: if (!*activep)
1620: continue;
1.314 djm 1621: array_append(filename, linenum, "DenyUsers",
1622: &options->deny_users, &options->num_deny_users,
1623: arg);
1.94 markus 1624: }
1625: break;
1.25 markus 1626:
1.94 markus 1627: case sAllowGroups:
1628: while ((arg = strdelim(&cp)) && *arg != '\0') {
1.227 markus 1629: if (!*activep)
1630: continue;
1.314 djm 1631: array_append(filename, linenum, "AllowGroups",
1632: &options->allow_groups, &options->num_allow_groups,
1633: arg);
1.94 markus 1634: }
1635: break;
1.33 markus 1636:
1.94 markus 1637: case sDenyGroups:
1638: while ((arg = strdelim(&cp)) && *arg != '\0') {
1.227 markus 1639: if (!*activep)
1640: continue;
1.314 djm 1641: array_append(filename, linenum, "DenyGroups",
1642: &options->deny_groups, &options->num_deny_groups,
1643: arg);
1.94 markus 1644: }
1645: break;
1.66 markus 1646:
1.94 markus 1647: case sCiphers:
1648: arg = strdelim(&cp);
1649: if (!arg || *arg == '\0')
1650: fatal("%s line %d: Missing argument.", filename, linenum);
1.304 djm 1651: if (*arg != '-' && !ciphers_valid(*arg == '+' ? arg + 1 : arg))
1.94 markus 1652: fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1653: filename, linenum, arg ? arg : "<NONE>");
1654: if (options->ciphers == NULL)
1655: options->ciphers = xstrdup(arg);
1656: break;
1.33 markus 1657:
1.94 markus 1658: case sMacs:
1659: arg = strdelim(&cp);
1660: if (!arg || *arg == '\0')
1661: fatal("%s line %d: Missing argument.", filename, linenum);
1.304 djm 1662: if (*arg != '-' && !mac_valid(*arg == '+' ? arg + 1 : arg))
1.94 markus 1663: fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1664: filename, linenum, arg ? arg : "<NONE>");
1665: if (options->macs == NULL)
1666: options->macs = xstrdup(arg);
1.211 djm 1667: break;
1668:
1669: case sKexAlgorithms:
1670: arg = strdelim(&cp);
1671: if (!arg || *arg == '\0')
1672: fatal("%s line %d: Missing argument.",
1673: filename, linenum);
1.304 djm 1674: if (*arg != '-' &&
1675: !kex_names_valid(*arg == '+' ? arg + 1 : arg))
1.211 djm 1676: fatal("%s line %d: Bad SSH2 KexAlgorithms '%s'.",
1677: filename, linenum, arg ? arg : "<NONE>");
1678: if (options->kex_algorithms == NULL)
1679: options->kex_algorithms = xstrdup(arg);
1.94 markus 1680: break;
1.43 jakob 1681:
1.94 markus 1682: case sSubsystem:
1683: if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1684: fatal("%s line %d: too many subsystems defined.",
1.95 deraadt 1685: filename, linenum);
1.94 markus 1686: }
1687: arg = strdelim(&cp);
1688: if (!arg || *arg == '\0')
1689: fatal("%s line %d: Missing subsystem name.",
1.95 deraadt 1690: filename, linenum);
1.153 dtucker 1691: if (!*activep) {
1692: arg = strdelim(&cp);
1693: break;
1694: }
1.94 markus 1695: for (i = 0; i < options->num_subsystems; i++)
1696: if (strcmp(arg, options->subsystem_name[i]) == 0)
1697: fatal("%s line %d: Subsystem '%s' already defined.",
1.95 deraadt 1698: filename, linenum, arg);
1.94 markus 1699: options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1700: arg = strdelim(&cp);
1701: if (!arg || *arg == '\0')
1702: fatal("%s line %d: Missing subsystem command.",
1.95 deraadt 1703: filename, linenum);
1.94 markus 1704: options->subsystem_command[options->num_subsystems] = xstrdup(arg);
1.151 djm 1705:
1706: /* Collect arguments (separate to executable) */
1707: p = xstrdup(arg);
1708: len = strlen(p) + 1;
1709: while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1710: len += 1 + strlen(arg);
1.264 deraadt 1711: p = xreallocarray(p, 1, len);
1.151 djm 1712: strlcat(p, " ", len);
1713: strlcat(p, arg, len);
1714: }
1715: options->subsystem_args[options->num_subsystems] = p;
1.94 markus 1716: options->num_subsystems++;
1717: break;
1.46 markus 1718:
1.94 markus 1719: case sMaxStartups:
1720: arg = strdelim(&cp);
1721: if (!arg || *arg == '\0')
1722: fatal("%s line %d: Missing MaxStartups spec.",
1.95 deraadt 1723: filename, linenum);
1.94 markus 1724: if ((n = sscanf(arg, "%d:%d:%d",
1725: &options->max_startups_begin,
1726: &options->max_startups_rate,
1727: &options->max_startups)) == 3) {
1728: if (options->max_startups_begin >
1729: options->max_startups ||
1730: options->max_startups_rate > 100 ||
1731: options->max_startups_rate < 1)
1.50 markus 1732: fatal("%s line %d: Illegal MaxStartups spec.",
1.87 stevesk 1733: filename, linenum);
1.94 markus 1734: } else if (n != 1)
1735: fatal("%s line %d: Illegal MaxStartups spec.",
1736: filename, linenum);
1737: else
1738: options->max_startups = options->max_startups_begin;
1739: break;
1.133 dtucker 1740:
1741: case sMaxAuthTries:
1742: intptr = &options->max_authtries;
1743: goto parse_int;
1.94 markus 1744:
1.180 djm 1745: case sMaxSessions:
1746: intptr = &options->max_sessions;
1747: goto parse_int;
1748:
1.94 markus 1749: case sBanner:
1750: charptr = &options->banner;
1751: goto parse_filename;
1.176 djm 1752:
1.94 markus 1753: /*
1754: * These options can contain %X options expanded at
1755: * connect time, so that you can specify paths like:
1756: *
1757: * AuthorizedKeysFile /etc/ssh_keys/%u
1758: */
1759: case sAuthorizedKeysFile:
1.219 djm 1760: if (*activep && options->num_authkeys_files == 0) {
1761: while ((arg = strdelim(&cp)) && *arg != '\0') {
1.314 djm 1762: arg = tilde_expand_filename(arg, getuid());
1763: array_append(filename, linenum,
1764: "AuthorizedKeysFile",
1765: &options->authorized_keys_files,
1766: &options->num_authkeys_files, arg);
1767: free(arg);
1.219 djm 1768: }
1769: }
1770: return 0;
1771:
1.208 djm 1772: case sAuthorizedPrincipalsFile:
1773: charptr = &options->authorized_principals_file;
1.205 djm 1774: arg = strdelim(&cp);
1775: if (!arg || *arg == '\0')
1776: fatal("%s line %d: missing file name.",
1777: filename, linenum);
1778: if (*activep && *charptr == NULL) {
1.206 markus 1779: *charptr = tilde_expand_filename(arg, getuid());
1.205 djm 1780: /* increase optional counter */
1781: if (intptr != NULL)
1782: *intptr = *intptr + 1;
1783: }
1784: break;
1.94 markus 1785:
1786: case sClientAliveInterval:
1787: intptr = &options->client_alive_interval;
1788: goto parse_time;
1789:
1790: case sClientAliveCountMax:
1791: intptr = &options->client_alive_count_max;
1792: goto parse_int;
1.131 djm 1793:
1794: case sAcceptEnv:
1795: while ((arg = strdelim(&cp)) && *arg != '\0') {
1796: if (strchr(arg, '=') != NULL)
1797: fatal("%s line %d: Invalid environment name.",
1798: filename, linenum);
1.153 dtucker 1799: if (!*activep)
1.227 markus 1800: continue;
1.314 djm 1801: array_append(filename, linenum, "AcceptEnv",
1802: &options->accept_env, &options->num_accept_env,
1803: arg);
1.131 djm 1804: }
1805: break;
1.145 reyk 1806:
1.332 djm 1807: case sSetEnv:
1808: uvalue = options->num_setenv;
1809: while ((arg = strdelimw(&cp)) && *arg != '\0') {
1810: if (strchr(arg, '=') == NULL)
1811: fatal("%s line %d: Invalid environment.",
1812: filename, linenum);
1813: if (!*activep || uvalue != 0)
1814: continue;
1815: array_append(filename, linenum, "SetEnv",
1816: &options->setenv, &options->num_setenv, arg);
1817: }
1818: break;
1819:
1.145 reyk 1820: case sPermitTunnel:
1821: intptr = &options->permit_tun;
1.146 reyk 1822: arg = strdelim(&cp);
1823: if (!arg || *arg == '\0')
1824: fatal("%s line %d: Missing yes/point-to-point/"
1825: "ethernet/no argument.", filename, linenum);
1.182 dtucker 1826: value = -1;
1827: for (i = 0; tunmode_desc[i].val != -1; i++)
1828: if (strcmp(tunmode_desc[i].text, arg) == 0) {
1829: value = tunmode_desc[i].val;
1830: break;
1831: }
1832: if (value == -1)
1.146 reyk 1833: fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1834: "no argument: %s", filename, linenum, arg);
1.268 djm 1835: if (*activep && *intptr == -1)
1.146 reyk 1836: *intptr = value;
1837: break;
1.94 markus 1838:
1.153 dtucker 1839: case sMatch:
1840: if (cmdline)
1841: fatal("Match directive not supported as a command-line "
1842: "option");
1.226 dtucker 1843: value = match_cfg_line(&cp, linenum, connectinfo);
1.153 dtucker 1844: if (value < 0)
1845: fatal("%s line %d: Bad Match condition", filename,
1846: linenum);
1847: *activep = value;
1.156 dtucker 1848: break;
1849:
1.330 djm 1850: case sPermitListen:
1.156 dtucker 1851: case sPermitOpen:
1.330 djm 1852: if (opcode == sPermitListen) {
1853: uintptr = &options->num_permitted_listens;
1854: chararrayptr = &options->permitted_listens;
1.329 djm 1855: } else {
1856: uintptr = &options->num_permitted_opens;
1857: chararrayptr = &options->permitted_opens;
1858: }
1.156 dtucker 1859: arg = strdelim(&cp);
1860: if (!arg || *arg == '\0')
1.329 djm 1861: fatal("%s line %d: missing %s specification",
1862: filename, linenum, lookup_opcode_name(opcode));
1863: uvalue = *uintptr; /* modified later */
1.310 djm 1864: if (strcmp(arg, "any") == 0 || strcmp(arg, "none") == 0) {
1.329 djm 1865: if (*activep && uvalue == 0) {
1866: *uintptr = 1;
1867: *chararrayptr = xcalloc(1,
1868: sizeof(**chararrayptr));
1869: (*chararrayptr)[0] = xstrdup(arg);
1.311 dtucker 1870: }
1.156 dtucker 1871: break;
1872: }
1.159 dtucker 1873: for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
1.333 djm 1874: if (opcode == sPermitListen &&
1875: strchr(arg, ':') == NULL) {
1876: /*
1877: * Allow bare port number for PermitListen
1878: * to indicate a wildcard listen host.
1879: */
1880: xasprintf(&arg2, "*:%s", arg);
1881: } else {
1882: arg2 = xstrdup(arg);
1883: p = hpdelim(&arg);
1884: if (p == NULL) {
1885: fatal("%s line %d: missing host in %s",
1886: filename, linenum,
1887: lookup_opcode_name(opcode));
1888: }
1889: p = cleanhostname(p);
1.329 djm 1890: }
1891: if (arg == NULL ||
1892: ((port = permitopen_port(arg)) < 0)) {
1893: fatal("%s line %d: bad port number in %s",
1894: filename, linenum,
1895: lookup_opcode_name(opcode));
1896: }
1897: if (*activep && uvalue == 0) {
1.314 djm 1898: array_append(filename, linenum,
1.329 djm 1899: lookup_opcode_name(opcode),
1900: chararrayptr, uintptr, arg2);
1.314 djm 1901: }
1902: free(arg2);
1.159 dtucker 1903: }
1.153 dtucker 1904: break;
1905:
1.158 dtucker 1906: case sForceCommand:
1.262 dtucker 1907: if (cp == NULL || *cp == '\0')
1.158 dtucker 1908: fatal("%.200s line %d: Missing argument.", filename,
1909: linenum);
1910: len = strspn(cp, WHITESPACE);
1911: if (*activep && options->adm_forced_command == NULL)
1912: options->adm_forced_command = xstrdup(cp + len);
1913: return 0;
1914:
1.176 djm 1915: case sChrootDirectory:
1916: charptr = &options->chroot_directory;
1.177 djm 1917:
1918: arg = strdelim(&cp);
1919: if (!arg || *arg == '\0')
1920: fatal("%s line %d: missing file name.",
1921: filename, linenum);
1922: if (*activep && *charptr == NULL)
1923: *charptr = xstrdup(arg);
1924: break;
1.176 djm 1925:
1.204 djm 1926: case sTrustedUserCAKeys:
1927: charptr = &options->trusted_user_ca_keys;
1928: goto parse_filename;
1929:
1930: case sRevokedKeys:
1931: charptr = &options->revoked_keys_file;
1932: goto parse_filename;
1933:
1.213 djm 1934: case sIPQoS:
1935: arg = strdelim(&cp);
1936: if ((value = parse_ipqos(arg)) == -1)
1937: fatal("%s line %d: Bad IPQoS value: %s",
1938: filename, linenum, arg);
1939: arg = strdelim(&cp);
1940: if (arg == NULL)
1941: value2 = value;
1942: else if ((value2 = parse_ipqos(arg)) == -1)
1943: fatal("%s line %d: Bad IPQoS value: %s",
1944: filename, linenum, arg);
1945: if (*activep) {
1946: options->ip_qos_interactive = value;
1947: options->ip_qos_bulk = value2;
1948: }
1949: break;
1950:
1.225 djm 1951: case sVersionAddendum:
1.262 dtucker 1952: if (cp == NULL || *cp == '\0')
1.225 djm 1953: fatal("%.200s line %d: Missing argument.", filename,
1954: linenum);
1955: len = strspn(cp, WHITESPACE);
1956: if (*activep && options->version_addendum == NULL) {
1957: if (strcasecmp(cp + len, "none") == 0)
1958: options->version_addendum = xstrdup("");
1959: else if (strchr(cp + len, '\r') != NULL)
1960: fatal("%.200s line %d: Invalid argument",
1961: filename, linenum);
1962: else
1963: options->version_addendum = xstrdup(cp + len);
1964: }
1965: return 0;
1966:
1.231 djm 1967: case sAuthorizedKeysCommand:
1.255 jsg 1968: if (cp == NULL)
1969: fatal("%.200s line %d: Missing argument.", filename,
1970: linenum);
1.231 djm 1971: len = strspn(cp, WHITESPACE);
1972: if (*activep && options->authorized_keys_command == NULL) {
1973: if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
1974: fatal("%.200s line %d: AuthorizedKeysCommand "
1975: "must be an absolute path",
1976: filename, linenum);
1977: options->authorized_keys_command = xstrdup(cp + len);
1978: }
1979: return 0;
1980:
1981: case sAuthorizedKeysCommandUser:
1982: charptr = &options->authorized_keys_command_user;
1983:
1984: arg = strdelim(&cp);
1.255 jsg 1985: if (!arg || *arg == '\0')
1986: fatal("%s line %d: missing AuthorizedKeysCommandUser "
1987: "argument.", filename, linenum);
1.231 djm 1988: if (*activep && *charptr == NULL)
1989: *charptr = xstrdup(arg);
1990: break;
1991:
1.270 djm 1992: case sAuthorizedPrincipalsCommand:
1993: if (cp == NULL)
1994: fatal("%.200s line %d: Missing argument.", filename,
1995: linenum);
1996: len = strspn(cp, WHITESPACE);
1997: if (*activep &&
1998: options->authorized_principals_command == NULL) {
1999: if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
2000: fatal("%.200s line %d: "
2001: "AuthorizedPrincipalsCommand must be "
2002: "an absolute path", filename, linenum);
2003: options->authorized_principals_command =
2004: xstrdup(cp + len);
2005: }
2006: return 0;
2007:
2008: case sAuthorizedPrincipalsCommandUser:
2009: charptr = &options->authorized_principals_command_user;
2010:
2011: arg = strdelim(&cp);
2012: if (!arg || *arg == '\0')
2013: fatal("%s line %d: missing "
2014: "AuthorizedPrincipalsCommandUser argument.",
2015: filename, linenum);
2016: if (*activep && *charptr == NULL)
2017: *charptr = xstrdup(arg);
2018: break;
2019:
1.232 djm 2020: case sAuthenticationMethods:
1.268 djm 2021: if (options->num_auth_methods == 0) {
1.291 djm 2022: value = 0; /* seen "any" pseudo-method */
1.328 djm 2023: value2 = 0; /* successfully parsed any method */
1.232 djm 2024: while ((arg = strdelim(&cp)) && *arg != '\0') {
1.291 djm 2025: if (strcmp(arg, "any") == 0) {
2026: if (options->num_auth_methods > 0) {
2027: fatal("%s line %d: \"any\" "
2028: "must appear alone in "
2029: "AuthenticationMethods",
2030: filename, linenum);
2031: }
2032: value = 1;
2033: } else if (value) {
2034: fatal("%s line %d: \"any\" must appear "
2035: "alone in AuthenticationMethods",
2036: filename, linenum);
2037: } else if (auth2_methods_valid(arg, 0) != 0) {
1.232 djm 2038: fatal("%s line %d: invalid "
2039: "authentication method list.",
2040: filename, linenum);
1.291 djm 2041: }
1.292 djm 2042: value2 = 1;
1.268 djm 2043: if (!*activep)
2044: continue;
1.314 djm 2045: array_append(filename, linenum,
2046: "AuthenticationMethods",
2047: &options->auth_methods,
2048: &options->num_auth_methods, arg);
1.232 djm 2049: }
1.292 djm 2050: if (value2 == 0) {
1.291 djm 2051: fatal("%s line %d: no AuthenticationMethods "
2052: "specified", filename, linenum);
2053: }
1.232 djm 2054: }
2055: return 0;
2056:
1.251 millert 2057: case sStreamLocalBindMask:
2058: arg = strdelim(&cp);
2059: if (!arg || *arg == '\0')
1.268 djm 2060: fatal("%s line %d: missing StreamLocalBindMask "
2061: "argument.", filename, linenum);
1.251 millert 2062: /* Parse mode in octal format */
2063: value = strtol(arg, &p, 8);
2064: if (arg == p || value < 0 || value > 0777)
2065: fatal("%s line %d: Bad mask.", filename, linenum);
1.268 djm 2066: if (*activep)
2067: options->fwd_opts.streamlocal_bind_mask = (mode_t)value;
1.251 millert 2068: break;
2069:
2070: case sStreamLocalBindUnlink:
2071: intptr = &options->fwd_opts.streamlocal_bind_unlink;
2072: goto parse_flag;
2073:
1.256 djm 2074: case sFingerprintHash:
2075: arg = strdelim(&cp);
2076: if (!arg || *arg == '\0')
2077: fatal("%.200s line %d: Missing argument.",
2078: filename, linenum);
2079: if ((value = ssh_digest_alg_by_name(arg)) == -1)
2080: fatal("%.200s line %d: Invalid hash algorithm \"%s\".",
2081: filename, linenum, arg);
2082: if (*activep)
2083: options->fingerprint_hash = value;
2084: break;
2085:
1.309 djm 2086: case sExposeAuthInfo:
2087: intptr = &options->expose_userauth_info;
2088: goto parse_flag;
2089:
1.316 djm 2090: case sRDomain:
2091: charptr = &options->routing_domain;
2092: arg = strdelim(&cp);
2093: if (!arg || *arg == '\0')
2094: fatal("%.200s line %d: Missing argument.",
2095: filename, linenum);
2096: if (strcasecmp(arg, "none") != 0 && strcmp(arg, "%D") != 0 &&
2097: !valid_rdomain(arg))
2098: fatal("%s line %d: bad routing domain",
2099: filename, linenum);
2100: if (*activep && *charptr == NULL)
2101: *charptr = xstrdup(arg);
1.321 dtucker 2102: break;
1.316 djm 2103:
1.94 markus 2104: case sDeprecated:
1.295 djm 2105: case sIgnore:
1.121 jakob 2106: case sUnsupported:
1.295 djm 2107: do_log2(opcode == sIgnore ?
2108: SYSLOG_LEVEL_DEBUG2 : SYSLOG_LEVEL_INFO,
2109: "%s line %d: %s option %s", filename, linenum,
2110: opcode == sUnsupported ? "Unsupported" : "Deprecated", arg);
1.94 markus 2111: while (arg)
2112: arg = strdelim(&cp);
2113: break;
2114:
2115: default:
2116: fatal("%s line %d: Missing handler for opcode %s (%d)",
2117: filename, linenum, arg, opcode);
2118: }
2119: if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
2120: fatal("%s line %d: garbage at end of line; \"%.200s\".",
2121: filename, linenum, arg);
2122: return 0;
2123: }
2124:
2125: /* Reads the server configuration file. */
1.25 markus 2126:
1.94 markus 2127: void
1.338 markus 2128: load_server_config(const char *filename, struct sshbuf *conf)
1.94 markus 2129: {
1.331 markus 2130: char *line = NULL, *cp;
2131: size_t linesize = 0;
1.94 markus 2132: FILE *f;
1.338 markus 2133: int r, lineno = 0;
1.81 stevesk 2134:
1.134 djm 2135: debug2("%s: filename %s", __func__, filename);
2136: if ((f = fopen(filename, "r")) == NULL) {
1.94 markus 2137: perror(filename);
2138: exit(1);
2139: }
1.338 markus 2140: sshbuf_reset(conf);
1.331 markus 2141: while (getline(&line, &linesize, f) != -1) {
1.229 dtucker 2142: lineno++;
1.134 djm 2143: /*
2144: * Trim out comments and strip whitespace
1.135 deraadt 2145: * NB - preserve newlines, they are needed to reproduce
1.134 djm 2146: * line numbers later for error messages
2147: */
2148: if ((cp = strchr(line, '#')) != NULL)
2149: memcpy(cp, "\n", 2);
2150: cp = line + strspn(line, " \t\r");
1.338 markus 2151: if ((r = sshbuf_put(conf, cp, strlen(cp))) != 0)
2152: fatal("%s: buffer error: %s", __func__, ssh_err(r));
1.134 djm 2153: }
1.331 markus 2154: free(line);
1.338 markus 2155: if ((r = sshbuf_put_u8(conf, 0)) != 0)
2156: fatal("%s: buffer error: %s", __func__, ssh_err(r));
1.134 djm 2157: fclose(f);
1.338 markus 2158: debug2("%s: done config len = %zu", __func__, sshbuf_len(conf));
1.134 djm 2159: }
2160:
2161: void
1.226 dtucker 2162: parse_server_match_config(ServerOptions *options,
2163: struct connection_info *connectinfo)
1.153 dtucker 2164: {
2165: ServerOptions mo;
2166:
2167: initialize_server_options(&mo);
1.338 markus 2168: parse_server_config(&mo, "reprocess config", cfg, connectinfo);
1.168 dtucker 2169: copy_set_server_options(options, &mo, 0);
1.153 dtucker 2170: }
2171:
1.226 dtucker 2172: int parse_server_match_testspec(struct connection_info *ci, char *spec)
2173: {
2174: char *p;
2175:
2176: while ((p = strsep(&spec, ",")) && *p != '\0') {
2177: if (strncmp(p, "addr=", 5) == 0) {
2178: ci->address = xstrdup(p + 5);
2179: } else if (strncmp(p, "host=", 5) == 0) {
2180: ci->host = xstrdup(p + 5);
2181: } else if (strncmp(p, "user=", 5) == 0) {
2182: ci->user = xstrdup(p + 5);
2183: } else if (strncmp(p, "laddr=", 6) == 0) {
2184: ci->laddress = xstrdup(p + 6);
1.317 djm 2185: } else if (strncmp(p, "rdomain=", 8) == 0) {
2186: ci->rdomain = xstrdup(p + 8);
1.226 dtucker 2187: } else if (strncmp(p, "lport=", 6) == 0) {
2188: ci->lport = a2port(p + 6);
2189: if (ci->lport == -1) {
2190: fprintf(stderr, "Invalid port '%s' in test mode"
2191: " specification %s\n", p+6, p);
2192: return -1;
2193: }
2194: } else {
2195: fprintf(stderr, "Invalid test mode specification %s\n",
2196: p);
2197: return -1;
2198: }
2199: }
2200: return 0;
2201: }
2202:
1.168 dtucker 2203: /*
2204: * Copy any supported values that are set.
2205: *
1.195 jj 2206: * If the preauth flag is set, we do not bother copying the string or
1.168 dtucker 2207: * array values that are not used pre-authentication, because any that we
1.328 djm 2208: * do use must be explicitly sent in mm_getpwnamallow().
1.168 dtucker 2209: */
1.153 dtucker 2210: void
1.168 dtucker 2211: copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
1.153 dtucker 2212: {
1.247 djm 2213: #define M_CP_INTOPT(n) do {\
2214: if (src->n != -1) \
2215: dst->n = src->n; \
2216: } while (0)
2217:
1.168 dtucker 2218: M_CP_INTOPT(password_authentication);
2219: M_CP_INTOPT(gss_authentication);
2220: M_CP_INTOPT(pubkey_authentication);
2221: M_CP_INTOPT(kerberos_authentication);
2222: M_CP_INTOPT(hostbased_authentication);
1.209 djm 2223: M_CP_INTOPT(hostbased_uses_name_from_packet_only);
1.168 dtucker 2224: M_CP_INTOPT(kbd_interactive_authentication);
1.175 dtucker 2225: M_CP_INTOPT(permit_root_login);
1.188 djm 2226: M_CP_INTOPT(permit_empty_passwd);
1.168 dtucker 2227:
2228: M_CP_INTOPT(allow_tcp_forwarding);
1.251 millert 2229: M_CP_INTOPT(allow_streamlocal_forwarding);
1.178 pyr 2230: M_CP_INTOPT(allow_agent_forwarding);
1.301 djm 2231: M_CP_INTOPT(disable_forwarding);
1.309 djm 2232: M_CP_INTOPT(expose_userauth_info);
1.209 djm 2233: M_CP_INTOPT(permit_tun);
1.251 millert 2234: M_CP_INTOPT(fwd_opts.gateway_ports);
1.289 djm 2235: M_CP_INTOPT(fwd_opts.streamlocal_bind_unlink);
1.168 dtucker 2236: M_CP_INTOPT(x11_display_offset);
2237: M_CP_INTOPT(x11_forwarding);
2238: M_CP_INTOPT(x11_use_localhost);
1.244 djm 2239: M_CP_INTOPT(permit_tty);
1.250 djm 2240: M_CP_INTOPT(permit_user_rc);
1.180 djm 2241: M_CP_INTOPT(max_sessions);
1.184 dtucker 2242: M_CP_INTOPT(max_authtries);
1.300 markus 2243: M_CP_INTOPT(client_alive_count_max);
2244: M_CP_INTOPT(client_alive_interval);
1.213 djm 2245: M_CP_INTOPT(ip_qos_interactive);
2246: M_CP_INTOPT(ip_qos_bulk);
1.235 dtucker 2247: M_CP_INTOPT(rekey_limit);
2248: M_CP_INTOPT(rekey_interval);
1.308 djm 2249: M_CP_INTOPT(log_level);
1.289 djm 2250:
2251: /*
2252: * The bind_mask is a mode_t that may be unsigned, so we can't use
2253: * M_CP_INTOPT - it does a signed comparison that causes compiler
2254: * warnings.
2255: */
1.290 dtucker 2256: if (src->fwd_opts.streamlocal_bind_mask != (mode_t)-1) {
1.289 djm 2257: dst->fwd_opts.streamlocal_bind_mask =
2258: src->fwd_opts.streamlocal_bind_mask;
2259: }
1.247 djm 2260:
2261: /* M_CP_STROPT and M_CP_STRARRAYOPT should not appear before here */
2262: #define M_CP_STROPT(n) do {\
2263: if (src->n != NULL && dst->n != src->n) { \
2264: free(dst->n); \
2265: dst->n = src->n; \
2266: } \
2267: } while(0)
1.314 djm 2268: #define M_CP_STRARRAYOPT(s, num_s) do {\
2269: u_int i; \
2270: if (src->num_s != 0) { \
2271: for (i = 0; i < dst->num_s; i++) \
2272: free(dst->s[i]); \
2273: free(dst->s); \
2274: dst->s = xcalloc(src->num_s, sizeof(*dst->s)); \
2275: for (i = 0; i < src->num_s; i++) \
2276: dst->s[i] = xstrdup(src->s[i]); \
2277: dst->num_s = src->num_s; \
1.312 djm 2278: } \
2279: } while(0)
1.168 dtucker 2280:
1.218 djm 2281: /* See comment in servconf.h */
2282: COPY_MATCH_STRING_OPTS();
1.282 djm 2283:
2284: /* Arguments that accept '+...' need to be expanded */
2285: assemble_algorithms(dst);
1.216 djm 2286:
1.217 dtucker 2287: /*
2288: * The only things that should be below this point are string options
2289: * which are only used after authentication.
2290: */
1.168 dtucker 2291: if (preauth)
2292: return;
1.219 djm 2293:
1.283 djm 2294: /* These options may be "none" to clear a global setting */
1.168 dtucker 2295: M_CP_STROPT(adm_forced_command);
1.283 djm 2296: if (option_clear_or_none(dst->adm_forced_command)) {
2297: free(dst->adm_forced_command);
2298: dst->adm_forced_command = NULL;
2299: }
1.176 djm 2300: M_CP_STROPT(chroot_directory);
1.283 djm 2301: if (option_clear_or_none(dst->chroot_directory)) {
2302: free(dst->chroot_directory);
2303: dst->chroot_directory = NULL;
2304: }
1.153 dtucker 2305: }
1.168 dtucker 2306:
2307: #undef M_CP_INTOPT
2308: #undef M_CP_STROPT
1.219 djm 2309: #undef M_CP_STRARRAYOPT
1.153 dtucker 2310:
2311: void
1.338 markus 2312: parse_server_config(ServerOptions *options, const char *filename,
2313: struct sshbuf *conf, struct connection_info *connectinfo)
1.134 djm 2314: {
1.153 dtucker 2315: int active, linenum, bad_options = 0;
1.136 dtucker 2316: char *cp, *obuf, *cbuf;
1.134 djm 2317:
1.338 markus 2318: debug2("%s: config %s len %zu", __func__, filename, sshbuf_len(conf));
1.134 djm 2319:
1.287 djm 2320: if ((obuf = cbuf = sshbuf_dup_string(conf)) == NULL)
2321: fatal("%s: sshbuf_dup_string failed", __func__);
1.226 dtucker 2322: active = connectinfo ? 0 : 1;
1.137 dtucker 2323: linenum = 1;
1.140 deraadt 2324: while ((cp = strsep(&cbuf, "\n")) != NULL) {
1.134 djm 2325: if (process_server_config_line(options, cp, filename,
1.226 dtucker 2326: linenum++, &active, connectinfo) != 0)
1.94 markus 2327: bad_options++;
1.1 deraadt 2328: }
1.239 djm 2329: free(obuf);
1.78 stevesk 2330: if (bad_options > 0)
2331: fatal("%s: terminating, %d bad configuration options",
2332: filename, bad_options);
1.266 dtucker 2333: process_queued_listen_addrs(options);
1.182 dtucker 2334: }
2335:
2336: static const char *
1.221 djm 2337: fmt_multistate_int(int val, const struct multistate *m)
2338: {
2339: u_int i;
2340:
2341: for (i = 0; m[i].key != NULL; i++) {
2342: if (m[i].value == val)
2343: return m[i].key;
2344: }
2345: return "UNKNOWN";
2346: }
2347:
2348: static const char *
1.182 dtucker 2349: fmt_intarg(ServerOpCodes code, int val)
2350: {
1.221 djm 2351: if (val == -1)
2352: return "unset";
2353: switch (code) {
2354: case sAddressFamily:
2355: return fmt_multistate_int(val, multistate_addressfamily);
2356: case sPermitRootLogin:
2357: return fmt_multistate_int(val, multistate_permitrootlogin);
2358: case sGatewayPorts:
2359: return fmt_multistate_int(val, multistate_gatewayports);
2360: case sCompression:
2361: return fmt_multistate_int(val, multistate_compression);
1.233 djm 2362: case sAllowTcpForwarding:
2363: return fmt_multistate_int(val, multistate_tcpfwd);
1.251 millert 2364: case sAllowStreamLocalForwarding:
2365: return fmt_multistate_int(val, multistate_tcpfwd);
1.256 djm 2366: case sFingerprintHash:
2367: return ssh_digest_alg_name(val);
1.221 djm 2368: default:
2369: switch (val) {
2370: case 0:
2371: return "no";
2372: case 1:
2373: return "yes";
2374: default:
2375: return "UNKNOWN";
2376: }
1.182 dtucker 2377: }
2378: }
2379:
2380: static void
2381: dump_cfg_int(ServerOpCodes code, int val)
2382: {
2383: printf("%s %d\n", lookup_opcode_name(code), val);
2384: }
2385:
2386: static void
1.263 dtucker 2387: dump_cfg_oct(ServerOpCodes code, int val)
2388: {
2389: printf("%s 0%o\n", lookup_opcode_name(code), val);
2390: }
2391:
2392: static void
1.182 dtucker 2393: dump_cfg_fmtint(ServerOpCodes code, int val)
2394: {
2395: printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
2396: }
2397:
2398: static void
2399: dump_cfg_string(ServerOpCodes code, const char *val)
2400: {
1.257 djm 2401: printf("%s %s\n", lookup_opcode_name(code),
2402: val == NULL ? "none" : val);
1.182 dtucker 2403: }
2404:
2405: static void
2406: dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
2407: {
2408: u_int i;
2409:
2410: for (i = 0; i < count; i++)
1.219 djm 2411: printf("%s %s\n", lookup_opcode_name(code), vals[i]);
2412: }
2413:
2414: static void
2415: dump_cfg_strarray_oneline(ServerOpCodes code, u_int count, char **vals)
2416: {
2417: u_int i;
2418:
1.291 djm 2419: if (count <= 0 && code != sAuthenticationMethods)
1.261 dtucker 2420: return;
1.219 djm 2421: printf("%s", lookup_opcode_name(code));
2422: for (i = 0; i < count; i++)
2423: printf(" %s", vals[i]);
1.291 djm 2424: if (code == sAuthenticationMethods && count == 0)
2425: printf(" any");
1.219 djm 2426: printf("\n");
1.182 dtucker 2427: }
2428:
1.315 djm 2429: static char *
2430: format_listen_addrs(struct listenaddr *la)
1.182 dtucker 2431: {
1.315 djm 2432: int r;
1.182 dtucker 2433: struct addrinfo *ai;
1.315 djm 2434: char addr[NI_MAXHOST], port[NI_MAXSERV];
1.263 dtucker 2435: char *laddr1 = xstrdup(""), *laddr2 = NULL;
1.182 dtucker 2436:
1.263 dtucker 2437: /*
2438: * ListenAddress must be after Port. add_one_listen_addr pushes
2439: * addresses onto a stack, so to maintain ordering we need to
2440: * print these in reverse order.
2441: */
1.315 djm 2442: for (ai = la->addrs; ai; ai = ai->ai_next) {
2443: if ((r = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
1.182 dtucker 2444: sizeof(addr), port, sizeof(port),
2445: NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
1.315 djm 2446: error("getnameinfo: %.100s", ssh_gai_strerror(r));
2447: continue;
2448: }
2449: laddr2 = laddr1;
2450: if (ai->ai_family == AF_INET6) {
2451: xasprintf(&laddr1, "listenaddress [%s]:%s%s%s\n%s",
2452: addr, port,
2453: la->rdomain == NULL ? "" : " rdomain ",
2454: la->rdomain == NULL ? "" : la->rdomain,
2455: laddr2);
1.182 dtucker 2456: } else {
1.315 djm 2457: xasprintf(&laddr1, "listenaddress %s:%s%s%s\n%s",
2458: addr, port,
2459: la->rdomain == NULL ? "" : " rdomain ",
2460: la->rdomain == NULL ? "" : la->rdomain,
2461: laddr2);
1.182 dtucker 2462: }
1.315 djm 2463: free(laddr2);
2464: }
2465: return laddr1;
2466: }
2467:
2468: void
2469: dump_config(ServerOptions *o)
2470: {
2471: char *s;
2472: u_int i;
2473:
2474: /* these are usually at the top of the config */
2475: for (i = 0; i < o->num_ports; i++)
2476: printf("port %d\n", o->ports[i]);
2477: dump_cfg_fmtint(sAddressFamily, o->address_family);
2478:
2479: for (i = 0; i < o->num_listen_addrs; i++) {
2480: s = format_listen_addrs(&o->listen_addrs[i]);
2481: printf("%s", s);
2482: free(s);
1.182 dtucker 2483: }
2484:
2485: /* integer arguments */
2486: dump_cfg_int(sLoginGraceTime, o->login_grace_time);
2487: dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
2488: dump_cfg_int(sMaxAuthTries, o->max_authtries);
1.189 djm 2489: dump_cfg_int(sMaxSessions, o->max_sessions);
1.182 dtucker 2490: dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
2491: dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
1.263 dtucker 2492: dump_cfg_oct(sStreamLocalBindMask, o->fwd_opts.streamlocal_bind_mask);
1.182 dtucker 2493:
2494: /* formatted integer arguments */
2495: dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
2496: dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
2497: dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
2498: dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
2499: dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
2500: o->hostbased_uses_name_from_packet_only);
2501: dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
1.187 djm 2502: #ifdef KRB5
1.182 dtucker 2503: dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
2504: dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
2505: dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
2506: dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
1.187 djm 2507: #endif
2508: #ifdef GSSAPI
1.182 dtucker 2509: dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
2510: dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
1.187 djm 2511: #endif
1.182 dtucker 2512: dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
2513: dump_cfg_fmtint(sKbdInteractiveAuthentication,
2514: o->kbd_interactive_authentication);
2515: dump_cfg_fmtint(sChallengeResponseAuthentication,
2516: o->challenge_response_authentication);
2517: dump_cfg_fmtint(sPrintMotd, o->print_motd);
2518: dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
2519: dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
2520: dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
1.244 djm 2521: dump_cfg_fmtint(sPermitTTY, o->permit_tty);
1.250 djm 2522: dump_cfg_fmtint(sPermitUserRC, o->permit_user_rc);
1.182 dtucker 2523: dump_cfg_fmtint(sStrictModes, o->strict_modes);
2524: dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
2525: dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
2526: dump_cfg_fmtint(sCompression, o->compression);
1.251 millert 2527: dump_cfg_fmtint(sGatewayPorts, o->fwd_opts.gateway_ports);
1.182 dtucker 2528: dump_cfg_fmtint(sUseDNS, o->use_dns);
2529: dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
1.261 dtucker 2530: dump_cfg_fmtint(sAllowAgentForwarding, o->allow_agent_forwarding);
1.301 djm 2531: dump_cfg_fmtint(sDisableForwarding, o->disable_forwarding);
1.251 millert 2532: dump_cfg_fmtint(sAllowStreamLocalForwarding, o->allow_streamlocal_forwarding);
1.288 djm 2533: dump_cfg_fmtint(sStreamLocalBindUnlink, o->fwd_opts.streamlocal_bind_unlink);
1.256 djm 2534: dump_cfg_fmtint(sFingerprintHash, o->fingerprint_hash);
1.309 djm 2535: dump_cfg_fmtint(sExposeAuthInfo, o->expose_userauth_info);
1.182 dtucker 2536:
2537: /* string arguments */
2538: dump_cfg_string(sPidFile, o->pid_file);
2539: dump_cfg_string(sXAuthLocation, o->xauth_location);
1.252 djm 2540: dump_cfg_string(sCiphers, o->ciphers ? o->ciphers : KEX_SERVER_ENCRYPT);
2541: dump_cfg_string(sMacs, o->macs ? o->macs : KEX_SERVER_MAC);
1.182 dtucker 2542: dump_cfg_string(sBanner, o->banner);
2543: dump_cfg_string(sForceCommand, o->adm_forced_command);
1.201 dtucker 2544: dump_cfg_string(sChrootDirectory, o->chroot_directory);
1.204 djm 2545: dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
2546: dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
1.208 djm 2547: dump_cfg_string(sAuthorizedPrincipalsFile,
2548: o->authorized_principals_file);
1.261 dtucker 2549: dump_cfg_string(sVersionAddendum, *o->version_addendum == '\0'
2550: ? "none" : o->version_addendum);
1.231 djm 2551: dump_cfg_string(sAuthorizedKeysCommand, o->authorized_keys_command);
2552: dump_cfg_string(sAuthorizedKeysCommandUser, o->authorized_keys_command_user);
1.270 djm 2553: dump_cfg_string(sAuthorizedPrincipalsCommand, o->authorized_principals_command);
2554: dump_cfg_string(sAuthorizedPrincipalsCommandUser, o->authorized_principals_command_user);
1.240 markus 2555: dump_cfg_string(sHostKeyAgent, o->host_key_agent);
1.252 djm 2556: dump_cfg_string(sKexAlgorithms,
1.253 djm 2557: o->kex_algorithms ? o->kex_algorithms : KEX_SERVER_KEX);
1.341 djm 2558: dump_cfg_string(sCASignatureAlgorithms, o->ca_sign_algorithms ?
2559: o->ca_sign_algorithms : SSH_ALLOWED_CA_SIGALGS);
1.258 djm 2560: dump_cfg_string(sHostbasedAcceptedKeyTypes, o->hostbased_key_types ?
2561: o->hostbased_key_types : KEX_DEFAULT_PK_ALG);
1.276 markus 2562: dump_cfg_string(sHostKeyAlgorithms, o->hostkeyalgorithms ?
2563: o->hostkeyalgorithms : KEX_DEFAULT_PK_ALG);
1.258 djm 2564: dump_cfg_string(sPubkeyAcceptedKeyTypes, o->pubkey_key_types ?
2565: o->pubkey_key_types : KEX_DEFAULT_PK_ALG);
1.316 djm 2566: dump_cfg_string(sRDomain, o->routing_domain);
1.182 dtucker 2567:
2568: /* string arguments requiring a lookup */
2569: dump_cfg_string(sLogLevel, log_level_name(o->log_level));
2570: dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
2571:
2572: /* string array arguments */
1.219 djm 2573: dump_cfg_strarray_oneline(sAuthorizedKeysFile, o->num_authkeys_files,
2574: o->authorized_keys_files);
1.182 dtucker 2575: dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
2576: o->host_key_files);
1.261 dtucker 2577: dump_cfg_strarray(sHostCertificate, o->num_host_cert_files,
1.203 djm 2578: o->host_cert_files);
1.182 dtucker 2579: dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
2580: dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
2581: dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
2582: dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
2583: dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
1.332 djm 2584: dump_cfg_strarray(sSetEnv, o->num_setenv, o->setenv);
1.232 djm 2585: dump_cfg_strarray_oneline(sAuthenticationMethods,
2586: o->num_auth_methods, o->auth_methods);
1.182 dtucker 2587:
2588: /* other arguments */
2589: for (i = 0; i < o->num_subsystems; i++)
2590: printf("subsystem %s %s\n", o->subsystem_name[i],
2591: o->subsystem_args[i]);
2592:
2593: printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
2594: o->max_startups_rate, o->max_startups);
2595:
1.318 djm 2596: s = NULL;
2597: for (i = 0; tunmode_desc[i].val != -1; i++) {
1.182 dtucker 2598: if (tunmode_desc[i].val == o->permit_tun) {
2599: s = tunmode_desc[i].text;
2600: break;
2601: }
1.318 djm 2602: }
1.182 dtucker 2603: dump_cfg_string(sPermitTunnel, s);
1.213 djm 2604:
1.214 stevesk 2605: printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
2606: printf("%s\n", iptos2str(o->ip_qos_bulk));
1.235 dtucker 2607:
1.284 dtucker 2608: printf("rekeylimit %llu %d\n", (unsigned long long)o->rekey_limit,
1.241 djm 2609: o->rekey_interval);
1.182 dtucker 2610:
1.310 djm 2611: printf("permitopen");
2612: if (o->num_permitted_opens == 0)
2613: printf(" any");
2614: else {
2615: for (i = 0; i < o->num_permitted_opens; i++)
2616: printf(" %s", o->permitted_opens[i]);
1.329 djm 2617: }
2618: printf("\n");
1.330 djm 2619: printf("permitlisten");
2620: if (o->num_permitted_listens == 0)
1.329 djm 2621: printf(" any");
2622: else {
1.330 djm 2623: for (i = 0; i < o->num_permitted_listens; i++)
2624: printf(" %s", o->permitted_listens[i]);
1.310 djm 2625: }
2626: printf("\n");
1.334 djm 2627:
2628: if (o->permit_user_env_whitelist == NULL) {
2629: dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
2630: } else {
2631: printf("permituserenvironment %s\n",
2632: o->permit_user_env_whitelist);
2633: }
2634:
1.1 deraadt 2635: }