Damien Miller | 4a5f0d3 | 2010-03-22 05:53:04 +1100 | [diff] [blame] | 1 | /* $OpenBSD: servconf.c,v 1.206 2010/03/12 11:37:40 markus Exp $ */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 2 | /* |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 3 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
| 4 | * All rights reserved |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 5 | * |
Damien Miller | e4340be | 2000-09-16 13:29:08 +1100 | [diff] [blame] | 6 | * As far as I am concerned, the code I have written for this software |
| 7 | * can be used freely for any purpose. Any derived versions of this |
| 8 | * software must be clearly marked as such, and if the derived work is |
| 9 | * incompatible with the protocol description in the RFC file, it must be |
| 10 | * called by a name other than "ssh" or "Secure Shell". |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 11 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 12 | |
| 13 | #include "includes.h" |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 14 | |
Damien Miller | e3b60b5 | 2006-07-10 21:08:03 +1000 | [diff] [blame] | 15 | #include <sys/types.h> |
| 16 | #include <sys/socket.h> |
| 17 | |
Damien Miller | b8fe89c | 2006-07-24 14:51:00 +1000 | [diff] [blame] | 18 | #include <netdb.h> |
Damien Miller | 565ca3f | 2006-08-19 00:23:15 +1000 | [diff] [blame] | 19 | #include <pwd.h> |
Damien Miller | a7a73ee | 2006-08-05 11:37:59 +1000 | [diff] [blame] | 20 | #include <stdio.h> |
Damien Miller | e7a1e5c | 2006-08-05 11:34:19 +1000 | [diff] [blame] | 21 | #include <stdlib.h> |
Damien Miller | e3476ed | 2006-07-24 14:13:33 +1000 | [diff] [blame] | 22 | #include <string.h> |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 23 | #include <signal.h> |
Damien Miller | e6b3b61 | 2006-07-24 14:01:23 +1000 | [diff] [blame] | 24 | #include <unistd.h> |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 25 | #include <stdarg.h> |
Darren Tucker | e7140f2 | 2008-06-10 23:01:51 +1000 | [diff] [blame] | 26 | #include <errno.h> |
Damien Miller | be43ebf | 2006-07-24 13:51:51 +1000 | [diff] [blame] | 27 | |
Damien Miller | b84886b | 2008-05-19 15:05:07 +1000 | [diff] [blame] | 28 | #include "openbsd-compat/sys-queue.h" |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 29 | #include "xmalloc.h" |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 30 | #include "ssh.h" |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 31 | #include "log.h" |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 32 | #include "buffer.h" |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 33 | #include "servconf.h" |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 34 | #include "compat.h" |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 35 | #include "pathnames.h" |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 36 | #include "misc.h" |
| 37 | #include "cipher.h" |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 38 | #include "key.h" |
Ben Lindstrom | 06b33aa | 2001-02-15 03:01:59 +0000 | [diff] [blame] | 39 | #include "kex.h" |
| 40 | #include "mac.h" |
Darren Tucker | 4515047 | 2006-07-12 22:34:17 +1000 | [diff] [blame] | 41 | #include "match.h" |
Damien Miller | 9b439df | 2006-07-24 14:04:00 +1000 | [diff] [blame] | 42 | #include "channels.h" |
Damien Miller | 565ca3f | 2006-08-19 00:23:15 +1000 | [diff] [blame] | 43 | #include "groupaccess.h" |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 44 | |
Damien Miller | 3dc71ad | 2009-01-28 16:31:22 +1100 | [diff] [blame] | 45 | static void add_listen_addr(ServerOptions *, char *, int); |
| 46 | static void add_one_listen_addr(ServerOptions *, char *, int); |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 47 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 48 | /* Use of privilege separation or not */ |
| 49 | extern int use_privsep; |
Darren Tucker | 4515047 | 2006-07-12 22:34:17 +1000 | [diff] [blame] | 50 | extern Buffer cfg; |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 51 | |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 52 | /* Initializes the server options to their default values. */ |
| 53 | |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 54 | void |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 55 | initialize_server_options(ServerOptions *options) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 56 | { |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 57 | memset(options, 0, sizeof(*options)); |
Damien Miller | 726273e | 2001-11-12 11:40:11 +1100 | [diff] [blame] | 58 | |
| 59 | /* Portable-specific options */ |
Damien Miller | 4e448a3 | 2003-05-14 15:11:48 +1000 | [diff] [blame] | 60 | options->use_pam = -1; |
Damien Miller | 726273e | 2001-11-12 11:40:11 +1100 | [diff] [blame] | 61 | |
| 62 | /* Standard Options */ |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 63 | options->num_ports = 0; |
| 64 | options->ports_from_cmdline = 0; |
| 65 | options->listen_addrs = NULL; |
Darren Tucker | 0f38323 | 2005-01-20 10:57:56 +1100 | [diff] [blame] | 66 | options->address_family = -1; |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 67 | options->num_host_key_files = 0; |
Damien Miller | 0a80ca1 | 2010-02-27 07:55:05 +1100 | [diff] [blame] | 68 | options->num_host_cert_files = 0; |
Damien Miller | 6f83b8e | 2000-05-02 09:23:45 +1000 | [diff] [blame] | 69 | options->pid_file = NULL; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 70 | options->server_key_bits = -1; |
| 71 | options->login_grace_time = -1; |
| 72 | options->key_regeneration_time = -1; |
Ben Lindstrom | d8a9021 | 2001-02-15 03:08:27 +0000 | [diff] [blame] | 73 | options->permit_root_login = PERMIT_NOT_SET; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 74 | options->ignore_rhosts = -1; |
| 75 | options->ignore_user_known_hosts = -1; |
| 76 | options->print_motd = -1; |
Ben Lindstrom | 7bfff36 | 2001-03-26 05:45:53 +0000 | [diff] [blame] | 77 | options->print_lastlog = -1; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 78 | options->x11_forwarding = -1; |
| 79 | options->x11_display_offset = -1; |
Damien Miller | 95c249f | 2002-02-05 12:11:34 +1100 | [diff] [blame] | 80 | options->x11_use_localhost = -1; |
Damien Miller | d3a1857 | 2000-06-07 19:55:44 +1000 | [diff] [blame] | 81 | options->xauth_location = NULL; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 82 | options->strict_modes = -1; |
Damien Miller | 12c150e | 2003-12-17 16:31:10 +1100 | [diff] [blame] | 83 | options->tcp_keep_alive = -1; |
Damien Miller | fcd9320 | 2002-02-05 12:26:34 +1100 | [diff] [blame] | 84 | options->log_facility = SYSLOG_FACILITY_NOT_SET; |
| 85 | options->log_level = SYSLOG_LEVEL_NOT_SET; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 86 | options->rhosts_rsa_authentication = -1; |
Ben Lindstrom | 5eabda3 | 2001-04-12 23:34:34 +0000 | [diff] [blame] | 87 | options->hostbased_authentication = -1; |
| 88 | options->hostbased_uses_name_from_packet_only = -1; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 89 | options->rsa_authentication = -1; |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 90 | options->pubkey_authentication = -1; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 91 | options->kerberos_authentication = -1; |
| 92 | options->kerberos_or_local_passwd = -1; |
| 93 | options->kerberos_ticket_cleanup = -1; |
Darren Tucker | 22ef508 | 2003-12-31 11:37:34 +1100 | [diff] [blame] | 94 | options->kerberos_get_afs_token = -1; |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 95 | options->gss_authentication=-1; |
| 96 | options->gss_cleanup_creds = -1; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 97 | options->password_authentication = -1; |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 98 | options->kbd_interactive_authentication = -1; |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 99 | options->challenge_response_authentication = -1; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 100 | options->permit_empty_passwd = -1; |
Ben Lindstrom | 5d860f0 | 2002-08-01 01:28:38 +0000 | [diff] [blame] | 101 | options->permit_user_env = -1; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 102 | options->use_login = -1; |
Ben Lindstrom | 23e0f66 | 2002-06-21 01:09:47 +0000 | [diff] [blame] | 103 | options->compression = -1; |
Damien Miller | 50a41ed | 2000-10-16 12:14:42 +1100 | [diff] [blame] | 104 | options->allow_tcp_forwarding = -1; |
Damien Miller | 4f755cd | 2008-05-19 14:57:41 +1000 | [diff] [blame] | 105 | options->allow_agent_forwarding = -1; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 106 | options->num_allow_users = 0; |
| 107 | options->num_deny_users = 0; |
| 108 | options->num_allow_groups = 0; |
| 109 | options->num_deny_groups = 0; |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 110 | options->ciphers = NULL; |
Ben Lindstrom | 06b33aa | 2001-02-15 03:01:59 +0000 | [diff] [blame] | 111 | options->macs = NULL; |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 112 | options->protocol = SSH_PROTO_UNKNOWN; |
Damien Miller | e247cc4 | 2000-05-07 12:03:14 +1000 | [diff] [blame] | 113 | options->gateway_ports = -1; |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 114 | options->num_subsystems = 0; |
Damien Miller | 942da03 | 2000-08-18 13:59:06 +1000 | [diff] [blame] | 115 | options->max_startups_begin = -1; |
| 116 | options->max_startups_rate = -1; |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 117 | options->max_startups = -1; |
Darren Tucker | 89413db | 2004-05-24 10:36:23 +1000 | [diff] [blame] | 118 | options->max_authtries = -1; |
Damien Miller | 7207f64 | 2008-05-19 15:34:50 +1000 | [diff] [blame] | 119 | options->max_sessions = -1; |
Ben Lindstrom | 48bd7c1 | 2001-01-09 00:35:42 +0000 | [diff] [blame] | 120 | options->banner = NULL; |
Damien Miller | 3a961dc | 2003-06-03 10:25:48 +1000 | [diff] [blame] | 121 | options->use_dns = -1; |
Ben Lindstrom | 5744dc4 | 2001-04-13 23:28:01 +0000 | [diff] [blame] | 122 | options->client_alive_interval = -1; |
| 123 | options->client_alive_count_max = -1; |
Ben Lindstrom | bfb3a0e | 2001-06-05 20:25:05 +0000 | [diff] [blame] | 124 | options->authorized_keys_file = NULL; |
| 125 | options->authorized_keys_file2 = NULL; |
Darren Tucker | 46bc075 | 2004-05-02 22:11:30 +1000 | [diff] [blame] | 126 | options->num_accept_env = 0; |
Damien Miller | d27b947 | 2005-12-13 19:29:02 +1100 | [diff] [blame] | 127 | options->permit_tun = -1; |
Damien Miller | a765cf4 | 2006-07-24 14:08:13 +1000 | [diff] [blame] | 128 | options->num_permitted_opens = -1; |
Damien Miller | e275443 | 2006-07-24 14:06:47 +1000 | [diff] [blame] | 129 | options->adm_forced_command = NULL; |
Damien Miller | d8cb1f1 | 2008-02-10 22:40:12 +1100 | [diff] [blame] | 130 | options->chroot_directory = NULL; |
Damien Miller | 01ed227 | 2008-11-05 16:20:46 +1100 | [diff] [blame] | 131 | options->zero_knowledge_password_authentication = -1; |
Damien Miller | 1aed65e | 2010-03-04 21:53:35 +1100 | [diff] [blame] | 132 | options->revoked_keys_file = NULL; |
| 133 | options->trusted_user_ca_keys = NULL; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 134 | } |
| 135 | |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 136 | void |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 137 | fill_default_server_options(ServerOptions *options) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 138 | { |
Damien Miller | 726273e | 2001-11-12 11:40:11 +1100 | [diff] [blame] | 139 | /* Portable-specific options */ |
Damien Miller | 4e448a3 | 2003-05-14 15:11:48 +1000 | [diff] [blame] | 140 | if (options->use_pam == -1) |
Damien Miller | 5c3a558 | 2003-09-23 22:12:38 +1000 | [diff] [blame] | 141 | options->use_pam = 0; |
Damien Miller | 726273e | 2001-11-12 11:40:11 +1100 | [diff] [blame] | 142 | |
| 143 | /* Standard Options */ |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 144 | if (options->protocol == SSH_PROTO_UNKNOWN) |
Darren Tucker | bad5076 | 2009-10-11 21:51:08 +1100 | [diff] [blame] | 145 | options->protocol = SSH_PROTO_2; |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 146 | if (options->num_host_key_files == 0) { |
| 147 | /* fill default hostkeys for protocols */ |
| 148 | if (options->protocol & SSH_PROTO_1) |
Damien Miller | 7fc2373 | 2002-01-22 23:19:11 +1100 | [diff] [blame] | 149 | options->host_key_files[options->num_host_key_files++] = |
| 150 | _PATH_HOST_KEY_FILE; |
| 151 | if (options->protocol & SSH_PROTO_2) { |
| 152 | options->host_key_files[options->num_host_key_files++] = |
| 153 | _PATH_HOST_RSA_KEY_FILE; |
| 154 | options->host_key_files[options->num_host_key_files++] = |
| 155 | _PATH_HOST_DSA_KEY_FILE; |
| 156 | } |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 157 | } |
Damien Miller | 0a80ca1 | 2010-02-27 07:55:05 +1100 | [diff] [blame] | 158 | /* No certificates by default */ |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 159 | if (options->num_ports == 0) |
| 160 | options->ports[options->num_ports++] = SSH_DEFAULT_PORT; |
| 161 | if (options->listen_addrs == NULL) |
Ben Lindstrom | 19066a1 | 2001-04-12 23:39:26 +0000 | [diff] [blame] | 162 | add_listen_addr(options, NULL, 0); |
Damien Miller | 6f83b8e | 2000-05-02 09:23:45 +1000 | [diff] [blame] | 163 | if (options->pid_file == NULL) |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 164 | options->pid_file = _PATH_SSH_DAEMON_PID_FILE; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 165 | if (options->server_key_bits == -1) |
Darren Tucker | 7499b0c | 2008-07-02 22:35:43 +1000 | [diff] [blame] | 166 | options->server_key_bits = 1024; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 167 | if (options->login_grace_time == -1) |
Damien Miller | c134863 | 2002-09-05 14:35:14 +1000 | [diff] [blame] | 168 | options->login_grace_time = 120; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 169 | if (options->key_regeneration_time == -1) |
| 170 | options->key_regeneration_time = 3600; |
Ben Lindstrom | d8a9021 | 2001-02-15 03:08:27 +0000 | [diff] [blame] | 171 | if (options->permit_root_login == PERMIT_NOT_SET) |
| 172 | options->permit_root_login = PERMIT_YES; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 173 | if (options->ignore_rhosts == -1) |
Damien Miller | 98c7ad6 | 2000-03-09 21:27:49 +1100 | [diff] [blame] | 174 | options->ignore_rhosts = 1; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 175 | if (options->ignore_user_known_hosts == -1) |
| 176 | options->ignore_user_known_hosts = 0; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 177 | if (options->print_motd == -1) |
| 178 | options->print_motd = 1; |
Ben Lindstrom | 7bfff36 | 2001-03-26 05:45:53 +0000 | [diff] [blame] | 179 | if (options->print_lastlog == -1) |
| 180 | options->print_lastlog = 1; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 181 | if (options->x11_forwarding == -1) |
Damien Miller | 98c7ad6 | 2000-03-09 21:27:49 +1100 | [diff] [blame] | 182 | options->x11_forwarding = 0; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 183 | if (options->x11_display_offset == -1) |
Damien Miller | 98c7ad6 | 2000-03-09 21:27:49 +1100 | [diff] [blame] | 184 | options->x11_display_offset = 10; |
Damien Miller | 95c249f | 2002-02-05 12:11:34 +1100 | [diff] [blame] | 185 | if (options->x11_use_localhost == -1) |
| 186 | options->x11_use_localhost = 1; |
Damien Miller | d3a1857 | 2000-06-07 19:55:44 +1000 | [diff] [blame] | 187 | if (options->xauth_location == NULL) |
Ben Lindstrom | 1bf11f6 | 2001-06-09 01:48:01 +0000 | [diff] [blame] | 188 | options->xauth_location = _PATH_XAUTH; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 189 | if (options->strict_modes == -1) |
| 190 | options->strict_modes = 1; |
Damien Miller | 12c150e | 2003-12-17 16:31:10 +1100 | [diff] [blame] | 191 | if (options->tcp_keep_alive == -1) |
| 192 | options->tcp_keep_alive = 1; |
Damien Miller | fcd9320 | 2002-02-05 12:26:34 +1100 | [diff] [blame] | 193 | if (options->log_facility == SYSLOG_FACILITY_NOT_SET) |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 194 | options->log_facility = SYSLOG_FACILITY_AUTH; |
Damien Miller | fcd9320 | 2002-02-05 12:26:34 +1100 | [diff] [blame] | 195 | if (options->log_level == SYSLOG_LEVEL_NOT_SET) |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 196 | options->log_level = SYSLOG_LEVEL_INFO; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 197 | if (options->rhosts_rsa_authentication == -1) |
Damien Miller | 98c7ad6 | 2000-03-09 21:27:49 +1100 | [diff] [blame] | 198 | options->rhosts_rsa_authentication = 0; |
Ben Lindstrom | 5eabda3 | 2001-04-12 23:34:34 +0000 | [diff] [blame] | 199 | if (options->hostbased_authentication == -1) |
| 200 | options->hostbased_authentication = 0; |
| 201 | if (options->hostbased_uses_name_from_packet_only == -1) |
| 202 | options->hostbased_uses_name_from_packet_only = 0; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 203 | if (options->rsa_authentication == -1) |
| 204 | options->rsa_authentication = 1; |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 205 | if (options->pubkey_authentication == -1) |
| 206 | options->pubkey_authentication = 1; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 207 | if (options->kerberos_authentication == -1) |
Damien Miller | d7de14b | 2002-04-23 21:04:51 +1000 | [diff] [blame] | 208 | options->kerberos_authentication = 0; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 209 | if (options->kerberos_or_local_passwd == -1) |
| 210 | options->kerberos_or_local_passwd = 1; |
| 211 | if (options->kerberos_ticket_cleanup == -1) |
| 212 | options->kerberos_ticket_cleanup = 1; |
Darren Tucker | 22ef508 | 2003-12-31 11:37:34 +1100 | [diff] [blame] | 213 | if (options->kerberos_get_afs_token == -1) |
| 214 | options->kerberos_get_afs_token = 0; |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 215 | if (options->gss_authentication == -1) |
| 216 | options->gss_authentication = 0; |
| 217 | if (options->gss_cleanup_creds == -1) |
| 218 | options->gss_cleanup_creds = 1; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 219 | if (options->password_authentication == -1) |
| 220 | options->password_authentication = 1; |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 221 | if (options->kbd_interactive_authentication == -1) |
| 222 | options->kbd_interactive_authentication = 0; |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 223 | if (options->challenge_response_authentication == -1) |
| 224 | options->challenge_response_authentication = 1; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 225 | if (options->permit_empty_passwd == -1) |
Damien Miller | 98c7ad6 | 2000-03-09 21:27:49 +1100 | [diff] [blame] | 226 | options->permit_empty_passwd = 0; |
Ben Lindstrom | 5d860f0 | 2002-08-01 01:28:38 +0000 | [diff] [blame] | 227 | if (options->permit_user_env == -1) |
| 228 | options->permit_user_env = 0; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 229 | if (options->use_login == -1) |
| 230 | options->use_login = 0; |
Ben Lindstrom | 23e0f66 | 2002-06-21 01:09:47 +0000 | [diff] [blame] | 231 | if (options->compression == -1) |
Damien Miller | 9786e6e | 2005-07-26 21:54:56 +1000 | [diff] [blame] | 232 | options->compression = COMP_DELAYED; |
Damien Miller | 50a41ed | 2000-10-16 12:14:42 +1100 | [diff] [blame] | 233 | if (options->allow_tcp_forwarding == -1) |
| 234 | options->allow_tcp_forwarding = 1; |
Damien Miller | 4f755cd | 2008-05-19 14:57:41 +1000 | [diff] [blame] | 235 | if (options->allow_agent_forwarding == -1) |
| 236 | options->allow_agent_forwarding = 1; |
Damien Miller | e247cc4 | 2000-05-07 12:03:14 +1000 | [diff] [blame] | 237 | if (options->gateway_ports == -1) |
| 238 | options->gateway_ports = 0; |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 239 | if (options->max_startups == -1) |
| 240 | options->max_startups = 10; |
Damien Miller | 942da03 | 2000-08-18 13:59:06 +1000 | [diff] [blame] | 241 | if (options->max_startups_rate == -1) |
| 242 | options->max_startups_rate = 100; /* 100% */ |
| 243 | if (options->max_startups_begin == -1) |
| 244 | options->max_startups_begin = options->max_startups; |
Darren Tucker | 89413db | 2004-05-24 10:36:23 +1000 | [diff] [blame] | 245 | if (options->max_authtries == -1) |
| 246 | options->max_authtries = DEFAULT_AUTH_FAIL_MAX; |
Damien Miller | 7207f64 | 2008-05-19 15:34:50 +1000 | [diff] [blame] | 247 | if (options->max_sessions == -1) |
| 248 | options->max_sessions = DEFAULT_SESSIONS_MAX; |
Damien Miller | 3a961dc | 2003-06-03 10:25:48 +1000 | [diff] [blame] | 249 | if (options->use_dns == -1) |
| 250 | options->use_dns = 1; |
Ben Lindstrom | 5744dc4 | 2001-04-13 23:28:01 +0000 | [diff] [blame] | 251 | if (options->client_alive_interval == -1) |
Damien Miller | 9f0f5c6 | 2001-12-21 14:45:46 +1100 | [diff] [blame] | 252 | options->client_alive_interval = 0; |
Ben Lindstrom | 5744dc4 | 2001-04-13 23:28:01 +0000 | [diff] [blame] | 253 | if (options->client_alive_count_max == -1) |
| 254 | options->client_alive_count_max = 3; |
Damien Miller | 75413ac | 2001-11-12 11:14:35 +1100 | [diff] [blame] | 255 | if (options->authorized_keys_file2 == NULL) { |
| 256 | /* authorized_keys_file2 falls back to authorized_keys_file */ |
| 257 | if (options->authorized_keys_file != NULL) |
| 258 | options->authorized_keys_file2 = options->authorized_keys_file; |
| 259 | else |
| 260 | options->authorized_keys_file2 = _PATH_SSH_USER_PERMITTED_KEYS2; |
| 261 | } |
| 262 | if (options->authorized_keys_file == NULL) |
| 263 | options->authorized_keys_file = _PATH_SSH_USER_PERMITTED_KEYS; |
Damien Miller | d27b947 | 2005-12-13 19:29:02 +1100 | [diff] [blame] | 264 | if (options->permit_tun == -1) |
Damien Miller | 7b58e80 | 2005-12-13 19:33:19 +1100 | [diff] [blame] | 265 | options->permit_tun = SSH_TUNMODE_NO; |
Damien Miller | 01ed227 | 2008-11-05 16:20:46 +1100 | [diff] [blame] | 266 | if (options->zero_knowledge_password_authentication == -1) |
| 267 | options->zero_knowledge_password_authentication = 0; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 268 | |
Ben Lindstrom | fb62a69 | 2002-06-06 19:47:11 +0000 | [diff] [blame] | 269 | /* Turn privilege separation on by default */ |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 270 | if (use_privsep == -1) |
Ben Lindstrom | fb62a69 | 2002-06-06 19:47:11 +0000 | [diff] [blame] | 271 | use_privsep = 1; |
Damien Miller | 4903eb4 | 2002-06-21 16:20:44 +1000 | [diff] [blame] | 272 | |
Tim Rice | 40017b0 | 2002-07-14 13:36:49 -0700 | [diff] [blame] | 273 | #ifndef HAVE_MMAP |
Damien Miller | 4903eb4 | 2002-06-21 16:20:44 +1000 | [diff] [blame] | 274 | if (use_privsep && options->compression == 1) { |
| 275 | error("This platform does not support both privilege " |
| 276 | "separation and compression"); |
| 277 | error("Compression disabled"); |
| 278 | options->compression = 0; |
| 279 | } |
| 280 | #endif |
| 281 | |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 282 | } |
| 283 | |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 284 | /* Keyword tokens. */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 285 | typedef enum { |
| 286 | sBadOption, /* == unknown option */ |
Damien Miller | 726273e | 2001-11-12 11:40:11 +1100 | [diff] [blame] | 287 | /* Portable-specific options */ |
Damien Miller | 4e448a3 | 2003-05-14 15:11:48 +1000 | [diff] [blame] | 288 | sUsePAM, |
Damien Miller | 726273e | 2001-11-12 11:40:11 +1100 | [diff] [blame] | 289 | /* Standard Options */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 290 | sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime, |
| 291 | sPermitRootLogin, sLogFacility, sLogLevel, |
Darren Tucker | ec960f2 | 2003-08-13 20:37:05 +1000 | [diff] [blame] | 292 | sRhostsRSAAuthentication, sRSAAuthentication, |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 293 | sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup, |
Darren Tucker | 22ef508 | 2003-12-31 11:37:34 +1100 | [diff] [blame] | 294 | sKerberosGetAFSToken, |
Darren Tucker | 6aaa58c | 2003-08-02 22:24:49 +1000 | [diff] [blame] | 295 | sKerberosTgtPassing, sChallengeResponseAuthentication, |
Darren Tucker | 0f38323 | 2005-01-20 10:57:56 +1100 | [diff] [blame] | 296 | sPasswordAuthentication, sKbdInteractiveAuthentication, |
| 297 | sListenAddress, sAddressFamily, |
Ben Lindstrom | 7bfff36 | 2001-03-26 05:45:53 +0000 | [diff] [blame] | 298 | sPrintMotd, sPrintLastLog, sIgnoreRhosts, |
Damien Miller | 95c249f | 2002-02-05 12:11:34 +1100 | [diff] [blame] | 299 | sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost, |
Damien Miller | 12c150e | 2003-12-17 16:31:10 +1100 | [diff] [blame] | 300 | sStrictModes, sEmptyPasswd, sTCPKeepAlive, |
Ben Lindstrom | 5d860f0 | 2002-08-01 01:28:38 +0000 | [diff] [blame] | 301 | sPermitUserEnvironment, sUseLogin, sAllowTcpForwarding, sCompression, |
Damien Miller | 50a41ed | 2000-10-16 12:14:42 +1100 | [diff] [blame] | 302 | sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups, |
Ben Lindstrom | 06b33aa | 2001-02-15 03:01:59 +0000 | [diff] [blame] | 303 | sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile, |
Darren Tucker | 89413db | 2004-05-24 10:36:23 +1000 | [diff] [blame] | 304 | sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem, |
Damien Miller | 7207f64 | 2008-05-19 15:34:50 +1000 | [diff] [blame] | 305 | sMaxStartups, sMaxAuthTries, sMaxSessions, |
Damien Miller | 3a961dc | 2003-06-03 10:25:48 +1000 | [diff] [blame] | 306 | sBanner, sUseDNS, sHostbasedAuthentication, |
Damien Miller | 9f0f5c6 | 2001-12-21 14:45:46 +1100 | [diff] [blame] | 307 | sHostbasedUsesNameFromPacketOnly, sClientAliveInterval, |
Ben Lindstrom | bfb3a0e | 2001-06-05 20:25:05 +0000 | [diff] [blame] | 308 | sClientAliveCountMax, sAuthorizedKeysFile, sAuthorizedKeysFile2, |
Damien Miller | d27b947 | 2005-12-13 19:29:02 +1100 | [diff] [blame] | 309 | sGssAuthentication, sGssCleanupCreds, sAcceptEnv, sPermitTunnel, |
Damien Miller | d8cb1f1 | 2008-02-10 22:40:12 +1100 | [diff] [blame] | 310 | sMatch, sPermitOpen, sForceCommand, sChrootDirectory, |
Darren Tucker | 7bd98e7 | 2010-01-10 10:31:12 +1100 | [diff] [blame] | 311 | sUsePrivilegeSeparation, sAllowAgentForwarding, |
Damien Miller | 0a80ca1 | 2010-02-27 07:55:05 +1100 | [diff] [blame] | 312 | sZeroKnowledgePasswordAuthentication, sHostCertificate, |
Damien Miller | 1aed65e | 2010-03-04 21:53:35 +1100 | [diff] [blame] | 313 | sRevokedKeys, sTrustedUserCAKeys, |
Damien Miller | f9b3feb | 2003-05-16 11:38:32 +1000 | [diff] [blame] | 314 | sDeprecated, sUnsupported |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 315 | } ServerOpCodes; |
| 316 | |
Darren Tucker | 4515047 | 2006-07-12 22:34:17 +1000 | [diff] [blame] | 317 | #define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */ |
| 318 | #define SSHCFG_MATCH 0x02 /* allowed inside a Match section */ |
| 319 | #define SSHCFG_ALL (SSHCFG_GLOBAL|SSHCFG_MATCH) |
| 320 | |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 321 | /* Textual representation of the tokens. */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 322 | static struct { |
| 323 | const char *name; |
| 324 | ServerOpCodes opcode; |
Darren Tucker | 4515047 | 2006-07-12 22:34:17 +1000 | [diff] [blame] | 325 | u_int flags; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 326 | } keywords[] = { |
Damien Miller | 726273e | 2001-11-12 11:40:11 +1100 | [diff] [blame] | 327 | /* Portable-specific options */ |
Damien Miller | 6ac2c48 | 2003-05-16 11:42:35 +1000 | [diff] [blame] | 328 | #ifdef USE_PAM |
Darren Tucker | 4515047 | 2006-07-12 22:34:17 +1000 | [diff] [blame] | 329 | { "usepam", sUsePAM, SSHCFG_GLOBAL }, |
Damien Miller | 6ac2c48 | 2003-05-16 11:42:35 +1000 | [diff] [blame] | 330 | #else |
Darren Tucker | 4515047 | 2006-07-12 22:34:17 +1000 | [diff] [blame] | 331 | { "usepam", sUnsupported, SSHCFG_GLOBAL }, |
Damien Miller | 6ac2c48 | 2003-05-16 11:42:35 +1000 | [diff] [blame] | 332 | #endif |
Darren Tucker | 4515047 | 2006-07-12 22:34:17 +1000 | [diff] [blame] | 333 | { "pamauthenticationviakbdint", sDeprecated, SSHCFG_GLOBAL }, |
Damien Miller | 726273e | 2001-11-12 11:40:11 +1100 | [diff] [blame] | 334 | /* Standard Options */ |
Darren Tucker | 4515047 | 2006-07-12 22:34:17 +1000 | [diff] [blame] | 335 | { "port", sPort, SSHCFG_GLOBAL }, |
| 336 | { "hostkey", sHostKeyFile, SSHCFG_GLOBAL }, |
| 337 | { "hostdsakey", sHostKeyFile, SSHCFG_GLOBAL }, /* alias */ |
| 338 | { "pidfile", sPidFile, SSHCFG_GLOBAL }, |
| 339 | { "serverkeybits", sServerKeyBits, SSHCFG_GLOBAL }, |
| 340 | { "logingracetime", sLoginGraceTime, SSHCFG_GLOBAL }, |
| 341 | { "keyregenerationinterval", sKeyRegenerationTime, SSHCFG_GLOBAL }, |
Darren Tucker | 15f9427 | 2008-01-01 20:36:56 +1100 | [diff] [blame] | 342 | { "permitrootlogin", sPermitRootLogin, SSHCFG_ALL }, |
Darren Tucker | 4515047 | 2006-07-12 22:34:17 +1000 | [diff] [blame] | 343 | { "syslogfacility", sLogFacility, SSHCFG_GLOBAL }, |
| 344 | { "loglevel", sLogLevel, SSHCFG_GLOBAL }, |
| 345 | { "rhostsauthentication", sDeprecated, SSHCFG_GLOBAL }, |
Darren Tucker | 1629c07 | 2007-02-19 22:25:37 +1100 | [diff] [blame] | 346 | { "rhostsrsaauthentication", sRhostsRSAAuthentication, SSHCFG_ALL }, |
| 347 | { "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_ALL }, |
Darren Tucker | 4515047 | 2006-07-12 22:34:17 +1000 | [diff] [blame] | 348 | { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly, SSHCFG_GLOBAL }, |
Darren Tucker | 1629c07 | 2007-02-19 22:25:37 +1100 | [diff] [blame] | 349 | { "rsaauthentication", sRSAAuthentication, SSHCFG_ALL }, |
| 350 | { "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_ALL }, |
Darren Tucker | 64cee36 | 2009-06-21 20:26:17 +1000 | [diff] [blame] | 351 | { "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL }, /* alias */ |
Darren Tucker | 6aaa58c | 2003-08-02 22:24:49 +1000 | [diff] [blame] | 352 | #ifdef KRB5 |
Darren Tucker | 1629c07 | 2007-02-19 22:25:37 +1100 | [diff] [blame] | 353 | { "kerberosauthentication", sKerberosAuthentication, SSHCFG_ALL }, |
Darren Tucker | 4515047 | 2006-07-12 22:34:17 +1000 | [diff] [blame] | 354 | { "kerberosorlocalpasswd", sKerberosOrLocalPasswd, SSHCFG_GLOBAL }, |
| 355 | { "kerberosticketcleanup", sKerberosTicketCleanup, SSHCFG_GLOBAL }, |
Darren Tucker | 3c78c5e | 2004-01-23 22:03:10 +1100 | [diff] [blame] | 356 | #ifdef USE_AFS |
Darren Tucker | 4515047 | 2006-07-12 22:34:17 +1000 | [diff] [blame] | 357 | { "kerberosgetafstoken", sKerberosGetAFSToken, SSHCFG_GLOBAL }, |
Damien Miller | f9b3feb | 2003-05-16 11:38:32 +1000 | [diff] [blame] | 358 | #else |
Darren Tucker | 4515047 | 2006-07-12 22:34:17 +1000 | [diff] [blame] | 359 | { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL }, |
Darren Tucker | 409cb32 | 2004-01-05 22:36:51 +1100 | [diff] [blame] | 360 | #endif |
| 361 | #else |
Darren Tucker | 1629c07 | 2007-02-19 22:25:37 +1100 | [diff] [blame] | 362 | { "kerberosauthentication", sUnsupported, SSHCFG_ALL }, |
Darren Tucker | 4515047 | 2006-07-12 22:34:17 +1000 | [diff] [blame] | 363 | { "kerberosorlocalpasswd", sUnsupported, SSHCFG_GLOBAL }, |
| 364 | { "kerberosticketcleanup", sUnsupported, SSHCFG_GLOBAL }, |
| 365 | { "kerberosgetafstoken", sUnsupported, SSHCFG_GLOBAL }, |
Damien Miller | f9b3feb | 2003-05-16 11:38:32 +1000 | [diff] [blame] | 366 | #endif |
Darren Tucker | 4515047 | 2006-07-12 22:34:17 +1000 | [diff] [blame] | 367 | { "kerberostgtpassing", sUnsupported, SSHCFG_GLOBAL }, |
| 368 | { "afstokenpassing", sUnsupported, SSHCFG_GLOBAL }, |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 369 | #ifdef GSSAPI |
Darren Tucker | 1629c07 | 2007-02-19 22:25:37 +1100 | [diff] [blame] | 370 | { "gssapiauthentication", sGssAuthentication, SSHCFG_ALL }, |
Darren Tucker | 4515047 | 2006-07-12 22:34:17 +1000 | [diff] [blame] | 371 | { "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL }, |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 372 | #else |
Darren Tucker | 1629c07 | 2007-02-19 22:25:37 +1100 | [diff] [blame] | 373 | { "gssapiauthentication", sUnsupported, SSHCFG_ALL }, |
Darren Tucker | 4515047 | 2006-07-12 22:34:17 +1000 | [diff] [blame] | 374 | { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL }, |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 375 | #endif |
Darren Tucker | 1629c07 | 2007-02-19 22:25:37 +1100 | [diff] [blame] | 376 | { "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL }, |
| 377 | { "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL }, |
Darren Tucker | 1d75f22 | 2007-03-01 21:31:28 +1100 | [diff] [blame] | 378 | { "challengeresponseauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, |
Darren Tucker | 4515047 | 2006-07-12 22:34:17 +1000 | [diff] [blame] | 379 | { "skeyauthentication", sChallengeResponseAuthentication, SSHCFG_GLOBAL }, /* alias */ |
Damien Miller | 01ed227 | 2008-11-05 16:20:46 +1100 | [diff] [blame] | 380 | #ifdef JPAKE |
| 381 | { "zeroknowledgepasswordauthentication", sZeroKnowledgePasswordAuthentication, SSHCFG_ALL }, |
| 382 | #else |
| 383 | { "zeroknowledgepasswordauthentication", sUnsupported, SSHCFG_ALL }, |
| 384 | #endif |
Darren Tucker | 4515047 | 2006-07-12 22:34:17 +1000 | [diff] [blame] | 385 | { "checkmail", sDeprecated, SSHCFG_GLOBAL }, |
| 386 | { "listenaddress", sListenAddress, SSHCFG_GLOBAL }, |
| 387 | { "addressfamily", sAddressFamily, SSHCFG_GLOBAL }, |
| 388 | { "printmotd", sPrintMotd, SSHCFG_GLOBAL }, |
| 389 | { "printlastlog", sPrintLastLog, SSHCFG_GLOBAL }, |
| 390 | { "ignorerhosts", sIgnoreRhosts, SSHCFG_GLOBAL }, |
| 391 | { "ignoreuserknownhosts", sIgnoreUserKnownHosts, SSHCFG_GLOBAL }, |
Damien Miller | d1de995 | 2006-07-24 14:05:48 +1000 | [diff] [blame] | 392 | { "x11forwarding", sX11Forwarding, SSHCFG_ALL }, |
| 393 | { "x11displayoffset", sX11DisplayOffset, SSHCFG_ALL }, |
| 394 | { "x11uselocalhost", sX11UseLocalhost, SSHCFG_ALL }, |
Darren Tucker | 4515047 | 2006-07-12 22:34:17 +1000 | [diff] [blame] | 395 | { "xauthlocation", sXAuthLocation, SSHCFG_GLOBAL }, |
| 396 | { "strictmodes", sStrictModes, SSHCFG_GLOBAL }, |
Damien Miller | 51bde60 | 2008-11-03 19:23:10 +1100 | [diff] [blame] | 397 | { "permitemptypasswords", sEmptyPasswd, SSHCFG_ALL }, |
Darren Tucker | 4515047 | 2006-07-12 22:34:17 +1000 | [diff] [blame] | 398 | { "permituserenvironment", sPermitUserEnvironment, SSHCFG_GLOBAL }, |
| 399 | { "uselogin", sUseLogin, SSHCFG_GLOBAL }, |
| 400 | { "compression", sCompression, SSHCFG_GLOBAL }, |
| 401 | { "tcpkeepalive", sTCPKeepAlive, SSHCFG_GLOBAL }, |
| 402 | { "keepalive", sTCPKeepAlive, SSHCFG_GLOBAL }, /* obsolete alias */ |
| 403 | { "allowtcpforwarding", sAllowTcpForwarding, SSHCFG_ALL }, |
Damien Miller | 4f755cd | 2008-05-19 14:57:41 +1000 | [diff] [blame] | 404 | { "allowagentforwarding", sAllowAgentForwarding, SSHCFG_ALL }, |
Darren Tucker | 4515047 | 2006-07-12 22:34:17 +1000 | [diff] [blame] | 405 | { "allowusers", sAllowUsers, SSHCFG_GLOBAL }, |
| 406 | { "denyusers", sDenyUsers, SSHCFG_GLOBAL }, |
| 407 | { "allowgroups", sAllowGroups, SSHCFG_GLOBAL }, |
| 408 | { "denygroups", sDenyGroups, SSHCFG_GLOBAL }, |
| 409 | { "ciphers", sCiphers, SSHCFG_GLOBAL }, |
| 410 | { "macs", sMacs, SSHCFG_GLOBAL }, |
| 411 | { "protocol", sProtocol, SSHCFG_GLOBAL }, |
| 412 | { "gatewayports", sGatewayPorts, SSHCFG_ALL }, |
| 413 | { "subsystem", sSubsystem, SSHCFG_GLOBAL }, |
| 414 | { "maxstartups", sMaxStartups, SSHCFG_GLOBAL }, |
Damien Miller | 307c1d1 | 2008-06-16 07:56:20 +1000 | [diff] [blame] | 415 | { "maxauthtries", sMaxAuthTries, SSHCFG_ALL }, |
Damien Miller | 7207f64 | 2008-05-19 15:34:50 +1000 | [diff] [blame] | 416 | { "maxsessions", sMaxSessions, SSHCFG_ALL }, |
Darren Tucker | 1629c07 | 2007-02-19 22:25:37 +1100 | [diff] [blame] | 417 | { "banner", sBanner, SSHCFG_ALL }, |
Darren Tucker | 4515047 | 2006-07-12 22:34:17 +1000 | [diff] [blame] | 418 | { "usedns", sUseDNS, SSHCFG_GLOBAL }, |
| 419 | { "verifyreversemapping", sDeprecated, SSHCFG_GLOBAL }, |
| 420 | { "reversemappingcheck", sDeprecated, SSHCFG_GLOBAL }, |
| 421 | { "clientaliveinterval", sClientAliveInterval, SSHCFG_GLOBAL }, |
| 422 | { "clientalivecountmax", sClientAliveCountMax, SSHCFG_GLOBAL }, |
| 423 | { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_GLOBAL }, |
| 424 | { "authorizedkeysfile2", sAuthorizedKeysFile2, SSHCFG_GLOBAL }, |
Darren Tucker | 64cee36 | 2009-06-21 20:26:17 +1000 | [diff] [blame] | 425 | { "useprivilegeseparation", sUsePrivilegeSeparation, SSHCFG_GLOBAL}, |
Darren Tucker | 4515047 | 2006-07-12 22:34:17 +1000 | [diff] [blame] | 426 | { "acceptenv", sAcceptEnv, SSHCFG_GLOBAL }, |
| 427 | { "permittunnel", sPermitTunnel, SSHCFG_GLOBAL }, |
Darren Tucker | 64cee36 | 2009-06-21 20:26:17 +1000 | [diff] [blame] | 428 | { "match", sMatch, SSHCFG_ALL }, |
Damien Miller | 9b439df | 2006-07-24 14:04:00 +1000 | [diff] [blame] | 429 | { "permitopen", sPermitOpen, SSHCFG_ALL }, |
Damien Miller | e275443 | 2006-07-24 14:06:47 +1000 | [diff] [blame] | 430 | { "forcecommand", sForceCommand, SSHCFG_ALL }, |
Damien Miller | d8cb1f1 | 2008-02-10 22:40:12 +1100 | [diff] [blame] | 431 | { "chrootdirectory", sChrootDirectory, SSHCFG_ALL }, |
Damien Miller | 0a80ca1 | 2010-02-27 07:55:05 +1100 | [diff] [blame] | 432 | { "hostcertificate", sHostCertificate, SSHCFG_GLOBAL }, |
Damien Miller | 1aed65e | 2010-03-04 21:53:35 +1100 | [diff] [blame] | 433 | { "revokedkeys", sRevokedKeys, SSHCFG_ALL }, |
| 434 | { "trustedusercakeys", sTrustedUserCAKeys, SSHCFG_ALL }, |
Darren Tucker | 4515047 | 2006-07-12 22:34:17 +1000 | [diff] [blame] | 435 | { NULL, sBadOption, 0 } |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 436 | }; |
| 437 | |
Darren Tucker | e7140f2 | 2008-06-10 23:01:51 +1000 | [diff] [blame] | 438 | static struct { |
| 439 | int val; |
| 440 | char *text; |
| 441 | } tunmode_desc[] = { |
| 442 | { SSH_TUNMODE_NO, "no" }, |
| 443 | { SSH_TUNMODE_POINTOPOINT, "point-to-point" }, |
| 444 | { SSH_TUNMODE_ETHERNET, "ethernet" }, |
| 445 | { SSH_TUNMODE_YES, "yes" }, |
| 446 | { -1, NULL } |
| 447 | }; |
| 448 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 449 | /* |
Ben Lindstrom | 3704c26 | 2001-04-02 18:20:03 +0000 | [diff] [blame] | 450 | * Returns the number of the token pointed to by cp or sBadOption. |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 451 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 452 | |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 453 | static ServerOpCodes |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 454 | parse_token(const char *cp, const char *filename, |
Darren Tucker | 4515047 | 2006-07-12 22:34:17 +1000 | [diff] [blame] | 455 | int linenum, u_int *flags) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 456 | { |
Ben Lindstrom | 46c1622 | 2000-12-22 01:43:59 +0000 | [diff] [blame] | 457 | u_int i; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 458 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 459 | for (i = 0; keywords[i].name; i++) |
Darren Tucker | 4515047 | 2006-07-12 22:34:17 +1000 | [diff] [blame] | 460 | if (strcasecmp(cp, keywords[i].name) == 0) { |
| 461 | *flags = keywords[i].flags; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 462 | return keywords[i].opcode; |
Darren Tucker | 4515047 | 2006-07-12 22:34:17 +1000 | [diff] [blame] | 463 | } |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 464 | |
Ben Lindstrom | b5cdc66 | 2001-04-16 02:13:26 +0000 | [diff] [blame] | 465 | error("%s: line %d: Bad configuration option: %s", |
| 466 | filename, linenum, cp); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 467 | return sBadOption; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 468 | } |
| 469 | |
Darren Tucker | 88b6fb2 | 2010-01-13 22:44:29 +1100 | [diff] [blame] | 470 | char * |
| 471 | derelativise_path(const char *path) |
| 472 | { |
| 473 | char *expanded, *ret, *cwd; |
| 474 | |
| 475 | expanded = tilde_expand_filename(path, getuid()); |
| 476 | if (*expanded == '/') |
| 477 | return expanded; |
| 478 | if ((cwd = getcwd(NULL, 0)) == NULL) |
| 479 | fatal("%s: getcwd: %s", __func__, strerror(errno)); |
| 480 | xasprintf(&ret, "%s/%s", cwd, expanded); |
Damien Miller | 4a5f0d3 | 2010-03-22 05:53:04 +1100 | [diff] [blame] | 481 | free(cwd); |
Darren Tucker | 88b6fb2 | 2010-01-13 22:44:29 +1100 | [diff] [blame] | 482 | xfree(expanded); |
| 483 | return ret; |
| 484 | } |
| 485 | |
Ben Lindstrom | bba8121 | 2001-06-25 05:01:22 +0000 | [diff] [blame] | 486 | static void |
Damien Miller | 3dc71ad | 2009-01-28 16:31:22 +1100 | [diff] [blame] | 487 | add_listen_addr(ServerOptions *options, char *addr, int port) |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 488 | { |
Damien Miller | eccb9de | 2005-06-17 12:59:34 +1000 | [diff] [blame] | 489 | u_int i; |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 490 | |
| 491 | if (options->num_ports == 0) |
| 492 | options->ports[options->num_ports++] = SSH_DEFAULT_PORT; |
Darren Tucker | 0f38323 | 2005-01-20 10:57:56 +1100 | [diff] [blame] | 493 | if (options->address_family == -1) |
| 494 | options->address_family = AF_UNSPEC; |
Ben Lindstrom | 19066a1 | 2001-04-12 23:39:26 +0000 | [diff] [blame] | 495 | if (port == 0) |
Ben Lindstrom | c510af4 | 2001-04-07 17:25:48 +0000 | [diff] [blame] | 496 | for (i = 0; i < options->num_ports; i++) |
| 497 | add_one_listen_addr(options, addr, options->ports[i]); |
| 498 | else |
Ben Lindstrom | 19066a1 | 2001-04-12 23:39:26 +0000 | [diff] [blame] | 499 | add_one_listen_addr(options, addr, port); |
Ben Lindstrom | c510af4 | 2001-04-07 17:25:48 +0000 | [diff] [blame] | 500 | } |
| 501 | |
Ben Lindstrom | bba8121 | 2001-06-25 05:01:22 +0000 | [diff] [blame] | 502 | static void |
Damien Miller | 3dc71ad | 2009-01-28 16:31:22 +1100 | [diff] [blame] | 503 | add_one_listen_addr(ServerOptions *options, char *addr, int port) |
Ben Lindstrom | c510af4 | 2001-04-07 17:25:48 +0000 | [diff] [blame] | 504 | { |
| 505 | struct addrinfo hints, *ai, *aitop; |
| 506 | char strport[NI_MAXSERV]; |
| 507 | int gaierr; |
| 508 | |
| 509 | memset(&hints, 0, sizeof(hints)); |
Darren Tucker | 0f38323 | 2005-01-20 10:57:56 +1100 | [diff] [blame] | 510 | hints.ai_family = options->address_family; |
Ben Lindstrom | c510af4 | 2001-04-07 17:25:48 +0000 | [diff] [blame] | 511 | hints.ai_socktype = SOCK_STREAM; |
| 512 | hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0; |
Damien Miller | 3dc71ad | 2009-01-28 16:31:22 +1100 | [diff] [blame] | 513 | snprintf(strport, sizeof strport, "%d", port); |
Ben Lindstrom | c510af4 | 2001-04-07 17:25:48 +0000 | [diff] [blame] | 514 | if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0) |
| 515 | fatal("bad addr or host: %s (%s)", |
| 516 | addr ? addr : "<NULL>", |
Darren Tucker | 4abde77 | 2007-12-29 02:43:51 +1100 | [diff] [blame] | 517 | ssh_gai_strerror(gaierr)); |
Ben Lindstrom | c510af4 | 2001-04-07 17:25:48 +0000 | [diff] [blame] | 518 | for (ai = aitop; ai->ai_next; ai = ai->ai_next) |
| 519 | ; |
| 520 | ai->ai_next = options->listen_addrs; |
| 521 | options->listen_addrs = aitop; |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 522 | } |
| 523 | |
Darren Tucker | 4515047 | 2006-07-12 22:34:17 +1000 | [diff] [blame] | 524 | /* |
| 525 | * The strategy for the Match blocks is that the config file is parsed twice. |
| 526 | * |
| 527 | * The first time is at startup. activep is initialized to 1 and the |
| 528 | * directives in the global context are processed and acted on. Hitting a |
| 529 | * Match directive unsets activep and the directives inside the block are |
| 530 | * checked for syntax only. |
| 531 | * |
| 532 | * The second time is after a connection has been established but before |
| 533 | * authentication. activep is initialized to 2 and global config directives |
| 534 | * are ignored since they have already been processed. If the criteria in a |
| 535 | * Match block is met, activep is set and the subsequent directives |
| 536 | * processed and actioned until EOF or another Match block unsets it. Any |
| 537 | * options set are copied into the main server config. |
| 538 | * |
| 539 | * Potential additions/improvements: |
| 540 | * - Add Match support for pre-kex directives, eg Protocol, Ciphers. |
| 541 | * |
| 542 | * - Add a Tag directive (idea from David Leonard) ala pf, eg: |
| 543 | * Match Address 192.168.0.* |
| 544 | * Tag trusted |
| 545 | * Match Group wheel |
| 546 | * Tag trusted |
| 547 | * Match Tag trusted |
| 548 | * AllowTcpForwarding yes |
| 549 | * GatewayPorts clientspecified |
| 550 | * [...] |
| 551 | * |
| 552 | * - Add a PermittedChannelRequests directive |
| 553 | * Match Group shell |
| 554 | * PermittedChannelRequests session,forwarded-tcpip |
| 555 | */ |
| 556 | |
| 557 | static int |
Damien Miller | 565ca3f | 2006-08-19 00:23:15 +1000 | [diff] [blame] | 558 | match_cfg_line_group(const char *grps, int line, const char *user) |
| 559 | { |
| 560 | int result = 0; |
Damien Miller | 565ca3f | 2006-08-19 00:23:15 +1000 | [diff] [blame] | 561 | struct passwd *pw; |
| 562 | |
Damien Miller | 565ca3f | 2006-08-19 00:23:15 +1000 | [diff] [blame] | 563 | if (user == NULL) |
| 564 | goto out; |
| 565 | |
| 566 | if ((pw = getpwnam(user)) == NULL) { |
| 567 | debug("Can't match group at line %d because user %.100s does " |
| 568 | "not exist", line, user); |
| 569 | } else if (ga_init(pw->pw_name, pw->pw_gid) == 0) { |
| 570 | debug("Can't Match group because user %.100s not in any group " |
| 571 | "at line %d", user, line); |
Darren Tucker | b03fd02 | 2008-07-04 13:51:12 +1000 | [diff] [blame] | 572 | } else if (ga_match_pattern_list(grps) != 1) { |
| 573 | debug("user %.100s does not match group list %.100s at line %d", |
| 574 | user, grps, line); |
Damien Miller | 565ca3f | 2006-08-19 00:23:15 +1000 | [diff] [blame] | 575 | } else { |
Darren Tucker | b03fd02 | 2008-07-04 13:51:12 +1000 | [diff] [blame] | 576 | debug("user %.100s matched group list %.100s at line %d", user, |
| 577 | grps, line); |
Damien Miller | 565ca3f | 2006-08-19 00:23:15 +1000 | [diff] [blame] | 578 | result = 1; |
| 579 | } |
| 580 | out: |
| 581 | ga_free(); |
Damien Miller | 565ca3f | 2006-08-19 00:23:15 +1000 | [diff] [blame] | 582 | return result; |
| 583 | } |
| 584 | |
| 585 | static int |
Darren Tucker | 4515047 | 2006-07-12 22:34:17 +1000 | [diff] [blame] | 586 | match_cfg_line(char **condition, int line, const char *user, const char *host, |
| 587 | const char *address) |
| 588 | { |
| 589 | int result = 1; |
| 590 | char *arg, *attrib, *cp = *condition; |
| 591 | size_t len; |
| 592 | |
| 593 | if (user == NULL) |
| 594 | debug3("checking syntax for 'Match %s'", cp); |
| 595 | else |
| 596 | debug3("checking match for '%s' user %s host %s addr %s", cp, |
| 597 | user ? user : "(null)", host ? host : "(null)", |
| 598 | address ? address : "(null)"); |
| 599 | |
| 600 | while ((attrib = strdelim(&cp)) && *attrib != '\0') { |
| 601 | if ((arg = strdelim(&cp)) == NULL || *arg == '\0') { |
| 602 | error("Missing Match criteria for %s", attrib); |
| 603 | return -1; |
| 604 | } |
| 605 | len = strlen(arg); |
| 606 | if (strcasecmp(attrib, "user") == 0) { |
| 607 | if (!user) { |
| 608 | result = 0; |
| 609 | continue; |
| 610 | } |
| 611 | if (match_pattern_list(user, arg, len, 0) != 1) |
| 612 | result = 0; |
| 613 | else |
| 614 | debug("user %.100s matched 'User %.100s' at " |
| 615 | "line %d", user, arg, line); |
Damien Miller | 565ca3f | 2006-08-19 00:23:15 +1000 | [diff] [blame] | 616 | } else if (strcasecmp(attrib, "group") == 0) { |
| 617 | switch (match_cfg_line_group(arg, line, user)) { |
| 618 | case -1: |
| 619 | return -1; |
| 620 | case 0: |
| 621 | result = 0; |
| 622 | } |
Darren Tucker | 4515047 | 2006-07-12 22:34:17 +1000 | [diff] [blame] | 623 | } else if (strcasecmp(attrib, "host") == 0) { |
| 624 | if (!host) { |
| 625 | result = 0; |
| 626 | continue; |
| 627 | } |
| 628 | if (match_hostname(host, arg, len) != 1) |
| 629 | result = 0; |
| 630 | else |
| 631 | debug("connection from %.100s matched 'Host " |
| 632 | "%.100s' at line %d", host, arg, line); |
| 633 | } else if (strcasecmp(attrib, "address") == 0) { |
Darren Tucker | 7a3935d | 2008-06-10 22:59:10 +1000 | [diff] [blame] | 634 | switch (addr_match_list(address, arg)) { |
| 635 | case 1: |
Darren Tucker | 4515047 | 2006-07-12 22:34:17 +1000 | [diff] [blame] | 636 | debug("connection from %.100s matched 'Address " |
| 637 | "%.100s' at line %d", address, arg, line); |
Darren Tucker | 7a3935d | 2008-06-10 22:59:10 +1000 | [diff] [blame] | 638 | break; |
| 639 | case 0: |
Darren Tucker | 896ad5a | 2008-06-11 09:34:46 +1000 | [diff] [blame] | 640 | case -1: |
Darren Tucker | 7a3935d | 2008-06-10 22:59:10 +1000 | [diff] [blame] | 641 | result = 0; |
| 642 | break; |
Darren Tucker | 896ad5a | 2008-06-11 09:34:46 +1000 | [diff] [blame] | 643 | case -2: |
Darren Tucker | 7a3935d | 2008-06-10 22:59:10 +1000 | [diff] [blame] | 644 | return -1; |
| 645 | } |
Darren Tucker | 4515047 | 2006-07-12 22:34:17 +1000 | [diff] [blame] | 646 | } else { |
| 647 | error("Unsupported Match attribute %s", attrib); |
| 648 | return -1; |
| 649 | } |
| 650 | } |
| 651 | if (user != NULL) |
| 652 | debug3("match %sfound", result ? "" : "not "); |
| 653 | *condition = cp; |
| 654 | return result; |
| 655 | } |
| 656 | |
Damien Miller | e275443 | 2006-07-24 14:06:47 +1000 | [diff] [blame] | 657 | #define WHITESPACE " \t\r\n" |
| 658 | |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 659 | int |
| 660 | process_server_config_line(ServerOptions *options, char *line, |
Darren Tucker | 4515047 | 2006-07-12 22:34:17 +1000 | [diff] [blame] | 661 | const char *filename, int linenum, int *activep, const char *user, |
| 662 | const char *host, const char *address) |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 663 | { |
| 664 | char *cp, **charptr, *arg, *p; |
Darren Tucker | 4515047 | 2006-07-12 22:34:17 +1000 | [diff] [blame] | 665 | int cmdline = 0, *intptr, value, n; |
Darren Tucker | 1e44c5d | 2008-01-01 20:32:26 +1100 | [diff] [blame] | 666 | SyslogFacility *log_facility_ptr; |
| 667 | LogLevel *log_level_ptr; |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 668 | ServerOpCodes opcode; |
Damien Miller | 3dc71ad | 2009-01-28 16:31:22 +1100 | [diff] [blame] | 669 | int port; |
Darren Tucker | 4515047 | 2006-07-12 22:34:17 +1000 | [diff] [blame] | 670 | u_int i, flags = 0; |
Damien Miller | 917f9b6 | 2006-07-10 20:36:47 +1000 | [diff] [blame] | 671 | size_t len; |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 672 | |
| 673 | cp = line; |
Damien Miller | 78f16cb | 2006-03-26 13:54:37 +1100 | [diff] [blame] | 674 | if ((arg = strdelim(&cp)) == NULL) |
Damien Miller | 928b236 | 2006-03-26 13:53:32 +1100 | [diff] [blame] | 675 | return 0; |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 676 | /* Ignore leading whitespace */ |
| 677 | if (*arg == '\0') |
| 678 | arg = strdelim(&cp); |
| 679 | if (!arg || !*arg || *arg == '#') |
| 680 | return 0; |
| 681 | intptr = NULL; |
| 682 | charptr = NULL; |
Darren Tucker | 4515047 | 2006-07-12 22:34:17 +1000 | [diff] [blame] | 683 | opcode = parse_token(arg, filename, linenum, &flags); |
| 684 | |
| 685 | if (activep == NULL) { /* We are processing a command line directive */ |
| 686 | cmdline = 1; |
| 687 | activep = &cmdline; |
| 688 | } |
| 689 | if (*activep && opcode != sMatch) |
| 690 | debug3("%s:%d setting %s %s", filename, linenum, arg, cp); |
| 691 | if (*activep == 0 && !(flags & SSHCFG_MATCH)) { |
| 692 | if (user == NULL) { |
| 693 | fatal("%s line %d: Directive '%s' is not allowed " |
| 694 | "within a Match block", filename, linenum, arg); |
| 695 | } else { /* this is a directive we have already processed */ |
| 696 | while (arg) |
| 697 | arg = strdelim(&cp); |
| 698 | return 0; |
| 699 | } |
| 700 | } |
| 701 | |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 702 | switch (opcode) { |
| 703 | /* Portable-specific options */ |
Damien Miller | 4e448a3 | 2003-05-14 15:11:48 +1000 | [diff] [blame] | 704 | case sUsePAM: |
| 705 | intptr = &options->use_pam; |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 706 | goto parse_flag; |
| 707 | |
| 708 | /* Standard Options */ |
| 709 | case sBadOption: |
| 710 | return -1; |
| 711 | case sPort: |
| 712 | /* ignore ports from configfile if cmdline specifies ports */ |
| 713 | if (options->ports_from_cmdline) |
| 714 | return 0; |
| 715 | if (options->listen_addrs != NULL) |
| 716 | fatal("%s line %d: ports must be specified before " |
Damien Miller | 4fbf08a | 2002-01-22 23:35:09 +1100 | [diff] [blame] | 717 | "ListenAddress.", filename, linenum); |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 718 | if (options->num_ports >= MAX_PORTS) |
| 719 | fatal("%s line %d: too many ports.", |
| 720 | filename, linenum); |
| 721 | arg = strdelim(&cp); |
| 722 | if (!arg || *arg == '\0') |
| 723 | fatal("%s line %d: missing port number.", |
| 724 | filename, linenum); |
| 725 | options->ports[options->num_ports++] = a2port(arg); |
Damien Miller | 3dc71ad | 2009-01-28 16:31:22 +1100 | [diff] [blame] | 726 | if (options->ports[options->num_ports-1] <= 0) |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 727 | fatal("%s line %d: Badly formatted port number.", |
| 728 | filename, linenum); |
| 729 | break; |
| 730 | |
| 731 | case sServerKeyBits: |
| 732 | intptr = &options->server_key_bits; |
Damien Miller | 7207f64 | 2008-05-19 15:34:50 +1000 | [diff] [blame] | 733 | parse_int: |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 734 | arg = strdelim(&cp); |
| 735 | if (!arg || *arg == '\0') |
| 736 | fatal("%s line %d: missing integer value.", |
| 737 | filename, linenum); |
| 738 | value = atoi(arg); |
Darren Tucker | 4515047 | 2006-07-12 22:34:17 +1000 | [diff] [blame] | 739 | if (*activep && *intptr == -1) |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 740 | *intptr = value; |
| 741 | break; |
| 742 | |
| 743 | case sLoginGraceTime: |
| 744 | intptr = &options->login_grace_time; |
Damien Miller | 7207f64 | 2008-05-19 15:34:50 +1000 | [diff] [blame] | 745 | parse_time: |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 746 | arg = strdelim(&cp); |
| 747 | if (!arg || *arg == '\0') |
| 748 | fatal("%s line %d: missing time value.", |
| 749 | filename, linenum); |
| 750 | if ((value = convtime(arg)) == -1) |
| 751 | fatal("%s line %d: invalid time value.", |
| 752 | filename, linenum); |
| 753 | if (*intptr == -1) |
| 754 | *intptr = value; |
| 755 | break; |
| 756 | |
| 757 | case sKeyRegenerationTime: |
| 758 | intptr = &options->key_regeneration_time; |
| 759 | goto parse_time; |
| 760 | |
| 761 | case sListenAddress: |
| 762 | arg = strdelim(&cp); |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 763 | if (arg == NULL || *arg == '\0') |
| 764 | fatal("%s line %d: missing address", |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 765 | filename, linenum); |
Damien Miller | 203c705 | 2005-08-12 22:11:37 +1000 | [diff] [blame] | 766 | /* check for bare IPv6 address: no "[]" and 2 or more ":" */ |
| 767 | if (strchr(arg, '[') == NULL && (p = strchr(arg, ':')) != NULL |
| 768 | && strchr(p+1, ':') != NULL) { |
| 769 | add_listen_addr(options, arg, 0); |
| 770 | break; |
| 771 | } |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 772 | p = hpdelim(&arg); |
| 773 | if (p == NULL) |
| 774 | fatal("%s line %d: bad address:port usage", |
| 775 | filename, linenum); |
| 776 | p = cleanhostname(p); |
| 777 | if (arg == NULL) |
| 778 | port = 0; |
Damien Miller | 3dc71ad | 2009-01-28 16:31:22 +1100 | [diff] [blame] | 779 | else if ((port = a2port(arg)) <= 0) |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 780 | fatal("%s line %d: bad port number", filename, linenum); |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 781 | |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 782 | add_listen_addr(options, p, port); |
| 783 | |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 784 | break; |
| 785 | |
Darren Tucker | 0f38323 | 2005-01-20 10:57:56 +1100 | [diff] [blame] | 786 | case sAddressFamily: |
| 787 | arg = strdelim(&cp); |
Damien Miller | 17b23d8 | 2005-05-26 12:11:56 +1000 | [diff] [blame] | 788 | if (!arg || *arg == '\0') |
| 789 | fatal("%s line %d: missing address family.", |
| 790 | filename, linenum); |
Darren Tucker | 0f38323 | 2005-01-20 10:57:56 +1100 | [diff] [blame] | 791 | intptr = &options->address_family; |
| 792 | if (options->listen_addrs != NULL) |
| 793 | fatal("%s line %d: address family must be specified before " |
| 794 | "ListenAddress.", filename, linenum); |
| 795 | if (strcasecmp(arg, "inet") == 0) |
| 796 | value = AF_INET; |
| 797 | else if (strcasecmp(arg, "inet6") == 0) |
| 798 | value = AF_INET6; |
| 799 | else if (strcasecmp(arg, "any") == 0) |
| 800 | value = AF_UNSPEC; |
| 801 | else |
| 802 | fatal("%s line %d: unsupported address family \"%s\".", |
| 803 | filename, linenum, arg); |
| 804 | if (*intptr == -1) |
| 805 | *intptr = value; |
| 806 | break; |
| 807 | |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 808 | case sHostKeyFile: |
| 809 | intptr = &options->num_host_key_files; |
| 810 | if (*intptr >= MAX_HOSTKEYS) |
| 811 | fatal("%s line %d: too many host keys specified (max %d).", |
| 812 | filename, linenum, MAX_HOSTKEYS); |
| 813 | charptr = &options->host_key_files[*intptr]; |
Damien Miller | 7207f64 | 2008-05-19 15:34:50 +1000 | [diff] [blame] | 814 | parse_filename: |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 815 | arg = strdelim(&cp); |
| 816 | if (!arg || *arg == '\0') |
| 817 | fatal("%s line %d: missing file name.", |
| 818 | filename, linenum); |
Darren Tucker | 4515047 | 2006-07-12 22:34:17 +1000 | [diff] [blame] | 819 | if (*activep && *charptr == NULL) { |
Darren Tucker | 88b6fb2 | 2010-01-13 22:44:29 +1100 | [diff] [blame] | 820 | *charptr = derelativise_path(arg); |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 821 | /* increase optional counter */ |
| 822 | if (intptr != NULL) |
| 823 | *intptr = *intptr + 1; |
| 824 | } |
| 825 | break; |
| 826 | |
Damien Miller | 0a80ca1 | 2010-02-27 07:55:05 +1100 | [diff] [blame] | 827 | case sHostCertificate: |
| 828 | intptr = &options->num_host_cert_files; |
| 829 | if (*intptr >= MAX_HOSTKEYS) |
| 830 | fatal("%s line %d: too many host certificates " |
| 831 | "specified (max %d).", filename, linenum, |
| 832 | MAX_HOSTCERTS); |
| 833 | charptr = &options->host_cert_files[*intptr]; |
| 834 | goto parse_filename; |
| 835 | break; |
| 836 | |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 837 | case sPidFile: |
| 838 | charptr = &options->pid_file; |
| 839 | goto parse_filename; |
| 840 | |
| 841 | case sPermitRootLogin: |
| 842 | intptr = &options->permit_root_login; |
| 843 | arg = strdelim(&cp); |
| 844 | if (!arg || *arg == '\0') |
| 845 | fatal("%s line %d: missing yes/" |
| 846 | "without-password/forced-commands-only/no " |
| 847 | "argument.", filename, linenum); |
| 848 | value = 0; /* silence compiler */ |
| 849 | if (strcmp(arg, "without-password") == 0) |
| 850 | value = PERMIT_NO_PASSWD; |
| 851 | else if (strcmp(arg, "forced-commands-only") == 0) |
| 852 | value = PERMIT_FORCED_ONLY; |
| 853 | else if (strcmp(arg, "yes") == 0) |
| 854 | value = PERMIT_YES; |
| 855 | else if (strcmp(arg, "no") == 0) |
| 856 | value = PERMIT_NO; |
| 857 | else |
| 858 | fatal("%s line %d: Bad yes/" |
| 859 | "without-password/forced-commands-only/no " |
| 860 | "argument: %s", filename, linenum, arg); |
Darren Tucker | 15f9427 | 2008-01-01 20:36:56 +1100 | [diff] [blame] | 861 | if (*activep && *intptr == -1) |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 862 | *intptr = value; |
| 863 | break; |
| 864 | |
| 865 | case sIgnoreRhosts: |
| 866 | intptr = &options->ignore_rhosts; |
Damien Miller | 7207f64 | 2008-05-19 15:34:50 +1000 | [diff] [blame] | 867 | parse_flag: |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 868 | arg = strdelim(&cp); |
| 869 | if (!arg || *arg == '\0') |
| 870 | fatal("%s line %d: missing yes/no argument.", |
| 871 | filename, linenum); |
| 872 | value = 0; /* silence compiler */ |
| 873 | if (strcmp(arg, "yes") == 0) |
| 874 | value = 1; |
| 875 | else if (strcmp(arg, "no") == 0) |
| 876 | value = 0; |
| 877 | else |
| 878 | fatal("%s line %d: Bad yes/no argument: %s", |
| 879 | filename, linenum, arg); |
Darren Tucker | 4515047 | 2006-07-12 22:34:17 +1000 | [diff] [blame] | 880 | if (*activep && *intptr == -1) |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 881 | *intptr = value; |
| 882 | break; |
| 883 | |
| 884 | case sIgnoreUserKnownHosts: |
| 885 | intptr = &options->ignore_user_known_hosts; |
| 886 | goto parse_flag; |
| 887 | |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 888 | case sRhostsRSAAuthentication: |
| 889 | intptr = &options->rhosts_rsa_authentication; |
| 890 | goto parse_flag; |
| 891 | |
| 892 | case sHostbasedAuthentication: |
| 893 | intptr = &options->hostbased_authentication; |
| 894 | goto parse_flag; |
| 895 | |
| 896 | case sHostbasedUsesNameFromPacketOnly: |
| 897 | intptr = &options->hostbased_uses_name_from_packet_only; |
| 898 | goto parse_flag; |
| 899 | |
| 900 | case sRSAAuthentication: |
| 901 | intptr = &options->rsa_authentication; |
| 902 | goto parse_flag; |
| 903 | |
| 904 | case sPubkeyAuthentication: |
| 905 | intptr = &options->pubkey_authentication; |
| 906 | goto parse_flag; |
Damien Miller | 2aa0ab4 | 2003-05-15 12:05:28 +1000 | [diff] [blame] | 907 | |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 908 | case sKerberosAuthentication: |
| 909 | intptr = &options->kerberos_authentication; |
| 910 | goto parse_flag; |
| 911 | |
| 912 | case sKerberosOrLocalPasswd: |
| 913 | intptr = &options->kerberos_or_local_passwd; |
| 914 | goto parse_flag; |
| 915 | |
| 916 | case sKerberosTicketCleanup: |
| 917 | intptr = &options->kerberos_ticket_cleanup; |
| 918 | goto parse_flag; |
Damien Miller | 2aa0ab4 | 2003-05-15 12:05:28 +1000 | [diff] [blame] | 919 | |
Darren Tucker | 22ef508 | 2003-12-31 11:37:34 +1100 | [diff] [blame] | 920 | case sKerberosGetAFSToken: |
| 921 | intptr = &options->kerberos_get_afs_token; |
| 922 | goto parse_flag; |
| 923 | |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 924 | case sGssAuthentication: |
| 925 | intptr = &options->gss_authentication; |
| 926 | goto parse_flag; |
| 927 | |
| 928 | case sGssCleanupCreds: |
| 929 | intptr = &options->gss_cleanup_creds; |
| 930 | goto parse_flag; |
| 931 | |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 932 | case sPasswordAuthentication: |
| 933 | intptr = &options->password_authentication; |
| 934 | goto parse_flag; |
| 935 | |
Damien Miller | 01ed227 | 2008-11-05 16:20:46 +1100 | [diff] [blame] | 936 | case sZeroKnowledgePasswordAuthentication: |
| 937 | intptr = &options->zero_knowledge_password_authentication; |
| 938 | goto parse_flag; |
| 939 | |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 940 | case sKbdInteractiveAuthentication: |
| 941 | intptr = &options->kbd_interactive_authentication; |
| 942 | goto parse_flag; |
| 943 | |
| 944 | case sChallengeResponseAuthentication: |
| 945 | intptr = &options->challenge_response_authentication; |
| 946 | goto parse_flag; |
| 947 | |
| 948 | case sPrintMotd: |
| 949 | intptr = &options->print_motd; |
| 950 | goto parse_flag; |
| 951 | |
| 952 | case sPrintLastLog: |
| 953 | intptr = &options->print_lastlog; |
| 954 | goto parse_flag; |
| 955 | |
| 956 | case sX11Forwarding: |
| 957 | intptr = &options->x11_forwarding; |
| 958 | goto parse_flag; |
| 959 | |
| 960 | case sX11DisplayOffset: |
| 961 | intptr = &options->x11_display_offset; |
| 962 | goto parse_int; |
| 963 | |
Damien Miller | 95c249f | 2002-02-05 12:11:34 +1100 | [diff] [blame] | 964 | case sX11UseLocalhost: |
| 965 | intptr = &options->x11_use_localhost; |
| 966 | goto parse_flag; |
| 967 | |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 968 | case sXAuthLocation: |
| 969 | charptr = &options->xauth_location; |
| 970 | goto parse_filename; |
| 971 | |
| 972 | case sStrictModes: |
| 973 | intptr = &options->strict_modes; |
| 974 | goto parse_flag; |
| 975 | |
Damien Miller | 12c150e | 2003-12-17 16:31:10 +1100 | [diff] [blame] | 976 | case sTCPKeepAlive: |
| 977 | intptr = &options->tcp_keep_alive; |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 978 | goto parse_flag; |
| 979 | |
| 980 | case sEmptyPasswd: |
| 981 | intptr = &options->permit_empty_passwd; |
| 982 | goto parse_flag; |
| 983 | |
Ben Lindstrom | 5d860f0 | 2002-08-01 01:28:38 +0000 | [diff] [blame] | 984 | case sPermitUserEnvironment: |
| 985 | intptr = &options->permit_user_env; |
| 986 | goto parse_flag; |
| 987 | |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 988 | case sUseLogin: |
| 989 | intptr = &options->use_login; |
| 990 | goto parse_flag; |
| 991 | |
Ben Lindstrom | 23e0f66 | 2002-06-21 01:09:47 +0000 | [diff] [blame] | 992 | case sCompression: |
| 993 | intptr = &options->compression; |
Damien Miller | 9786e6e | 2005-07-26 21:54:56 +1000 | [diff] [blame] | 994 | arg = strdelim(&cp); |
| 995 | if (!arg || *arg == '\0') |
| 996 | fatal("%s line %d: missing yes/no/delayed " |
| 997 | "argument.", filename, linenum); |
| 998 | value = 0; /* silence compiler */ |
| 999 | if (strcmp(arg, "delayed") == 0) |
| 1000 | value = COMP_DELAYED; |
| 1001 | else if (strcmp(arg, "yes") == 0) |
| 1002 | value = COMP_ZLIB; |
| 1003 | else if (strcmp(arg, "no") == 0) |
| 1004 | value = COMP_NONE; |
| 1005 | else |
| 1006 | fatal("%s line %d: Bad yes/no/delayed " |
| 1007 | "argument: %s", filename, linenum, arg); |
| 1008 | if (*intptr == -1) |
| 1009 | *intptr = value; |
| 1010 | break; |
Ben Lindstrom | 23e0f66 | 2002-06-21 01:09:47 +0000 | [diff] [blame] | 1011 | |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 1012 | case sGatewayPorts: |
| 1013 | intptr = &options->gateway_ports; |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 1014 | arg = strdelim(&cp); |
| 1015 | if (!arg || *arg == '\0') |
| 1016 | fatal("%s line %d: missing yes/no/clientspecified " |
| 1017 | "argument.", filename, linenum); |
| 1018 | value = 0; /* silence compiler */ |
| 1019 | if (strcmp(arg, "clientspecified") == 0) |
| 1020 | value = 2; |
| 1021 | else if (strcmp(arg, "yes") == 0) |
| 1022 | value = 1; |
| 1023 | else if (strcmp(arg, "no") == 0) |
| 1024 | value = 0; |
| 1025 | else |
| 1026 | fatal("%s line %d: Bad yes/no/clientspecified " |
| 1027 | "argument: %s", filename, linenum, arg); |
Darren Tucker | 82347a8 | 2007-02-25 20:37:52 +1100 | [diff] [blame] | 1028 | if (*activep && *intptr == -1) |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 1029 | *intptr = value; |
| 1030 | break; |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 1031 | |
Damien Miller | 3a961dc | 2003-06-03 10:25:48 +1000 | [diff] [blame] | 1032 | case sUseDNS: |
| 1033 | intptr = &options->use_dns; |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 1034 | goto parse_flag; |
| 1035 | |
| 1036 | case sLogFacility: |
Darren Tucker | 1e44c5d | 2008-01-01 20:32:26 +1100 | [diff] [blame] | 1037 | log_facility_ptr = &options->log_facility; |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 1038 | arg = strdelim(&cp); |
| 1039 | value = log_facility_number(arg); |
Damien Miller | fcd9320 | 2002-02-05 12:26:34 +1100 | [diff] [blame] | 1040 | if (value == SYSLOG_FACILITY_NOT_SET) |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 1041 | fatal("%.200s line %d: unsupported log facility '%s'", |
| 1042 | filename, linenum, arg ? arg : "<NONE>"); |
Darren Tucker | 1e44c5d | 2008-01-01 20:32:26 +1100 | [diff] [blame] | 1043 | if (*log_facility_ptr == -1) |
| 1044 | *log_facility_ptr = (SyslogFacility) value; |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 1045 | break; |
| 1046 | |
| 1047 | case sLogLevel: |
Darren Tucker | 1e44c5d | 2008-01-01 20:32:26 +1100 | [diff] [blame] | 1048 | log_level_ptr = &options->log_level; |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 1049 | arg = strdelim(&cp); |
| 1050 | value = log_level_number(arg); |
Damien Miller | fcd9320 | 2002-02-05 12:26:34 +1100 | [diff] [blame] | 1051 | if (value == SYSLOG_LEVEL_NOT_SET) |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 1052 | fatal("%.200s line %d: unsupported log level '%s'", |
| 1053 | filename, linenum, arg ? arg : "<NONE>"); |
Darren Tucker | 1e44c5d | 2008-01-01 20:32:26 +1100 | [diff] [blame] | 1054 | if (*log_level_ptr == -1) |
| 1055 | *log_level_ptr = (LogLevel) value; |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 1056 | break; |
| 1057 | |
| 1058 | case sAllowTcpForwarding: |
| 1059 | intptr = &options->allow_tcp_forwarding; |
| 1060 | goto parse_flag; |
| 1061 | |
Damien Miller | 4f755cd | 2008-05-19 14:57:41 +1000 | [diff] [blame] | 1062 | case sAllowAgentForwarding: |
| 1063 | intptr = &options->allow_agent_forwarding; |
| 1064 | goto parse_flag; |
| 1065 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1066 | case sUsePrivilegeSeparation: |
| 1067 | intptr = &use_privsep; |
| 1068 | goto parse_flag; |
| 1069 | |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 1070 | case sAllowUsers: |
| 1071 | while ((arg = strdelim(&cp)) && *arg != '\0') { |
| 1072 | if (options->num_allow_users >= MAX_ALLOW_USERS) |
| 1073 | fatal("%s line %d: too many allow users.", |
| 1074 | filename, linenum); |
Ben Lindstrom | e135363 | 2002-06-23 21:29:23 +0000 | [diff] [blame] | 1075 | options->allow_users[options->num_allow_users++] = |
| 1076 | xstrdup(arg); |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 1077 | } |
| 1078 | break; |
| 1079 | |
| 1080 | case sDenyUsers: |
| 1081 | while ((arg = strdelim(&cp)) && *arg != '\0') { |
| 1082 | if (options->num_deny_users >= MAX_DENY_USERS) |
Damien Miller | 4dec5d7 | 2006-08-05 11:38:40 +1000 | [diff] [blame] | 1083 | fatal("%s line %d: too many deny users.", |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 1084 | filename, linenum); |
Ben Lindstrom | e135363 | 2002-06-23 21:29:23 +0000 | [diff] [blame] | 1085 | options->deny_users[options->num_deny_users++] = |
| 1086 | xstrdup(arg); |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 1087 | } |
| 1088 | break; |
| 1089 | |
| 1090 | case sAllowGroups: |
| 1091 | while ((arg = strdelim(&cp)) && *arg != '\0') { |
| 1092 | if (options->num_allow_groups >= MAX_ALLOW_GROUPS) |
| 1093 | fatal("%s line %d: too many allow groups.", |
| 1094 | filename, linenum); |
Ben Lindstrom | e135363 | 2002-06-23 21:29:23 +0000 | [diff] [blame] | 1095 | options->allow_groups[options->num_allow_groups++] = |
| 1096 | xstrdup(arg); |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 1097 | } |
| 1098 | break; |
| 1099 | |
| 1100 | case sDenyGroups: |
| 1101 | while ((arg = strdelim(&cp)) && *arg != '\0') { |
| 1102 | if (options->num_deny_groups >= MAX_DENY_GROUPS) |
| 1103 | fatal("%s line %d: too many deny groups.", |
| 1104 | filename, linenum); |
| 1105 | options->deny_groups[options->num_deny_groups++] = xstrdup(arg); |
| 1106 | } |
| 1107 | break; |
| 1108 | |
| 1109 | case sCiphers: |
| 1110 | arg = strdelim(&cp); |
| 1111 | if (!arg || *arg == '\0') |
| 1112 | fatal("%s line %d: Missing argument.", filename, linenum); |
| 1113 | if (!ciphers_valid(arg)) |
| 1114 | fatal("%s line %d: Bad SSH2 cipher spec '%s'.", |
| 1115 | filename, linenum, arg ? arg : "<NONE>"); |
| 1116 | if (options->ciphers == NULL) |
| 1117 | options->ciphers = xstrdup(arg); |
| 1118 | break; |
| 1119 | |
| 1120 | case sMacs: |
| 1121 | arg = strdelim(&cp); |
| 1122 | if (!arg || *arg == '\0') |
| 1123 | fatal("%s line %d: Missing argument.", filename, linenum); |
| 1124 | if (!mac_valid(arg)) |
| 1125 | fatal("%s line %d: Bad SSH2 mac spec '%s'.", |
| 1126 | filename, linenum, arg ? arg : "<NONE>"); |
| 1127 | if (options->macs == NULL) |
| 1128 | options->macs = xstrdup(arg); |
| 1129 | break; |
| 1130 | |
| 1131 | case sProtocol: |
| 1132 | intptr = &options->protocol; |
| 1133 | arg = strdelim(&cp); |
| 1134 | if (!arg || *arg == '\0') |
| 1135 | fatal("%s line %d: Missing argument.", filename, linenum); |
| 1136 | value = proto_spec(arg); |
| 1137 | if (value == SSH_PROTO_UNKNOWN) |
| 1138 | fatal("%s line %d: Bad protocol spec '%s'.", |
Damien Miller | 9f0f5c6 | 2001-12-21 14:45:46 +1100 | [diff] [blame] | 1139 | filename, linenum, arg ? arg : "<NONE>"); |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 1140 | if (*intptr == SSH_PROTO_UNKNOWN) |
| 1141 | *intptr = value; |
| 1142 | break; |
| 1143 | |
| 1144 | case sSubsystem: |
| 1145 | if (options->num_subsystems >= MAX_SUBSYSTEMS) { |
| 1146 | fatal("%s line %d: too many subsystems defined.", |
Damien Miller | 9f0f5c6 | 2001-12-21 14:45:46 +1100 | [diff] [blame] | 1147 | filename, linenum); |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 1148 | } |
| 1149 | arg = strdelim(&cp); |
| 1150 | if (!arg || *arg == '\0') |
| 1151 | fatal("%s line %d: Missing subsystem name.", |
Damien Miller | 9f0f5c6 | 2001-12-21 14:45:46 +1100 | [diff] [blame] | 1152 | filename, linenum); |
Darren Tucker | 4515047 | 2006-07-12 22:34:17 +1000 | [diff] [blame] | 1153 | if (!*activep) { |
| 1154 | arg = strdelim(&cp); |
| 1155 | break; |
| 1156 | } |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 1157 | for (i = 0; i < options->num_subsystems; i++) |
| 1158 | if (strcmp(arg, options->subsystem_name[i]) == 0) |
| 1159 | fatal("%s line %d: Subsystem '%s' already defined.", |
Damien Miller | 9f0f5c6 | 2001-12-21 14:45:46 +1100 | [diff] [blame] | 1160 | filename, linenum, arg); |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 1161 | options->subsystem_name[options->num_subsystems] = xstrdup(arg); |
| 1162 | arg = strdelim(&cp); |
| 1163 | if (!arg || *arg == '\0') |
| 1164 | fatal("%s line %d: Missing subsystem command.", |
Damien Miller | 9f0f5c6 | 2001-12-21 14:45:46 +1100 | [diff] [blame] | 1165 | filename, linenum); |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 1166 | options->subsystem_command[options->num_subsystems] = xstrdup(arg); |
Damien Miller | 917f9b6 | 2006-07-10 20:36:47 +1000 | [diff] [blame] | 1167 | |
| 1168 | /* Collect arguments (separate to executable) */ |
| 1169 | p = xstrdup(arg); |
| 1170 | len = strlen(p) + 1; |
| 1171 | while ((arg = strdelim(&cp)) != NULL && *arg != '\0') { |
| 1172 | len += 1 + strlen(arg); |
| 1173 | p = xrealloc(p, 1, len); |
| 1174 | strlcat(p, " ", len); |
| 1175 | strlcat(p, arg, len); |
| 1176 | } |
| 1177 | options->subsystem_args[options->num_subsystems] = p; |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 1178 | options->num_subsystems++; |
| 1179 | break; |
| 1180 | |
| 1181 | case sMaxStartups: |
| 1182 | arg = strdelim(&cp); |
| 1183 | if (!arg || *arg == '\0') |
| 1184 | fatal("%s line %d: Missing MaxStartups spec.", |
Damien Miller | 9f0f5c6 | 2001-12-21 14:45:46 +1100 | [diff] [blame] | 1185 | filename, linenum); |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 1186 | if ((n = sscanf(arg, "%d:%d:%d", |
| 1187 | &options->max_startups_begin, |
| 1188 | &options->max_startups_rate, |
| 1189 | &options->max_startups)) == 3) { |
| 1190 | if (options->max_startups_begin > |
| 1191 | options->max_startups || |
| 1192 | options->max_startups_rate > 100 || |
| 1193 | options->max_startups_rate < 1) |
| 1194 | fatal("%s line %d: Illegal MaxStartups spec.", |
| 1195 | filename, linenum); |
| 1196 | } else if (n != 1) |
| 1197 | fatal("%s line %d: Illegal MaxStartups spec.", |
| 1198 | filename, linenum); |
| 1199 | else |
| 1200 | options->max_startups = options->max_startups_begin; |
| 1201 | break; |
| 1202 | |
Darren Tucker | 89413db | 2004-05-24 10:36:23 +1000 | [diff] [blame] | 1203 | case sMaxAuthTries: |
| 1204 | intptr = &options->max_authtries; |
| 1205 | goto parse_int; |
| 1206 | |
Damien Miller | 7207f64 | 2008-05-19 15:34:50 +1000 | [diff] [blame] | 1207 | case sMaxSessions: |
| 1208 | intptr = &options->max_sessions; |
| 1209 | goto parse_int; |
| 1210 | |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 1211 | case sBanner: |
| 1212 | charptr = &options->banner; |
| 1213 | goto parse_filename; |
Damien Miller | d8cb1f1 | 2008-02-10 22:40:12 +1100 | [diff] [blame] | 1214 | |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 1215 | /* |
| 1216 | * These options can contain %X options expanded at |
| 1217 | * connect time, so that you can specify paths like: |
| 1218 | * |
| 1219 | * AuthorizedKeysFile /etc/ssh_keys/%u |
| 1220 | */ |
| 1221 | case sAuthorizedKeysFile: |
| 1222 | case sAuthorizedKeysFile2: |
Damien Miller | 4dec5d7 | 2006-08-05 11:38:40 +1000 | [diff] [blame] | 1223 | charptr = (opcode == sAuthorizedKeysFile) ? |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 1224 | &options->authorized_keys_file : |
| 1225 | &options->authorized_keys_file2; |
Damien Miller | c4cb47b | 2010-03-22 05:52:26 +1100 | [diff] [blame] | 1226 | arg = strdelim(&cp); |
| 1227 | if (!arg || *arg == '\0') |
| 1228 | fatal("%s line %d: missing file name.", |
| 1229 | filename, linenum); |
| 1230 | if (*activep && *charptr == NULL) { |
Damien Miller | 4a5f0d3 | 2010-03-22 05:53:04 +1100 | [diff] [blame] | 1231 | *charptr = tilde_expand_filename(arg, getuid()); |
Damien Miller | c4cb47b | 2010-03-22 05:52:26 +1100 | [diff] [blame] | 1232 | /* increase optional counter */ |
| 1233 | if (intptr != NULL) |
| 1234 | *intptr = *intptr + 1; |
| 1235 | } |
| 1236 | break; |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 1237 | |
| 1238 | case sClientAliveInterval: |
| 1239 | intptr = &options->client_alive_interval; |
| 1240 | goto parse_time; |
| 1241 | |
| 1242 | case sClientAliveCountMax: |
| 1243 | intptr = &options->client_alive_count_max; |
| 1244 | goto parse_int; |
| 1245 | |
Darren Tucker | 46bc075 | 2004-05-02 22:11:30 +1000 | [diff] [blame] | 1246 | case sAcceptEnv: |
| 1247 | while ((arg = strdelim(&cp)) && *arg != '\0') { |
| 1248 | if (strchr(arg, '=') != NULL) |
| 1249 | fatal("%s line %d: Invalid environment name.", |
| 1250 | filename, linenum); |
| 1251 | if (options->num_accept_env >= MAX_ACCEPT_ENV) |
| 1252 | fatal("%s line %d: too many allow env.", |
| 1253 | filename, linenum); |
Darren Tucker | 4515047 | 2006-07-12 22:34:17 +1000 | [diff] [blame] | 1254 | if (!*activep) |
| 1255 | break; |
Darren Tucker | 46bc075 | 2004-05-02 22:11:30 +1000 | [diff] [blame] | 1256 | options->accept_env[options->num_accept_env++] = |
| 1257 | xstrdup(arg); |
| 1258 | } |
| 1259 | break; |
| 1260 | |
Damien Miller | d27b947 | 2005-12-13 19:29:02 +1100 | [diff] [blame] | 1261 | case sPermitTunnel: |
| 1262 | intptr = &options->permit_tun; |
Damien Miller | 7b58e80 | 2005-12-13 19:33:19 +1100 | [diff] [blame] | 1263 | arg = strdelim(&cp); |
| 1264 | if (!arg || *arg == '\0') |
| 1265 | fatal("%s line %d: Missing yes/point-to-point/" |
| 1266 | "ethernet/no argument.", filename, linenum); |
Darren Tucker | e7140f2 | 2008-06-10 23:01:51 +1000 | [diff] [blame] | 1267 | value = -1; |
| 1268 | for (i = 0; tunmode_desc[i].val != -1; i++) |
| 1269 | if (strcmp(tunmode_desc[i].text, arg) == 0) { |
| 1270 | value = tunmode_desc[i].val; |
| 1271 | break; |
| 1272 | } |
| 1273 | if (value == -1) |
Damien Miller | 7b58e80 | 2005-12-13 19:33:19 +1100 | [diff] [blame] | 1274 | fatal("%s line %d: Bad yes/point-to-point/ethernet/" |
| 1275 | "no argument: %s", filename, linenum, arg); |
| 1276 | if (*intptr == -1) |
| 1277 | *intptr = value; |
| 1278 | break; |
Damien Miller | d27b947 | 2005-12-13 19:29:02 +1100 | [diff] [blame] | 1279 | |
Darren Tucker | 4515047 | 2006-07-12 22:34:17 +1000 | [diff] [blame] | 1280 | case sMatch: |
| 1281 | if (cmdline) |
| 1282 | fatal("Match directive not supported as a command-line " |
| 1283 | "option"); |
| 1284 | value = match_cfg_line(&cp, linenum, user, host, address); |
| 1285 | if (value < 0) |
| 1286 | fatal("%s line %d: Bad Match condition", filename, |
| 1287 | linenum); |
| 1288 | *activep = value; |
| 1289 | break; |
| 1290 | |
Damien Miller | 9b439df | 2006-07-24 14:04:00 +1000 | [diff] [blame] | 1291 | case sPermitOpen: |
| 1292 | arg = strdelim(&cp); |
| 1293 | if (!arg || *arg == '\0') |
| 1294 | fatal("%s line %d: missing PermitOpen specification", |
| 1295 | filename, linenum); |
Damien Miller | 9fc6a56 | 2007-01-05 16:29:02 +1100 | [diff] [blame] | 1296 | n = options->num_permitted_opens; /* modified later */ |
Damien Miller | 9b439df | 2006-07-24 14:04:00 +1000 | [diff] [blame] | 1297 | if (strcmp(arg, "any") == 0) { |
Damien Miller | 9fc6a56 | 2007-01-05 16:29:02 +1100 | [diff] [blame] | 1298 | if (*activep && n == -1) { |
Damien Miller | 9b439df | 2006-07-24 14:04:00 +1000 | [diff] [blame] | 1299 | channel_clear_adm_permitted_opens(); |
Damien Miller | a765cf4 | 2006-07-24 14:08:13 +1000 | [diff] [blame] | 1300 | options->num_permitted_opens = 0; |
| 1301 | } |
Damien Miller | 9b439df | 2006-07-24 14:04:00 +1000 | [diff] [blame] | 1302 | break; |
| 1303 | } |
Damien Miller | a29b95e | 2007-01-05 16:28:36 +1100 | [diff] [blame] | 1304 | if (*activep && n == -1) |
| 1305 | channel_clear_adm_permitted_opens(); |
Damien Miller | a765cf4 | 2006-07-24 14:08:13 +1000 | [diff] [blame] | 1306 | for (; arg != NULL && *arg != '\0'; arg = strdelim(&cp)) { |
| 1307 | p = hpdelim(&arg); |
| 1308 | if (p == NULL) |
| 1309 | fatal("%s line %d: missing host in PermitOpen", |
| 1310 | filename, linenum); |
| 1311 | p = cleanhostname(p); |
Damien Miller | 3dc71ad | 2009-01-28 16:31:22 +1100 | [diff] [blame] | 1312 | if (arg == NULL || (port = a2port(arg)) <= 0) |
Damien Miller | a765cf4 | 2006-07-24 14:08:13 +1000 | [diff] [blame] | 1313 | fatal("%s line %d: bad port number in " |
| 1314 | "PermitOpen", filename, linenum); |
Damien Miller | a29b95e | 2007-01-05 16:28:36 +1100 | [diff] [blame] | 1315 | if (*activep && n == -1) |
Damien Miller | a765cf4 | 2006-07-24 14:08:13 +1000 | [diff] [blame] | 1316 | options->num_permitted_opens = |
| 1317 | channel_add_adm_permitted_opens(p, port); |
Damien Miller | a765cf4 | 2006-07-24 14:08:13 +1000 | [diff] [blame] | 1318 | } |
Damien Miller | 9b439df | 2006-07-24 14:04:00 +1000 | [diff] [blame] | 1319 | break; |
| 1320 | |
Damien Miller | e275443 | 2006-07-24 14:06:47 +1000 | [diff] [blame] | 1321 | case sForceCommand: |
| 1322 | if (cp == NULL) |
| 1323 | fatal("%.200s line %d: Missing argument.", filename, |
| 1324 | linenum); |
| 1325 | len = strspn(cp, WHITESPACE); |
| 1326 | if (*activep && options->adm_forced_command == NULL) |
| 1327 | options->adm_forced_command = xstrdup(cp + len); |
| 1328 | return 0; |
| 1329 | |
Damien Miller | d8cb1f1 | 2008-02-10 22:40:12 +1100 | [diff] [blame] | 1330 | case sChrootDirectory: |
| 1331 | charptr = &options->chroot_directory; |
Damien Miller | 54e3773 | 2008-02-10 22:48:55 +1100 | [diff] [blame] | 1332 | |
| 1333 | arg = strdelim(&cp); |
| 1334 | if (!arg || *arg == '\0') |
| 1335 | fatal("%s line %d: missing file name.", |
| 1336 | filename, linenum); |
| 1337 | if (*activep && *charptr == NULL) |
| 1338 | *charptr = xstrdup(arg); |
| 1339 | break; |
Damien Miller | d8cb1f1 | 2008-02-10 22:40:12 +1100 | [diff] [blame] | 1340 | |
Damien Miller | 1aed65e | 2010-03-04 21:53:35 +1100 | [diff] [blame] | 1341 | case sTrustedUserCAKeys: |
| 1342 | charptr = &options->trusted_user_ca_keys; |
| 1343 | goto parse_filename; |
| 1344 | |
| 1345 | case sRevokedKeys: |
| 1346 | charptr = &options->revoked_keys_file; |
| 1347 | goto parse_filename; |
| 1348 | |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 1349 | case sDeprecated: |
Damien Miller | 996acd2 | 2003-04-09 20:59:48 +1000 | [diff] [blame] | 1350 | logit("%s line %d: Deprecated option %s", |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 1351 | filename, linenum, arg); |
| 1352 | while (arg) |
| 1353 | arg = strdelim(&cp); |
| 1354 | break; |
| 1355 | |
Damien Miller | f9b3feb | 2003-05-16 11:38:32 +1000 | [diff] [blame] | 1356 | case sUnsupported: |
| 1357 | logit("%s line %d: Unsupported option %s", |
| 1358 | filename, linenum, arg); |
| 1359 | while (arg) |
| 1360 | arg = strdelim(&cp); |
| 1361 | break; |
| 1362 | |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 1363 | default: |
| 1364 | fatal("%s line %d: Missing handler for opcode %s (%d)", |
| 1365 | filename, linenum, arg, opcode); |
| 1366 | } |
| 1367 | if ((arg = strdelim(&cp)) != NULL && *arg != '\0') |
| 1368 | fatal("%s line %d: garbage at end of line; \"%.200s\".", |
| 1369 | filename, linenum, arg); |
| 1370 | return 0; |
| 1371 | } |
| 1372 | |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1373 | /* Reads the server configuration file. */ |
| 1374 | |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 1375 | void |
Darren Tucker | 645ab75 | 2004-06-25 13:33:20 +1000 | [diff] [blame] | 1376 | load_server_config(const char *filename, Buffer *conf) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1377 | { |
Darren Tucker | 645ab75 | 2004-06-25 13:33:20 +1000 | [diff] [blame] | 1378 | char line[1024], *cp; |
Ben Lindstrom | e135363 | 2002-06-23 21:29:23 +0000 | [diff] [blame] | 1379 | FILE *f; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1380 | |
Darren Tucker | 645ab75 | 2004-06-25 13:33:20 +1000 | [diff] [blame] | 1381 | debug2("%s: filename %s", __func__, filename); |
| 1382 | if ((f = fopen(filename, "r")) == NULL) { |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1383 | perror(filename); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1384 | exit(1); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1385 | } |
Darren Tucker | 645ab75 | 2004-06-25 13:33:20 +1000 | [diff] [blame] | 1386 | buffer_clear(conf); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1387 | while (fgets(line, sizeof(line), f)) { |
Darren Tucker | 645ab75 | 2004-06-25 13:33:20 +1000 | [diff] [blame] | 1388 | /* |
| 1389 | * Trim out comments and strip whitespace |
Darren Tucker | fc95970 | 2004-07-17 16:12:08 +1000 | [diff] [blame] | 1390 | * NB - preserve newlines, they are needed to reproduce |
Darren Tucker | 645ab75 | 2004-06-25 13:33:20 +1000 | [diff] [blame] | 1391 | * line numbers later for error messages |
| 1392 | */ |
| 1393 | if ((cp = strchr(line, '#')) != NULL) |
| 1394 | memcpy(cp, "\n", 2); |
| 1395 | cp = line + strspn(line, " \t\r"); |
| 1396 | |
| 1397 | buffer_append(conf, cp, strlen(cp)); |
| 1398 | } |
| 1399 | buffer_append(conf, "\0", 1); |
| 1400 | fclose(f); |
| 1401 | debug2("%s: done config len = %d", __func__, buffer_len(conf)); |
| 1402 | } |
| 1403 | |
| 1404 | void |
Darren Tucker | 4515047 | 2006-07-12 22:34:17 +1000 | [diff] [blame] | 1405 | parse_server_match_config(ServerOptions *options, const char *user, |
| 1406 | const char *host, const char *address) |
Darren Tucker | 645ab75 | 2004-06-25 13:33:20 +1000 | [diff] [blame] | 1407 | { |
Darren Tucker | 4515047 | 2006-07-12 22:34:17 +1000 | [diff] [blame] | 1408 | ServerOptions mo; |
| 1409 | |
| 1410 | initialize_server_options(&mo); |
| 1411 | parse_server_config(&mo, "reprocess config", &cfg, user, host, address); |
Darren Tucker | 1629c07 | 2007-02-19 22:25:37 +1100 | [diff] [blame] | 1412 | copy_set_server_options(options, &mo, 0); |
Darren Tucker | 4515047 | 2006-07-12 22:34:17 +1000 | [diff] [blame] | 1413 | } |
| 1414 | |
Darren Tucker | 1629c07 | 2007-02-19 22:25:37 +1100 | [diff] [blame] | 1415 | /* Helper macros */ |
| 1416 | #define M_CP_INTOPT(n) do {\ |
| 1417 | if (src->n != -1) \ |
| 1418 | dst->n = src->n; \ |
| 1419 | } while (0) |
| 1420 | #define M_CP_STROPT(n) do {\ |
| 1421 | if (src->n != NULL) { \ |
| 1422 | if (dst->n != NULL) \ |
| 1423 | xfree(dst->n); \ |
| 1424 | dst->n = src->n; \ |
| 1425 | } \ |
| 1426 | } while(0) |
| 1427 | |
| 1428 | /* |
| 1429 | * Copy any supported values that are set. |
| 1430 | * |
Darren Tucker | 3b59dfa | 2009-06-21 17:54:47 +1000 | [diff] [blame] | 1431 | * 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] | 1432 | * array values that are not used pre-authentication, because any that we |
| 1433 | * do use must be explictly sent in mm_getpwnamallow(). |
| 1434 | */ |
Darren Tucker | 4515047 | 2006-07-12 22:34:17 +1000 | [diff] [blame] | 1435 | void |
Darren Tucker | 1629c07 | 2007-02-19 22:25:37 +1100 | [diff] [blame] | 1436 | copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth) |
Darren Tucker | 4515047 | 2006-07-12 22:34:17 +1000 | [diff] [blame] | 1437 | { |
Darren Tucker | 1629c07 | 2007-02-19 22:25:37 +1100 | [diff] [blame] | 1438 | M_CP_INTOPT(password_authentication); |
| 1439 | M_CP_INTOPT(gss_authentication); |
| 1440 | M_CP_INTOPT(rsa_authentication); |
| 1441 | M_CP_INTOPT(pubkey_authentication); |
| 1442 | M_CP_INTOPT(kerberos_authentication); |
| 1443 | M_CP_INTOPT(hostbased_authentication); |
| 1444 | M_CP_INTOPT(kbd_interactive_authentication); |
Damien Miller | 01ed227 | 2008-11-05 16:20:46 +1100 | [diff] [blame] | 1445 | M_CP_INTOPT(zero_knowledge_password_authentication); |
Darren Tucker | 15f9427 | 2008-01-01 20:36:56 +1100 | [diff] [blame] | 1446 | M_CP_INTOPT(permit_root_login); |
Damien Miller | 51bde60 | 2008-11-03 19:23:10 +1100 | [diff] [blame] | 1447 | M_CP_INTOPT(permit_empty_passwd); |
Darren Tucker | 1629c07 | 2007-02-19 22:25:37 +1100 | [diff] [blame] | 1448 | |
| 1449 | M_CP_INTOPT(allow_tcp_forwarding); |
Damien Miller | 4f755cd | 2008-05-19 14:57:41 +1000 | [diff] [blame] | 1450 | M_CP_INTOPT(allow_agent_forwarding); |
Darren Tucker | 1629c07 | 2007-02-19 22:25:37 +1100 | [diff] [blame] | 1451 | M_CP_INTOPT(gateway_ports); |
| 1452 | M_CP_INTOPT(x11_display_offset); |
| 1453 | M_CP_INTOPT(x11_forwarding); |
| 1454 | M_CP_INTOPT(x11_use_localhost); |
Damien Miller | 7207f64 | 2008-05-19 15:34:50 +1000 | [diff] [blame] | 1455 | M_CP_INTOPT(max_sessions); |
Damien Miller | 307c1d1 | 2008-06-16 07:56:20 +1000 | [diff] [blame] | 1456 | M_CP_INTOPT(max_authtries); |
Darren Tucker | 1629c07 | 2007-02-19 22:25:37 +1100 | [diff] [blame] | 1457 | |
| 1458 | M_CP_STROPT(banner); |
| 1459 | if (preauth) |
| 1460 | return; |
| 1461 | M_CP_STROPT(adm_forced_command); |
Damien Miller | d8cb1f1 | 2008-02-10 22:40:12 +1100 | [diff] [blame] | 1462 | M_CP_STROPT(chroot_directory); |
Damien Miller | 1aed65e | 2010-03-04 21:53:35 +1100 | [diff] [blame] | 1463 | M_CP_STROPT(trusted_user_ca_keys); |
| 1464 | M_CP_STROPT(revoked_keys_file); |
Darren Tucker | 4515047 | 2006-07-12 22:34:17 +1000 | [diff] [blame] | 1465 | } |
| 1466 | |
Darren Tucker | 1629c07 | 2007-02-19 22:25:37 +1100 | [diff] [blame] | 1467 | #undef M_CP_INTOPT |
| 1468 | #undef M_CP_STROPT |
| 1469 | |
Darren Tucker | 4515047 | 2006-07-12 22:34:17 +1000 | [diff] [blame] | 1470 | void |
| 1471 | parse_server_config(ServerOptions *options, const char *filename, Buffer *conf, |
| 1472 | const char *user, const char *host, const char *address) |
| 1473 | { |
| 1474 | int active, linenum, bad_options = 0; |
Darren Tucker | 9fbac71 | 2004-08-12 22:41:44 +1000 | [diff] [blame] | 1475 | char *cp, *obuf, *cbuf; |
Darren Tucker | 645ab75 | 2004-06-25 13:33:20 +1000 | [diff] [blame] | 1476 | |
| 1477 | debug2("%s: config %s len %d", __func__, filename, buffer_len(conf)); |
| 1478 | |
Darren Tucker | 9fbac71 | 2004-08-12 22:41:44 +1000 | [diff] [blame] | 1479 | obuf = cbuf = xstrdup(buffer_ptr(conf)); |
Darren Tucker | 4515047 | 2006-07-12 22:34:17 +1000 | [diff] [blame] | 1480 | active = user ? 0 : 1; |
Darren Tucker | 137e9c9 | 2004-08-13 21:30:24 +1000 | [diff] [blame] | 1481 | linenum = 1; |
Darren Tucker | 47eede7 | 2005-03-14 23:08:12 +1100 | [diff] [blame] | 1482 | while ((cp = strsep(&cbuf, "\n")) != NULL) { |
Darren Tucker | 645ab75 | 2004-06-25 13:33:20 +1000 | [diff] [blame] | 1483 | if (process_server_config_line(options, cp, filename, |
Darren Tucker | 4515047 | 2006-07-12 22:34:17 +1000 | [diff] [blame] | 1484 | linenum++, &active, user, host, address) != 0) |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1485 | bad_options++; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1486 | } |
Darren Tucker | 9fbac71 | 2004-08-12 22:41:44 +1000 | [diff] [blame] | 1487 | xfree(obuf); |
Ben Lindstrom | b5cdc66 | 2001-04-16 02:13:26 +0000 | [diff] [blame] | 1488 | if (bad_options > 0) |
| 1489 | fatal("%s: terminating, %d bad configuration options", |
| 1490 | filename, bad_options); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1491 | } |
Darren Tucker | e7140f2 | 2008-06-10 23:01:51 +1000 | [diff] [blame] | 1492 | |
| 1493 | static const char * |
| 1494 | fmt_intarg(ServerOpCodes code, int val) |
| 1495 | { |
| 1496 | if (code == sAddressFamily) { |
| 1497 | switch (val) { |
| 1498 | case AF_INET: |
| 1499 | return "inet"; |
| 1500 | case AF_INET6: |
| 1501 | return "inet6"; |
| 1502 | case AF_UNSPEC: |
| 1503 | return "any"; |
| 1504 | default: |
| 1505 | return "UNKNOWN"; |
| 1506 | } |
| 1507 | } |
| 1508 | if (code == sPermitRootLogin) { |
| 1509 | switch (val) { |
| 1510 | case PERMIT_NO_PASSWD: |
Darren Tucker | ff4350e | 2008-11-11 16:31:05 +1100 | [diff] [blame] | 1511 | return "without-password"; |
Darren Tucker | e7140f2 | 2008-06-10 23:01:51 +1000 | [diff] [blame] | 1512 | case PERMIT_FORCED_ONLY: |
| 1513 | return "forced-commands-only"; |
| 1514 | case PERMIT_YES: |
| 1515 | return "yes"; |
| 1516 | } |
| 1517 | } |
| 1518 | if (code == sProtocol) { |
| 1519 | switch (val) { |
| 1520 | case SSH_PROTO_1: |
| 1521 | return "1"; |
| 1522 | case SSH_PROTO_2: |
| 1523 | return "2"; |
| 1524 | case (SSH_PROTO_1|SSH_PROTO_2): |
| 1525 | return "2,1"; |
| 1526 | default: |
| 1527 | return "UNKNOWN"; |
| 1528 | } |
| 1529 | } |
| 1530 | if (code == sGatewayPorts && val == 2) |
| 1531 | return "clientspecified"; |
| 1532 | if (code == sCompression && val == COMP_DELAYED) |
| 1533 | return "delayed"; |
| 1534 | switch (val) { |
| 1535 | case -1: |
| 1536 | return "unset"; |
| 1537 | case 0: |
| 1538 | return "no"; |
| 1539 | case 1: |
| 1540 | return "yes"; |
| 1541 | } |
| 1542 | return "UNKNOWN"; |
| 1543 | } |
| 1544 | |
| 1545 | static const char * |
| 1546 | lookup_opcode_name(ServerOpCodes code) |
| 1547 | { |
| 1548 | u_int i; |
| 1549 | |
| 1550 | for (i = 0; keywords[i].name != NULL; i++) |
| 1551 | if (keywords[i].opcode == code) |
| 1552 | return(keywords[i].name); |
| 1553 | return "UNKNOWN"; |
| 1554 | } |
| 1555 | |
| 1556 | static void |
| 1557 | dump_cfg_int(ServerOpCodes code, int val) |
| 1558 | { |
| 1559 | printf("%s %d\n", lookup_opcode_name(code), val); |
| 1560 | } |
| 1561 | |
| 1562 | static void |
| 1563 | dump_cfg_fmtint(ServerOpCodes code, int val) |
| 1564 | { |
| 1565 | printf("%s %s\n", lookup_opcode_name(code), fmt_intarg(code, val)); |
| 1566 | } |
| 1567 | |
| 1568 | static void |
| 1569 | dump_cfg_string(ServerOpCodes code, const char *val) |
| 1570 | { |
| 1571 | if (val == NULL) |
| 1572 | return; |
| 1573 | printf("%s %s\n", lookup_opcode_name(code), val); |
| 1574 | } |
| 1575 | |
| 1576 | static void |
| 1577 | dump_cfg_strarray(ServerOpCodes code, u_int count, char **vals) |
| 1578 | { |
| 1579 | u_int i; |
| 1580 | |
| 1581 | for (i = 0; i < count; i++) |
| 1582 | printf("%s %s\n", lookup_opcode_name(code), vals[i]); |
| 1583 | } |
| 1584 | |
| 1585 | void |
| 1586 | dump_config(ServerOptions *o) |
| 1587 | { |
| 1588 | u_int i; |
| 1589 | int ret; |
| 1590 | struct addrinfo *ai; |
| 1591 | char addr[NI_MAXHOST], port[NI_MAXSERV], *s = NULL; |
| 1592 | |
| 1593 | /* these are usually at the top of the config */ |
| 1594 | for (i = 0; i < o->num_ports; i++) |
| 1595 | printf("port %d\n", o->ports[i]); |
| 1596 | dump_cfg_fmtint(sProtocol, o->protocol); |
| 1597 | dump_cfg_fmtint(sAddressFamily, o->address_family); |
| 1598 | |
| 1599 | /* ListenAddress must be after Port */ |
| 1600 | for (ai = o->listen_addrs; ai; ai = ai->ai_next) { |
| 1601 | if ((ret = getnameinfo(ai->ai_addr, ai->ai_addrlen, addr, |
| 1602 | sizeof(addr), port, sizeof(port), |
| 1603 | NI_NUMERICHOST|NI_NUMERICSERV)) != 0) { |
| 1604 | error("getnameinfo failed: %.100s", |
| 1605 | (ret != EAI_SYSTEM) ? gai_strerror(ret) : |
| 1606 | strerror(errno)); |
| 1607 | } else { |
| 1608 | if (ai->ai_family == AF_INET6) |
| 1609 | printf("listenaddress [%s]:%s\n", addr, port); |
| 1610 | else |
| 1611 | printf("listenaddress %s:%s\n", addr, port); |
| 1612 | } |
| 1613 | } |
| 1614 | |
| 1615 | /* integer arguments */ |
Damien Miller | 212f0b0 | 2008-07-23 17:42:29 +1000 | [diff] [blame] | 1616 | #ifdef USE_PAM |
| 1617 | dump_cfg_int(sUsePAM, o->use_pam); |
| 1618 | #endif |
Darren Tucker | e7140f2 | 2008-06-10 23:01:51 +1000 | [diff] [blame] | 1619 | dump_cfg_int(sServerKeyBits, o->server_key_bits); |
| 1620 | dump_cfg_int(sLoginGraceTime, o->login_grace_time); |
| 1621 | dump_cfg_int(sKeyRegenerationTime, o->key_regeneration_time); |
| 1622 | dump_cfg_int(sX11DisplayOffset, o->x11_display_offset); |
| 1623 | dump_cfg_int(sMaxAuthTries, o->max_authtries); |
Damien Miller | 7fc5c0f | 2008-11-05 16:12:11 +1100 | [diff] [blame] | 1624 | dump_cfg_int(sMaxSessions, o->max_sessions); |
Darren Tucker | e7140f2 | 2008-06-10 23:01:51 +1000 | [diff] [blame] | 1625 | dump_cfg_int(sClientAliveInterval, o->client_alive_interval); |
| 1626 | dump_cfg_int(sClientAliveCountMax, o->client_alive_count_max); |
| 1627 | |
| 1628 | /* formatted integer arguments */ |
| 1629 | dump_cfg_fmtint(sPermitRootLogin, o->permit_root_login); |
| 1630 | dump_cfg_fmtint(sIgnoreRhosts, o->ignore_rhosts); |
| 1631 | dump_cfg_fmtint(sIgnoreUserKnownHosts, o->ignore_user_known_hosts); |
| 1632 | dump_cfg_fmtint(sRhostsRSAAuthentication, o->rhosts_rsa_authentication); |
| 1633 | dump_cfg_fmtint(sHostbasedAuthentication, o->hostbased_authentication); |
| 1634 | dump_cfg_fmtint(sHostbasedUsesNameFromPacketOnly, |
| 1635 | o->hostbased_uses_name_from_packet_only); |
| 1636 | dump_cfg_fmtint(sRSAAuthentication, o->rsa_authentication); |
| 1637 | dump_cfg_fmtint(sPubkeyAuthentication, o->pubkey_authentication); |
Damien Miller | 6ef430d | 2008-07-23 17:40:04 +1000 | [diff] [blame] | 1638 | #ifdef KRB5 |
Darren Tucker | e7140f2 | 2008-06-10 23:01:51 +1000 | [diff] [blame] | 1639 | dump_cfg_fmtint(sKerberosAuthentication, o->kerberos_authentication); |
| 1640 | dump_cfg_fmtint(sKerberosOrLocalPasswd, o->kerberos_or_local_passwd); |
| 1641 | dump_cfg_fmtint(sKerberosTicketCleanup, o->kerberos_ticket_cleanup); |
Damien Miller | 6ef430d | 2008-07-23 17:40:04 +1000 | [diff] [blame] | 1642 | # ifdef USE_AFS |
Darren Tucker | e7140f2 | 2008-06-10 23:01:51 +1000 | [diff] [blame] | 1643 | dump_cfg_fmtint(sKerberosGetAFSToken, o->kerberos_get_afs_token); |
Damien Miller | 6ef430d | 2008-07-23 17:40:04 +1000 | [diff] [blame] | 1644 | # endif |
| 1645 | #endif |
| 1646 | #ifdef GSSAPI |
Darren Tucker | e7140f2 | 2008-06-10 23:01:51 +1000 | [diff] [blame] | 1647 | dump_cfg_fmtint(sGssAuthentication, o->gss_authentication); |
| 1648 | dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds); |
Damien Miller | 6ef430d | 2008-07-23 17:40:04 +1000 | [diff] [blame] | 1649 | #endif |
Damien Miller | 01ed227 | 2008-11-05 16:20:46 +1100 | [diff] [blame] | 1650 | #ifdef JPAKE |
| 1651 | dump_cfg_fmtint(sZeroKnowledgePasswordAuthentication, |
| 1652 | o->zero_knowledge_password_authentication); |
| 1653 | #endif |
Darren Tucker | e7140f2 | 2008-06-10 23:01:51 +1000 | [diff] [blame] | 1654 | dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication); |
| 1655 | dump_cfg_fmtint(sKbdInteractiveAuthentication, |
| 1656 | o->kbd_interactive_authentication); |
| 1657 | dump_cfg_fmtint(sChallengeResponseAuthentication, |
| 1658 | o->challenge_response_authentication); |
| 1659 | dump_cfg_fmtint(sPrintMotd, o->print_motd); |
| 1660 | dump_cfg_fmtint(sPrintLastLog, o->print_lastlog); |
| 1661 | dump_cfg_fmtint(sX11Forwarding, o->x11_forwarding); |
| 1662 | dump_cfg_fmtint(sX11UseLocalhost, o->x11_use_localhost); |
| 1663 | dump_cfg_fmtint(sStrictModes, o->strict_modes); |
| 1664 | dump_cfg_fmtint(sTCPKeepAlive, o->tcp_keep_alive); |
| 1665 | dump_cfg_fmtint(sEmptyPasswd, o->permit_empty_passwd); |
| 1666 | dump_cfg_fmtint(sPermitUserEnvironment, o->permit_user_env); |
| 1667 | dump_cfg_fmtint(sUseLogin, o->use_login); |
| 1668 | dump_cfg_fmtint(sCompression, o->compression); |
| 1669 | dump_cfg_fmtint(sGatewayPorts, o->gateway_ports); |
| 1670 | dump_cfg_fmtint(sUseDNS, o->use_dns); |
| 1671 | dump_cfg_fmtint(sAllowTcpForwarding, o->allow_tcp_forwarding); |
| 1672 | dump_cfg_fmtint(sUsePrivilegeSeparation, use_privsep); |
| 1673 | |
| 1674 | /* string arguments */ |
| 1675 | dump_cfg_string(sPidFile, o->pid_file); |
| 1676 | dump_cfg_string(sXAuthLocation, o->xauth_location); |
| 1677 | dump_cfg_string(sCiphers, o->ciphers); |
| 1678 | dump_cfg_string(sMacs, o->macs); |
| 1679 | dump_cfg_string(sBanner, o->banner); |
| 1680 | dump_cfg_string(sAuthorizedKeysFile, o->authorized_keys_file); |
| 1681 | dump_cfg_string(sAuthorizedKeysFile2, o->authorized_keys_file2); |
| 1682 | dump_cfg_string(sForceCommand, o->adm_forced_command); |
Darren Tucker | d330045 | 2010-01-10 19:26:43 +1100 | [diff] [blame] | 1683 | dump_cfg_string(sChrootDirectory, o->chroot_directory); |
Damien Miller | 1aed65e | 2010-03-04 21:53:35 +1100 | [diff] [blame] | 1684 | dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys); |
| 1685 | dump_cfg_string(sRevokedKeys, o->revoked_keys_file); |
Darren Tucker | e7140f2 | 2008-06-10 23:01:51 +1000 | [diff] [blame] | 1686 | |
| 1687 | /* string arguments requiring a lookup */ |
| 1688 | dump_cfg_string(sLogLevel, log_level_name(o->log_level)); |
| 1689 | dump_cfg_string(sLogFacility, log_facility_name(o->log_facility)); |
| 1690 | |
| 1691 | /* string array arguments */ |
| 1692 | dump_cfg_strarray(sHostKeyFile, o->num_host_key_files, |
| 1693 | o->host_key_files); |
Damien Miller | 0a80ca1 | 2010-02-27 07:55:05 +1100 | [diff] [blame] | 1694 | dump_cfg_strarray(sHostKeyFile, o->num_host_cert_files, |
| 1695 | o->host_cert_files); |
Darren Tucker | e7140f2 | 2008-06-10 23:01:51 +1000 | [diff] [blame] | 1696 | dump_cfg_strarray(sAllowUsers, o->num_allow_users, o->allow_users); |
| 1697 | dump_cfg_strarray(sDenyUsers, o->num_deny_users, o->deny_users); |
| 1698 | dump_cfg_strarray(sAllowGroups, o->num_allow_groups, o->allow_groups); |
| 1699 | dump_cfg_strarray(sDenyGroups, o->num_deny_groups, o->deny_groups); |
| 1700 | dump_cfg_strarray(sAcceptEnv, o->num_accept_env, o->accept_env); |
| 1701 | |
| 1702 | /* other arguments */ |
| 1703 | for (i = 0; i < o->num_subsystems; i++) |
| 1704 | printf("subsystem %s %s\n", o->subsystem_name[i], |
| 1705 | o->subsystem_args[i]); |
| 1706 | |
| 1707 | printf("maxstartups %d:%d:%d\n", o->max_startups_begin, |
| 1708 | o->max_startups_rate, o->max_startups); |
| 1709 | |
| 1710 | for (i = 0; tunmode_desc[i].val != -1; i++) |
| 1711 | if (tunmode_desc[i].val == o->permit_tun) { |
| 1712 | s = tunmode_desc[i].text; |
| 1713 | break; |
| 1714 | } |
| 1715 | dump_cfg_string(sPermitTunnel, s); |
| 1716 | |
Darren Tucker | e7140f2 | 2008-06-10 23:01:51 +1000 | [diff] [blame] | 1717 | channel_print_adm_permitted_opens(); |
Darren Tucker | e7140f2 | 2008-06-10 23:01:51 +1000 | [diff] [blame] | 1718 | } |