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