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