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