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