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