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