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