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