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