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