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