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