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