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