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