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