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