Annotation of src/usr.bin/ssh/servconf.c, Revision 1.368
1.226 dtucker 1:
1.368 ! djm 2: /* $OpenBSD: servconf.c,v 1.367 2020/07/05 23:59:45 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.226 dtucker 1061: result = 0;
1062: continue;
1063: }
1.319 dtucker 1064: if (ci->address == NULL)
1065: match_test_missing_fatal("Address", "addr");
1.226 dtucker 1066: switch (addr_match_list(ci->address, arg)) {
1.181 djm 1067: case 1:
1068: debug("connection from %.100s matched 'Address "
1.226 dtucker 1069: "%.100s' at line %d", ci->address, arg, line);
1.181 djm 1070: break;
1071: case 0:
1.183 djm 1072: case -1:
1.153 dtucker 1073: result = 0;
1.181 djm 1074: break;
1.183 djm 1075: case -2:
1.181 djm 1076: return -1;
1.153 dtucker 1077: }
1.226 dtucker 1078: } else if (strcasecmp(attrib, "localaddress") == 0){
1.351 dtucker 1079: if (ci == NULL || (ci->test && ci->laddress == NULL)) {
1.226 dtucker 1080: result = 0;
1081: continue;
1082: }
1.319 dtucker 1083: if (ci->laddress == NULL)
1084: match_test_missing_fatal("LocalAddress",
1085: "laddr");
1.226 dtucker 1086: switch (addr_match_list(ci->laddress, arg)) {
1087: case 1:
1088: debug("connection from %.100s matched "
1089: "'LocalAddress %.100s' at line %d",
1090: ci->laddress, arg, line);
1091: break;
1092: case 0:
1093: case -1:
1094: result = 0;
1095: break;
1096: case -2:
1097: return -1;
1098: }
1099: } else if (strcasecmp(attrib, "localport") == 0) {
1100: if ((port = a2port(arg)) == -1) {
1101: error("Invalid LocalPort '%s' on Match line",
1102: arg);
1103: return -1;
1104: }
1.351 dtucker 1105: if (ci == NULL || (ci->test && ci->lport == -1)) {
1.226 dtucker 1106: result = 0;
1107: continue;
1108: }
1.319 dtucker 1109: if (ci->lport == 0)
1110: match_test_missing_fatal("LocalPort", "lport");
1.226 dtucker 1111: /* TODO support port lists */
1112: if (port == ci->lport)
1113: debug("connection from %.100s matched "
1114: "'LocalPort %d' at line %d",
1115: ci->laddress, port, line);
1116: else
1117: result = 0;
1.317 djm 1118: } else if (strcasecmp(attrib, "rdomain") == 0) {
1.351 dtucker 1119: if (ci == NULL || (ci->test && ci->rdomain == NULL)) {
1.317 djm 1120: result = 0;
1121: continue;
1122: }
1.351 dtucker 1123: if (ci->rdomain == NULL)
1124: match_test_missing_fatal("RDomain", "rdomain");
1.317 djm 1125: if (match_pattern_list(ci->rdomain, arg, 0) != 1)
1126: result = 0;
1127: else
1128: debug("user %.100s matched 'RDomain %.100s' at "
1129: "line %d", ci->rdomain, arg, line);
1.153 dtucker 1130: } else {
1131: error("Unsupported Match attribute %s", attrib);
1132: return -1;
1133: }
1.243 dtucker 1134: }
1135: if (attributes == 0) {
1136: error("One or more attributes required for Match");
1137: return -1;
1.153 dtucker 1138: }
1.226 dtucker 1139: if (ci != NULL)
1.153 dtucker 1140: debug3("match %sfound", result ? "" : "not ");
1141: *condition = cp;
1142: return result;
1143: }
1144:
1.158 dtucker 1145: #define WHITESPACE " \t\r\n"
1146:
1.220 djm 1147: /* Multistate option parsing */
1148: struct multistate {
1149: char *key;
1150: int value;
1151: };
1.320 djm 1152: static const struct multistate multistate_flag[] = {
1153: { "yes", 1 },
1154: { "no", 0 },
1155: { NULL, -1 }
1156: };
1.363 djm 1157: static const struct multistate multistate_ignore_rhosts[] = {
1158: { "yes", IGNORE_RHOSTS_YES },
1159: { "no", IGNORE_RHOSTS_NO },
1160: { "shosts-only", IGNORE_RHOSTS_SHOSTS },
1161: { NULL, -1 }
1162: };
1.220 djm 1163: static const struct multistate multistate_addressfamily[] = {
1164: { "inet", AF_INET },
1165: { "inet6", AF_INET6 },
1166: { "any", AF_UNSPEC },
1167: { NULL, -1 }
1168: };
1169: static const struct multistate multistate_permitrootlogin[] = {
1170: { "without-password", PERMIT_NO_PASSWD },
1.280 deraadt 1171: { "prohibit-password", PERMIT_NO_PASSWD },
1.220 djm 1172: { "forced-commands-only", PERMIT_FORCED_ONLY },
1173: { "yes", PERMIT_YES },
1174: { "no", PERMIT_NO },
1175: { NULL, -1 }
1176: };
1177: static const struct multistate multistate_compression[] = {
1.359 dtucker 1178: #ifdef WITH_ZLIB
1.337 sf 1179: { "yes", COMP_DELAYED },
1180: { "delayed", COMP_DELAYED },
1.359 dtucker 1181: #endif
1.220 djm 1182: { "no", COMP_NONE },
1183: { NULL, -1 }
1184: };
1185: static const struct multistate multistate_gatewayports[] = {
1186: { "clientspecified", 2 },
1187: { "yes", 1 },
1188: { "no", 0 },
1.222 djm 1189: { NULL, -1 }
1190: };
1.233 djm 1191: static const struct multistate multistate_tcpfwd[] = {
1192: { "yes", FORWARD_ALLOW },
1193: { "all", FORWARD_ALLOW },
1194: { "no", FORWARD_DENY },
1195: { "remote", FORWARD_REMOTE },
1196: { "local", FORWARD_LOCAL },
1197: { NULL, -1 }
1198: };
1.220 djm 1199:
1.360 djm 1200: static int
1201: process_server_config_line_depth(ServerOptions *options, char *line,
1.226 dtucker 1202: const char *filename, int linenum, int *activep,
1.365 djm 1203: struct connection_info *connectinfo, int *inc_flags, int depth,
1.360 djm 1204: struct include_list *includes)
1.1 deraadt 1205: {
1.348 dtucker 1206: char ch, *cp, ***chararrayptr, **charptr, *arg, *arg2, *p;
1.360 djm 1207: int cmdline = 0, *intptr, value, value2, n, port, oactive, r, found;
1.174 dtucker 1208: SyslogFacility *log_facility_ptr;
1209: LogLevel *log_level_ptr;
1.25 markus 1210: ServerOpCodes opcode;
1.329 djm 1211: u_int i, *uintptr, uvalue, flags = 0;
1.151 djm 1212: size_t len;
1.237 dtucker 1213: long long val64;
1.220 djm 1214: const struct multistate *multistate_ptr;
1.322 dtucker 1215: const char *errstr;
1.360 djm 1216: struct include_item *item;
1217: glob_t gbuf;
1.303 djm 1218:
1219: /* Strip trailing whitespace. Allow \f (form feed) at EOL only */
1220: if ((len = strlen(line)) == 0)
1221: return 0;
1222: for (len--; len > 0; len--) {
1223: if (strchr(WHITESPACE "\f", line[len]) == NULL)
1224: break;
1225: line[len] = '\0';
1226: }
1.25 markus 1227:
1.94 markus 1228: cp = line;
1.148 dtucker 1229: if ((arg = strdelim(&cp)) == NULL)
1.147 djm 1230: return 0;
1.94 markus 1231: /* Ignore leading whitespace */
1232: if (*arg == '\0')
1233: arg = strdelim(&cp);
1234: if (!arg || !*arg || *arg == '#')
1235: return 0;
1236: intptr = NULL;
1237: charptr = NULL;
1.153 dtucker 1238: opcode = parse_token(arg, filename, linenum, &flags);
1239:
1240: if (activep == NULL) { /* We are processing a command line directive */
1241: cmdline = 1;
1242: activep = &cmdline;
1243: }
1.360 djm 1244: if (*activep && opcode != sMatch && opcode != sInclude)
1.153 dtucker 1245: debug3("%s:%d setting %s %s", filename, linenum, arg, cp);
1246: if (*activep == 0 && !(flags & SSHCFG_MATCH)) {
1.226 dtucker 1247: if (connectinfo == NULL) {
1.153 dtucker 1248: fatal("%s line %d: Directive '%s' is not allowed "
1249: "within a Match block", filename, linenum, arg);
1250: } else { /* this is a directive we have already processed */
1251: while (arg)
1252: arg = strdelim(&cp);
1253: return 0;
1254: }
1255: }
1256:
1.94 markus 1257: switch (opcode) {
1258: case sBadOption:
1259: return -1;
1260: case sPort:
1261: /* ignore ports from configfile if cmdline specifies ports */
1262: if (options->ports_from_cmdline)
1263: return 0;
1264: if (options->num_ports >= MAX_PORTS)
1265: fatal("%s line %d: too many ports.",
1266: filename, linenum);
1.48 provos 1267: arg = strdelim(&cp);
1.94 markus 1268: if (!arg || *arg == '\0')
1269: fatal("%s line %d: missing port number.",
1270: filename, linenum);
1271: options->ports[options->num_ports++] = a2port(arg);
1.194 djm 1272: if (options->ports[options->num_ports-1] <= 0)
1.94 markus 1273: fatal("%s line %d: Badly formatted port number.",
1274: filename, linenum);
1275: break;
1.29 markus 1276:
1.94 markus 1277: case sLoginGraceTime:
1278: intptr = &options->login_grace_time;
1.180 djm 1279: parse_time:
1.94 markus 1280: arg = strdelim(&cp);
1281: if (!arg || *arg == '\0')
1282: fatal("%s line %d: missing time value.",
1283: filename, linenum);
1284: if ((value = convtime(arg)) == -1)
1285: fatal("%s line %d: invalid time value.",
1286: filename, linenum);
1.268 djm 1287: if (*activep && *intptr == -1)
1.94 markus 1288: *intptr = value;
1289: break;
1290:
1291: case sListenAddress:
1292: arg = strdelim(&cp);
1.139 djm 1293: if (arg == NULL || *arg == '\0')
1294: fatal("%s line %d: missing address",
1.94 markus 1295: filename, linenum);
1.144 dtucker 1296: /* check for bare IPv6 address: no "[]" and 2 or more ":" */
1297: if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL
1298: && strchr(p+1, ':') != NULL) {
1.315 djm 1299: port = 0;
1300: p = arg;
1301: } else {
1.347 dtucker 1302: arg2 = NULL;
1.348 dtucker 1303: ch = '\0';
1.347 dtucker 1304: p = hpdelim2(&arg, &ch);
1305: if (p == NULL || ch == '/')
1.315 djm 1306: fatal("%s line %d: bad address:port usage",
1307: filename, linenum);
1308: p = cleanhostname(p);
1309: if (arg == NULL)
1310: port = 0;
1311: else if ((port = a2port(arg)) <= 0)
1312: fatal("%s line %d: bad port number",
1313: filename, linenum);
1314: }
1315: /* Optional routing table */
1316: arg2 = NULL;
1317: if ((arg = strdelim(&cp)) != NULL) {
1318: if (strcmp(arg, "rdomain") != 0 ||
1319: (arg2 = strdelim(&cp)) == NULL)
1320: fatal("%s line %d: bad ListenAddress syntax",
1321: filename, linenum);
1322: if (!valid_rdomain(arg2))
1323: fatal("%s line %d: bad routing domain",
1324: filename, linenum);
1.144 dtucker 1325: }
1.139 djm 1326:
1.315 djm 1327: queue_listen_addr(options, p, arg2, port);
1.25 markus 1328:
1.138 djm 1329: break;
1330:
1331: case sAddressFamily:
1.220 djm 1332: intptr = &options->address_family;
1333: multistate_ptr = multistate_addressfamily;
1334: parse_multistate:
1.138 djm 1335: arg = strdelim(&cp);
1.141 markus 1336: if (!arg || *arg == '\0')
1.220 djm 1337: fatal("%s line %d: missing argument.",
1.141 markus 1338: filename, linenum);
1.220 djm 1339: value = -1;
1340: for (i = 0; multistate_ptr[i].key != NULL; i++) {
1341: if (strcasecmp(arg, multistate_ptr[i].key) == 0) {
1342: value = multistate_ptr[i].value;
1343: break;
1344: }
1345: }
1346: if (value == -1)
1347: fatal("%s line %d: unsupported option \"%s\".",
1.138 djm 1348: filename, linenum, arg);
1.220 djm 1349: if (*activep && *intptr == -1)
1.138 djm 1350: *intptr = value;
1.94 markus 1351: break;
1352:
1353: case sHostKeyFile:
1354: arg = strdelim(&cp);
1355: if (!arg || *arg == '\0')
1356: fatal("%s line %d: missing file name.",
1357: filename, linenum);
1.344 djm 1358: if (*activep) {
1359: servconf_add_hostkey(filename, linenum,
1360: options, arg, 1);
1361: }
1.94 markus 1362: break;
1.76 stevesk 1363:
1.240 markus 1364: case sHostKeyAgent:
1365: charptr = &options->host_key_agent;
1366: arg = strdelim(&cp);
1367: if (!arg || *arg == '\0')
1368: fatal("%s line %d: missing socket name.",
1369: filename, linenum);
1370: if (*activep && *charptr == NULL)
1371: *charptr = !strcmp(arg, SSH_AUTHSOCKET_ENV_NAME) ?
1372: xstrdup(arg) : derelativise_path(arg);
1373: break;
1374:
1.203 djm 1375: case sHostCertificate:
1.314 djm 1376: arg = strdelim(&cp);
1377: if (!arg || *arg == '\0')
1378: fatal("%s line %d: missing file name.",
1379: filename, linenum);
1380: if (*activep)
1381: servconf_add_hostcert(filename, linenum, options, arg);
1382: break;
1.203 djm 1383:
1.94 markus 1384: case sPidFile:
1385: charptr = &options->pid_file;
1.314 djm 1386: parse_filename:
1387: arg = strdelim(&cp);
1388: if (!arg || *arg == '\0')
1389: fatal("%s line %d: missing file name.",
1390: filename, linenum);
1391: if (*activep && *charptr == NULL) {
1392: *charptr = derelativise_path(arg);
1393: /* increase optional counter */
1394: if (intptr != NULL)
1395: *intptr = *intptr + 1;
1396: }
1397: break;
1.25 markus 1398:
1.94 markus 1399: case sPermitRootLogin:
1400: intptr = &options->permit_root_login;
1.220 djm 1401: multistate_ptr = multistate_permitrootlogin;
1402: goto parse_multistate;
1.36 markus 1403:
1.94 markus 1404: case sIgnoreRhosts:
1405: intptr = &options->ignore_rhosts;
1.363 djm 1406: multistate_ptr = multistate_ignore_rhosts;
1.320 djm 1407: goto parse_multistate;
1.94 markus 1408:
1409: case sIgnoreUserKnownHosts:
1410: intptr = &options->ignore_user_known_hosts;
1.363 djm 1411: parse_flag:
1412: multistate_ptr = multistate_flag;
1413: goto parse_multistate;
1.94 markus 1414:
1415: case sHostbasedAuthentication:
1416: intptr = &options->hostbased_authentication;
1417: goto parse_flag;
1418:
1419: case sHostbasedUsesNameFromPacketOnly:
1420: intptr = &options->hostbased_uses_name_from_packet_only;
1421: goto parse_flag;
1422:
1.258 djm 1423: case sHostbasedAcceptedKeyTypes:
1424: charptr = &options->hostbased_key_types;
1425: parse_keytypes:
1426: arg = strdelim(&cp);
1427: if (!arg || *arg == '\0')
1428: fatal("%s line %d: Missing argument.",
1429: filename, linenum);
1.304 djm 1430: if (*arg != '-' &&
1.352 naddy 1431: !sshkey_names_valid2(*arg == '+' || *arg == '^' ?
1432: arg + 1 : arg, 1))
1.258 djm 1433: fatal("%s line %d: Bad key types '%s'.",
1434: filename, linenum, arg ? arg : "<NONE>");
1435: if (*activep && *charptr == NULL)
1436: *charptr = xstrdup(arg);
1437: break;
1438:
1.276 markus 1439: case sHostKeyAlgorithms:
1440: charptr = &options->hostkeyalgorithms;
1441: goto parse_keytypes;
1442:
1.341 djm 1443: case sCASignatureAlgorithms:
1444: charptr = &options->ca_sign_algorithms;
1445: goto parse_keytypes;
1446:
1.94 markus 1447: case sPubkeyAuthentication:
1448: intptr = &options->pubkey_authentication;
1449: goto parse_flag;
1.119 jakob 1450:
1.258 djm 1451: case sPubkeyAcceptedKeyTypes:
1452: charptr = &options->pubkey_key_types;
1453: goto parse_keytypes;
1454:
1.354 djm 1455: case sPubkeyAuthOptions:
1456: intptr = &options->pubkey_auth_options;
1457: value = 0;
1458: while ((arg = strdelim(&cp)) && *arg != '\0') {
1459: if (strcasecmp(arg, "none") == 0)
1460: continue;
1461: if (strcasecmp(arg, "touch-required") == 0)
1462: value |= PUBKEYAUTH_TOUCH_REQUIRED;
1.368 ! djm 1463: else if (strcasecmp(arg, "verify-required") == 0)
! 1464: value |= PUBKEYAUTH_VERIFY_REQUIRED;
1.354 djm 1465: else {
1466: fatal("%s line %d: unsupported "
1467: "PubkeyAuthOptions option %s",
1468: filename, linenum, arg);
1469: }
1470: }
1471: if (*activep && *intptr == -1)
1472: *intptr = value;
1473: break;
1474:
1.94 markus 1475: case sKerberosAuthentication:
1476: intptr = &options->kerberos_authentication;
1477: goto parse_flag;
1478:
1479: case sKerberosOrLocalPasswd:
1480: intptr = &options->kerberos_or_local_passwd;
1481: goto parse_flag;
1482:
1483: case sKerberosTicketCleanup:
1484: intptr = &options->kerberos_ticket_cleanup;
1.130 jakob 1485: goto parse_flag;
1486:
1487: case sKerberosGetAFSToken:
1488: intptr = &options->kerberos_get_afs_token;
1.125 markus 1489: goto parse_flag;
1490:
1491: case sGssAuthentication:
1492: intptr = &options->gss_authentication;
1493: goto parse_flag;
1494:
1495: case sGssCleanupCreds:
1496: intptr = &options->gss_cleanup_creds;
1.271 djm 1497: goto parse_flag;
1498:
1499: case sGssStrictAcceptor:
1500: intptr = &options->gss_strict_acceptor;
1.94 markus 1501: goto parse_flag;
1502:
1503: case sPasswordAuthentication:
1504: intptr = &options->password_authentication;
1505: goto parse_flag;
1506:
1507: case sKbdInteractiveAuthentication:
1508: intptr = &options->kbd_interactive_authentication;
1509: goto parse_flag;
1510:
1511: case sChallengeResponseAuthentication:
1512: intptr = &options->challenge_response_authentication;
1513: goto parse_flag;
1514:
1515: case sPrintMotd:
1516: intptr = &options->print_motd;
1517: goto parse_flag;
1518:
1519: case sPrintLastLog:
1520: intptr = &options->print_lastlog;
1521: goto parse_flag;
1522:
1523: case sX11Forwarding:
1524: intptr = &options->x11_forwarding;
1525: goto parse_flag;
1526:
1527: case sX11DisplayOffset:
1528: intptr = &options->x11_display_offset;
1.293 naddy 1529: parse_int:
1530: arg = strdelim(&cp);
1.322 dtucker 1531: if ((errstr = atoi_err(arg, &value)) != NULL)
1532: fatal("%s line %d: integer value %s.",
1533: filename, linenum, errstr);
1.293 naddy 1534: if (*activep && *intptr == -1)
1535: *intptr = value;
1536: break;
1.99 stevesk 1537:
1538: case sX11UseLocalhost:
1539: intptr = &options->x11_use_localhost;
1540: goto parse_flag;
1.94 markus 1541:
1542: case sXAuthLocation:
1543: charptr = &options->xauth_location;
1544: goto parse_filename;
1545:
1.244 djm 1546: case sPermitTTY:
1547: intptr = &options->permit_tty;
1548: goto parse_flag;
1549:
1.250 djm 1550: case sPermitUserRC:
1551: intptr = &options->permit_user_rc;
1552: goto parse_flag;
1553:
1.94 markus 1554: case sStrictModes:
1555: intptr = &options->strict_modes;
1556: goto parse_flag;
1557:
1.129 markus 1558: case sTCPKeepAlive:
1559: intptr = &options->tcp_keep_alive;
1.94 markus 1560: goto parse_flag;
1561:
1562: case sEmptyPasswd:
1563: intptr = &options->permit_empty_passwd;
1.113 markus 1564: goto parse_flag;
1565:
1566: case sPermitUserEnvironment:
1567: intptr = &options->permit_user_env;
1.367 djm 1568: charptr = &options->permit_user_env_allowlist;
1.334 djm 1569: arg = strdelim(&cp);
1570: if (!arg || *arg == '\0')
1571: fatal("%s line %d: missing argument.",
1572: filename, linenum);
1573: value = 0;
1574: p = NULL;
1575: if (strcmp(arg, "yes") == 0)
1576: value = 1;
1577: else if (strcmp(arg, "no") == 0)
1578: value = 0;
1579: else {
1580: /* Pattern-list specified */
1581: value = 1;
1582: p = xstrdup(arg);
1583: }
1584: if (*activep && *intptr == -1) {
1585: *intptr = value;
1586: *charptr = p;
1587: p = NULL;
1588: }
1589: free(p);
1590: break;
1.94 markus 1591:
1.111 markus 1592: case sCompression:
1593: intptr = &options->compression;
1.220 djm 1594: multistate_ptr = multistate_compression;
1595: goto parse_multistate;
1.94 markus 1596:
1.235 dtucker 1597: case sRekeyLimit:
1598: arg = strdelim(&cp);
1599: if (!arg || *arg == '\0')
1600: fatal("%.200s line %d: Missing argument.", filename,
1601: linenum);
1602: if (strcmp(arg, "default") == 0) {
1603: val64 = 0;
1604: } else {
1.236 dtucker 1605: if (scan_scaled(arg, &val64) == -1)
1606: fatal("%.200s line %d: Bad number '%s': %s",
1607: filename, linenum, arg, strerror(errno));
1.235 dtucker 1608: if (val64 != 0 && val64 < 16)
1609: fatal("%.200s line %d: RekeyLimit too small",
1610: filename, linenum);
1611: }
1612: if (*activep && options->rekey_limit == -1)
1.284 dtucker 1613: options->rekey_limit = val64;
1.235 dtucker 1614: if (cp != NULL) { /* optional rekey interval present */
1615: if (strcmp(cp, "none") == 0) {
1616: (void)strdelim(&cp); /* discard */
1617: break;
1618: }
1619: intptr = &options->rekey_interval;
1620: goto parse_time;
1621: }
1622: break;
1623:
1.94 markus 1624: case sGatewayPorts:
1.251 millert 1625: intptr = &options->fwd_opts.gateway_ports;
1.220 djm 1626: multistate_ptr = multistate_gatewayports;
1627: goto parse_multistate;
1.25 markus 1628:
1.122 markus 1629: case sUseDNS:
1630: intptr = &options->use_dns;
1.94 markus 1631: goto parse_flag;
1.53 markus 1632:
1.94 markus 1633: case sLogFacility:
1.174 dtucker 1634: log_facility_ptr = &options->log_facility;
1.94 markus 1635: arg = strdelim(&cp);
1636: value = log_facility_number(arg);
1.101 markus 1637: if (value == SYSLOG_FACILITY_NOT_SET)
1.94 markus 1638: fatal("%.200s line %d: unsupported log facility '%s'",
1639: filename, linenum, arg ? arg : "<NONE>");
1.174 dtucker 1640: if (*log_facility_ptr == -1)
1641: *log_facility_ptr = (SyslogFacility) value;
1.94 markus 1642: break;
1.25 markus 1643:
1.94 markus 1644: case sLogLevel:
1.174 dtucker 1645: log_level_ptr = &options->log_level;
1.94 markus 1646: arg = strdelim(&cp);
1647: value = log_level_number(arg);
1.101 markus 1648: if (value == SYSLOG_LEVEL_NOT_SET)
1.94 markus 1649: fatal("%.200s line %d: unsupported log level '%s'",
1650: filename, linenum, arg ? arg : "<NONE>");
1.308 djm 1651: if (*activep && *log_level_ptr == -1)
1.174 dtucker 1652: *log_level_ptr = (LogLevel) value;
1.94 markus 1653: break;
1654:
1655: case sAllowTcpForwarding:
1656: intptr = &options->allow_tcp_forwarding;
1.233 djm 1657: multistate_ptr = multistate_tcpfwd;
1658: goto parse_multistate;
1.102 provos 1659:
1.251 millert 1660: case sAllowStreamLocalForwarding:
1661: intptr = &options->allow_streamlocal_forwarding;
1662: multistate_ptr = multistate_tcpfwd;
1663: goto parse_multistate;
1664:
1.178 pyr 1665: case sAllowAgentForwarding:
1666: intptr = &options->allow_agent_forwarding;
1667: goto parse_flag;
1668:
1.301 djm 1669: case sDisableForwarding:
1670: intptr = &options->disable_forwarding;
1671: goto parse_flag;
1672:
1.94 markus 1673: case sAllowUsers:
1674: while ((arg = strdelim(&cp)) && *arg != '\0') {
1.299 djm 1675: if (match_user(NULL, NULL, NULL, arg) == -1)
1676: fatal("%s line %d: invalid AllowUsers pattern: "
1677: "\"%.100s\"", filename, linenum, arg);
1.227 markus 1678: if (!*activep)
1679: continue;
1.314 djm 1680: array_append(filename, linenum, "AllowUsers",
1681: &options->allow_users, &options->num_allow_users,
1682: arg);
1.94 markus 1683: }
1684: break;
1.25 markus 1685:
1.94 markus 1686: case sDenyUsers:
1687: while ((arg = strdelim(&cp)) && *arg != '\0') {
1.299 djm 1688: if (match_user(NULL, NULL, NULL, arg) == -1)
1689: fatal("%s line %d: invalid DenyUsers pattern: "
1690: "\"%.100s\"", filename, linenum, arg);
1.227 markus 1691: if (!*activep)
1692: continue;
1.314 djm 1693: array_append(filename, linenum, "DenyUsers",
1694: &options->deny_users, &options->num_deny_users,
1695: arg);
1.94 markus 1696: }
1697: break;
1.25 markus 1698:
1.94 markus 1699: case sAllowGroups:
1700: while ((arg = strdelim(&cp)) && *arg != '\0') {
1.227 markus 1701: if (!*activep)
1702: continue;
1.314 djm 1703: array_append(filename, linenum, "AllowGroups",
1704: &options->allow_groups, &options->num_allow_groups,
1705: arg);
1.94 markus 1706: }
1707: break;
1.33 markus 1708:
1.94 markus 1709: case sDenyGroups:
1710: while ((arg = strdelim(&cp)) && *arg != '\0') {
1.227 markus 1711: if (!*activep)
1712: continue;
1.314 djm 1713: array_append(filename, linenum, "DenyGroups",
1714: &options->deny_groups, &options->num_deny_groups,
1715: arg);
1.94 markus 1716: }
1717: break;
1.66 markus 1718:
1.94 markus 1719: case sCiphers:
1720: arg = strdelim(&cp);
1721: if (!arg || *arg == '\0')
1722: fatal("%s line %d: Missing argument.", filename, linenum);
1.352 naddy 1723: if (*arg != '-' &&
1724: !ciphers_valid(*arg == '+' || *arg == '^' ? arg + 1 : arg))
1.94 markus 1725: fatal("%s line %d: Bad SSH2 cipher spec '%s'.",
1726: filename, linenum, arg ? arg : "<NONE>");
1727: if (options->ciphers == NULL)
1728: options->ciphers = xstrdup(arg);
1729: break;
1.33 markus 1730:
1.94 markus 1731: case sMacs:
1732: arg = strdelim(&cp);
1733: if (!arg || *arg == '\0')
1734: fatal("%s line %d: Missing argument.", filename, linenum);
1.352 naddy 1735: if (*arg != '-' &&
1736: !mac_valid(*arg == '+' || *arg == '^' ? arg + 1 : arg))
1.94 markus 1737: fatal("%s line %d: Bad SSH2 mac spec '%s'.",
1738: filename, linenum, arg ? arg : "<NONE>");
1739: if (options->macs == NULL)
1740: options->macs = xstrdup(arg);
1.211 djm 1741: break;
1742:
1743: case sKexAlgorithms:
1744: arg = strdelim(&cp);
1745: if (!arg || *arg == '\0')
1746: fatal("%s line %d: Missing argument.",
1747: filename, linenum);
1.304 djm 1748: if (*arg != '-' &&
1.352 naddy 1749: !kex_names_valid(*arg == '+' || *arg == '^' ?
1750: arg + 1 : arg))
1.211 djm 1751: fatal("%s line %d: Bad SSH2 KexAlgorithms '%s'.",
1752: filename, linenum, arg ? arg : "<NONE>");
1753: if (options->kex_algorithms == NULL)
1754: options->kex_algorithms = xstrdup(arg);
1.94 markus 1755: break;
1.43 jakob 1756:
1.94 markus 1757: case sSubsystem:
1758: if (options->num_subsystems >= MAX_SUBSYSTEMS) {
1759: fatal("%s line %d: too many subsystems defined.",
1.95 deraadt 1760: filename, linenum);
1.94 markus 1761: }
1762: arg = strdelim(&cp);
1763: if (!arg || *arg == '\0')
1764: fatal("%s line %d: Missing subsystem name.",
1.95 deraadt 1765: filename, linenum);
1.153 dtucker 1766: if (!*activep) {
1767: arg = strdelim(&cp);
1768: break;
1769: }
1.94 markus 1770: for (i = 0; i < options->num_subsystems; i++)
1771: if (strcmp(arg, options->subsystem_name[i]) == 0)
1772: fatal("%s line %d: Subsystem '%s' already defined.",
1.95 deraadt 1773: filename, linenum, arg);
1.94 markus 1774: options->subsystem_name[options->num_subsystems] = xstrdup(arg);
1775: arg = strdelim(&cp);
1776: if (!arg || *arg == '\0')
1777: fatal("%s line %d: Missing subsystem command.",
1.95 deraadt 1778: filename, linenum);
1.94 markus 1779: options->subsystem_command[options->num_subsystems] = xstrdup(arg);
1.151 djm 1780:
1781: /* Collect arguments (separate to executable) */
1782: p = xstrdup(arg);
1783: len = strlen(p) + 1;
1784: while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1785: len += 1 + strlen(arg);
1.264 deraadt 1786: p = xreallocarray(p, 1, len);
1.151 djm 1787: strlcat(p, " ", len);
1788: strlcat(p, arg, len);
1789: }
1790: options->subsystem_args[options->num_subsystems] = p;
1.94 markus 1791: options->num_subsystems++;
1792: break;
1.46 markus 1793:
1.94 markus 1794: case sMaxStartups:
1795: arg = strdelim(&cp);
1796: if (!arg || *arg == '\0')
1797: fatal("%s line %d: Missing MaxStartups spec.",
1.95 deraadt 1798: filename, linenum);
1.94 markus 1799: if ((n = sscanf(arg, "%d:%d:%d",
1800: &options->max_startups_begin,
1801: &options->max_startups_rate,
1802: &options->max_startups)) == 3) {
1803: if (options->max_startups_begin >
1804: options->max_startups ||
1805: options->max_startups_rate > 100 ||
1806: options->max_startups_rate < 1)
1.50 markus 1807: fatal("%s line %d: Illegal MaxStartups spec.",
1.87 stevesk 1808: filename, linenum);
1.94 markus 1809: } else if (n != 1)
1810: fatal("%s line %d: Illegal MaxStartups spec.",
1811: filename, linenum);
1812: else
1813: options->max_startups = options->max_startups_begin;
1814: break;
1.133 dtucker 1815:
1816: case sMaxAuthTries:
1817: intptr = &options->max_authtries;
1818: goto parse_int;
1.94 markus 1819:
1.180 djm 1820: case sMaxSessions:
1821: intptr = &options->max_sessions;
1822: goto parse_int;
1823:
1.94 markus 1824: case sBanner:
1825: charptr = &options->banner;
1826: goto parse_filename;
1.176 djm 1827:
1.94 markus 1828: /*
1829: * These options can contain %X options expanded at
1830: * connect time, so that you can specify paths like:
1831: *
1832: * AuthorizedKeysFile /etc/ssh_keys/%u
1833: */
1834: case sAuthorizedKeysFile:
1.219 djm 1835: if (*activep && options->num_authkeys_files == 0) {
1836: while ((arg = strdelim(&cp)) && *arg != '\0') {
1.314 djm 1837: arg = tilde_expand_filename(arg, getuid());
1838: array_append(filename, linenum,
1839: "AuthorizedKeysFile",
1840: &options->authorized_keys_files,
1841: &options->num_authkeys_files, arg);
1842: free(arg);
1.219 djm 1843: }
1844: }
1845: return 0;
1846:
1.208 djm 1847: case sAuthorizedPrincipalsFile:
1848: charptr = &options->authorized_principals_file;
1.205 djm 1849: arg = strdelim(&cp);
1850: if (!arg || *arg == '\0')
1851: fatal("%s line %d: missing file name.",
1852: filename, linenum);
1853: if (*activep && *charptr == NULL) {
1.206 markus 1854: *charptr = tilde_expand_filename(arg, getuid());
1.205 djm 1855: /* increase optional counter */
1856: if (intptr != NULL)
1857: *intptr = *intptr + 1;
1858: }
1859: break;
1.94 markus 1860:
1861: case sClientAliveInterval:
1862: intptr = &options->client_alive_interval;
1863: goto parse_time;
1864:
1865: case sClientAliveCountMax:
1866: intptr = &options->client_alive_count_max;
1867: goto parse_int;
1.131 djm 1868:
1869: case sAcceptEnv:
1870: while ((arg = strdelim(&cp)) && *arg != '\0') {
1871: if (strchr(arg, '=') != NULL)
1872: fatal("%s line %d: Invalid environment name.",
1873: filename, linenum);
1.153 dtucker 1874: if (!*activep)
1.227 markus 1875: continue;
1.314 djm 1876: array_append(filename, linenum, "AcceptEnv",
1877: &options->accept_env, &options->num_accept_env,
1878: arg);
1.131 djm 1879: }
1880: break;
1.145 reyk 1881:
1.332 djm 1882: case sSetEnv:
1883: uvalue = options->num_setenv;
1884: while ((arg = strdelimw(&cp)) && *arg != '\0') {
1885: if (strchr(arg, '=') == NULL)
1886: fatal("%s line %d: Invalid environment.",
1887: filename, linenum);
1888: if (!*activep || uvalue != 0)
1889: continue;
1890: array_append(filename, linenum, "SetEnv",
1891: &options->setenv, &options->num_setenv, arg);
1892: }
1893: break;
1894:
1.145 reyk 1895: case sPermitTunnel:
1896: intptr = &options->permit_tun;
1.146 reyk 1897: arg = strdelim(&cp);
1898: if (!arg || *arg == '\0')
1899: fatal("%s line %d: Missing yes/point-to-point/"
1900: "ethernet/no argument.", filename, linenum);
1.182 dtucker 1901: value = -1;
1902: for (i = 0; tunmode_desc[i].val != -1; i++)
1903: if (strcmp(tunmode_desc[i].text, arg) == 0) {
1904: value = tunmode_desc[i].val;
1905: break;
1906: }
1907: if (value == -1)
1.146 reyk 1908: fatal("%s line %d: Bad yes/point-to-point/ethernet/"
1909: "no argument: %s", filename, linenum, arg);
1.268 djm 1910: if (*activep && *intptr == -1)
1.146 reyk 1911: *intptr = value;
1912: break;
1.94 markus 1913:
1.360 djm 1914: case sInclude:
1915: if (cmdline) {
1916: fatal("Include directive not supported as a "
1917: "command-line option");
1918: }
1919: value = 0;
1920: while ((arg2 = strdelim(&cp)) != NULL && *arg2 != '\0') {
1921: value++;
1922: found = 0;
1923: if (*arg2 != '/' && *arg2 != '~') {
1.361 markus 1924: xasprintf(&arg, "%s/%s", SSHDIR, arg2);
1.360 djm 1925: } else
1926: arg = xstrdup(arg2);
1927:
1928: /*
1929: * Don't let included files clobber the containing
1930: * file's Match state.
1931: */
1932: oactive = *activep;
1933:
1934: /* consult cache of include files */
1935: TAILQ_FOREACH(item, includes, entry) {
1936: if (strcmp(item->selector, arg) != 0)
1937: continue;
1938: if (item->filename != NULL) {
1939: parse_server_config_depth(options,
1940: item->filename, item->contents,
1941: includes, connectinfo,
1.365 djm 1942: (*inc_flags & SSHCFG_MATCH_ONLY
1943: ? SSHCFG_MATCH_ONLY : (oactive
1944: ? 0 : SSHCFG_NEVERMATCH)),
1.360 djm 1945: activep, depth + 1);
1946: }
1947: found = 1;
1948: *activep = oactive;
1949: }
1950: if (found != 0) {
1951: free(arg);
1952: continue;
1953: }
1954:
1955: /* requested glob was not in cache */
1956: debug2("%s line %d: new include %s",
1957: filename, linenum, arg);
1958: if ((r = glob(arg, 0, NULL, &gbuf)) != 0) {
1959: if (r != GLOB_NOMATCH) {
1960: fatal("%s line %d: include \"%s\" "
1961: "glob failed", filename,
1962: linenum, arg);
1963: }
1964: /*
1965: * If no entry matched then record a
1966: * placeholder to skip later glob calls.
1967: */
1968: debug2("%s line %d: no match for %s",
1969: filename, linenum, arg);
1970: item = xcalloc(1, sizeof(*item));
1971: item->selector = strdup(arg);
1972: TAILQ_INSERT_TAIL(includes,
1973: item, entry);
1974: }
1975: if (gbuf.gl_pathc > INT_MAX)
1976: fatal("%s: too many glob results", __func__);
1977: for (n = 0; n < (int)gbuf.gl_pathc; n++) {
1978: debug2("%s line %d: including %s",
1979: filename, linenum, gbuf.gl_pathv[n]);
1980: item = xcalloc(1, sizeof(*item));
1981: item->selector = strdup(arg);
1982: item->filename = strdup(gbuf.gl_pathv[n]);
1983: if ((item->contents = sshbuf_new()) == NULL) {
1984: fatal("%s: sshbuf_new failed",
1985: __func__);
1986: }
1987: load_server_config(item->filename,
1988: item->contents);
1989: parse_server_config_depth(options,
1990: item->filename, item->contents,
1991: includes, connectinfo,
1.365 djm 1992: (*inc_flags & SSHCFG_MATCH_ONLY
1993: ? SSHCFG_MATCH_ONLY : (oactive
1994: ? 0 : SSHCFG_NEVERMATCH)),
1.360 djm 1995: activep, depth + 1);
1996: *activep = oactive;
1997: TAILQ_INSERT_TAIL(includes, item, entry);
1998: }
1999: globfree(&gbuf);
2000: free(arg);
2001: }
2002: if (value == 0) {
2003: fatal("%s line %d: Include missing filename argument",
2004: filename, linenum);
2005: }
2006: break;
2007:
1.153 dtucker 2008: case sMatch:
2009: if (cmdline)
2010: fatal("Match directive not supported as a command-line "
2011: "option");
1.365 djm 2012: value = match_cfg_line(&cp, linenum,
2013: (*inc_flags & SSHCFG_NEVERMATCH ? NULL : connectinfo));
1.153 dtucker 2014: if (value < 0)
2015: fatal("%s line %d: Bad Match condition", filename,
2016: linenum);
1.365 djm 2017: *activep = (*inc_flags & SSHCFG_NEVERMATCH) ? 0 : value;
2018: /* The MATCH_ONLY is applicable only until the first match block */
2019: *inc_flags &= ~SSHCFG_MATCH_ONLY;
1.156 dtucker 2020: break;
2021:
1.330 djm 2022: case sPermitListen:
1.156 dtucker 2023: case sPermitOpen:
1.330 djm 2024: if (opcode == sPermitListen) {
2025: uintptr = &options->num_permitted_listens;
2026: chararrayptr = &options->permitted_listens;
1.329 djm 2027: } else {
2028: uintptr = &options->num_permitted_opens;
2029: chararrayptr = &options->permitted_opens;
2030: }
1.156 dtucker 2031: arg = strdelim(&cp);
2032: if (!arg || *arg == '\0')
1.329 djm 2033: fatal("%s line %d: missing %s specification",
2034: filename, linenum, lookup_opcode_name(opcode));
2035: uvalue = *uintptr; /* modified later */
1.310 djm 2036: if (strcmp(arg, "any") == 0 || strcmp(arg, "none") == 0) {
1.329 djm 2037: if (*activep && uvalue == 0) {
2038: *uintptr = 1;
2039: *chararrayptr = xcalloc(1,
2040: sizeof(**chararrayptr));
2041: (*chararrayptr)[0] = xstrdup(arg);
1.311 dtucker 2042: }
1.156 dtucker 2043: break;
2044: }
1.159 dtucker 2045: for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) {
1.333 djm 2046: if (opcode == sPermitListen &&
2047: strchr(arg, ':') == NULL) {
2048: /*
2049: * Allow bare port number for PermitListen
2050: * to indicate a wildcard listen host.
2051: */
2052: xasprintf(&arg2, "*:%s", arg);
2053: } else {
2054: arg2 = xstrdup(arg);
1.348 dtucker 2055: ch = '\0';
1.347 dtucker 2056: p = hpdelim2(&arg, &ch);
2057: if (p == NULL || ch == '/') {
1.333 djm 2058: fatal("%s line %d: missing host in %s",
2059: filename, linenum,
2060: lookup_opcode_name(opcode));
2061: }
2062: p = cleanhostname(p);
1.329 djm 2063: }
2064: if (arg == NULL ||
2065: ((port = permitopen_port(arg)) < 0)) {
2066: fatal("%s line %d: bad port number in %s",
2067: filename, linenum,
2068: lookup_opcode_name(opcode));
2069: }
2070: if (*activep && uvalue == 0) {
1.314 djm 2071: array_append(filename, linenum,
1.329 djm 2072: lookup_opcode_name(opcode),
2073: chararrayptr, uintptr, arg2);
1.314 djm 2074: }
2075: free(arg2);
1.159 dtucker 2076: }
1.153 dtucker 2077: break;
2078:
1.158 dtucker 2079: case sForceCommand:
1.262 dtucker 2080: if (cp == NULL || *cp == '\0')
1.158 dtucker 2081: fatal("%.200s line %d: Missing argument.", filename,
2082: linenum);
2083: len = strspn(cp, WHITESPACE);
2084: if (*activep && options->adm_forced_command == NULL)
2085: options->adm_forced_command = xstrdup(cp + len);
2086: return 0;
2087:
1.176 djm 2088: case sChrootDirectory:
2089: charptr = &options->chroot_directory;
1.177 djm 2090:
2091: arg = strdelim(&cp);
2092: if (!arg || *arg == '\0')
2093: fatal("%s line %d: missing file name.",
2094: filename, linenum);
2095: if (*activep && *charptr == NULL)
2096: *charptr = xstrdup(arg);
2097: break;
1.176 djm 2098:
1.204 djm 2099: case sTrustedUserCAKeys:
2100: charptr = &options->trusted_user_ca_keys;
2101: goto parse_filename;
2102:
2103: case sRevokedKeys:
2104: charptr = &options->revoked_keys_file;
2105: goto parse_filename;
2106:
1.355 djm 2107: case sSecurityKeyProvider:
2108: charptr = &options->sk_provider;
1.356 djm 2109: arg = strdelim(&cp);
2110: if (!arg || *arg == '\0')
2111: fatal("%s line %d: missing file name.",
2112: filename, linenum);
2113: if (*activep && *charptr == NULL) {
2114: *charptr = strcasecmp(arg, "internal") == 0 ?
2115: xstrdup(arg) : derelativise_path(arg);
2116: /* increase optional counter */
2117: if (intptr != NULL)
2118: *intptr = *intptr + 1;
2119: }
2120: break;
1.355 djm 2121:
1.213 djm 2122: case sIPQoS:
2123: arg = strdelim(&cp);
2124: if ((value = parse_ipqos(arg)) == -1)
2125: fatal("%s line %d: Bad IPQoS value: %s",
2126: filename, linenum, arg);
2127: arg = strdelim(&cp);
2128: if (arg == NULL)
2129: value2 = value;
2130: else if ((value2 = parse_ipqos(arg)) == -1)
2131: fatal("%s line %d: Bad IPQoS value: %s",
2132: filename, linenum, arg);
2133: if (*activep) {
2134: options->ip_qos_interactive = value;
2135: options->ip_qos_bulk = value2;
2136: }
2137: break;
2138:
1.225 djm 2139: case sVersionAddendum:
1.262 dtucker 2140: if (cp == NULL || *cp == '\0')
1.225 djm 2141: fatal("%.200s line %d: Missing argument.", filename,
2142: linenum);
2143: len = strspn(cp, WHITESPACE);
2144: if (*activep && options->version_addendum == NULL) {
2145: if (strcasecmp(cp + len, "none") == 0)
2146: options->version_addendum = xstrdup("");
2147: else if (strchr(cp + len, '\r') != NULL)
2148: fatal("%.200s line %d: Invalid argument",
2149: filename, linenum);
2150: else
2151: options->version_addendum = xstrdup(cp + len);
2152: }
2153: return 0;
2154:
1.231 djm 2155: case sAuthorizedKeysCommand:
1.255 jsg 2156: if (cp == NULL)
2157: fatal("%.200s line %d: Missing argument.", filename,
2158: linenum);
1.231 djm 2159: len = strspn(cp, WHITESPACE);
2160: if (*activep && options->authorized_keys_command == NULL) {
2161: if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
2162: fatal("%.200s line %d: AuthorizedKeysCommand "
2163: "must be an absolute path",
2164: filename, linenum);
2165: options->authorized_keys_command = xstrdup(cp + len);
2166: }
2167: return 0;
2168:
2169: case sAuthorizedKeysCommandUser:
2170: charptr = &options->authorized_keys_command_user;
2171:
2172: arg = strdelim(&cp);
1.255 jsg 2173: if (!arg || *arg == '\0')
2174: fatal("%s line %d: missing AuthorizedKeysCommandUser "
2175: "argument.", filename, linenum);
1.231 djm 2176: if (*activep && *charptr == NULL)
2177: *charptr = xstrdup(arg);
2178: break;
2179:
1.270 djm 2180: case sAuthorizedPrincipalsCommand:
2181: if (cp == NULL)
2182: fatal("%.200s line %d: Missing argument.", filename,
2183: linenum);
2184: len = strspn(cp, WHITESPACE);
2185: if (*activep &&
2186: options->authorized_principals_command == NULL) {
2187: if (cp[len] != '/' && strcasecmp(cp + len, "none") != 0)
2188: fatal("%.200s line %d: "
2189: "AuthorizedPrincipalsCommand must be "
2190: "an absolute path", filename, linenum);
2191: options->authorized_principals_command =
2192: xstrdup(cp + len);
2193: }
2194: return 0;
2195:
2196: case sAuthorizedPrincipalsCommandUser:
2197: charptr = &options->authorized_principals_command_user;
2198:
2199: arg = strdelim(&cp);
2200: if (!arg || *arg == '\0')
2201: fatal("%s line %d: missing "
2202: "AuthorizedPrincipalsCommandUser argument.",
2203: filename, linenum);
2204: if (*activep && *charptr == NULL)
2205: *charptr = xstrdup(arg);
2206: break;
2207:
1.232 djm 2208: case sAuthenticationMethods:
1.268 djm 2209: if (options->num_auth_methods == 0) {
1.291 djm 2210: value = 0; /* seen "any" pseudo-method */
1.328 djm 2211: value2 = 0; /* successfully parsed any method */
1.232 djm 2212: while ((arg = strdelim(&cp)) && *arg != '\0') {
1.291 djm 2213: if (strcmp(arg, "any") == 0) {
2214: if (options->num_auth_methods > 0) {
2215: fatal("%s line %d: \"any\" "
2216: "must appear alone in "
2217: "AuthenticationMethods",
2218: filename, linenum);
2219: }
2220: value = 1;
2221: } else if (value) {
2222: fatal("%s line %d: \"any\" must appear "
2223: "alone in AuthenticationMethods",
2224: filename, linenum);
2225: } else if (auth2_methods_valid(arg, 0) != 0) {
1.232 djm 2226: fatal("%s line %d: invalid "
2227: "authentication method list.",
2228: filename, linenum);
1.291 djm 2229: }
1.292 djm 2230: value2 = 1;
1.268 djm 2231: if (!*activep)
2232: continue;
1.314 djm 2233: array_append(filename, linenum,
2234: "AuthenticationMethods",
2235: &options->auth_methods,
2236: &options->num_auth_methods, arg);
1.232 djm 2237: }
1.292 djm 2238: if (value2 == 0) {
1.291 djm 2239: fatal("%s line %d: no AuthenticationMethods "
2240: "specified", filename, linenum);
2241: }
1.232 djm 2242: }
2243: return 0;
2244:
1.251 millert 2245: case sStreamLocalBindMask:
2246: arg = strdelim(&cp);
2247: if (!arg || *arg == '\0')
1.268 djm 2248: fatal("%s line %d: missing StreamLocalBindMask "
2249: "argument.", filename, linenum);
1.251 millert 2250: /* Parse mode in octal format */
2251: value = strtol(arg, &p, 8);
2252: if (arg == p || value < 0 || value > 0777)
2253: fatal("%s line %d: Bad mask.", filename, linenum);
1.268 djm 2254: if (*activep)
2255: options->fwd_opts.streamlocal_bind_mask = (mode_t)value;
1.251 millert 2256: break;
2257:
2258: case sStreamLocalBindUnlink:
2259: intptr = &options->fwd_opts.streamlocal_bind_unlink;
2260: goto parse_flag;
2261:
1.256 djm 2262: case sFingerprintHash:
2263: arg = strdelim(&cp);
2264: if (!arg || *arg == '\0')
2265: fatal("%.200s line %d: Missing argument.",
2266: filename, linenum);
2267: if ((value = ssh_digest_alg_by_name(arg)) == -1)
2268: fatal("%.200s line %d: Invalid hash algorithm \"%s\".",
2269: filename, linenum, arg);
2270: if (*activep)
2271: options->fingerprint_hash = value;
2272: break;
2273:
1.309 djm 2274: case sExposeAuthInfo:
2275: intptr = &options->expose_userauth_info;
2276: goto parse_flag;
2277:
1.316 djm 2278: case sRDomain:
2279: charptr = &options->routing_domain;
2280: arg = strdelim(&cp);
2281: if (!arg || *arg == '\0')
2282: fatal("%.200s line %d: Missing argument.",
2283: filename, linenum);
2284: if (strcasecmp(arg, "none") != 0 && strcmp(arg, "%D") != 0 &&
2285: !valid_rdomain(arg))
2286: fatal("%s line %d: bad routing domain",
2287: filename, linenum);
2288: if (*activep && *charptr == NULL)
2289: *charptr = xstrdup(arg);
1.321 dtucker 2290: break;
1.316 djm 2291:
1.94 markus 2292: case sDeprecated:
1.295 djm 2293: case sIgnore:
1.121 jakob 2294: case sUnsupported:
1.295 djm 2295: do_log2(opcode == sIgnore ?
2296: SYSLOG_LEVEL_DEBUG2 : SYSLOG_LEVEL_INFO,
2297: "%s line %d: %s option %s", filename, linenum,
2298: opcode == sUnsupported ? "Unsupported" : "Deprecated", arg);
1.94 markus 2299: while (arg)
2300: arg = strdelim(&cp);
2301: break;
2302:
2303: default:
2304: fatal("%s line %d: Missing handler for opcode %s (%d)",
2305: filename, linenum, arg, opcode);
2306: }
2307: if ((arg = strdelim(&cp)) != NULL && *arg != '\0')
2308: fatal("%s line %d: garbage at end of line; \"%.200s\".",
2309: filename, linenum, arg);
2310: return 0;
2311: }
2312:
1.360 djm 2313: int
2314: process_server_config_line(ServerOptions *options, char *line,
2315: const char *filename, int linenum, int *activep,
2316: struct connection_info *connectinfo, struct include_list *includes)
2317: {
1.365 djm 2318: int inc_flags = 0;
2319:
1.360 djm 2320: return process_server_config_line_depth(options, line, filename,
1.365 djm 2321: linenum, activep, connectinfo, &inc_flags, 0, includes);
1.360 djm 2322: }
2323:
2324:
1.94 markus 2325: /* Reads the server configuration file. */
1.25 markus 2326:
1.94 markus 2327: void
1.338 markus 2328: load_server_config(const char *filename, struct sshbuf *conf)
1.94 markus 2329: {
1.366 markus 2330: struct stat st;
1.331 markus 2331: char *line = NULL, *cp;
2332: size_t linesize = 0;
1.94 markus 2333: FILE *f;
1.338 markus 2334: int r, lineno = 0;
1.81 stevesk 2335:
1.134 djm 2336: debug2("%s: filename %s", __func__, filename);
2337: if ((f = fopen(filename, "r")) == NULL) {
1.94 markus 2338: perror(filename);
2339: exit(1);
2340: }
1.338 markus 2341: sshbuf_reset(conf);
1.366 markus 2342: /* grow buffer, so realloc is avoided for large config files */
2343: if (fstat(fileno(f), &st) == 0 && st.st_size > 0 &&
2344: (r = sshbuf_allocate(conf, st.st_size)) != 0)
2345: fatal("%s: allocate failed: %s", __func__, ssh_err(r));
1.331 markus 2346: while (getline(&line, &linesize, f) != -1) {
1.229 dtucker 2347: lineno++;
1.134 djm 2348: /*
2349: * Trim out comments and strip whitespace
1.135 deraadt 2350: * NB - preserve newlines, they are needed to reproduce
1.134 djm 2351: * line numbers later for error messages
2352: */
2353: if ((cp = strchr(line, '#')) != NULL)
2354: memcpy(cp, "\n", 2);
2355: cp = line + strspn(line, " \t\r");
1.338 markus 2356: if ((r = sshbuf_put(conf, cp, strlen(cp))) != 0)
2357: fatal("%s: buffer error: %s", __func__, ssh_err(r));
1.134 djm 2358: }
1.331 markus 2359: free(line);
1.338 markus 2360: if ((r = sshbuf_put_u8(conf, 0)) != 0)
2361: fatal("%s: buffer error: %s", __func__, ssh_err(r));
1.134 djm 2362: fclose(f);
1.338 markus 2363: debug2("%s: done config len = %zu", __func__, sshbuf_len(conf));
1.134 djm 2364: }
2365:
2366: void
1.226 dtucker 2367: parse_server_match_config(ServerOptions *options,
1.360 djm 2368: struct include_list *includes, struct connection_info *connectinfo)
1.153 dtucker 2369: {
2370: ServerOptions mo;
2371:
2372: initialize_server_options(&mo);
1.360 djm 2373: parse_server_config(&mo, "reprocess config", cfg, includes,
2374: connectinfo);
1.168 dtucker 2375: copy_set_server_options(options, &mo, 0);
1.153 dtucker 2376: }
2377:
1.226 dtucker 2378: int parse_server_match_testspec(struct connection_info *ci, char *spec)
2379: {
2380: char *p;
2381:
2382: while ((p = strsep(&spec, ",")) && *p != '\0') {
2383: if (strncmp(p, "addr=", 5) == 0) {
2384: ci->address = xstrdup(p + 5);
2385: } else if (strncmp(p, "host=", 5) == 0) {
2386: ci->host = xstrdup(p + 5);
2387: } else if (strncmp(p, "user=", 5) == 0) {
2388: ci->user = xstrdup(p + 5);
2389: } else if (strncmp(p, "laddr=", 6) == 0) {
2390: ci->laddress = xstrdup(p + 6);
1.317 djm 2391: } else if (strncmp(p, "rdomain=", 8) == 0) {
2392: ci->rdomain = xstrdup(p + 8);
1.226 dtucker 2393: } else if (strncmp(p, "lport=", 6) == 0) {
2394: ci->lport = a2port(p + 6);
2395: if (ci->lport == -1) {
2396: fprintf(stderr, "Invalid port '%s' in test mode"
2397: " specification %s\n", p+6, p);
2398: return -1;
2399: }
2400: } else {
2401: fprintf(stderr, "Invalid test mode specification %s\n",
2402: p);
2403: return -1;
2404: }
2405: }
2406: return 0;
2407: }
2408:
1.168 dtucker 2409: /*
2410: * Copy any supported values that are set.
2411: *
1.195 jj 2412: * If the preauth flag is set, we do not bother copying the string or
1.168 dtucker 2413: * array values that are not used pre-authentication, because any that we
1.328 djm 2414: * do use must be explicitly sent in mm_getpwnamallow().
1.168 dtucker 2415: */
1.153 dtucker 2416: void
1.168 dtucker 2417: copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
1.153 dtucker 2418: {
1.247 djm 2419: #define M_CP_INTOPT(n) do {\
2420: if (src->n != -1) \
2421: dst->n = src->n; \
2422: } while (0)
2423:
1.168 dtucker 2424: M_CP_INTOPT(password_authentication);
2425: M_CP_INTOPT(gss_authentication);
2426: M_CP_INTOPT(pubkey_authentication);
1.354 djm 2427: M_CP_INTOPT(pubkey_auth_options);
1.168 dtucker 2428: M_CP_INTOPT(kerberos_authentication);
2429: M_CP_INTOPT(hostbased_authentication);
1.209 djm 2430: M_CP_INTOPT(hostbased_uses_name_from_packet_only);
1.168 dtucker 2431: M_CP_INTOPT(kbd_interactive_authentication);
1.175 dtucker 2432: M_CP_INTOPT(permit_root_login);
1.188 djm 2433: M_CP_INTOPT(permit_empty_passwd);
1.362 djm 2434: M_CP_INTOPT(ignore_rhosts);
1.168 dtucker 2435:
2436: M_CP_INTOPT(allow_tcp_forwarding);
1.251 millert 2437: M_CP_INTOPT(allow_streamlocal_forwarding);
1.178 pyr 2438: M_CP_INTOPT(allow_agent_forwarding);
1.301 djm 2439: M_CP_INTOPT(disable_forwarding);
1.309 djm 2440: M_CP_INTOPT(expose_userauth_info);
1.209 djm 2441: M_CP_INTOPT(permit_tun);
1.251 millert 2442: M_CP_INTOPT(fwd_opts.gateway_ports);
1.289 djm 2443: M_CP_INTOPT(fwd_opts.streamlocal_bind_unlink);
1.168 dtucker 2444: M_CP_INTOPT(x11_display_offset);
2445: M_CP_INTOPT(x11_forwarding);
2446: M_CP_INTOPT(x11_use_localhost);
1.244 djm 2447: M_CP_INTOPT(permit_tty);
1.250 djm 2448: M_CP_INTOPT(permit_user_rc);
1.180 djm 2449: M_CP_INTOPT(max_sessions);
1.184 dtucker 2450: M_CP_INTOPT(max_authtries);
1.300 markus 2451: M_CP_INTOPT(client_alive_count_max);
2452: M_CP_INTOPT(client_alive_interval);
1.213 djm 2453: M_CP_INTOPT(ip_qos_interactive);
2454: M_CP_INTOPT(ip_qos_bulk);
1.235 dtucker 2455: M_CP_INTOPT(rekey_limit);
2456: M_CP_INTOPT(rekey_interval);
1.308 djm 2457: M_CP_INTOPT(log_level);
1.289 djm 2458:
2459: /*
2460: * The bind_mask is a mode_t that may be unsigned, so we can't use
2461: * M_CP_INTOPT - it does a signed comparison that causes compiler
2462: * warnings.
2463: */
1.290 dtucker 2464: if (src->fwd_opts.streamlocal_bind_mask != (mode_t)-1) {
1.289 djm 2465: dst->fwd_opts.streamlocal_bind_mask =
2466: src->fwd_opts.streamlocal_bind_mask;
2467: }
1.247 djm 2468:
2469: /* M_CP_STROPT and M_CP_STRARRAYOPT should not appear before here */
2470: #define M_CP_STROPT(n) do {\
2471: if (src->n != NULL && dst->n != src->n) { \
2472: free(dst->n); \
2473: dst->n = src->n; \
2474: } \
2475: } while(0)
1.314 djm 2476: #define M_CP_STRARRAYOPT(s, num_s) do {\
2477: u_int i; \
2478: if (src->num_s != 0) { \
2479: for (i = 0; i < dst->num_s; i++) \
2480: free(dst->s[i]); \
2481: free(dst->s); \
2482: dst->s = xcalloc(src->num_s, sizeof(*dst->s)); \
2483: for (i = 0; i < src->num_s; i++) \
2484: dst->s[i] = xstrdup(src->s[i]); \
2485: dst->num_s = src->num_s; \
1.312 djm 2486: } \
2487: } while(0)
1.168 dtucker 2488:
1.218 djm 2489: /* See comment in servconf.h */
2490: COPY_MATCH_STRING_OPTS();
1.282 djm 2491:
2492: /* Arguments that accept '+...' need to be expanded */
2493: assemble_algorithms(dst);
1.216 djm 2494:
1.217 dtucker 2495: /*
2496: * The only things that should be below this point are string options
2497: * which are only used after authentication.
2498: */
1.168 dtucker 2499: if (preauth)
2500: return;
1.219 djm 2501:
1.283 djm 2502: /* These options may be "none" to clear a global setting */
1.168 dtucker 2503: M_CP_STROPT(adm_forced_command);
1.283 djm 2504: if (option_clear_or_none(dst->adm_forced_command)) {
2505: free(dst->adm_forced_command);
2506: dst->adm_forced_command = NULL;
2507: }
1.176 djm 2508: M_CP_STROPT(chroot_directory);
1.283 djm 2509: if (option_clear_or_none(dst->chroot_directory)) {
2510: free(dst->chroot_directory);
2511: dst->chroot_directory = NULL;
2512: }
1.153 dtucker 2513: }
1.168 dtucker 2514:
2515: #undef M_CP_INTOPT
2516: #undef M_CP_STROPT
1.219 djm 2517: #undef M_CP_STRARRAYOPT
1.153 dtucker 2518:
1.360 djm 2519: #define SERVCONF_MAX_DEPTH 16
1.364 djm 2520: static void
1.360 djm 2521: parse_server_config_depth(ServerOptions *options, const char *filename,
2522: struct sshbuf *conf, struct include_list *includes,
2523: struct connection_info *connectinfo, int flags, int *activep, int depth)
1.134 djm 2524: {
1.360 djm 2525: int linenum, bad_options = 0;
1.136 dtucker 2526: char *cp, *obuf, *cbuf;
1.134 djm 2527:
1.360 djm 2528: if (depth < 0 || depth > SERVCONF_MAX_DEPTH)
2529: fatal("Too many recursive configuration includes");
2530:
1.365 djm 2531: debug2("%s: config %s len %zu%s", __func__, filename, sshbuf_len(conf),
2532: (flags & SSHCFG_NEVERMATCH ? " [checking syntax only]" : ""));
1.134 djm 2533:
1.287 djm 2534: if ((obuf = cbuf = sshbuf_dup_string(conf)) == NULL)
2535: fatal("%s: sshbuf_dup_string failed", __func__);
1.137 dtucker 2536: linenum = 1;
1.140 deraadt 2537: while ((cp = strsep(&cbuf, "\n")) != NULL) {
1.360 djm 2538: if (process_server_config_line_depth(options, cp,
1.365 djm 2539: filename, linenum++, activep, connectinfo, &flags,
1.360 djm 2540: depth, includes) != 0)
1.94 markus 2541: bad_options++;
1.1 deraadt 2542: }
1.239 djm 2543: free(obuf);
1.78 stevesk 2544: if (bad_options > 0)
2545: fatal("%s: terminating, %d bad configuration options",
2546: filename, bad_options);
1.360 djm 2547: }
2548:
2549: void
2550: parse_server_config(ServerOptions *options, const char *filename,
2551: struct sshbuf *conf, struct include_list *includes,
2552: struct connection_info *connectinfo)
2553: {
2554: int active = connectinfo ? 0 : 1;
2555: parse_server_config_depth(options, filename, conf, includes,
1.365 djm 2556: connectinfo, (connectinfo ? SSHCFG_MATCH_ONLY : 0), &active, 0);
1.364 djm 2557: process_queued_listen_addrs(options);
1.182 dtucker 2558: }
2559:
2560: static const char *
1.221 djm 2561: fmt_multistate_int(int val, const struct multistate *m)
2562: {
2563: u_int i;
2564:
2565: for (i = 0; m[i].key != NULL; i++) {
2566: if (m[i].value == val)
2567: return m[i].key;
2568: }
2569: return "UNKNOWN";
2570: }
2571:
2572: static const char *
1.182 dtucker 2573: fmt_intarg(ServerOpCodes code, int val)
2574: {
1.221 djm 2575: if (val == -1)
2576: return "unset";
2577: switch (code) {
2578: case sAddressFamily:
2579: return fmt_multistate_int(val, multistate_addressfamily);
2580: case sPermitRootLogin:
2581: return fmt_multistate_int(val, multistate_permitrootlogin);
2582: case sGatewayPorts:
2583: return fmt_multistate_int(val, multistate_gatewayports);
2584: case sCompression:
2585: return fmt_multistate_int(val, multistate_compression);
1.233 djm 2586: case sAllowTcpForwarding:
2587: return fmt_multistate_int(val, multistate_tcpfwd);
1.251 millert 2588: case sAllowStreamLocalForwarding:
2589: return fmt_multistate_int(val, multistate_tcpfwd);
1.363 djm 2590: case sIgnoreRhosts:
2591: return fmt_multistate_int(val, multistate_ignore_rhosts);
1.256 djm 2592: case sFingerprintHash:
2593: return ssh_digest_alg_name(val);
1.221 djm 2594: default:
2595: switch (val) {
2596: case 0:
2597: return "no";
2598: case 1:
2599: return "yes";
2600: default:
2601: return "UNKNOWN";
2602: }
1.182 dtucker 2603: }
2604: }
2605:
2606: static void
2607: dump_cfg_int(ServerOpCodes code, int val)
2608: {
2609: printf("%s %d\n", lookup_opcode_name(code), val);
2610: }
2611:
2612: static void
1.263 dtucker 2613: dump_cfg_oct(ServerOpCodes code, int val)
2614: {
2615: printf("%s 0%o\n", lookup_opcode_name(code), val);
2616: }
2617:
2618: static void
1.182 dtucker 2619: dump_cfg_fmtint(ServerOpCodes code, int val)
2620: {
2621: printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val));
2622: }
2623:
2624: static void
2625: dump_cfg_string(ServerOpCodes code, const char *val)
2626: {
1.257 djm 2627: printf("%s %s\n", lookup_opcode_name(code),
2628: val == NULL ? "none" : val);
1.182 dtucker 2629: }
2630:
2631: static void
2632: dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals)
2633: {
2634: u_int i;
2635:
2636: for (i = 0; i < count; i++)
1.219 djm 2637: printf("%s %s\n", lookup_opcode_name(code), vals[i]);
2638: }
2639:
2640: static void
2641: dump_cfg_strarray_oneline(ServerOpCodes code, u_int count, char **vals)
2642: {
2643: u_int i;
2644:
1.291 djm 2645: if (count <= 0 && code != sAuthenticationMethods)
1.261 dtucker 2646: return;
1.219 djm 2647: printf("%s", lookup_opcode_name(code));
2648: for (i = 0; i < count; i++)
2649: printf(" %s", vals[i]);
1.291 djm 2650: if (code == sAuthenticationMethods && count == 0)
2651: printf(" any");
1.219 djm 2652: printf("\n");
1.182 dtucker 2653: }
2654:
1.315 djm 2655: static char *
2656: format_listen_addrs(struct listenaddr *la)
1.182 dtucker 2657: {
1.315 djm 2658: int r;
1.182 dtucker 2659: struct addrinfo *ai;
1.315 djm 2660: char addr[NI_MAXHOST], port[NI_MAXSERV];
1.263 dtucker 2661: char *laddr1 = xstrdup(""), *laddr2 = NULL;
1.182 dtucker 2662:
1.263 dtucker 2663: /*
2664: * ListenAddress must be after Port. add_one_listen_addr pushes
2665: * addresses onto a stack, so to maintain ordering we need to
2666: * print these in reverse order.
2667: */
1.315 djm 2668: for (ai = la->addrs; ai; ai = ai->ai_next) {
2669: if ((r = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr,
1.182 dtucker 2670: sizeof(addr), port, sizeof(port),
2671: NI_NUMERICHOST|NI_NUMERICSERV)) != 0) {
1.315 djm 2672: error("getnameinfo: %.100s", ssh_gai_strerror(r));
2673: continue;
2674: }
2675: laddr2 = laddr1;
2676: if (ai->ai_family == AF_INET6) {
2677: xasprintf(&laddr1, "listenaddress [%s]:%s%s%s\n%s",
2678: addr, port,
2679: la->rdomain == NULL ? "" : " rdomain ",
2680: la->rdomain == NULL ? "" : la->rdomain,
2681: laddr2);
1.182 dtucker 2682: } else {
1.315 djm 2683: xasprintf(&laddr1, "listenaddress %s:%s%s%s\n%s",
2684: addr, port,
2685: la->rdomain == NULL ? "" : " rdomain ",
2686: la->rdomain == NULL ? "" : la->rdomain,
2687: laddr2);
1.182 dtucker 2688: }
1.315 djm 2689: free(laddr2);
2690: }
2691: return laddr1;
2692: }
2693:
2694: void
2695: dump_config(ServerOptions *o)
2696: {
2697: char *s;
2698: u_int i;
2699:
2700: /* these are usually at the top of the config */
2701: for (i = 0; i < o->num_ports; i++)
2702: printf("port %d\n", o->ports[i]);
2703: dump_cfg_fmtint(sAddressFamily, o->address_family);
2704:
2705: for (i = 0; i < o->num_listen_addrs; i++) {
2706: s = format_listen_addrs(&o->listen_addrs[i]);
2707: printf("%s", s);
2708: free(s);
1.182 dtucker 2709: }
2710:
2711: /* integer arguments */
2712: dump_cfg_int(sLoginGraceTime, o->login_grace_time);
2713: dump_cfg_int(sX11DisplayOffset, o->x11_display_offset);
2714: dump_cfg_int(sMaxAuthTries, o->max_authtries);
1.189 djm 2715: dump_cfg_int(sMaxSessions, o->max_sessions);
1.182 dtucker 2716: dump_cfg_int(sClientAliveInterval, o->client_alive_interval);
2717: dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max);
1.263 dtucker 2718: dump_cfg_oct(sStreamLocalBindMask, o->fwd_opts.streamlocal_bind_mask);
1.182 dtucker 2719:
2720: /* formatted integer arguments */
2721: dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login);
2722: dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts);
2723: dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts);
2724: dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication);
2725: dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly,
2726: o->hostbased_uses_name_from_packet_only);
2727: dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication);
1.187 djm 2728: #ifdef KRB5
1.182 dtucker 2729: dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication);
2730: dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd);
2731: dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup);
2732: dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token);
1.187 djm 2733: #endif
2734: #ifdef GSSAPI
1.182 dtucker 2735: dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
2736: dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
1.187 djm 2737: #endif
1.182 dtucker 2738: dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
2739: dump_cfg_fmtint(sKbdInteractiveAuthentication,
2740: o->kbd_interactive_authentication);
2741: dump_cfg_fmtint(sChallengeResponseAuthentication,
2742: o->challenge_response_authentication);
2743: dump_cfg_fmtint(sPrintMotd, o->print_motd);
2744: dump_cfg_fmtint(sPrintLastLog, o->print_lastlog);
2745: dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding);
2746: dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost);
1.244 djm 2747: dump_cfg_fmtint(sPermitTTY, o->permit_tty);
1.250 djm 2748: dump_cfg_fmtint(sPermitUserRC, o->permit_user_rc);
1.182 dtucker 2749: dump_cfg_fmtint(sStrictModes, o->strict_modes);
2750: dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive);
2751: dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd);
2752: dump_cfg_fmtint(sCompression, o->compression);
1.251 millert 2753: dump_cfg_fmtint(sGatewayPorts, o->fwd_opts.gateway_ports);
1.182 dtucker 2754: dump_cfg_fmtint(sUseDNS, o->use_dns);
2755: dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding);
1.261 dtucker 2756: dump_cfg_fmtint(sAllowAgentForwarding, o->allow_agent_forwarding);
1.301 djm 2757: dump_cfg_fmtint(sDisableForwarding, o->disable_forwarding);
1.251 millert 2758: dump_cfg_fmtint(sAllowStreamLocalForwarding, o->allow_streamlocal_forwarding);
1.288 djm 2759: dump_cfg_fmtint(sStreamLocalBindUnlink, o->fwd_opts.streamlocal_bind_unlink);
1.256 djm 2760: dump_cfg_fmtint(sFingerprintHash, o->fingerprint_hash);
1.309 djm 2761: dump_cfg_fmtint(sExposeAuthInfo, o->expose_userauth_info);
1.182 dtucker 2762:
2763: /* string arguments */
2764: dump_cfg_string(sPidFile, o->pid_file);
2765: dump_cfg_string(sXAuthLocation, o->xauth_location);
1.358 dtucker 2766: dump_cfg_string(sCiphers, o->ciphers);
2767: dump_cfg_string(sMacs, o->macs);
1.182 dtucker 2768: dump_cfg_string(sBanner, o->banner);
2769: dump_cfg_string(sForceCommand, o->adm_forced_command);
1.201 dtucker 2770: dump_cfg_string(sChrootDirectory, o->chroot_directory);
1.204 djm 2771: dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
2772: dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
1.355 djm 2773: dump_cfg_string(sSecurityKeyProvider, o->sk_provider);
1.208 djm 2774: dump_cfg_string(sAuthorizedPrincipalsFile,
2775: o->authorized_principals_file);
1.261 dtucker 2776: dump_cfg_string(sVersionAddendum, *o->version_addendum == '\0'
2777: ? "none" : o->version_addendum);
1.231 djm 2778: dump_cfg_string(sAuthorizedKeysCommand, o->authorized_keys_command);
2779: dump_cfg_string(sAuthorizedKeysCommandUser, o->authorized_keys_command_user);
1.270 djm 2780: dump_cfg_string(sAuthorizedPrincipalsCommand, o->authorized_principals_command);
2781: dump_cfg_string(sAuthorizedPrincipalsCommandUser, o->authorized_principals_command_user);
1.240 markus 2782: dump_cfg_string(sHostKeyAgent, o->host_key_agent);
1.358 dtucker 2783: dump_cfg_string(sKexAlgorithms, o->kex_algorithms);
2784: dump_cfg_string(sCASignatureAlgorithms, o->ca_sign_algorithms);
2785: dump_cfg_string(sHostbasedAcceptedKeyTypes, o->hostbased_key_types);
2786: dump_cfg_string(sHostKeyAlgorithms, o->hostkeyalgorithms);
2787: dump_cfg_string(sPubkeyAcceptedKeyTypes, o->pubkey_key_types);
1.316 djm 2788: dump_cfg_string(sRDomain, o->routing_domain);
1.182 dtucker 2789:
2790: /* string arguments requiring a lookup */
2791: dump_cfg_string(sLogLevel, log_level_name(o->log_level));
2792: dump_cfg_string(sLogFacility, log_facility_name(o->log_facility));
2793:
2794: /* string array arguments */
1.219 djm 2795: dump_cfg_strarray_oneline(sAuthorizedKeysFile, o->num_authkeys_files,
2796: o->authorized_keys_files);
1.182 dtucker 2797: dump_cfg_strarray(sHostKeyFile, o->num_host_key_files,
2798: o->host_key_files);
1.261 dtucker 2799: dump_cfg_strarray(sHostCertificate, o->num_host_cert_files,
1.203 djm 2800: o->host_cert_files);
1.182 dtucker 2801: dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users);
2802: dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users);
2803: dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups);
2804: dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups);
2805: dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env);
1.332 djm 2806: dump_cfg_strarray(sSetEnv, o->num_setenv, o->setenv);
1.232 djm 2807: dump_cfg_strarray_oneline(sAuthenticationMethods,
2808: o->num_auth_methods, o->auth_methods);
1.182 dtucker 2809:
2810: /* other arguments */
2811: for (i = 0; i < o->num_subsystems; i++)
2812: printf("subsystem %s %s\n", o->subsystem_name[i],
2813: o->subsystem_args[i]);
2814:
2815: printf("maxstartups %d:%d:%d\n", o->max_startups_begin,
2816: o->max_startups_rate, o->max_startups);
2817:
1.318 djm 2818: s = NULL;
2819: for (i = 0; tunmode_desc[i].val != -1; i++) {
1.182 dtucker 2820: if (tunmode_desc[i].val == o->permit_tun) {
2821: s = tunmode_desc[i].text;
2822: break;
2823: }
1.318 djm 2824: }
1.182 dtucker 2825: dump_cfg_string(sPermitTunnel, s);
1.213 djm 2826:
1.214 stevesk 2827: printf("ipqos %s ", iptos2str(o->ip_qos_interactive));
2828: printf("%s\n", iptos2str(o->ip_qos_bulk));
1.235 dtucker 2829:
1.284 dtucker 2830: printf("rekeylimit %llu %d\n", (unsigned long long)o->rekey_limit,
1.241 djm 2831: o->rekey_interval);
1.182 dtucker 2832:
1.310 djm 2833: printf("permitopen");
2834: if (o->num_permitted_opens == 0)
2835: printf(" any");
2836: else {
2837: for (i = 0; i < o->num_permitted_opens; i++)
2838: printf(" %s", o->permitted_opens[i]);
1.329 djm 2839: }
2840: printf("\n");
1.330 djm 2841: printf("permitlisten");
2842: if (o->num_permitted_listens == 0)
1.329 djm 2843: printf(" any");
2844: else {
1.330 djm 2845: for (i = 0; i < o->num_permitted_listens; i++)
2846: printf(" %s", o->permitted_listens[i]);
1.310 djm 2847: }
2848: printf("\n");
1.334 djm 2849:
1.367 djm 2850: if (o->permit_user_env_allowlist == NULL) {
1.334 djm 2851: dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env);
2852: } else {
2853: printf("permituserenvironment %s\n",
1.367 djm 2854: o->permit_user_env_allowlist);
1.334 djm 2855: }
2856:
1.354 djm 2857: printf("pubkeyauthoptions");
2858: if (o->pubkey_auth_options == 0)
2859: printf(" none");
2860: if (o->pubkey_auth_options & PUBKEYAUTH_TOUCH_REQUIRED)
2861: printf(" touch-required");
1.368 ! djm 2862: if (o->pubkey_auth_options & PUBKEYAUTH_VERIFY_REQUIRED)
! 2863: printf(" verify-required");
1.354 djm 2864: printf("\n");
1.1 deraadt 2865: }