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