1997-02-18 14:27:53 +00:00
|
|
|
/* clparse.c
|
|
|
|
|
|
|
|
Parser for dhclient config and lease files... */
|
|
|
|
|
|
|
|
/*
|
1998-03-16 06:02:14 +00:00
|
|
|
* Copyright (c) 1997, 1998 The Internet Software Consortium.
|
1997-02-18 14:27:53 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the name of The Internet Software Consortium nor the names
|
|
|
|
* of its contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE INTERNET SOFTWARE CONSORTIUM AND
|
|
|
|
* CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
|
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE INTERNET SOFTWARE CONSORTIUM OR
|
|
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
|
|
|
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
|
|
|
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* This software has been written for the Internet Software Consortium
|
|
|
|
* by Ted Lemon <mellon@fugue.com> in cooperation with Vixie
|
|
|
|
* Enterprises. To learn more about the Internet Software Consortium,
|
|
|
|
* see ``http://www.vix.com/isc''. To learn more about Vixie
|
|
|
|
* Enterprises, see ``http://www.vix.com''.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef lint
|
|
|
|
static char copyright[] =
|
1999-02-25 23:30:43 +00:00
|
|
|
"$Id: clparse.c,v 1.23 1999/02/25 23:30:31 mellon Exp $ Copyright (c) 1997 The Internet Software Consortium. All rights reserved.\n";
|
1997-02-18 14:27:53 +00:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include "dhcpd.h"
|
|
|
|
#include "dhctoken.h"
|
|
|
|
|
|
|
|
static TIME parsed_time;
|
|
|
|
|
1997-03-28 23:50:15 +00:00
|
|
|
struct client_config top_level_config;
|
|
|
|
|
1998-11-05 18:43:23 +00:00
|
|
|
u_int32_t default_requested_options [] = {
|
|
|
|
DHO_SUBNET_MASK,
|
|
|
|
DHO_BROADCAST_ADDRESS,
|
|
|
|
DHO_TIME_OFFSET,
|
|
|
|
DHO_ROUTERS,
|
|
|
|
DHO_DOMAIN_NAME,
|
|
|
|
DHO_DOMAIN_NAME_SERVERS,
|
|
|
|
DHO_HOST_NAME,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
1997-02-18 14:27:53 +00:00
|
|
|
/* client-conf-file :== client-declarations EOF
|
|
|
|
client-declarations :== <nil>
|
|
|
|
| client-declaration
|
|
|
|
| client-declarations client-declaration */
|
|
|
|
|
|
|
|
int read_client_conf ()
|
|
|
|
{
|
|
|
|
FILE *cfile;
|
|
|
|
char *val;
|
|
|
|
int token;
|
|
|
|
int declaration = 0;
|
|
|
|
struct client_config *config;
|
|
|
|
struct client_state *state;
|
|
|
|
struct interface_info *ip;
|
|
|
|
|
|
|
|
new_parse (path_dhclient_conf);
|
|
|
|
|
|
|
|
/* Set up the initial dhcp option universe. */
|
|
|
|
initialize_universes ();
|
|
|
|
|
|
|
|
/* Initialize the top level client configuration. */
|
|
|
|
memset (&top_level_config, 0, sizeof top_level_config);
|
|
|
|
|
1997-03-28 23:50:15 +00:00
|
|
|
/* Set some defaults... */
|
|
|
|
top_level_config.timeout = 60;
|
|
|
|
top_level_config.select_interval = 0;
|
|
|
|
top_level_config.reboot_timeout = 10;
|
|
|
|
top_level_config.retry_interval = 300;
|
|
|
|
top_level_config.backoff_cutoff = 120;
|
|
|
|
top_level_config.initial_interval = 10;
|
|
|
|
top_level_config.bootp_policy = ACCEPT;
|
|
|
|
top_level_config.script_name = "/etc/dhclient-script";
|
1998-11-05 18:43:23 +00:00
|
|
|
top_level_config.requested_options = default_requested_options;
|
|
|
|
top_level_config.requested_lease = 7200;
|
1997-03-28 23:50:15 +00:00
|
|
|
|
1998-11-11 07:48:23 +00:00
|
|
|
top_level_config.on_receipt = new_group ("read_client_conf");
|
|
|
|
if (!top_level_config.on_receipt)
|
1999-02-24 17:56:53 +00:00
|
|
|
log_fatal ("no memory for top-level on_receipt group");
|
1998-11-11 07:48:23 +00:00
|
|
|
|
|
|
|
top_level_config.on_transmission = new_group ("read_client_conf");
|
|
|
|
if (!top_level_config.on_transmission)
|
1999-02-24 17:56:53 +00:00
|
|
|
log_fatal ("no memory for top-level on_transmission group");
|
1998-11-11 07:48:23 +00:00
|
|
|
|
1998-03-16 20:00:00 +00:00
|
|
|
if ((cfile = fopen (path_dhclient_conf, "r")) != NULL) {
|
|
|
|
do {
|
|
|
|
token = peek_token (&val, cfile);
|
|
|
|
if (token == EOF)
|
|
|
|
break;
|
|
|
|
parse_client_statement (cfile,
|
|
|
|
(struct interface_info *)0,
|
|
|
|
&top_level_config);
|
|
|
|
} while (1);
|
|
|
|
token = next_token (&val, cfile); /* Clear the peek buffer */
|
|
|
|
fclose (cfile);
|
|
|
|
}
|
1997-02-18 14:27:53 +00:00
|
|
|
|
|
|
|
/* Set up state and config structures for clients that don't
|
1998-10-22 04:52:23 +00:00
|
|
|
have per-interface configuration statements. */
|
1997-02-18 14:27:53 +00:00
|
|
|
config = (struct client_config *)0;
|
|
|
|
for (ip = interfaces; ip; ip = ip -> next) {
|
|
|
|
if (!ip -> client) {
|
|
|
|
ip -> client = (struct client_state *)
|
|
|
|
malloc (sizeof (struct client_state));
|
|
|
|
if (!ip -> client)
|
1999-02-24 17:56:53 +00:00
|
|
|
log_fatal ("no memory for client state.");
|
1997-02-18 14:27:53 +00:00
|
|
|
memset (ip -> client, 0, sizeof *(ip -> client));
|
1997-02-19 10:53:16 +00:00
|
|
|
}
|
1998-10-22 04:52:23 +00:00
|
|
|
|
1997-02-19 10:53:16 +00:00
|
|
|
if (!ip -> client -> config) {
|
1997-02-18 14:27:53 +00:00
|
|
|
if (!config) {
|
|
|
|
config = (struct client_config *)
|
|
|
|
malloc (sizeof (struct client_config));
|
|
|
|
if (!config)
|
1999-02-24 17:56:53 +00:00
|
|
|
log_fatal ("no memory for client config.");
|
1997-02-18 14:27:53 +00:00
|
|
|
memcpy (config, &top_level_config,
|
|
|
|
sizeof top_level_config);
|
|
|
|
}
|
|
|
|
ip -> client -> config = config;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return !warnings_occurred;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* lease-file :== client-lease-statements EOF
|
|
|
|
client-lease-statements :== <nil>
|
1997-02-22 12:25:32 +00:00
|
|
|
| client-lease-statements LEASE client-lease-statement */
|
1997-02-18 14:27:53 +00:00
|
|
|
|
|
|
|
void read_client_leases ()
|
|
|
|
{
|
|
|
|
FILE *cfile;
|
|
|
|
char *val;
|
|
|
|
int token;
|
|
|
|
|
|
|
|
new_parse (path_dhclient_db);
|
|
|
|
|
|
|
|
/* Open the lease file. If we can't open it, just return -
|
|
|
|
we can safely trust the server to remember our state. */
|
|
|
|
if ((cfile = fopen (path_dhclient_db, "r")) == NULL)
|
|
|
|
return;
|
|
|
|
do {
|
|
|
|
token = next_token (&val, cfile);
|
|
|
|
if (token == EOF)
|
|
|
|
break;
|
|
|
|
if (token != LEASE) {
|
1999-02-24 17:56:53 +00:00
|
|
|
log_error ("Corrupt lease file - possible data loss!");
|
1997-02-18 14:27:53 +00:00
|
|
|
skip_to_semi (cfile);
|
|
|
|
break;
|
|
|
|
} else
|
1997-02-19 10:53:16 +00:00
|
|
|
parse_client_lease_statement (cfile, 0);
|
1997-02-18 14:27:53 +00:00
|
|
|
|
|
|
|
} while (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* client-declaration :==
|
1997-02-22 08:38:32 +00:00
|
|
|
SEND option-decl |
|
|
|
|
DEFAULT option-decl |
|
1997-10-27 20:13:21 +00:00
|
|
|
SUPERSEDE option-decl |
|
1997-05-09 07:48:34 +00:00
|
|
|
PREPEND option-decl |
|
|
|
|
APPEND option-decl |
|
1997-02-18 14:27:53 +00:00
|
|
|
hardware-declaration |
|
|
|
|
REQUEST option-list |
|
|
|
|
REQUIRE option-list |
|
|
|
|
TIMEOUT number |
|
|
|
|
RETRY number |
|
1997-03-05 06:24:21 +00:00
|
|
|
REBOOT number |
|
1997-02-18 14:27:53 +00:00
|
|
|
SELECT_TIMEOUT number |
|
|
|
|
SCRIPT string |
|
|
|
|
interface-declaration |
|
1997-02-22 12:25:32 +00:00
|
|
|
LEASE client-lease-statement |
|
1999-02-25 23:30:43 +00:00
|
|
|
ALIAS client-lease-statement |
|
|
|
|
AUTH_KEY key_id key_data */
|
1997-02-18 14:27:53 +00:00
|
|
|
|
|
|
|
void parse_client_statement (cfile, ip, config)
|
|
|
|
FILE *cfile;
|
|
|
|
struct interface_info *ip;
|
|
|
|
struct client_config *config;
|
|
|
|
{
|
|
|
|
int token;
|
|
|
|
char *val;
|
1997-05-09 07:48:34 +00:00
|
|
|
struct option *option;
|
1998-10-22 04:52:23 +00:00
|
|
|
struct executable_statement *stmt, **p;
|
1998-11-05 18:43:23 +00:00
|
|
|
enum statement_op op;
|
1998-11-06 00:10:58 +00:00
|
|
|
int lose;
|
1998-11-09 02:43:23 +00:00
|
|
|
char *name;
|
1999-02-25 23:30:43 +00:00
|
|
|
struct data_string key_id;
|
1997-02-18 14:27:53 +00:00
|
|
|
|
1998-11-06 00:10:58 +00:00
|
|
|
switch (peek_token (&val, cfile)) {
|
1999-02-25 23:30:43 +00:00
|
|
|
case AUTH_KEY:
|
|
|
|
memset (&key_id, 0, sizeof key_id);
|
|
|
|
if (parse_auth_key (&key_id, cfile))
|
|
|
|
data_string_forget (&key_id, "parse_client_statement");
|
|
|
|
break;
|
1997-02-22 08:38:32 +00:00
|
|
|
case SEND:
|
1998-11-11 07:48:23 +00:00
|
|
|
p = &config -> on_transmission -> statements;
|
1998-11-06 00:10:58 +00:00
|
|
|
op = supersede_option_statement;
|
1998-10-22 04:52:23 +00:00
|
|
|
do_option:
|
|
|
|
token = next_token (&val, cfile);
|
|
|
|
option = parse_option_name (cfile);
|
1998-11-05 18:43:23 +00:00
|
|
|
if (!option)
|
|
|
|
return;
|
1998-11-06 00:10:58 +00:00
|
|
|
stmt = parse_option_statement (cfile, 1, option, op);
|
1998-10-22 04:52:23 +00:00
|
|
|
for (; *p; p = &((*p) -> next))
|
|
|
|
;
|
|
|
|
*p = stmt;
|
|
|
|
stmt -> next = (struct executable_statement *)0;
|
1997-02-18 14:27:53 +00:00
|
|
|
return;
|
|
|
|
|
1997-02-22 08:38:32 +00:00
|
|
|
case DEFAULT:
|
1998-11-11 07:48:23 +00:00
|
|
|
p = &config -> on_receipt -> statements;
|
1998-10-22 04:52:23 +00:00
|
|
|
op = default_option_statement;
|
|
|
|
goto do_option;
|
1997-05-09 07:48:34 +00:00
|
|
|
|
|
|
|
case SUPERSEDE:
|
1998-11-11 07:48:23 +00:00
|
|
|
p = &config -> on_receipt -> statements;
|
1998-10-22 04:52:23 +00:00
|
|
|
op = supersede_option_statement;
|
|
|
|
goto do_option;
|
1997-05-09 07:48:34 +00:00
|
|
|
|
|
|
|
case APPEND:
|
1998-11-11 07:48:23 +00:00
|
|
|
p = &config -> on_receipt -> statements;
|
1998-10-22 04:52:23 +00:00
|
|
|
op = append_option_statement;
|
|
|
|
goto do_option;
|
1997-05-09 07:48:34 +00:00
|
|
|
|
|
|
|
case PREPEND:
|
1998-11-11 07:48:23 +00:00
|
|
|
p = &config -> on_receipt -> statements;
|
1998-10-22 04:52:23 +00:00
|
|
|
op = prepend_option_statement;
|
|
|
|
goto do_option;
|
1997-02-22 08:38:32 +00:00
|
|
|
|
|
|
|
case MEDIA:
|
1998-11-06 00:10:58 +00:00
|
|
|
token = next_token (&val, cfile);
|
1997-02-22 08:38:32 +00:00
|
|
|
parse_string_list (cfile, &config -> media, 1);
|
|
|
|
return;
|
1997-02-18 14:27:53 +00:00
|
|
|
|
|
|
|
case HARDWARE:
|
1998-11-06 00:10:58 +00:00
|
|
|
token = next_token (&val, cfile);
|
1997-02-18 14:27:53 +00:00
|
|
|
if (ip) {
|
|
|
|
parse_hardware_param (cfile, &ip -> hw_address);
|
|
|
|
} else {
|
|
|
|
parse_warn ("hardware address parameter %s",
|
|
|
|
"not allowed here.");
|
|
|
|
skip_to_semi (cfile);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
case REQUEST:
|
1998-11-06 00:10:58 +00:00
|
|
|
token = next_token (&val, cfile);
|
1998-11-05 18:43:23 +00:00
|
|
|
parse_option_list (cfile, &config -> requested_options);
|
1997-02-18 14:27:53 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
case REQUIRE:
|
1998-11-06 00:10:58 +00:00
|
|
|
token = next_token (&val, cfile);
|
1998-11-05 18:43:23 +00:00
|
|
|
parse_option_list (cfile, &config -> required_options);
|
1997-02-18 14:27:53 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
case TIMEOUT:
|
1998-11-06 00:10:58 +00:00
|
|
|
token = next_token (&val, cfile);
|
1997-02-18 14:27:53 +00:00
|
|
|
parse_lease_time (cfile, &config -> timeout);
|
|
|
|
return;
|
|
|
|
|
|
|
|
case RETRY:
|
1998-11-06 00:10:58 +00:00
|
|
|
token = next_token (&val, cfile);
|
1997-02-18 14:27:53 +00:00
|
|
|
parse_lease_time (cfile, &config -> retry_interval);
|
|
|
|
return;
|
|
|
|
|
|
|
|
case SELECT_TIMEOUT:
|
1998-11-06 00:10:58 +00:00
|
|
|
token = next_token (&val, cfile);
|
1997-02-18 14:27:53 +00:00
|
|
|
parse_lease_time (cfile, &config -> select_interval);
|
|
|
|
return;
|
|
|
|
|
1997-03-05 06:24:21 +00:00
|
|
|
case REBOOT:
|
1998-11-06 00:10:58 +00:00
|
|
|
token = next_token (&val, cfile);
|
1997-03-05 06:24:21 +00:00
|
|
|
parse_lease_time (cfile, &config -> reboot_timeout);
|
|
|
|
return;
|
|
|
|
|
1997-03-29 01:23:17 +00:00
|
|
|
case BACKOFF_CUTOFF:
|
1998-11-06 00:10:58 +00:00
|
|
|
token = next_token (&val, cfile);
|
1997-03-29 01:23:17 +00:00
|
|
|
parse_lease_time (cfile, &config -> backoff_cutoff);
|
|
|
|
return;
|
|
|
|
|
|
|
|
case INITIAL_INTERVAL:
|
1998-11-06 00:10:58 +00:00
|
|
|
token = next_token (&val, cfile);
|
1997-03-29 01:23:17 +00:00
|
|
|
parse_lease_time (cfile, &config -> initial_interval);
|
|
|
|
return;
|
|
|
|
|
1997-02-18 14:27:53 +00:00
|
|
|
case SCRIPT:
|
1998-11-06 00:10:58 +00:00
|
|
|
token = next_token (&val, cfile);
|
1997-02-18 14:27:53 +00:00
|
|
|
config -> script_name = parse_string (cfile);
|
|
|
|
return;
|
|
|
|
|
|
|
|
case INTERFACE:
|
1998-11-06 00:10:58 +00:00
|
|
|
token = next_token (&val, cfile);
|
1997-02-18 14:27:53 +00:00
|
|
|
if (ip)
|
|
|
|
parse_warn ("nested interface declaration.");
|
1998-11-09 02:43:23 +00:00
|
|
|
parse_interface_declaration (cfile, config, (char *)0);
|
1997-02-18 14:27:53 +00:00
|
|
|
return;
|
|
|
|
|
1998-11-09 02:43:23 +00:00
|
|
|
case PSEUDO:
|
|
|
|
token = next_token (&val, cfile);
|
|
|
|
token = next_token (&val, cfile);
|
|
|
|
name = dmalloc (strlen (val) + 1, "parse_client_statement");
|
|
|
|
if (!name)
|
1999-02-24 17:56:53 +00:00
|
|
|
log_fatal ("no memory for pseudo interface name");
|
1998-11-09 02:43:23 +00:00
|
|
|
strcpy (name, val);
|
|
|
|
parse_interface_declaration (cfile, config, name);
|
|
|
|
return;
|
|
|
|
|
1997-02-18 14:27:53 +00:00
|
|
|
case LEASE:
|
1998-11-06 00:10:58 +00:00
|
|
|
token = next_token (&val, cfile);
|
1997-02-19 10:53:16 +00:00
|
|
|
parse_client_lease_statement (cfile, 1);
|
1997-02-18 14:27:53 +00:00
|
|
|
return;
|
|
|
|
|
1997-02-22 12:25:32 +00:00
|
|
|
case ALIAS:
|
1998-11-06 00:10:58 +00:00
|
|
|
token = next_token (&val, cfile);
|
1997-02-22 12:25:32 +00:00
|
|
|
parse_client_lease_statement (cfile, 2);
|
|
|
|
return;
|
|
|
|
|
1997-06-02 22:34:19 +00:00
|
|
|
case REJECT:
|
1998-11-06 00:10:58 +00:00
|
|
|
token = next_token (&val, cfile);
|
1997-06-02 22:34:19 +00:00
|
|
|
parse_reject_statement (cfile, config);
|
|
|
|
return;
|
|
|
|
|
1997-02-18 14:27:53 +00:00
|
|
|
default:
|
1998-11-06 00:10:58 +00:00
|
|
|
lose = 0;
|
|
|
|
stmt = parse_executable_statement (cfile, &lose);
|
|
|
|
if (!stmt) {
|
|
|
|
if (!lose) {
|
|
|
|
parse_warn ("expecting a statement.");
|
|
|
|
skip_to_semi (cfile);
|
|
|
|
}
|
|
|
|
} else {
|
1998-11-11 07:48:23 +00:00
|
|
|
if (!config -> on_receipt -> statements) {
|
|
|
|
config -> on_receipt -> statements = stmt;
|
1998-11-06 00:10:58 +00:00
|
|
|
} else {
|
|
|
|
struct executable_statement *s;
|
1998-11-11 07:48:23 +00:00
|
|
|
for (s = config -> on_receipt -> statements;
|
1998-11-06 00:10:58 +00:00
|
|
|
s -> next; s = s -> next)
|
|
|
|
;
|
|
|
|
s -> next = stmt;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
1997-02-18 14:27:53 +00:00
|
|
|
break;
|
|
|
|
}
|
1998-11-06 00:10:58 +00:00
|
|
|
parse_semi (cfile);
|
1997-02-18 14:27:53 +00:00
|
|
|
}
|
|
|
|
|
1997-02-19 10:53:16 +00:00
|
|
|
int parse_X (cfile, buf, max)
|
1997-02-18 14:27:53 +00:00
|
|
|
FILE *cfile;
|
1997-02-19 10:53:16 +00:00
|
|
|
u_int8_t *buf;
|
|
|
|
int max;
|
1997-02-18 14:27:53 +00:00
|
|
|
{
|
|
|
|
int token;
|
|
|
|
char *val;
|
1997-02-19 10:53:16 +00:00
|
|
|
int len;
|
|
|
|
u_int8_t *s;
|
1997-02-18 14:27:53 +00:00
|
|
|
|
|
|
|
token = peek_token (&val, cfile);
|
|
|
|
if (token == NUMBER_OR_NAME || token == NUMBER) {
|
1997-02-19 10:53:16 +00:00
|
|
|
len = 0;
|
1997-02-18 14:27:53 +00:00
|
|
|
do {
|
|
|
|
token = next_token (&val, cfile);
|
|
|
|
if (token != NUMBER && token != NUMBER_OR_NAME) {
|
|
|
|
parse_warn ("expecting hexadecimal constant.");
|
|
|
|
skip_to_semi (cfile);
|
|
|
|
return 0;
|
|
|
|
}
|
1997-02-19 10:53:16 +00:00
|
|
|
convert_num (&buf [len], val, 16, 8);
|
|
|
|
if (len++ > max) {
|
1997-02-18 14:27:53 +00:00
|
|
|
parse_warn ("hexadecimal constant too long.");
|
|
|
|
skip_to_semi (cfile);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
token = peek_token (&val, cfile);
|
|
|
|
if (token == COLON)
|
|
|
|
token = next_token (&val, cfile);
|
|
|
|
} while (token == COLON);
|
1997-02-27 03:39:11 +00:00
|
|
|
val = (char *)buf;
|
1997-02-18 14:27:53 +00:00
|
|
|
} else if (token == STRING) {
|
|
|
|
token = next_token (&val, cfile);
|
1997-02-19 10:53:16 +00:00
|
|
|
len = strlen (val);
|
|
|
|
if (len + 1 > max) {
|
|
|
|
parse_warn ("string constant too long.");
|
|
|
|
skip_to_semi (cfile);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
memcpy (buf, val, len + 1);
|
1997-02-18 14:27:53 +00:00
|
|
|
} else {
|
|
|
|
parse_warn ("expecting string or hexadecimal data");
|
|
|
|
skip_to_semi (cfile);
|
|
|
|
return 0;
|
|
|
|
}
|
1997-02-19 10:53:16 +00:00
|
|
|
return len;
|
1997-02-18 14:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* option-list :== option_name |
|
|
|
|
option_list COMMA option_name */
|
|
|
|
|
1998-11-05 18:43:23 +00:00
|
|
|
void parse_option_list (cfile, list)
|
1997-02-18 14:27:53 +00:00
|
|
|
FILE *cfile;
|
1998-11-05 18:43:23 +00:00
|
|
|
u_int32_t **list;
|
1997-02-18 14:27:53 +00:00
|
|
|
{
|
|
|
|
int ix, i;
|
|
|
|
int token;
|
|
|
|
char *val;
|
1998-11-05 18:43:23 +00:00
|
|
|
pair p = (pair)0, q, r;
|
1997-02-18 14:27:53 +00:00
|
|
|
|
|
|
|
ix = 0;
|
|
|
|
do {
|
|
|
|
token = next_token (&val, cfile);
|
|
|
|
if (!is_identifier (token)) {
|
|
|
|
parse_warn ("expected option name.");
|
|
|
|
skip_to_semi (cfile);
|
1998-11-05 18:43:23 +00:00
|
|
|
return;
|
1997-02-18 14:27:53 +00:00
|
|
|
}
|
|
|
|
for (i = 0; i < 256; i++) {
|
|
|
|
if (!strcasecmp (dhcp_options [i].name, val))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i == 256) {
|
|
|
|
parse_warn ("%s: expected option name.");
|
|
|
|
skip_to_semi (cfile);
|
1998-11-05 18:43:23 +00:00
|
|
|
return;
|
1997-02-18 14:27:53 +00:00
|
|
|
}
|
1998-11-05 18:43:23 +00:00
|
|
|
r = new_pair ("parse_option_list");
|
|
|
|
if (!r)
|
1999-02-24 17:56:53 +00:00
|
|
|
log_fatal ("can't allocate pair for option code.");
|
1998-11-05 18:43:23 +00:00
|
|
|
r -> car = (caddr_t)i;
|
|
|
|
r -> cdr = (pair)0;
|
|
|
|
if (p)
|
|
|
|
q -> cdr = r;
|
|
|
|
else
|
|
|
|
p = r;
|
|
|
|
q = r;
|
|
|
|
++ix;
|
1997-02-18 14:27:53 +00:00
|
|
|
token = next_token (&val, cfile);
|
|
|
|
} while (token == COMMA);
|
|
|
|
if (token != SEMI) {
|
|
|
|
parse_warn ("expecting semicolon.");
|
|
|
|
skip_to_semi (cfile);
|
1998-11-05 18:43:23 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (*list)
|
|
|
|
dfree (*list, "parse_option_list");
|
|
|
|
*list = dmalloc (ix * sizeof **list, "parse_option_list");
|
|
|
|
if (!*list)
|
1999-02-24 17:56:53 +00:00
|
|
|
log_error ("no memory for option list.");
|
1998-11-05 18:43:23 +00:00
|
|
|
else {
|
|
|
|
ix = 0;
|
|
|
|
for (q = p; q; q = q -> cdr)
|
|
|
|
(*list) [ix++] = (u_int32_t)q -> car;
|
|
|
|
(*list) [ix] = 0;
|
|
|
|
}
|
|
|
|
while (p) {
|
|
|
|
q = p -> cdr;
|
|
|
|
free_pair (p, "parse_option_list");
|
|
|
|
p = q;
|
1997-02-18 14:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* interface-declaration :==
|
|
|
|
INTERFACE string LBRACE client-declarations RBRACE */
|
|
|
|
|
1998-11-09 02:43:23 +00:00
|
|
|
void parse_interface_declaration (cfile, outer_config, name)
|
1997-02-18 14:27:53 +00:00
|
|
|
FILE *cfile;
|
|
|
|
struct client_config *outer_config;
|
1998-11-09 02:43:23 +00:00
|
|
|
char *name;
|
1997-02-18 14:27:53 +00:00
|
|
|
{
|
|
|
|
int token;
|
|
|
|
char *val;
|
1998-11-09 02:43:23 +00:00
|
|
|
struct client_state *client, **cp;
|
|
|
|
struct interface_info *ip;
|
1997-02-18 14:27:53 +00:00
|
|
|
|
|
|
|
token = next_token (&val, cfile);
|
|
|
|
if (token != STRING) {
|
|
|
|
parse_warn ("expecting interface name (in quotes).");
|
|
|
|
skip_to_semi (cfile);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1997-02-19 10:53:16 +00:00
|
|
|
ip = interface_or_dummy (val);
|
1997-02-18 14:27:53 +00:00
|
|
|
|
1998-11-09 02:43:23 +00:00
|
|
|
/* If we were given a name, this is a pseudo-interface. */
|
|
|
|
if (name) {
|
|
|
|
make_client_state (&client);
|
|
|
|
client -> name = name;
|
|
|
|
client -> interface = ip;
|
|
|
|
for (cp = &ip -> client; *cp; cp = &((*cp) -> next))
|
|
|
|
;
|
|
|
|
*cp = client;
|
|
|
|
} else {
|
|
|
|
if (!ip -> client) {
|
|
|
|
make_client_state (&ip -> client);
|
|
|
|
ip -> client -> interface = ip;
|
|
|
|
}
|
|
|
|
client = ip -> client;
|
|
|
|
}
|
1997-02-19 10:53:16 +00:00
|
|
|
|
1998-11-09 02:43:23 +00:00
|
|
|
if (!client -> config)
|
|
|
|
make_client_config (client, outer_config);
|
1997-02-18 14:27:53 +00:00
|
|
|
|
1997-09-16 18:08:32 +00:00
|
|
|
ip -> flags &= ~INTERFACE_AUTOMATIC;
|
|
|
|
interfaces_requested = 1;
|
|
|
|
|
1997-02-18 14:27:53 +00:00
|
|
|
token = next_token (&val, cfile);
|
|
|
|
if (token != LBRACE) {
|
|
|
|
parse_warn ("expecting left brace.");
|
|
|
|
skip_to_semi (cfile);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
|
|
|
token = peek_token (&val, cfile);
|
|
|
|
if (token == EOF) {
|
|
|
|
parse_warn ("unterminated interface declaration.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (token == RBRACE)
|
|
|
|
break;
|
1998-11-09 02:43:23 +00:00
|
|
|
parse_client_statement (cfile, ip, client -> config);
|
1997-02-18 14:27:53 +00:00
|
|
|
} while (1);
|
|
|
|
token = next_token (&val, cfile);
|
|
|
|
}
|
|
|
|
|
1997-02-19 10:53:16 +00:00
|
|
|
struct interface_info *interface_or_dummy (name)
|
|
|
|
char *name;
|
|
|
|
{
|
|
|
|
struct interface_info *ip;
|
|
|
|
|
|
|
|
/* Find the interface (if any) that matches the name. */
|
|
|
|
for (ip = interfaces; ip; ip = ip -> next) {
|
|
|
|
if (!strcmp (ip -> name, name))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If it's not a real interface, see if it's on the dummy list. */
|
|
|
|
if (!ip) {
|
|
|
|
for (ip = dummy_interfaces; ip; ip = ip -> next) {
|
|
|
|
if (!strcmp (ip -> name, name))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we didn't find an interface, make a dummy interface as
|
|
|
|
a placeholder. */
|
|
|
|
if (!ip) {
|
|
|
|
ip = ((struct interface_info *)malloc (sizeof *ip));
|
|
|
|
if (!ip)
|
1999-02-24 17:56:53 +00:00
|
|
|
log_fatal ("Insufficient memory to record interface %s",
|
1997-02-19 10:53:16 +00:00
|
|
|
name);
|
|
|
|
memset (ip, 0, sizeof *ip);
|
|
|
|
strcpy (ip -> name, name);
|
|
|
|
ip -> next = dummy_interfaces;
|
|
|
|
dummy_interfaces = ip;
|
|
|
|
}
|
|
|
|
return ip;
|
|
|
|
}
|
|
|
|
|
1998-11-09 02:43:23 +00:00
|
|
|
void make_client_state (state)
|
|
|
|
struct client_state **state;
|
1997-02-19 10:53:16 +00:00
|
|
|
{
|
1998-11-09 02:43:23 +00:00
|
|
|
*state = ((struct client_state *)dmalloc (sizeof **state,
|
|
|
|
"make_client_state"));
|
|
|
|
if (!*state)
|
1999-02-24 17:56:53 +00:00
|
|
|
log_fatal ("no memory for client state\n");
|
1998-11-09 02:43:23 +00:00
|
|
|
memset (*state, 0, sizeof **state);
|
1997-02-19 10:53:16 +00:00
|
|
|
}
|
|
|
|
|
1998-11-09 02:43:23 +00:00
|
|
|
void make_client_config (client, config)
|
|
|
|
struct client_state *client;
|
1997-02-19 10:53:16 +00:00
|
|
|
struct client_config *config;
|
|
|
|
{
|
1998-11-09 02:43:23 +00:00
|
|
|
client -> config = (((struct client_config *)
|
|
|
|
dmalloc (sizeof (struct client_config),
|
|
|
|
"make_client_config")));
|
|
|
|
if (!client -> config)
|
1999-02-24 17:56:53 +00:00
|
|
|
log_fatal ("no memory for client config\n");
|
1998-11-09 02:43:23 +00:00
|
|
|
memcpy (client -> config, config, sizeof *config);
|
1998-11-11 07:48:23 +00:00
|
|
|
client -> config -> on_receipt =
|
|
|
|
clone_group (config -> on_receipt, "make_client_config");
|
|
|
|
client -> config -> on_transmission =
|
|
|
|
clone_group (config -> on_transmission, "make_client_config");
|
1997-02-19 10:53:16 +00:00
|
|
|
}
|
|
|
|
|
1997-02-18 14:27:53 +00:00
|
|
|
/* client-lease-statement :==
|
1997-02-22 12:25:32 +00:00
|
|
|
RBRACE client-lease-declarations LBRACE
|
1997-02-18 14:27:53 +00:00
|
|
|
|
|
|
|
client-lease-declarations :==
|
|
|
|
<nil> |
|
|
|
|
client-lease-declaration |
|
|
|
|
client-lease-declarations client-lease-declaration */
|
|
|
|
|
|
|
|
|
1997-02-19 10:53:16 +00:00
|
|
|
void parse_client_lease_statement (cfile, is_static)
|
1997-02-18 14:27:53 +00:00
|
|
|
FILE *cfile;
|
1997-02-19 10:53:16 +00:00
|
|
|
int is_static;
|
1997-02-18 14:27:53 +00:00
|
|
|
{
|
|
|
|
struct client_lease *lease, *lp, *pl;
|
1998-11-09 02:43:23 +00:00
|
|
|
struct interface_info *ip = (struct interface_info *)0;
|
1997-02-18 14:27:53 +00:00
|
|
|
int token;
|
|
|
|
char *val;
|
1998-11-09 02:43:23 +00:00
|
|
|
struct client_state *client = (struct client_state *)0;
|
1997-02-18 14:27:53 +00:00
|
|
|
|
|
|
|
token = next_token (&val, cfile);
|
|
|
|
if (token != LBRACE) {
|
|
|
|
parse_warn ("expecting left brace.");
|
|
|
|
skip_to_semi (cfile);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
lease = (struct client_lease *)malloc (sizeof (struct client_lease));
|
|
|
|
if (!lease)
|
1999-02-24 17:56:53 +00:00
|
|
|
log_fatal ("no memory for lease.\n");
|
1997-02-18 14:27:53 +00:00
|
|
|
memset (lease, 0, sizeof *lease);
|
1997-02-19 10:53:16 +00:00
|
|
|
lease -> is_static = is_static;
|
1997-02-18 14:27:53 +00:00
|
|
|
|
|
|
|
do {
|
|
|
|
token = peek_token (&val, cfile);
|
|
|
|
if (token == EOF) {
|
|
|
|
parse_warn ("unterminated lease declaration.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (token == RBRACE)
|
|
|
|
break;
|
1998-11-09 02:43:23 +00:00
|
|
|
parse_client_lease_declaration (cfile, lease, &ip, &client);
|
1997-02-18 14:27:53 +00:00
|
|
|
} while (1);
|
|
|
|
token = next_token (&val, cfile);
|
|
|
|
|
|
|
|
/* If the lease declaration didn't include an interface
|
|
|
|
declaration that we recognized, it's of no use to us. */
|
|
|
|
if (!ip) {
|
1998-11-05 18:43:23 +00:00
|
|
|
destroy_client_lease (lease);
|
1997-02-18 14:27:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1997-02-19 10:53:16 +00:00
|
|
|
/* Make sure there's a client state structure... */
|
1998-11-09 02:43:23 +00:00
|
|
|
if (!ip -> client) {
|
|
|
|
make_client_state (&ip -> client);
|
|
|
|
ip -> client -> interface = ip;
|
|
|
|
}
|
|
|
|
if (!client)
|
|
|
|
client = ip -> client;
|
1997-02-19 10:53:16 +00:00
|
|
|
|
1997-02-22 12:25:32 +00:00
|
|
|
/* If this is an alias lease, it doesn't need to be sorted in. */
|
|
|
|
if (is_static == 2) {
|
|
|
|
ip -> client -> alias = lease;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1997-03-05 06:24:21 +00:00
|
|
|
/* The new lease may supersede a lease that's not the
|
|
|
|
active lease but is still on the lease list, so scan the
|
|
|
|
lease list looking for a lease with the same address, and
|
|
|
|
if we find it, toss it. */
|
|
|
|
pl = (struct client_lease *)0;
|
1998-11-09 02:43:23 +00:00
|
|
|
for (lp = client -> leases; lp; lp = lp -> next) {
|
1997-03-05 06:24:21 +00:00
|
|
|
if (lp -> address.len == lease -> address.len &&
|
|
|
|
!memcmp (lp -> address.iabuf, lease -> address.iabuf,
|
|
|
|
lease -> address.len)) {
|
|
|
|
if (pl)
|
|
|
|
pl -> next = lp -> next;
|
|
|
|
else
|
1998-11-09 02:43:23 +00:00
|
|
|
client -> leases = lp -> next;
|
1998-11-05 18:43:23 +00:00
|
|
|
destroy_client_lease (lp);
|
1997-03-05 06:24:21 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If this is a preloaded lease, just put it on the list of recorded
|
|
|
|
leases - don't make it the active lease. */
|
|
|
|
if (is_static) {
|
1998-11-09 02:43:23 +00:00
|
|
|
lease -> next = client -> leases;
|
|
|
|
client -> leases = lease;
|
1997-03-05 06:24:21 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1997-02-18 14:27:53 +00:00
|
|
|
/* The last lease in the lease file on a particular interface is
|
|
|
|
the active lease for that interface. Of course, we don't know
|
|
|
|
what the last lease in the file is until we've parsed the whole
|
|
|
|
file, so at this point, we assume that the lease we just parsed
|
|
|
|
is the active lease for its interface. If there's already
|
|
|
|
an active lease for the interface, and this lease is for the same
|
|
|
|
ip address, then we just toss the old active lease and replace
|
|
|
|
it with this one. If this lease is for a different address,
|
|
|
|
then if the old active lease has expired, we dump it; if not,
|
|
|
|
we put it on the list of leases for this interface which are
|
|
|
|
still valid but no longer active. */
|
1998-11-09 02:43:23 +00:00
|
|
|
if (client -> active) {
|
|
|
|
if (client -> active -> expiry < cur_time)
|
|
|
|
destroy_client_lease (client -> active);
|
|
|
|
else if (client -> active -> address.len ==
|
1997-02-18 14:27:53 +00:00
|
|
|
lease -> address.len &&
|
1998-11-09 02:43:23 +00:00
|
|
|
!memcmp (client -> active -> address.iabuf,
|
1997-02-18 14:27:53 +00:00
|
|
|
lease -> address.iabuf,
|
|
|
|
lease -> address.len))
|
1998-11-09 02:43:23 +00:00
|
|
|
destroy_client_lease (client -> active);
|
1997-02-18 14:27:53 +00:00
|
|
|
else {
|
1998-11-09 02:43:23 +00:00
|
|
|
client -> active -> next = client -> leases;
|
|
|
|
client -> leases = client -> active;
|
1997-02-18 14:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
1998-11-09 02:43:23 +00:00
|
|
|
client -> active = lease;
|
1997-02-18 14:27:53 +00:00
|
|
|
|
|
|
|
/* phew. */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* client-lease-declaration :==
|
1997-05-09 07:48:34 +00:00
|
|
|
BOOTP |
|
1997-02-18 14:27:53 +00:00
|
|
|
INTERFACE string |
|
|
|
|
FIXED_ADDR ip_address |
|
|
|
|
FILENAME string |
|
|
|
|
SERVER_NAME string |
|
1997-02-22 08:38:32 +00:00
|
|
|
OPTION option-decl |
|
1997-02-18 14:27:53 +00:00
|
|
|
RENEW time-decl |
|
|
|
|
REBIND time-decl |
|
|
|
|
EXPIRE time-decl */
|
|
|
|
|
1998-11-09 02:43:23 +00:00
|
|
|
void parse_client_lease_declaration (cfile, lease, ipp, clientp)
|
1997-02-18 14:27:53 +00:00
|
|
|
FILE *cfile;
|
|
|
|
struct client_lease *lease;
|
|
|
|
struct interface_info **ipp;
|
1998-11-09 02:43:23 +00:00
|
|
|
struct client_state **clientp;
|
1997-02-18 14:27:53 +00:00
|
|
|
{
|
|
|
|
int token;
|
|
|
|
char *val;
|
|
|
|
char *t, *n;
|
|
|
|
struct interface_info *ip;
|
1998-11-05 18:43:23 +00:00
|
|
|
struct option_cache *oc;
|
1998-11-09 02:43:23 +00:00
|
|
|
struct client_state *client = (struct client_state *)0;
|
1997-02-18 14:27:53 +00:00
|
|
|
|
|
|
|
switch (next_token (&val, cfile)) {
|
1997-05-09 07:48:34 +00:00
|
|
|
case BOOTP:
|
|
|
|
lease -> is_bootp = 1;
|
|
|
|
break;
|
|
|
|
|
1997-02-18 14:27:53 +00:00
|
|
|
case INTERFACE:
|
|
|
|
token = next_token (&val, cfile);
|
|
|
|
if (token != STRING) {
|
|
|
|
parse_warn ("expecting interface name (in quotes).");
|
|
|
|
skip_to_semi (cfile);
|
|
|
|
break;
|
|
|
|
}
|
1997-02-19 10:53:16 +00:00
|
|
|
ip = interface_or_dummy (val);
|
1997-02-18 14:27:53 +00:00
|
|
|
*ipp = ip;
|
|
|
|
break;
|
|
|
|
|
1998-11-09 02:43:23 +00:00
|
|
|
case NAME:
|
|
|
|
token = next_token (&val, cfile);
|
|
|
|
ip = *ipp;
|
|
|
|
if (!ip) {
|
|
|
|
parse_warn ("state name precedes interface.");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
for (client = ip -> client; client; client = client -> next)
|
1998-11-11 07:48:23 +00:00
|
|
|
if (client -> name && !strcmp (client -> name, val))
|
1998-11-09 02:43:23 +00:00
|
|
|
break;
|
|
|
|
if (!client)
|
|
|
|
parse_warn ("lease specified for unknown pseudo.");
|
|
|
|
*clientp = client;
|
|
|
|
break;
|
|
|
|
|
1997-02-18 14:27:53 +00:00
|
|
|
case FIXED_ADDR:
|
1997-05-09 07:48:34 +00:00
|
|
|
if (!parse_ip_addr (cfile, &lease -> address))
|
|
|
|
return;
|
1997-02-18 14:27:53 +00:00
|
|
|
break;
|
|
|
|
|
1997-02-22 08:38:32 +00:00
|
|
|
case MEDIUM:
|
|
|
|
parse_string_list (cfile, &lease -> medium, 0);
|
|
|
|
return;
|
|
|
|
|
1997-02-18 14:27:53 +00:00
|
|
|
case FILENAME:
|
|
|
|
lease -> filename = parse_string (cfile);
|
|
|
|
return;
|
|
|
|
|
|
|
|
case SERVER_NAME:
|
|
|
|
lease -> server_name = parse_string (cfile);
|
|
|
|
return;
|
|
|
|
|
|
|
|
case RENEW:
|
|
|
|
lease -> renewal = parse_date (cfile);
|
|
|
|
return;
|
|
|
|
|
|
|
|
case REBIND:
|
|
|
|
lease -> rebind = parse_date (cfile);
|
|
|
|
return;
|
|
|
|
|
|
|
|
case EXPIRE:
|
|
|
|
lease -> expiry = parse_date (cfile);
|
|
|
|
return;
|
|
|
|
|
|
|
|
case OPTION:
|
1998-11-05 18:43:23 +00:00
|
|
|
oc = (struct option_cache *)0;
|
|
|
|
if (parse_option_decl (&oc, cfile)) {
|
|
|
|
/* XXX save_option here ought to account for the
|
|
|
|
XXX correct option universe, but it doesn't. */
|
|
|
|
save_option (lease -> options.dhcp_hash, oc);
|
|
|
|
option_cache_dereference
|
|
|
|
(&oc, "parse_client_lease_declaration");
|
|
|
|
}
|
1997-02-18 14:27:53 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
default:
|
|
|
|
parse_warn ("expecting lease declaration.");
|
|
|
|
skip_to_semi (cfile);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
token = next_token (&val, cfile);
|
|
|
|
if (token != SEMI) {
|
|
|
|
parse_warn ("expecting semicolon.");
|
|
|
|
skip_to_semi (cfile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-11-05 18:43:23 +00:00
|
|
|
int parse_option_decl (oc, cfile)
|
|
|
|
struct option_cache **oc;
|
1997-02-18 14:27:53 +00:00
|
|
|
FILE *cfile;
|
|
|
|
{
|
|
|
|
char *val;
|
|
|
|
int token;
|
1997-02-19 10:53:16 +00:00
|
|
|
u_int8_t buf [4];
|
|
|
|
u_int8_t hunkbuf [1024];
|
|
|
|
int hunkix = 0;
|
1997-02-18 14:27:53 +00:00
|
|
|
char *fmt;
|
|
|
|
struct option *option;
|
|
|
|
struct iaddr ip_addr;
|
1997-02-27 03:39:11 +00:00
|
|
|
u_int8_t *dp;
|
1997-02-18 14:27:53 +00:00
|
|
|
int len;
|
1997-02-19 10:53:16 +00:00
|
|
|
int nul_term = 0;
|
1998-11-05 18:43:23 +00:00
|
|
|
struct buffer *bp;
|
1997-02-18 14:27:53 +00:00
|
|
|
|
1998-04-20 18:05:44 +00:00
|
|
|
option = parse_option_name (cfile);
|
|
|
|
if (!option)
|
1998-11-05 18:43:23 +00:00
|
|
|
return 0;
|
1997-02-18 14:27:53 +00:00
|
|
|
|
|
|
|
/* Parse the option data... */
|
|
|
|
do {
|
|
|
|
/* Set a flag if this is an array of a simple type (i.e.,
|
|
|
|
not an array of pairs of IP addresses, or something
|
|
|
|
like that. */
|
|
|
|
int uniform = option -> format [1] == 'A';
|
|
|
|
|
|
|
|
for (fmt = option -> format; *fmt; fmt++) {
|
|
|
|
if (*fmt == 'A')
|
|
|
|
break;
|
|
|
|
switch (*fmt) {
|
|
|
|
case 'X':
|
1997-02-19 10:53:16 +00:00
|
|
|
len = parse_X (cfile, &hunkbuf [hunkix],
|
|
|
|
sizeof hunkbuf - hunkix);
|
|
|
|
hunkix += len;
|
1997-02-18 14:27:53 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 't': /* Text string... */
|
1997-02-19 10:53:16 +00:00
|
|
|
token = next_token (&val, cfile);
|
|
|
|
if (token != STRING) {
|
|
|
|
parse_warn ("expecting string.");
|
|
|
|
skip_to_semi (cfile);
|
1998-11-05 18:43:23 +00:00
|
|
|
return 0;
|
1997-02-19 10:53:16 +00:00
|
|
|
}
|
|
|
|
len = strlen (val);
|
|
|
|
if (hunkix + len + 1 > sizeof hunkbuf) {
|
|
|
|
parse_warn ("option data buffer %s",
|
|
|
|
"overflow");
|
|
|
|
skip_to_semi (cfile);
|
1998-11-05 18:43:23 +00:00
|
|
|
return 0;
|
1997-02-19 10:53:16 +00:00
|
|
|
}
|
|
|
|
memcpy (&hunkbuf [hunkix], val, len + 1);
|
|
|
|
nul_term = 1;
|
|
|
|
hunkix += len;
|
1997-02-18 14:27:53 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'I': /* IP address. */
|
1997-05-09 07:48:34 +00:00
|
|
|
if (!parse_ip_addr (cfile, &ip_addr))
|
1998-11-05 18:43:23 +00:00
|
|
|
return 0;
|
1997-02-18 14:27:53 +00:00
|
|
|
len = ip_addr.len;
|
|
|
|
dp = ip_addr.iabuf;
|
|
|
|
|
|
|
|
alloc:
|
1997-02-19 10:53:16 +00:00
|
|
|
if (hunkix + len > sizeof hunkbuf) {
|
|
|
|
parse_warn ("option data buffer %s",
|
|
|
|
"overflow");
|
|
|
|
skip_to_semi (cfile);
|
1998-11-05 18:43:23 +00:00
|
|
|
return 0;
|
1997-02-19 10:53:16 +00:00
|
|
|
}
|
|
|
|
memcpy (&hunkbuf [hunkix], dp, len);
|
|
|
|
hunkix += len;
|
1997-02-18 14:27:53 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'L': /* Unsigned 32-bit integer... */
|
|
|
|
case 'l': /* Signed 32-bit integer... */
|
|
|
|
token = next_token (&val, cfile);
|
|
|
|
if (token != NUMBER) {
|
|
|
|
need_number:
|
|
|
|
parse_warn ("expecting number.");
|
|
|
|
if (token != SEMI)
|
|
|
|
skip_to_semi (cfile);
|
1998-11-05 18:43:23 +00:00
|
|
|
return 0;
|
1997-02-18 14:27:53 +00:00
|
|
|
}
|
|
|
|
convert_num (buf, val, 0, 32);
|
|
|
|
len = 4;
|
|
|
|
dp = buf;
|
|
|
|
goto alloc;
|
|
|
|
|
|
|
|
case 's': /* Signed 16-bit integer. */
|
|
|
|
case 'S': /* Unsigned 16-bit integer. */
|
|
|
|
token = next_token (&val, cfile);
|
|
|
|
if (token != NUMBER)
|
|
|
|
goto need_number;
|
|
|
|
convert_num (buf, val, 0, 16);
|
|
|
|
len = 2;
|
|
|
|
dp = buf;
|
|
|
|
goto alloc;
|
|
|
|
|
|
|
|
case 'b': /* Signed 8-bit integer. */
|
|
|
|
case 'B': /* Unsigned 8-bit integer. */
|
|
|
|
token = next_token (&val, cfile);
|
|
|
|
if (token != NUMBER)
|
|
|
|
goto need_number;
|
|
|
|
convert_num (buf, val, 0, 8);
|
|
|
|
len = 1;
|
|
|
|
dp = buf;
|
|
|
|
goto alloc;
|
|
|
|
|
|
|
|
case 'f': /* Boolean flag. */
|
|
|
|
token = next_token (&val, cfile);
|
|
|
|
if (!is_identifier (token)) {
|
|
|
|
parse_warn ("expecting identifier.");
|
|
|
|
bad_flag:
|
|
|
|
if (token != SEMI)
|
|
|
|
skip_to_semi (cfile);
|
1998-11-05 18:43:23 +00:00
|
|
|
return 0;
|
1997-02-18 14:27:53 +00:00
|
|
|
}
|
|
|
|
if (!strcasecmp (val, "true")
|
|
|
|
|| !strcasecmp (val, "on"))
|
|
|
|
buf [0] = 1;
|
|
|
|
else if (!strcasecmp (val, "false")
|
|
|
|
|| !strcasecmp (val, "off"))
|
|
|
|
buf [0] = 0;
|
|
|
|
else {
|
|
|
|
parse_warn ("expecting boolean.");
|
|
|
|
goto bad_flag;
|
|
|
|
}
|
|
|
|
len = 1;
|
|
|
|
dp = buf;
|
|
|
|
goto alloc;
|
|
|
|
|
|
|
|
default:
|
1999-02-24 17:56:53 +00:00
|
|
|
log_error ("Bad format %c in parse_option_param.",
|
1997-02-18 14:27:53 +00:00
|
|
|
*fmt);
|
|
|
|
skip_to_semi (cfile);
|
1998-11-05 18:43:23 +00:00
|
|
|
return 0;
|
1997-02-18 14:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
1997-02-19 10:53:16 +00:00
|
|
|
token = next_token (&val, cfile);
|
|
|
|
} while (*fmt == 'A' && token == COMMA);
|
1997-02-18 14:27:53 +00:00
|
|
|
|
|
|
|
if (token != SEMI) {
|
|
|
|
parse_warn ("semicolon expected.");
|
|
|
|
skip_to_semi (cfile);
|
1998-11-05 18:43:23 +00:00
|
|
|
return 0;
|
1997-02-18 14:27:53 +00:00
|
|
|
}
|
|
|
|
|
1998-11-05 18:43:23 +00:00
|
|
|
bp = (struct buffer *)0;
|
|
|
|
if (!buffer_allocate (&bp, hunkix + nul_term, "parse_option_decl"))
|
1999-02-24 17:56:53 +00:00
|
|
|
log_fatal ("no memory to store option declaration.");
|
1998-11-05 18:43:23 +00:00
|
|
|
if (!bp -> data)
|
1999-02-24 17:56:53 +00:00
|
|
|
log_fatal ("out of memory allocating option data.");
|
1998-11-05 18:43:23 +00:00
|
|
|
memcpy (bp -> data, hunkbuf, hunkix + nul_term);
|
|
|
|
|
|
|
|
if (!option_cache_allocate (oc, "parse_option_decl"))
|
1999-02-24 17:56:53 +00:00
|
|
|
log_fatal ("out of memory allocating option cache.");
|
1998-11-05 18:43:23 +00:00
|
|
|
|
|
|
|
(*oc) -> data.buffer = bp;
|
|
|
|
(*oc) -> data.data = &bp -> data [0];
|
|
|
|
(*oc) -> data.terminated = nul_term;
|
|
|
|
(*oc) -> data.len = hunkix;
|
|
|
|
(*oc) -> option = option;
|
|
|
|
return 1;
|
1997-02-19 10:53:16 +00:00
|
|
|
}
|
1997-02-22 08:38:32 +00:00
|
|
|
|
|
|
|
void parse_string_list (cfile, lp, multiple)
|
|
|
|
FILE *cfile;
|
|
|
|
struct string_list **lp;
|
|
|
|
int multiple;
|
|
|
|
{
|
|
|
|
int token;
|
|
|
|
char *val;
|
|
|
|
struct string_list *cur, *tmp;
|
|
|
|
|
|
|
|
/* Find the last medium in the media list. */
|
|
|
|
if (*lp) {
|
|
|
|
for (cur = *lp; cur -> next; cur = cur -> next)
|
|
|
|
;
|
|
|
|
} else {
|
|
|
|
cur = (struct string_list *)0;
|
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
|
|
|
token = next_token (&val, cfile);
|
|
|
|
if (token != STRING) {
|
|
|
|
parse_warn ("Expecting media options.");
|
|
|
|
skip_to_semi (cfile);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = (struct string_list *)malloc (strlen (val) + 1 +
|
|
|
|
sizeof
|
|
|
|
(struct string_list *));
|
|
|
|
if (!tmp)
|
1999-02-24 17:56:53 +00:00
|
|
|
log_fatal ("no memory for string list entry.");
|
1997-02-22 08:38:32 +00:00
|
|
|
|
|
|
|
strcpy (tmp -> string, val);
|
|
|
|
tmp -> next = (struct string_list *)0;
|
|
|
|
|
|
|
|
/* Store this medium at the end of the media list. */
|
|
|
|
if (cur)
|
|
|
|
cur -> next = tmp;
|
|
|
|
else
|
|
|
|
*lp = tmp;
|
|
|
|
cur = tmp;
|
|
|
|
|
|
|
|
token = next_token (&val, cfile);
|
|
|
|
} while (multiple && token == COMMA);
|
|
|
|
|
|
|
|
if (token != SEMI) {
|
|
|
|
parse_warn ("expecting semicolon.");
|
|
|
|
skip_to_semi (cfile);
|
|
|
|
}
|
|
|
|
}
|
1997-06-02 22:34:19 +00:00
|
|
|
|
|
|
|
void parse_reject_statement (cfile, config)
|
|
|
|
FILE *cfile;
|
|
|
|
struct client_config *config;
|
|
|
|
{
|
|
|
|
int token;
|
|
|
|
char *val;
|
|
|
|
struct iaddr addr;
|
|
|
|
struct iaddrlist *list;
|
|
|
|
|
|
|
|
do {
|
|
|
|
if (!parse_ip_addr (cfile, &addr)) {
|
|
|
|
parse_warn ("expecting IP address.");
|
|
|
|
skip_to_semi (cfile);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
list = (struct iaddrlist *)malloc (sizeof (struct iaddrlist));
|
|
|
|
if (!list)
|
1999-02-24 17:56:53 +00:00
|
|
|
log_fatal ("no memory for reject list!");
|
1997-06-02 22:34:19 +00:00
|
|
|
|
|
|
|
list -> addr = addr;
|
|
|
|
list -> next = config -> reject_list;
|
|
|
|
config -> reject_list = list;
|
|
|
|
|
|
|
|
token = next_token (&val, cfile);
|
|
|
|
} while (token == COMMA);
|
|
|
|
|
|
|
|
if (token != SEMI) {
|
|
|
|
parse_warn ("expecting semicolon.");
|
|
|
|
skip_to_semi (cfile);
|
|
|
|
}
|
|
|
|
}
|