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