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