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