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