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