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