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