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