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