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