Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1 | /* |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 2 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
| 3 | * All rights reserved |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 4 | * |
Damien Miller | e4340be | 2000-09-16 13:29:08 +1100 | [diff] [blame] | 5 | * As far as I am concerned, the code I have written for this software |
| 6 | * can be used freely for any purpose. Any derived versions of this |
| 7 | * software must be clearly marked as such, and if the derived work is |
| 8 | * incompatible with the protocol description in the RFC file, it must be |
| 9 | * called by a name other than "ssh" or "Secure Shell". |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 10 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 11 | |
| 12 | #include "includes.h" |
Damien Miller | c5d8635 | 2002-02-05 12:13:41 +1100 | [diff] [blame] | 13 | RCSID("$OpenBSD: servconf.c,v 1.100 2002/01/29 14:32:03 markus Exp $"); |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 14 | |
Damien Miller | c4b7fea | 2001-07-14 12:20:32 +1000 | [diff] [blame] | 15 | #if defined(KRB4) || defined(KRB5) |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 16 | #include <krb.h> |
| 17 | #endif |
Ben Lindstrom | eb7a84c | 2001-07-04 04:48:36 +0000 | [diff] [blame] | 18 | #ifdef AFS |
| 19 | #include <kafs.h> |
| 20 | #endif |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 21 | |
| 22 | #include "ssh.h" |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 23 | #include "log.h" |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 24 | #include "servconf.h" |
| 25 | #include "xmalloc.h" |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 26 | #include "compat.h" |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 27 | #include "pathnames.h" |
| 28 | #include "tildexpand.h" |
| 29 | #include "misc.h" |
| 30 | #include "cipher.h" |
Ben Lindstrom | 06b33aa | 2001-02-15 03:01:59 +0000 | [diff] [blame] | 31 | #include "kex.h" |
| 32 | #include "mac.h" |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 33 | |
Ben Lindstrom | bba8121 | 2001-06-25 05:01:22 +0000 | [diff] [blame] | 34 | static void add_listen_addr(ServerOptions *, char *, u_short); |
| 35 | static void add_one_listen_addr(ServerOptions *, char *, u_short); |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 36 | |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 37 | /* AF_UNSPEC or AF_INET or AF_INET6 */ |
| 38 | extern int IPv4or6; |
| 39 | |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 40 | /* Initializes the server options to their default values. */ |
| 41 | |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 42 | void |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 43 | initialize_server_options(ServerOptions *options) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 44 | { |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 45 | memset(options, 0, sizeof(*options)); |
Damien Miller | 726273e | 2001-11-12 11:40:11 +1100 | [diff] [blame] | 46 | |
| 47 | /* Portable-specific options */ |
| 48 | options->pam_authentication_via_kbd_int = -1; |
| 49 | |
| 50 | /* Standard Options */ |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 51 | options->num_ports = 0; |
| 52 | options->ports_from_cmdline = 0; |
| 53 | options->listen_addrs = NULL; |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 54 | options->num_host_key_files = 0; |
Damien Miller | 6f83b8e | 2000-05-02 09:23:45 +1000 | [diff] [blame] | 55 | options->pid_file = NULL; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 56 | options->server_key_bits = -1; |
| 57 | options->login_grace_time = -1; |
| 58 | options->key_regeneration_time = -1; |
Ben Lindstrom | d8a9021 | 2001-02-15 03:08:27 +0000 | [diff] [blame] | 59 | options->permit_root_login = PERMIT_NOT_SET; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 60 | options->ignore_rhosts = -1; |
| 61 | options->ignore_user_known_hosts = -1; |
| 62 | options->print_motd = -1; |
Ben Lindstrom | 7bfff36 | 2001-03-26 05:45:53 +0000 | [diff] [blame] | 63 | options->print_lastlog = -1; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 64 | options->x11_forwarding = -1; |
| 65 | options->x11_display_offset = -1; |
Damien Miller | 95c249f | 2002-02-05 12:11:34 +1100 | [diff] [blame] | 66 | options->x11_use_localhost = -1; |
Damien Miller | d3a1857 | 2000-06-07 19:55:44 +1000 | [diff] [blame] | 67 | options->xauth_location = NULL; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 68 | options->strict_modes = -1; |
| 69 | options->keepalives = -1; |
| 70 | options->log_facility = (SyslogFacility) - 1; |
| 71 | options->log_level = (LogLevel) - 1; |
| 72 | options->rhosts_authentication = -1; |
| 73 | options->rhosts_rsa_authentication = -1; |
Ben Lindstrom | 5eabda3 | 2001-04-12 23:34:34 +0000 | [diff] [blame] | 74 | options->hostbased_authentication = -1; |
| 75 | options->hostbased_uses_name_from_packet_only = -1; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 76 | options->rsa_authentication = -1; |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 77 | options->pubkey_authentication = -1; |
Ben Lindstrom | ec95ed9 | 2001-07-04 04:21:14 +0000 | [diff] [blame] | 78 | #if defined(KRB4) || defined(KRB5) |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 79 | options->kerberos_authentication = -1; |
| 80 | options->kerberos_or_local_passwd = -1; |
| 81 | options->kerberos_ticket_cleanup = -1; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 82 | #endif |
Ben Lindstrom | ec95ed9 | 2001-07-04 04:21:14 +0000 | [diff] [blame] | 83 | #if defined(AFS) || defined(KRB5) |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 84 | options->kerberos_tgt_passing = -1; |
Ben Lindstrom | ec95ed9 | 2001-07-04 04:21:14 +0000 | [diff] [blame] | 85 | #endif |
| 86 | #ifdef AFS |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 87 | options->afs_token_passing = -1; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 88 | #endif |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 89 | options->password_authentication = -1; |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 90 | options->kbd_interactive_authentication = -1; |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 91 | options->challenge_response_authentication = -1; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 92 | options->permit_empty_passwd = -1; |
| 93 | options->use_login = -1; |
Damien Miller | 50a41ed | 2000-10-16 12:14:42 +1100 | [diff] [blame] | 94 | options->allow_tcp_forwarding = -1; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 95 | options->num_allow_users = 0; |
| 96 | options->num_deny_users = 0; |
| 97 | options->num_allow_groups = 0; |
| 98 | options->num_deny_groups = 0; |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 99 | options->ciphers = NULL; |
Ben Lindstrom | 06b33aa | 2001-02-15 03:01:59 +0000 | [diff] [blame] | 100 | options->macs = NULL; |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 101 | options->protocol = SSH_PROTO_UNKNOWN; |
Damien Miller | e247cc4 | 2000-05-07 12:03:14 +1000 | [diff] [blame] | 102 | options->gateway_ports = -1; |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 103 | options->num_subsystems = 0; |
Damien Miller | 942da03 | 2000-08-18 13:59:06 +1000 | [diff] [blame] | 104 | options->max_startups_begin = -1; |
| 105 | options->max_startups_rate = -1; |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 106 | options->max_startups = -1; |
Ben Lindstrom | 48bd7c1 | 2001-01-09 00:35:42 +0000 | [diff] [blame] | 107 | options->banner = NULL; |
Damien Miller | c5d8635 | 2002-02-05 12:13:41 +1100 | [diff] [blame] | 108 | options->verify_reverse_mapping = -1; |
Ben Lindstrom | 5744dc4 | 2001-04-13 23:28:01 +0000 | [diff] [blame] | 109 | options->client_alive_interval = -1; |
| 110 | options->client_alive_count_max = -1; |
Ben Lindstrom | bfb3a0e | 2001-06-05 20:25:05 +0000 | [diff] [blame] | 111 | options->authorized_keys_file = NULL; |
| 112 | options->authorized_keys_file2 = NULL; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 113 | } |
| 114 | |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 115 | void |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 116 | fill_default_server_options(ServerOptions *options) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 117 | { |
Damien Miller | 726273e | 2001-11-12 11:40:11 +1100 | [diff] [blame] | 118 | /* Portable-specific options */ |
| 119 | if (options->pam_authentication_via_kbd_int == -1) |
| 120 | options->pam_authentication_via_kbd_int = 0; |
| 121 | |
| 122 | /* Standard Options */ |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 123 | if (options->protocol == SSH_PROTO_UNKNOWN) |
| 124 | options->protocol = SSH_PROTO_1|SSH_PROTO_2; |
| 125 | if (options->num_host_key_files == 0) { |
| 126 | /* fill default hostkeys for protocols */ |
| 127 | if (options->protocol & SSH_PROTO_1) |
Damien Miller | 7fc2373 | 2002-01-22 23:19:11 +1100 | [diff] [blame] | 128 | options->host_key_files[options->num_host_key_files++] = |
| 129 | _PATH_HOST_KEY_FILE; |
| 130 | if (options->protocol & SSH_PROTO_2) { |
| 131 | options->host_key_files[options->num_host_key_files++] = |
| 132 | _PATH_HOST_RSA_KEY_FILE; |
| 133 | options->host_key_files[options->num_host_key_files++] = |
| 134 | _PATH_HOST_DSA_KEY_FILE; |
| 135 | } |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 136 | } |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 137 | if (options->num_ports == 0) |
| 138 | options->ports[options->num_ports++] = SSH_DEFAULT_PORT; |
| 139 | if (options->listen_addrs == NULL) |
Ben Lindstrom | 19066a1 | 2001-04-12 23:39:26 +0000 | [diff] [blame] | 140 | add_listen_addr(options, NULL, 0); |
Damien Miller | 6f83b8e | 2000-05-02 09:23:45 +1000 | [diff] [blame] | 141 | if (options->pid_file == NULL) |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 142 | options->pid_file = _PATH_SSH_DAEMON_PID_FILE; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 143 | if (options->server_key_bits == -1) |
| 144 | options->server_key_bits = 768; |
| 145 | if (options->login_grace_time == -1) |
| 146 | options->login_grace_time = 600; |
| 147 | if (options->key_regeneration_time == -1) |
| 148 | options->key_regeneration_time = 3600; |
Ben Lindstrom | d8a9021 | 2001-02-15 03:08:27 +0000 | [diff] [blame] | 149 | if (options->permit_root_login == PERMIT_NOT_SET) |
| 150 | options->permit_root_login = PERMIT_YES; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 151 | if (options->ignore_rhosts == -1) |
Damien Miller | 98c7ad6 | 2000-03-09 21:27:49 +1100 | [diff] [blame] | 152 | options->ignore_rhosts = 1; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 153 | if (options->ignore_user_known_hosts == -1) |
| 154 | options->ignore_user_known_hosts = 0; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 155 | if (options->print_motd == -1) |
| 156 | options->print_motd = 1; |
Ben Lindstrom | 7bfff36 | 2001-03-26 05:45:53 +0000 | [diff] [blame] | 157 | if (options->print_lastlog == -1) |
| 158 | options->print_lastlog = 1; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 159 | if (options->x11_forwarding == -1) |
Damien Miller | 98c7ad6 | 2000-03-09 21:27:49 +1100 | [diff] [blame] | 160 | options->x11_forwarding = 0; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 161 | if (options->x11_display_offset == -1) |
Damien Miller | 98c7ad6 | 2000-03-09 21:27:49 +1100 | [diff] [blame] | 162 | options->x11_display_offset = 10; |
Damien Miller | 95c249f | 2002-02-05 12:11:34 +1100 | [diff] [blame] | 163 | if (options->x11_use_localhost == -1) |
| 164 | options->x11_use_localhost = 1; |
Damien Miller | d3a1857 | 2000-06-07 19:55:44 +1000 | [diff] [blame] | 165 | if (options->xauth_location == NULL) |
Ben Lindstrom | 1bf11f6 | 2001-06-09 01:48:01 +0000 | [diff] [blame] | 166 | options->xauth_location = _PATH_XAUTH; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 167 | if (options->strict_modes == -1) |
| 168 | options->strict_modes = 1; |
| 169 | if (options->keepalives == -1) |
| 170 | options->keepalives = 1; |
| 171 | if (options->log_facility == (SyslogFacility) (-1)) |
| 172 | options->log_facility = SYSLOG_FACILITY_AUTH; |
| 173 | if (options->log_level == (LogLevel) (-1)) |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 174 | options->log_level = SYSLOG_LEVEL_INFO; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 175 | if (options->rhosts_authentication == -1) |
| 176 | options->rhosts_authentication = 0; |
| 177 | if (options->rhosts_rsa_authentication == -1) |
Damien Miller | 98c7ad6 | 2000-03-09 21:27:49 +1100 | [diff] [blame] | 178 | options->rhosts_rsa_authentication = 0; |
Ben Lindstrom | 5eabda3 | 2001-04-12 23:34:34 +0000 | [diff] [blame] | 179 | if (options->hostbased_authentication == -1) |
| 180 | options->hostbased_authentication = 0; |
| 181 | if (options->hostbased_uses_name_from_packet_only == -1) |
| 182 | options->hostbased_uses_name_from_packet_only = 0; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 183 | if (options->rsa_authentication == -1) |
| 184 | options->rsa_authentication = 1; |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 185 | if (options->pubkey_authentication == -1) |
| 186 | options->pubkey_authentication = 1; |
Ben Lindstrom | ec95ed9 | 2001-07-04 04:21:14 +0000 | [diff] [blame] | 187 | #if defined(KRB4) || defined(KRB5) |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 188 | if (options->kerberos_authentication == -1) |
| 189 | options->kerberos_authentication = (access(KEYFILE, R_OK) == 0); |
| 190 | if (options->kerberos_or_local_passwd == -1) |
| 191 | options->kerberos_or_local_passwd = 1; |
| 192 | if (options->kerberos_ticket_cleanup == -1) |
| 193 | options->kerberos_ticket_cleanup = 1; |
Ben Lindstrom | ec95ed9 | 2001-07-04 04:21:14 +0000 | [diff] [blame] | 194 | #endif |
| 195 | #if defined(AFS) || defined(KRB5) |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 196 | if (options->kerberos_tgt_passing == -1) |
| 197 | options->kerberos_tgt_passing = 0; |
Ben Lindstrom | ec95ed9 | 2001-07-04 04:21:14 +0000 | [diff] [blame] | 198 | #endif |
Damien Miller | 9f0f5c6 | 2001-12-21 14:45:46 +1100 | [diff] [blame] | 199 | #ifdef AFS |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 200 | if (options->afs_token_passing == -1) |
| 201 | options->afs_token_passing = k_hasafs(); |
Ben Lindstrom | ec95ed9 | 2001-07-04 04:21:14 +0000 | [diff] [blame] | 202 | #endif |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 203 | if (options->password_authentication == -1) |
| 204 | options->password_authentication = 1; |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 205 | if (options->kbd_interactive_authentication == -1) |
| 206 | options->kbd_interactive_authentication = 0; |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 207 | if (options->challenge_response_authentication == -1) |
| 208 | options->challenge_response_authentication = 1; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 209 | if (options->permit_empty_passwd == -1) |
Damien Miller | 98c7ad6 | 2000-03-09 21:27:49 +1100 | [diff] [blame] | 210 | options->permit_empty_passwd = 0; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 211 | if (options->use_login == -1) |
| 212 | options->use_login = 0; |
Damien Miller | 50a41ed | 2000-10-16 12:14:42 +1100 | [diff] [blame] | 213 | if (options->allow_tcp_forwarding == -1) |
| 214 | options->allow_tcp_forwarding = 1; |
Damien Miller | e247cc4 | 2000-05-07 12:03:14 +1000 | [diff] [blame] | 215 | if (options->gateway_ports == -1) |
| 216 | options->gateway_ports = 0; |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 217 | if (options->max_startups == -1) |
| 218 | options->max_startups = 10; |
Damien Miller | 942da03 | 2000-08-18 13:59:06 +1000 | [diff] [blame] | 219 | if (options->max_startups_rate == -1) |
| 220 | options->max_startups_rate = 100; /* 100% */ |
| 221 | if (options->max_startups_begin == -1) |
| 222 | options->max_startups_begin = options->max_startups; |
Damien Miller | c5d8635 | 2002-02-05 12:13:41 +1100 | [diff] [blame] | 223 | if (options->verify_reverse_mapping == -1) |
| 224 | options->verify_reverse_mapping = 0; |
Ben Lindstrom | 5744dc4 | 2001-04-13 23:28:01 +0000 | [diff] [blame] | 225 | if (options->client_alive_interval == -1) |
Damien Miller | 9f0f5c6 | 2001-12-21 14:45:46 +1100 | [diff] [blame] | 226 | options->client_alive_interval = 0; |
Ben Lindstrom | 5744dc4 | 2001-04-13 23:28:01 +0000 | [diff] [blame] | 227 | if (options->client_alive_count_max == -1) |
| 228 | options->client_alive_count_max = 3; |
Damien Miller | 75413ac | 2001-11-12 11:14:35 +1100 | [diff] [blame] | 229 | if (options->authorized_keys_file2 == NULL) { |
| 230 | /* authorized_keys_file2 falls back to authorized_keys_file */ |
| 231 | if (options->authorized_keys_file != NULL) |
| 232 | options->authorized_keys_file2 = options->authorized_keys_file; |
| 233 | else |
| 234 | options->authorized_keys_file2 = _PATH_SSH_USER_PERMITTED_KEYS2; |
| 235 | } |
| 236 | if (options->authorized_keys_file == NULL) |
| 237 | options->authorized_keys_file = _PATH_SSH_USER_PERMITTED_KEYS; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 238 | } |
| 239 | |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 240 | /* Keyword tokens. */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 241 | typedef enum { |
| 242 | sBadOption, /* == unknown option */ |
Damien Miller | 726273e | 2001-11-12 11:40:11 +1100 | [diff] [blame] | 243 | /* Portable-specific options */ |
| 244 | sPAMAuthenticationViaKbdInt, |
| 245 | /* Standard Options */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 246 | sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime, sKeyRegenerationTime, |
| 247 | sPermitRootLogin, sLogFacility, sLogLevel, |
| 248 | sRhostsAuthentication, sRhostsRSAAuthentication, sRSAAuthentication, |
Ben Lindstrom | ec95ed9 | 2001-07-04 04:21:14 +0000 | [diff] [blame] | 249 | #if defined(KRB4) || defined(KRB5) |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 250 | sKerberosAuthentication, sKerberosOrLocalPasswd, sKerberosTicketCleanup, |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 251 | #endif |
Ben Lindstrom | ec95ed9 | 2001-07-04 04:21:14 +0000 | [diff] [blame] | 252 | #if defined(AFS) || defined(KRB5) |
| 253 | sKerberosTgtPassing, |
| 254 | #endif |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 255 | #ifdef AFS |
Ben Lindstrom | ec95ed9 | 2001-07-04 04:21:14 +0000 | [diff] [blame] | 256 | sAFSTokenPassing, |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 257 | #endif |
Ben Lindstrom | 95fb2dd | 2001-01-23 03:12:10 +0000 | [diff] [blame] | 258 | sChallengeResponseAuthentication, |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 259 | sPasswordAuthentication, sKbdInteractiveAuthentication, sListenAddress, |
Ben Lindstrom | 7bfff36 | 2001-03-26 05:45:53 +0000 | [diff] [blame] | 260 | sPrintMotd, sPrintLastLog, sIgnoreRhosts, |
Damien Miller | 95c249f | 2002-02-05 12:11:34 +1100 | [diff] [blame] | 261 | sX11Forwarding, sX11DisplayOffset, sX11UseLocalhost, |
Ben Lindstrom | 91e9868 | 2001-09-12 16:32:14 +0000 | [diff] [blame] | 262 | sStrictModes, sEmptyPasswd, sKeepAlives, |
Damien Miller | 50a41ed | 2000-10-16 12:14:42 +1100 | [diff] [blame] | 263 | sUseLogin, sAllowTcpForwarding, |
| 264 | sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups, |
Ben Lindstrom | 06b33aa | 2001-02-15 03:01:59 +0000 | [diff] [blame] | 265 | sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile, |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 266 | sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem, sMaxStartups, |
Damien Miller | c5d8635 | 2002-02-05 12:13:41 +1100 | [diff] [blame] | 267 | sBanner, sVerifyReverseMapping, sHostbasedAuthentication, |
Damien Miller | 9f0f5c6 | 2001-12-21 14:45:46 +1100 | [diff] [blame] | 268 | sHostbasedUsesNameFromPacketOnly, sClientAliveInterval, |
Ben Lindstrom | bfb3a0e | 2001-06-05 20:25:05 +0000 | [diff] [blame] | 269 | sClientAliveCountMax, sAuthorizedKeysFile, sAuthorizedKeysFile2, |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 270 | sDeprecated |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 271 | } ServerOpCodes; |
| 272 | |
| 273 | /* Textual representation of the tokens. */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 274 | static struct { |
| 275 | const char *name; |
| 276 | ServerOpCodes opcode; |
| 277 | } keywords[] = { |
Damien Miller | 726273e | 2001-11-12 11:40:11 +1100 | [diff] [blame] | 278 | /* Portable-specific options */ |
| 279 | { "PAMAuthenticationViaKbdInt", sPAMAuthenticationViaKbdInt }, |
| 280 | /* Standard Options */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 281 | { "port", sPort }, |
| 282 | { "hostkey", sHostKeyFile }, |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 283 | { "hostdsakey", sHostKeyFile }, /* alias */ |
Kevin Steves | ef4eea9 | 2001-02-05 12:42:17 +0000 | [diff] [blame] | 284 | { "pidfile", sPidFile }, |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 285 | { "serverkeybits", sServerKeyBits }, |
| 286 | { "logingracetime", sLoginGraceTime }, |
| 287 | { "keyregenerationinterval", sKeyRegenerationTime }, |
| 288 | { "permitrootlogin", sPermitRootLogin }, |
| 289 | { "syslogfacility", sLogFacility }, |
| 290 | { "loglevel", sLogLevel }, |
| 291 | { "rhostsauthentication", sRhostsAuthentication }, |
| 292 | { "rhostsrsaauthentication", sRhostsRSAAuthentication }, |
Ben Lindstrom | 5eabda3 | 2001-04-12 23:34:34 +0000 | [diff] [blame] | 293 | { "hostbasedauthentication", sHostbasedAuthentication }, |
| 294 | { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly }, |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 295 | { "rsaauthentication", sRSAAuthentication }, |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 296 | { "pubkeyauthentication", sPubkeyAuthentication }, |
| 297 | { "dsaauthentication", sPubkeyAuthentication }, /* alias */ |
Ben Lindstrom | ec95ed9 | 2001-07-04 04:21:14 +0000 | [diff] [blame] | 298 | #if defined(KRB4) || defined(KRB5) |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 299 | { "kerberosauthentication", sKerberosAuthentication }, |
| 300 | { "kerberosorlocalpasswd", sKerberosOrLocalPasswd }, |
| 301 | { "kerberosticketcleanup", sKerberosTicketCleanup }, |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 302 | #endif |
Ben Lindstrom | ec95ed9 | 2001-07-04 04:21:14 +0000 | [diff] [blame] | 303 | #if defined(AFS) || defined(KRB5) |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 304 | { "kerberostgtpassing", sKerberosTgtPassing }, |
Ben Lindstrom | ec95ed9 | 2001-07-04 04:21:14 +0000 | [diff] [blame] | 305 | #endif |
| 306 | #ifdef AFS |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 307 | { "afstokenpassing", sAFSTokenPassing }, |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 308 | #endif |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 309 | { "passwordauthentication", sPasswordAuthentication }, |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 310 | { "kbdinteractiveauthentication", sKbdInteractiveAuthentication }, |
Ben Lindstrom | 95fb2dd | 2001-01-23 03:12:10 +0000 | [diff] [blame] | 311 | { "challengeresponseauthentication", sChallengeResponseAuthentication }, |
| 312 | { "skeyauthentication", sChallengeResponseAuthentication }, /* alias */ |
Ben Lindstrom | 91e9868 | 2001-09-12 16:32:14 +0000 | [diff] [blame] | 313 | { "checkmail", sDeprecated }, |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 314 | { "listenaddress", sListenAddress }, |
| 315 | { "printmotd", sPrintMotd }, |
Ben Lindstrom | 7bfff36 | 2001-03-26 05:45:53 +0000 | [diff] [blame] | 316 | { "printlastlog", sPrintLastLog }, |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 317 | { "ignorerhosts", sIgnoreRhosts }, |
| 318 | { "ignoreuserknownhosts", sIgnoreUserKnownHosts }, |
| 319 | { "x11forwarding", sX11Forwarding }, |
| 320 | { "x11displayoffset", sX11DisplayOffset }, |
Damien Miller | 95c249f | 2002-02-05 12:11:34 +1100 | [diff] [blame] | 321 | { "x11uselocalhost", sX11UseLocalhost }, |
Damien Miller | d3a1857 | 2000-06-07 19:55:44 +1000 | [diff] [blame] | 322 | { "xauthlocation", sXAuthLocation }, |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 323 | { "strictmodes", sStrictModes }, |
| 324 | { "permitemptypasswords", sEmptyPasswd }, |
| 325 | { "uselogin", sUseLogin }, |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 326 | { "keepalive", sKeepAlives }, |
Damien Miller | 50a41ed | 2000-10-16 12:14:42 +1100 | [diff] [blame] | 327 | { "allowtcpforwarding", sAllowTcpForwarding }, |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 328 | { "allowusers", sAllowUsers }, |
| 329 | { "denyusers", sDenyUsers }, |
| 330 | { "allowgroups", sAllowGroups }, |
| 331 | { "denygroups", sDenyGroups }, |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 332 | { "ciphers", sCiphers }, |
Ben Lindstrom | 06b33aa | 2001-02-15 03:01:59 +0000 | [diff] [blame] | 333 | { "macs", sMacs }, |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 334 | { "protocol", sProtocol }, |
Damien Miller | e247cc4 | 2000-05-07 12:03:14 +1000 | [diff] [blame] | 335 | { "gatewayports", sGatewayPorts }, |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 336 | { "subsystem", sSubsystem }, |
Damien Miller | 3702396 | 2000-07-11 17:31:38 +1000 | [diff] [blame] | 337 | { "maxstartups", sMaxStartups }, |
Ben Lindstrom | 48bd7c1 | 2001-01-09 00:35:42 +0000 | [diff] [blame] | 338 | { "banner", sBanner }, |
Damien Miller | c5d8635 | 2002-02-05 12:13:41 +1100 | [diff] [blame] | 339 | { "verifyreversemapping", sVerifyReverseMapping }, |
| 340 | { "reversemappingcheck", sVerifyReverseMapping }, |
Ben Lindstrom | 5744dc4 | 2001-04-13 23:28:01 +0000 | [diff] [blame] | 341 | { "clientaliveinterval", sClientAliveInterval }, |
| 342 | { "clientalivecountmax", sClientAliveCountMax }, |
Ben Lindstrom | bfb3a0e | 2001-06-05 20:25:05 +0000 | [diff] [blame] | 343 | { "authorizedkeysfile", sAuthorizedKeysFile }, |
| 344 | { "authorizedkeysfile2", sAuthorizedKeysFile2 }, |
Ben Lindstrom | 65366a8 | 2001-12-06 16:32:47 +0000 | [diff] [blame] | 345 | { NULL, sBadOption } |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 346 | }; |
| 347 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 348 | /* |
Ben Lindstrom | 3704c26 | 2001-04-02 18:20:03 +0000 | [diff] [blame] | 349 | * Returns the number of the token pointed to by cp or sBadOption. |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 350 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 351 | |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 352 | static ServerOpCodes |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 353 | parse_token(const char *cp, const char *filename, |
| 354 | int linenum) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 355 | { |
Ben Lindstrom | 46c1622 | 2000-12-22 01:43:59 +0000 | [diff] [blame] | 356 | u_int i; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 357 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 358 | for (i = 0; keywords[i].name; i++) |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 359 | if (strcasecmp(cp, keywords[i].name) == 0) |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 360 | return keywords[i].opcode; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 361 | |
Ben Lindstrom | b5cdc66 | 2001-04-16 02:13:26 +0000 | [diff] [blame] | 362 | error("%s: line %d: Bad configuration option: %s", |
| 363 | filename, linenum, cp); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 364 | return sBadOption; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 365 | } |
| 366 | |
Ben Lindstrom | bba8121 | 2001-06-25 05:01:22 +0000 | [diff] [blame] | 367 | static void |
Ben Lindstrom | 19066a1 | 2001-04-12 23:39:26 +0000 | [diff] [blame] | 368 | add_listen_addr(ServerOptions *options, char *addr, u_short port) |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 369 | { |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 370 | int i; |
| 371 | |
| 372 | if (options->num_ports == 0) |
| 373 | options->ports[options->num_ports++] = SSH_DEFAULT_PORT; |
Ben Lindstrom | 19066a1 | 2001-04-12 23:39:26 +0000 | [diff] [blame] | 374 | if (port == 0) |
Ben Lindstrom | c510af4 | 2001-04-07 17:25:48 +0000 | [diff] [blame] | 375 | for (i = 0; i < options->num_ports; i++) |
| 376 | add_one_listen_addr(options, addr, options->ports[i]); |
| 377 | else |
Ben Lindstrom | 19066a1 | 2001-04-12 23:39:26 +0000 | [diff] [blame] | 378 | add_one_listen_addr(options, addr, port); |
Ben Lindstrom | c510af4 | 2001-04-07 17:25:48 +0000 | [diff] [blame] | 379 | } |
| 380 | |
Ben Lindstrom | bba8121 | 2001-06-25 05:01:22 +0000 | [diff] [blame] | 381 | static void |
Ben Lindstrom | c510af4 | 2001-04-07 17:25:48 +0000 | [diff] [blame] | 382 | add_one_listen_addr(ServerOptions *options, char *addr, u_short port) |
| 383 | { |
| 384 | struct addrinfo hints, *ai, *aitop; |
| 385 | char strport[NI_MAXSERV]; |
| 386 | int gaierr; |
| 387 | |
| 388 | memset(&hints, 0, sizeof(hints)); |
| 389 | hints.ai_family = IPv4or6; |
| 390 | hints.ai_socktype = SOCK_STREAM; |
| 391 | hints.ai_flags = (addr == NULL) ? AI_PASSIVE : 0; |
| 392 | snprintf(strport, sizeof strport, "%d", port); |
| 393 | if ((gaierr = getaddrinfo(addr, strport, &hints, &aitop)) != 0) |
| 394 | fatal("bad addr or host: %s (%s)", |
| 395 | addr ? addr : "<NULL>", |
| 396 | gai_strerror(gaierr)); |
| 397 | for (ai = aitop; ai->ai_next; ai = ai->ai_next) |
| 398 | ; |
| 399 | ai->ai_next = options->listen_addrs; |
| 400 | options->listen_addrs = aitop; |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 401 | } |
| 402 | |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 403 | int |
| 404 | process_server_config_line(ServerOptions *options, char *line, |
| 405 | const char *filename, int linenum) |
| 406 | { |
| 407 | char *cp, **charptr, *arg, *p; |
| 408 | int *intptr, value; |
| 409 | ServerOpCodes opcode; |
| 410 | int i, n; |
| 411 | |
| 412 | cp = line; |
| 413 | arg = strdelim(&cp); |
| 414 | /* Ignore leading whitespace */ |
| 415 | if (*arg == '\0') |
| 416 | arg = strdelim(&cp); |
| 417 | if (!arg || !*arg || *arg == '#') |
| 418 | return 0; |
| 419 | intptr = NULL; |
| 420 | charptr = NULL; |
| 421 | opcode = parse_token(arg, filename, linenum); |
| 422 | switch (opcode) { |
| 423 | /* Portable-specific options */ |
| 424 | case sPAMAuthenticationViaKbdInt: |
| 425 | intptr = &options->pam_authentication_via_kbd_int; |
| 426 | goto parse_flag; |
| 427 | |
| 428 | /* Standard Options */ |
| 429 | case sBadOption: |
| 430 | return -1; |
| 431 | case sPort: |
| 432 | /* ignore ports from configfile if cmdline specifies ports */ |
| 433 | if (options->ports_from_cmdline) |
| 434 | return 0; |
| 435 | if (options->listen_addrs != NULL) |
| 436 | fatal("%s line %d: ports must be specified before " |
Damien Miller | 4fbf08a | 2002-01-22 23:35:09 +1100 | [diff] [blame] | 437 | "ListenAddress.", filename, linenum); |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 438 | if (options->num_ports >= MAX_PORTS) |
| 439 | fatal("%s line %d: too many ports.", |
| 440 | filename, linenum); |
| 441 | arg = strdelim(&cp); |
| 442 | if (!arg || *arg == '\0') |
| 443 | fatal("%s line %d: missing port number.", |
| 444 | filename, linenum); |
| 445 | options->ports[options->num_ports++] = a2port(arg); |
| 446 | if (options->ports[options->num_ports-1] == 0) |
| 447 | fatal("%s line %d: Badly formatted port number.", |
| 448 | filename, linenum); |
| 449 | break; |
| 450 | |
| 451 | case sServerKeyBits: |
| 452 | intptr = &options->server_key_bits; |
| 453 | parse_int: |
| 454 | arg = strdelim(&cp); |
| 455 | if (!arg || *arg == '\0') |
| 456 | fatal("%s line %d: missing integer value.", |
| 457 | filename, linenum); |
| 458 | value = atoi(arg); |
| 459 | if (*intptr == -1) |
| 460 | *intptr = value; |
| 461 | break; |
| 462 | |
| 463 | case sLoginGraceTime: |
| 464 | intptr = &options->login_grace_time; |
| 465 | parse_time: |
| 466 | arg = strdelim(&cp); |
| 467 | if (!arg || *arg == '\0') |
| 468 | fatal("%s line %d: missing time value.", |
| 469 | filename, linenum); |
| 470 | if ((value = convtime(arg)) == -1) |
| 471 | fatal("%s line %d: invalid time value.", |
| 472 | filename, linenum); |
| 473 | if (*intptr == -1) |
| 474 | *intptr = value; |
| 475 | break; |
| 476 | |
| 477 | case sKeyRegenerationTime: |
| 478 | intptr = &options->key_regeneration_time; |
| 479 | goto parse_time; |
| 480 | |
| 481 | case sListenAddress: |
| 482 | arg = strdelim(&cp); |
| 483 | if (!arg || *arg == '\0' || strncmp(arg, "[]", 2) == 0) |
| 484 | fatal("%s line %d: missing inet addr.", |
| 485 | filename, linenum); |
| 486 | if (*arg == '[') { |
| 487 | if ((p = strchr(arg, ']')) == NULL) |
| 488 | fatal("%s line %d: bad ipv6 inet addr usage.", |
| 489 | filename, linenum); |
| 490 | arg++; |
| 491 | memmove(p, p+1, strlen(p+1)+1); |
| 492 | } else if (((p = strchr(arg, ':')) == NULL) || |
| 493 | (strchr(p+1, ':') != NULL)) { |
| 494 | add_listen_addr(options, arg, 0); |
| 495 | break; |
| 496 | } |
| 497 | if (*p == ':') { |
| 498 | u_short port; |
| 499 | |
| 500 | p++; |
| 501 | if (*p == '\0') |
| 502 | fatal("%s line %d: bad inet addr:port usage.", |
| 503 | filename, linenum); |
| 504 | else { |
| 505 | *(p-1) = '\0'; |
| 506 | if ((port = a2port(p)) == 0) |
| 507 | fatal("%s line %d: bad port number.", |
| 508 | filename, linenum); |
| 509 | add_listen_addr(options, arg, port); |
| 510 | } |
| 511 | } else if (*p == '\0') |
| 512 | add_listen_addr(options, arg, 0); |
| 513 | else |
| 514 | fatal("%s line %d: bad inet addr usage.", |
| 515 | filename, linenum); |
| 516 | break; |
| 517 | |
| 518 | case sHostKeyFile: |
| 519 | intptr = &options->num_host_key_files; |
| 520 | if (*intptr >= MAX_HOSTKEYS) |
| 521 | fatal("%s line %d: too many host keys specified (max %d).", |
| 522 | filename, linenum, MAX_HOSTKEYS); |
| 523 | charptr = &options->host_key_files[*intptr]; |
| 524 | parse_filename: |
| 525 | arg = strdelim(&cp); |
| 526 | if (!arg || *arg == '\0') |
| 527 | fatal("%s line %d: missing file name.", |
| 528 | filename, linenum); |
| 529 | if (*charptr == NULL) { |
| 530 | *charptr = tilde_expand_filename(arg, getuid()); |
| 531 | /* increase optional counter */ |
| 532 | if (intptr != NULL) |
| 533 | *intptr = *intptr + 1; |
| 534 | } |
| 535 | break; |
| 536 | |
| 537 | case sPidFile: |
| 538 | charptr = &options->pid_file; |
| 539 | goto parse_filename; |
| 540 | |
| 541 | case sPermitRootLogin: |
| 542 | intptr = &options->permit_root_login; |
| 543 | arg = strdelim(&cp); |
| 544 | if (!arg || *arg == '\0') |
| 545 | fatal("%s line %d: missing yes/" |
| 546 | "without-password/forced-commands-only/no " |
| 547 | "argument.", filename, linenum); |
| 548 | value = 0; /* silence compiler */ |
| 549 | if (strcmp(arg, "without-password") == 0) |
| 550 | value = PERMIT_NO_PASSWD; |
| 551 | else if (strcmp(arg, "forced-commands-only") == 0) |
| 552 | value = PERMIT_FORCED_ONLY; |
| 553 | else if (strcmp(arg, "yes") == 0) |
| 554 | value = PERMIT_YES; |
| 555 | else if (strcmp(arg, "no") == 0) |
| 556 | value = PERMIT_NO; |
| 557 | else |
| 558 | fatal("%s line %d: Bad yes/" |
| 559 | "without-password/forced-commands-only/no " |
| 560 | "argument: %s", filename, linenum, arg); |
| 561 | if (*intptr == -1) |
| 562 | *intptr = value; |
| 563 | break; |
| 564 | |
| 565 | case sIgnoreRhosts: |
| 566 | intptr = &options->ignore_rhosts; |
| 567 | parse_flag: |
| 568 | arg = strdelim(&cp); |
| 569 | if (!arg || *arg == '\0') |
| 570 | fatal("%s line %d: missing yes/no argument.", |
| 571 | filename, linenum); |
| 572 | value = 0; /* silence compiler */ |
| 573 | if (strcmp(arg, "yes") == 0) |
| 574 | value = 1; |
| 575 | else if (strcmp(arg, "no") == 0) |
| 576 | value = 0; |
| 577 | else |
| 578 | fatal("%s line %d: Bad yes/no argument: %s", |
| 579 | filename, linenum, arg); |
| 580 | if (*intptr == -1) |
| 581 | *intptr = value; |
| 582 | break; |
| 583 | |
| 584 | case sIgnoreUserKnownHosts: |
| 585 | intptr = &options->ignore_user_known_hosts; |
| 586 | goto parse_flag; |
| 587 | |
| 588 | case sRhostsAuthentication: |
| 589 | intptr = &options->rhosts_authentication; |
| 590 | goto parse_flag; |
| 591 | |
| 592 | case sRhostsRSAAuthentication: |
| 593 | intptr = &options->rhosts_rsa_authentication; |
| 594 | goto parse_flag; |
| 595 | |
| 596 | case sHostbasedAuthentication: |
| 597 | intptr = &options->hostbased_authentication; |
| 598 | goto parse_flag; |
| 599 | |
| 600 | case sHostbasedUsesNameFromPacketOnly: |
| 601 | intptr = &options->hostbased_uses_name_from_packet_only; |
| 602 | goto parse_flag; |
| 603 | |
| 604 | case sRSAAuthentication: |
| 605 | intptr = &options->rsa_authentication; |
| 606 | goto parse_flag; |
| 607 | |
| 608 | case sPubkeyAuthentication: |
| 609 | intptr = &options->pubkey_authentication; |
| 610 | goto parse_flag; |
| 611 | #if defined(KRB4) || defined(KRB5) |
| 612 | case sKerberosAuthentication: |
| 613 | intptr = &options->kerberos_authentication; |
| 614 | goto parse_flag; |
| 615 | |
| 616 | case sKerberosOrLocalPasswd: |
| 617 | intptr = &options->kerberos_or_local_passwd; |
| 618 | goto parse_flag; |
| 619 | |
| 620 | case sKerberosTicketCleanup: |
| 621 | intptr = &options->kerberos_ticket_cleanup; |
| 622 | goto parse_flag; |
| 623 | #endif |
| 624 | #if defined(AFS) || defined(KRB5) |
| 625 | case sKerberosTgtPassing: |
| 626 | intptr = &options->kerberos_tgt_passing; |
| 627 | goto parse_flag; |
| 628 | #endif |
| 629 | #ifdef AFS |
| 630 | case sAFSTokenPassing: |
| 631 | intptr = &options->afs_token_passing; |
| 632 | goto parse_flag; |
| 633 | #endif |
| 634 | |
| 635 | case sPasswordAuthentication: |
| 636 | intptr = &options->password_authentication; |
| 637 | goto parse_flag; |
| 638 | |
| 639 | case sKbdInteractiveAuthentication: |
| 640 | intptr = &options->kbd_interactive_authentication; |
| 641 | goto parse_flag; |
| 642 | |
| 643 | case sChallengeResponseAuthentication: |
| 644 | intptr = &options->challenge_response_authentication; |
| 645 | goto parse_flag; |
| 646 | |
| 647 | case sPrintMotd: |
| 648 | intptr = &options->print_motd; |
| 649 | goto parse_flag; |
| 650 | |
| 651 | case sPrintLastLog: |
| 652 | intptr = &options->print_lastlog; |
| 653 | goto parse_flag; |
| 654 | |
| 655 | case sX11Forwarding: |
| 656 | intptr = &options->x11_forwarding; |
| 657 | goto parse_flag; |
| 658 | |
| 659 | case sX11DisplayOffset: |
| 660 | intptr = &options->x11_display_offset; |
| 661 | goto parse_int; |
| 662 | |
Damien Miller | 95c249f | 2002-02-05 12:11:34 +1100 | [diff] [blame] | 663 | case sX11UseLocalhost: |
| 664 | intptr = &options->x11_use_localhost; |
| 665 | goto parse_flag; |
| 666 | |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 667 | case sXAuthLocation: |
| 668 | charptr = &options->xauth_location; |
| 669 | goto parse_filename; |
| 670 | |
| 671 | case sStrictModes: |
| 672 | intptr = &options->strict_modes; |
| 673 | goto parse_flag; |
| 674 | |
| 675 | case sKeepAlives: |
| 676 | intptr = &options->keepalives; |
| 677 | goto parse_flag; |
| 678 | |
| 679 | case sEmptyPasswd: |
| 680 | intptr = &options->permit_empty_passwd; |
| 681 | goto parse_flag; |
| 682 | |
| 683 | case sUseLogin: |
| 684 | intptr = &options->use_login; |
| 685 | goto parse_flag; |
| 686 | |
| 687 | case sGatewayPorts: |
| 688 | intptr = &options->gateway_ports; |
| 689 | goto parse_flag; |
| 690 | |
Damien Miller | c5d8635 | 2002-02-05 12:13:41 +1100 | [diff] [blame] | 691 | case sVerifyReverseMapping: |
| 692 | intptr = &options->verify_reverse_mapping; |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 693 | goto parse_flag; |
| 694 | |
| 695 | case sLogFacility: |
| 696 | intptr = (int *) &options->log_facility; |
| 697 | arg = strdelim(&cp); |
| 698 | value = log_facility_number(arg); |
| 699 | if (value == (SyslogFacility) - 1) |
| 700 | fatal("%.200s line %d: unsupported log facility '%s'", |
| 701 | filename, linenum, arg ? arg : "<NONE>"); |
| 702 | if (*intptr == -1) |
| 703 | *intptr = (SyslogFacility) value; |
| 704 | break; |
| 705 | |
| 706 | case sLogLevel: |
| 707 | intptr = (int *) &options->log_level; |
| 708 | arg = strdelim(&cp); |
| 709 | value = log_level_number(arg); |
| 710 | if (value == (LogLevel) - 1) |
| 711 | fatal("%.200s line %d: unsupported log level '%s'", |
| 712 | filename, linenum, arg ? arg : "<NONE>"); |
| 713 | if (*intptr == -1) |
| 714 | *intptr = (LogLevel) value; |
| 715 | break; |
| 716 | |
| 717 | case sAllowTcpForwarding: |
| 718 | intptr = &options->allow_tcp_forwarding; |
| 719 | goto parse_flag; |
| 720 | |
| 721 | case sAllowUsers: |
| 722 | while ((arg = strdelim(&cp)) && *arg != '\0') { |
| 723 | if (options->num_allow_users >= MAX_ALLOW_USERS) |
| 724 | fatal("%s line %d: too many allow users.", |
| 725 | filename, linenum); |
| 726 | options->allow_users[options->num_allow_users++] = xstrdup(arg); |
| 727 | } |
| 728 | break; |
| 729 | |
| 730 | case sDenyUsers: |
| 731 | while ((arg = strdelim(&cp)) && *arg != '\0') { |
| 732 | if (options->num_deny_users >= MAX_DENY_USERS) |
| 733 | fatal( "%s line %d: too many deny users.", |
| 734 | filename, linenum); |
| 735 | options->deny_users[options->num_deny_users++] = xstrdup(arg); |
| 736 | } |
| 737 | break; |
| 738 | |
| 739 | case sAllowGroups: |
| 740 | while ((arg = strdelim(&cp)) && *arg != '\0') { |
| 741 | if (options->num_allow_groups >= MAX_ALLOW_GROUPS) |
| 742 | fatal("%s line %d: too many allow groups.", |
| 743 | filename, linenum); |
| 744 | options->allow_groups[options->num_allow_groups++] = xstrdup(arg); |
| 745 | } |
| 746 | break; |
| 747 | |
| 748 | case sDenyGroups: |
| 749 | while ((arg = strdelim(&cp)) && *arg != '\0') { |
| 750 | if (options->num_deny_groups >= MAX_DENY_GROUPS) |
| 751 | fatal("%s line %d: too many deny groups.", |
| 752 | filename, linenum); |
| 753 | options->deny_groups[options->num_deny_groups++] = xstrdup(arg); |
| 754 | } |
| 755 | break; |
| 756 | |
| 757 | case sCiphers: |
| 758 | arg = strdelim(&cp); |
| 759 | if (!arg || *arg == '\0') |
| 760 | fatal("%s line %d: Missing argument.", filename, linenum); |
| 761 | if (!ciphers_valid(arg)) |
| 762 | fatal("%s line %d: Bad SSH2 cipher spec '%s'.", |
| 763 | filename, linenum, arg ? arg : "<NONE>"); |
| 764 | if (options->ciphers == NULL) |
| 765 | options->ciphers = xstrdup(arg); |
| 766 | break; |
| 767 | |
| 768 | case sMacs: |
| 769 | arg = strdelim(&cp); |
| 770 | if (!arg || *arg == '\0') |
| 771 | fatal("%s line %d: Missing argument.", filename, linenum); |
| 772 | if (!mac_valid(arg)) |
| 773 | fatal("%s line %d: Bad SSH2 mac spec '%s'.", |
| 774 | filename, linenum, arg ? arg : "<NONE>"); |
| 775 | if (options->macs == NULL) |
| 776 | options->macs = xstrdup(arg); |
| 777 | break; |
| 778 | |
| 779 | case sProtocol: |
| 780 | intptr = &options->protocol; |
| 781 | arg = strdelim(&cp); |
| 782 | if (!arg || *arg == '\0') |
| 783 | fatal("%s line %d: Missing argument.", filename, linenum); |
| 784 | value = proto_spec(arg); |
| 785 | if (value == SSH_PROTO_UNKNOWN) |
| 786 | fatal("%s line %d: Bad protocol spec '%s'.", |
Damien Miller | 9f0f5c6 | 2001-12-21 14:45:46 +1100 | [diff] [blame] | 787 | filename, linenum, arg ? arg : "<NONE>"); |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 788 | if (*intptr == SSH_PROTO_UNKNOWN) |
| 789 | *intptr = value; |
| 790 | break; |
| 791 | |
| 792 | case sSubsystem: |
| 793 | if (options->num_subsystems >= MAX_SUBSYSTEMS) { |
| 794 | fatal("%s line %d: too many subsystems defined.", |
Damien Miller | 9f0f5c6 | 2001-12-21 14:45:46 +1100 | [diff] [blame] | 795 | filename, linenum); |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 796 | } |
| 797 | arg = strdelim(&cp); |
| 798 | if (!arg || *arg == '\0') |
| 799 | fatal("%s line %d: Missing subsystem name.", |
Damien Miller | 9f0f5c6 | 2001-12-21 14:45:46 +1100 | [diff] [blame] | 800 | filename, linenum); |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 801 | for (i = 0; i < options->num_subsystems; i++) |
| 802 | if (strcmp(arg, options->subsystem_name[i]) == 0) |
| 803 | fatal("%s line %d: Subsystem '%s' already defined.", |
Damien Miller | 9f0f5c6 | 2001-12-21 14:45:46 +1100 | [diff] [blame] | 804 | filename, linenum, arg); |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 805 | options->subsystem_name[options->num_subsystems] = xstrdup(arg); |
| 806 | arg = strdelim(&cp); |
| 807 | if (!arg || *arg == '\0') |
| 808 | fatal("%s line %d: Missing subsystem command.", |
Damien Miller | 9f0f5c6 | 2001-12-21 14:45:46 +1100 | [diff] [blame] | 809 | filename, linenum); |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 810 | options->subsystem_command[options->num_subsystems] = xstrdup(arg); |
| 811 | options->num_subsystems++; |
| 812 | break; |
| 813 | |
| 814 | case sMaxStartups: |
| 815 | arg = strdelim(&cp); |
| 816 | if (!arg || *arg == '\0') |
| 817 | fatal("%s line %d: Missing MaxStartups spec.", |
Damien Miller | 9f0f5c6 | 2001-12-21 14:45:46 +1100 | [diff] [blame] | 818 | filename, linenum); |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 819 | if ((n = sscanf(arg, "%d:%d:%d", |
| 820 | &options->max_startups_begin, |
| 821 | &options->max_startups_rate, |
| 822 | &options->max_startups)) == 3) { |
| 823 | if (options->max_startups_begin > |
| 824 | options->max_startups || |
| 825 | options->max_startups_rate > 100 || |
| 826 | options->max_startups_rate < 1) |
| 827 | fatal("%s line %d: Illegal MaxStartups spec.", |
| 828 | filename, linenum); |
| 829 | } else if (n != 1) |
| 830 | fatal("%s line %d: Illegal MaxStartups spec.", |
| 831 | filename, linenum); |
| 832 | else |
| 833 | options->max_startups = options->max_startups_begin; |
| 834 | break; |
| 835 | |
| 836 | case sBanner: |
| 837 | charptr = &options->banner; |
| 838 | goto parse_filename; |
| 839 | /* |
| 840 | * These options can contain %X options expanded at |
| 841 | * connect time, so that you can specify paths like: |
| 842 | * |
| 843 | * AuthorizedKeysFile /etc/ssh_keys/%u |
| 844 | */ |
| 845 | case sAuthorizedKeysFile: |
| 846 | case sAuthorizedKeysFile2: |
| 847 | charptr = (opcode == sAuthorizedKeysFile ) ? |
| 848 | &options->authorized_keys_file : |
| 849 | &options->authorized_keys_file2; |
| 850 | goto parse_filename; |
| 851 | |
| 852 | case sClientAliveInterval: |
| 853 | intptr = &options->client_alive_interval; |
| 854 | goto parse_time; |
| 855 | |
| 856 | case sClientAliveCountMax: |
| 857 | intptr = &options->client_alive_count_max; |
| 858 | goto parse_int; |
| 859 | |
| 860 | case sDeprecated: |
| 861 | log("%s line %d: Deprecated option %s", |
| 862 | filename, linenum, arg); |
| 863 | while (arg) |
| 864 | arg = strdelim(&cp); |
| 865 | break; |
| 866 | |
| 867 | default: |
| 868 | fatal("%s line %d: Missing handler for opcode %s (%d)", |
| 869 | filename, linenum, arg, opcode); |
| 870 | } |
| 871 | if ((arg = strdelim(&cp)) != NULL && *arg != '\0') |
| 872 | fatal("%s line %d: garbage at end of line; \"%.200s\".", |
| 873 | filename, linenum, arg); |
| 874 | return 0; |
| 875 | } |
| 876 | |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 877 | /* Reads the server configuration file. */ |
| 878 | |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 879 | void |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 880 | read_server_config(ServerOptions *options, const char *filename) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 881 | { |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 882 | FILE *f; |
| 883 | char line[1024]; |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 884 | int linenum; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 885 | int bad_options = 0; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 886 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 887 | f = fopen(filename, "r"); |
| 888 | if (!f) { |
| 889 | perror(filename); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 890 | exit(1); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 891 | } |
| 892 | linenum = 0; |
| 893 | while (fgets(line, sizeof(line), f)) { |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 894 | /* Update line number counter. */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 895 | linenum++; |
Ben Lindstrom | ade03f6 | 2001-12-06 18:22:17 +0000 | [diff] [blame] | 896 | if (process_server_config_line(options, line, filename, linenum) != 0) |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 897 | bad_options++; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 898 | } |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 899 | fclose(f); |
Ben Lindstrom | b5cdc66 | 2001-04-16 02:13:26 +0000 | [diff] [blame] | 900 | if (bad_options > 0) |
| 901 | fatal("%s: terminating, %d bad configuration options", |
| 902 | filename, bad_options); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 903 | } |