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