2
0
mirror of https://gitlab.isc.org/isc-projects/dhcp synced 2025-08-23 02:17:31 +00:00
isc-dhcp/server/confpars.c

1785 lines
44 KiB
C
Raw Normal View History

1995-11-29 07:40:04 +00:00
/* confpars.c
Parser for dhcpd config file... */
/*
* Copyright (c) 1995, 1996, 1997, 1998, 1999
* The Internet Software Consortium. All rights reserved.
1995-11-29 07:40:04 +00:00
*
* 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-23 19:07:14 +00:00
"$Id: confpars.c,v 1.59 1999/02/23 19:07:14 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n";
1995-11-29 07:40:04 +00:00
#endif /* not lint */
#include "dhcpd.h"
#include "dhctoken.h"
static TIME parsed_time;
/* conf-file :== parameters declarations EOF
parameters :== <nil> | parameter | parameters parameter
declarations :== <nil> | declaration | declarations declaration */
1995-11-29 07:40:04 +00:00
int readconf ()
1995-11-29 07:40:04 +00:00
{
FILE *cfile;
char *val;
enum dhcp_token token;
int declaration = 0;
1995-11-29 07:40:04 +00:00
1996-09-02 21:16:25 +00:00
new_parse (path_dhcpd_conf);
1995-11-29 07:40:04 +00:00
/* Set up the initial dhcp option universe. */
initialize_universes ();
root_group.authoritative = 0;
1996-09-02 21:16:25 +00:00
if ((cfile = fopen (path_dhcpd_conf, "r")) == NULL)
error ("Can't open %s: %m", path_dhcpd_conf);
1995-11-29 07:40:04 +00:00
do {
token = peek_token (&val, cfile);
if (token == EOF)
break;
declaration = parse_statement (cfile, &root_group,
ROOT_GROUP,
(struct host_decl *)0,
declaration);
1995-11-29 07:40:04 +00:00
} while (1);
token = next_token (&val, cfile); /* Clear the peek buffer */
return !warnings_occurred;
1996-03-02 05:13:36 +00:00
}
/* lease-file :== lease-declarations EOF
lease-statments :== <nil>
| lease-declaration
| lease-declarations lease-declaration */
void read_leases ()
1996-03-02 05:13:36 +00:00
{
FILE *cfile;
char *val;
enum dhcp_token token;
1996-03-02 05:13:36 +00:00
1996-09-02 21:16:25 +00:00
new_parse (path_dhcpd_db);
1996-08-27 09:40:17 +00:00
/* Open the lease file. If we can't open it, fail. The reason
for this is that although on initial startup, the absence of
a lease file is perfectly benign, if dhcpd has been running
and this file is absent, it means that dhcpd tried and failed
to rewrite the lease database. If we proceed and the
problem which caused the rewrite to fail has been fixed, but no
human has corrected the database problem, then we are left
thinking that no leases have been assigned to anybody, which
could create severe network chaos. */
1996-09-02 21:16:25 +00:00
if ((cfile = fopen (path_dhcpd_db, "r")) == NULL)
1996-08-27 09:40:17 +00:00
error ("Can't open lease database %s: %m -- %s",
1996-09-02 21:16:25 +00:00
path_dhcpd_db,
1996-08-27 09:40:17 +00:00
"check for failed database rewrite attempt!");
1996-03-02 05:13:36 +00:00
do {
token = next_token (&val, cfile);
if (token == EOF)
break;
if (token != LEASE) {
warn ("Corrupt lease file - possible data loss!");
skip_to_semi (cfile);
} else {
1996-08-27 09:40:17 +00:00
struct lease *lease;
lease = parse_lease_declaration (cfile);
1996-08-27 09:40:17 +00:00
if (lease)
1996-03-02 05:13:36 +00:00
enter_lease (lease);
1996-08-27 09:40:17 +00:00
else
parse_warn ("possibly corrupt lease file");
1996-03-02 05:13:36 +00:00
}
} while (1);
1995-11-29 07:40:04 +00:00
}
/* statement :== parameter | declaration
parameter :== timestamp
| DEFAULT_LEASE_TIME lease_time
| MAX_LEASE_TIME lease_time
| DYNAMIC_BOOTP_LEASE_CUTOFF date
| DYNAMIC_BOOTP_LEASE_LENGTH lease_time
| BOOT_UNKNOWN_CLIENTS boolean
| ONE_LEASE_PER_CLIENT boolean
1996-08-29 23:02:40 +00:00
| GET_LEASE_HOSTNAMES boolean
1996-09-09 07:04:29 +00:00
| USE_HOST_DECL_NAME boolean
| NEXT_SERVER ip-addr-or-hostname SEMI
| option_parameter
| SERVER-IDENTIFIER ip-addr-or-hostname SEMI
| FILENAME string-parameter
| SERVER_NAME string-parameter
| hardware-parameter
| fixed-address-parameter
| ALLOW allow-deny-keyword
| DENY allow-deny-keyword
| USE_LEASE_ADDR_FOR_DEFAULT_ROUTE boolean
| AUTHORITATIVE
| NOT AUTHORITATIVE
declaration :== host-declaration
| group-declaration
| shared-network-declaration
| subnet-declaration
| VENDOR_CLASS class-declaration
| USER_CLASS class-declaration
| RANGE address-range-declaration */
int parse_statement (cfile, group, type, host_decl, declaration)
1995-11-29 07:40:04 +00:00
FILE *cfile;
1996-08-27 09:40:17 +00:00
struct group *group;
int type;
struct host_decl *host_decl;
int declaration;
1995-11-29 07:40:04 +00:00
{
enum dhcp_token token;
1995-11-29 07:40:04 +00:00
char *val;
1996-08-27 09:40:17 +00:00
struct shared_network *share;
char *t, *n;
struct expression *expr;
struct data_string data;
1996-08-27 09:40:17 +00:00
struct hardware hardware;
struct executable_statement *et, *ep;
struct option *option;
struct option_cache *cache;
int lose;
1995-11-29 07:40:04 +00:00
switch (peek_token (&val, cfile)) {
1995-11-29 07:40:04 +00:00
case HOST:
next_token (&val, cfile);
if (type != HOST_DECL && type != CLASS_DECL)
parse_host_declaration (cfile, group);
1996-08-27 09:40:17 +00:00
else {
parse_warn ("host declarations not allowed here.");
1996-08-27 09:40:17 +00:00
skip_to_semi (cfile);
1995-11-29 07:40:04 +00:00
}
1996-08-27 09:40:17 +00:00
return 1;
case GROUP:
next_token (&val, cfile);
if (type != HOST_DECL && type != CLASS_DECL)
parse_group_declaration (cfile, group);
1996-08-27 09:40:17 +00:00
else {
parse_warn ("host declarations not allowed here.");
1996-08-27 09:40:17 +00:00
skip_to_semi (cfile);
1995-11-29 07:40:04 +00:00
}
1996-08-27 09:40:17 +00:00
return 1;
1995-11-29 07:40:04 +00:00
case TIMESTAMP:
next_token (&val, cfile);
1996-08-27 09:40:17 +00:00
parsed_time = parse_timestamp (cfile);
1995-11-29 07:40:04 +00:00
break;
1996-08-27 09:40:17 +00:00
case SHARED_NETWORK:
next_token (&val, cfile);
if (type == SHARED_NET_DECL ||
type == HOST_DECL ||
type == SUBNET_DECL ||
type == CLASS_DECL) {
parse_warn ("shared-network parameters not %s.",
1996-08-27 09:40:17 +00:00
"allowed here");
skip_to_semi (cfile);
break;
}
1996-08-27 09:40:17 +00:00
parse_shared_net_declaration (cfile, group);
1996-08-27 09:40:17 +00:00
return 1;
case SUBNET:
next_token (&val, cfile);
if (type == HOST_DECL || type == SUBNET_DECL ||
type == CLASS_DECL) {
parse_warn ("subnet declarations not allowed here.");
1996-08-27 09:40:17 +00:00
skip_to_semi (cfile);
return 1;
}
/* If we're in a subnet declaration, just do the parse. */
1996-08-27 09:40:17 +00:00
if (group -> shared_network) {
parse_subnet_declaration (cfile,
group -> shared_network);
1996-08-27 09:40:17 +00:00
break;
}
/* Otherwise, cons up a fake shared network structure
and populate it with the lone subnet... */
share = new_shared_network ("parse_statement");
if (!share)
error ("No memory for shared subnet");
share -> group = clone_group (group, "parse_statement:subnet");
share -> group -> shared_network = share;
parse_subnet_declaration (cfile, share);
/* share -> subnets is the subnet we just parsed. */
1996-08-27 09:40:17 +00:00
if (share -> subnets) {
share -> interface =
share -> subnets -> interface;
/* Make the shared network name from network number. */
1996-08-27 09:40:17 +00:00
n = piaddr (share -> subnets -> net);
t = malloc (strlen (n) + 1);
if (!t)
error ("no memory for subnet name");
strcpy (t, n);
share -> name = t;
/* Copy the authoritative parameter from the subnet,
since there is no opportunity to declare it here. */
share -> group -> authoritative =
share -> subnets -> group -> authoritative;
enter_shared_network (share);
1995-11-29 07:40:04 +00:00
}
1996-08-27 09:40:17 +00:00
return 1;
case VENDOR_CLASS:
next_token (&val, cfile);
if (type == CLASS_DECL) {
parse_warn ("class declarations not allowed here.");
skip_to_semi (cfile);
break;
}
parse_class_declaration (cfile, group, 0);
1996-08-27 09:40:17 +00:00
return 1;
case USER_CLASS:
next_token (&val, cfile);
if (type == CLASS_DECL) {
parse_warn ("class declarations not allowed here.");
skip_to_semi (cfile);
break;
}
parse_class_declaration (cfile, group, 1);
1996-08-27 09:40:17 +00:00
return 1;
case CLASS:
next_token (&val, cfile);
if (type == CLASS_DECL) {
parse_warn ("class declarations not allowed here.");
skip_to_semi (cfile);
break;
}
parse_class_declaration (cfile, group, 2);
return 1;
case SUBCLASS:
next_token (&val, cfile);
if (type == CLASS_DECL) {
parse_warn ("class declarations not allowed here.");
skip_to_semi (cfile);
1996-08-27 09:40:17 +00:00
break;
}
parse_class_declaration (cfile, group, 3);
return 1;
1996-08-27 09:40:17 +00:00
case HARDWARE:
next_token (&val, cfile);
parse_hardware_param (cfile, &hardware);
1996-08-27 09:40:17 +00:00
if (host_decl)
host_decl -> interface = hardware;
else
parse_warn ("hardware address parameter %s",
1996-08-27 09:40:17 +00:00
"not allowed here.");
break;
case FIXED_ADDR:
next_token (&val, cfile);
cache = (struct option_cache *)0;
parse_fixed_addr_param (&cache, cfile);
1996-08-27 09:40:17 +00:00
if (host_decl)
host_decl -> fixed_addr = cache;
else {
parse_warn ("fixed-address parameter not %s",
1996-08-27 09:40:17 +00:00
"allowed here.");
option_cache_dereference (&cache, "parse_statement");
}
1996-08-27 09:40:17 +00:00
break;
1998-11-09 02:46:58 +00:00
case POOL:
next_token (&val, cfile);
if (type != SUBNET_DECL && type != SHARED_NET_DECL) {
parse_warn ("pool declared outside of network");
}
parse_pool_statement (cfile, group, type);
return declaration;
1996-08-27 09:40:17 +00:00
case RANGE:
next_token (&val, cfile);
if (type != SUBNET_DECL || !group -> subnet) {
parse_warn ("range declaration not allowed here.");
1996-08-27 09:40:17 +00:00
skip_to_semi (cfile);
return declaration;
1996-08-27 09:40:17 +00:00
}
1998-11-09 02:46:58 +00:00
parse_address_range (cfile, group, type, (struct pool *)0);
return declaration;
1996-08-27 09:40:17 +00:00
case ALLOW:
case DENY:
token = next_token (&val, cfile);
cache = (struct option_cache *)0;
if (!parse_allow_deny (&cache, cfile,
token == ALLOW ? 1 : 0))
return declaration;
et = (struct executable_statement *)dmalloc (sizeof *et,
"allow/deny");
if (!et)
error ("no memory for %s statement",
token == ALLOW ? "allow" : "deny");
memset (et, 0, sizeof *et);
et -> op = supersede_option_statement;
et -> data.option = cache;
goto insert_statement;
case TOKEN_NOT:
1999-02-23 19:07:14 +00:00
token = next_token (&val, cfile);
token = next_token (&val, cfile);
switch (token) {
case AUTHORITATIVE:
group -> authoritative = 0;
goto authoritative;
default:
parse_warn ("expecting assertion");
skip_to_semi (cfile);
break;
}
break;
case AUTHORITATIVE:
1999-02-23 19:07:14 +00:00
token = next_token (&val, cfile);
group -> authoritative = 1;
authoritative:
1999-02-23 19:07:14 +00:00
if (type == HOST_DECL)
parse_warn ("authority makes no sense here.");
parse_semi (cfile);
break;
case OPTION:
token = next_token (&val, cfile);
option = parse_option_name (cfile);
if (option) {
et = parse_option_statement
(cfile, 1, option,
supersede_option_statement);
if (!et)
return declaration;
goto insert_statement;
} else
return declaration;
break;
#if defined (FAILOVER_PROTOCOL)
case FAILOVER:
parse_failover_peer (cfile, group, type);
break;
#endif
1995-11-29 07:40:04 +00:00
default:
et = (struct executable_statement *)0;
if (is_identifier (token)) {
option = ((struct option *)
hash_lookup (server_universe.hash,
(unsigned char *)val, 0));
if (option) {
token = next_token (&val, cfile);
et = parse_option_statement
(cfile, 1, option,
supersede_option_statement);
if (!et)
return declaration;
}
}
if (!et) {
lose = 0;
et = parse_executable_statement (cfile, &lose);
if (!et) {
if (!lose) {
if (declaration)
parse_warn ("expecting a %s.",
"declaration");
else
parse_warn ("expecting a%s%s.",
" parameter",
" or declaration");
skip_to_semi (cfile);
}
return declaration;
}
}
if (!et) {
parse_warn ("expecting a %sdeclaration",
declaration ? "" : "parameter or ");
return declaration;
}
insert_statement:
if (group -> statements) {
for (ep = group -> statements; ep -> next;
ep = ep -> next)
;
ep -> next = et;
} else
group -> statements = et;
return declaration;
1995-11-29 07:40:04 +00:00
}
if (declaration) {
parse_warn ("parameters not allowed after first declaration.");
1996-08-27 09:40:17 +00:00
return 1;
}
1996-08-27 09:40:17 +00:00
return 0;
1995-11-29 07:40:04 +00:00
}
#if defined (FAILOVER_PROTOCOL)
void parse_failover_peer (cfile, group, type)
FILE *cfile;
struct group *group;
int type;
{
enum dhcp_token token;
char *val;
struct failover_peer *peer;
TIME *tp;
char *name;
if (type != SHARED_NET_DECL && type != ROOT_GROUP) {
parse_warn ("failover peer statements not in shared-network%s"
" declaration or at top level.");
skip_to_semi (cfile);
return;
}
token = next_token (&val, cfile);
if (token != PEER) {
parse_warn ("expecting peer keyword");
skip_to_semi (cfile);
return;
}
token = next_token (&val, cfile);
if (is_identifier (token) || token == STRING) {
name = dmalloc (strlen (name) + 1, "peer name");
if (!peer -> name)
error ("no memory for peer name %s", name);
} else {
parse_warn ("expecting identifier or left brace");
skip_to_semi (cfile);
return;
}
/* See if there's a peer declaration by this name. */
peer = find_failover_peer (name);
token = next_token (&val, cfile);
if (token == SEMI) {
dfree (name, "peer name");
if (type != SHARED_NET_DECL)
parse_warn ("failover peer reference not %s",
"in shared-network declaration");
else {
if (!peer) {
parse_warn ("reference to unknown%s%s",
" failover peer ", name);
return;
}
group -> shared_network -> failover_peer =
peer;
}
return;
} else if (token == MY || token == PARTNER) {
if (!peer) {
parse_warn ("reference to unknown%s%s",
" failover peer ", name);
return;
}
if ((token == MY
? peer -> my_state
: peer -> partner_state) = parse_failover_state (cfile) ==
invalid_state)
skip_to_semi (cfile);
else
parse_semi (cfile);
return;
} else if (token != LBRACE) {
parse_warn ("expecting left brace");
skip_to_semi (cfile);
}
/* Make sure this isn't a redeclaration. */
if (peer) {
parse_warn ("redeclaration of failover peer %s", name);
skip_to_rbrace (cfile, 1);
return;
}
peer = new_failover_peer ("parse_failover_peer");
if (!peer)
error ("no memory for %sfailover peer%s%s.",
name ? "" : "anonymous", name ? " " : "", name);
/* Save the name. */
peer -> name = name;
do {
token = next_token (&val, cfile);
switch (token) {
case RBRACE:
break;
case PRIMARY:
peer -> i_am = primary;
break;
case SECONDARY:
peer -> i_am = secondary;
break;
case IDENTIFIER:
if (!parse_ip_addr_or_hostname (&peer -> address,
cfile, 0)) {
skip_to_rbrace (cfile, 1);
return;
}
break;
case PORT:
token = next_token (&val, cfile);
if (token != NUMBER) {
parse_warn ("expecting number");
skip_to_rbrace (cfile, 1);
}
peer -> port = atoi (val);
if (!parse_semi (cfile)) {
skip_to_rbrace (cfile, 1);
return;
}
break;
case MAX_TRANSMIT_IDLE:
tp = &peer -> max_transmit_idle;
goto parse_idle;
case MAX_RESPONSE_DELAY:
tp = &peer -> max_transmit_idle;
parse_idle:
token = next_token (&val, cfile);
if (token != NUMBER) {
parse_warn ("expecting number.");
skip_to_rbrace (cfile, 1);
return;
}
*tp = atoi (val);
default:
parse_warn ("invalid statement in peer declaration");
skip_to_rbrace (cfile, 1);
return;
}
} while (token != RBRACE);
if (type == SHARED_NET_DECL) {
group -> shared_network -> failover_peer = peer;
}
enter_failover_peer (peer);
}
enum failover_state parse_failover_state (cfile)
FILE *cfile;
{
enum dhcp_token token;
char *val;
token = next_token (&val, cfile);
switch (token) {
case PARTNER_DOWN:
return partner_down;
case NORMAL:
return normal;
case COMMUNICATIONS_INTERRUPTED:
return communications_interrupted;
case POTENTIAL_CONFLICT:
return potential_conflict;
case RECOVER:
return recover;
default:
parse_warn ("unknown failover state");
break;
}
return invalid_state;
}
#endif /* defined (FAILOVER_PROTOCOL) */
1998-11-09 02:46:58 +00:00
void parse_pool_statement (cfile, group, type)
FILE *cfile;
struct group *group;
int type;
{
enum dhcp_token token;
char *val;
int done = 0;
struct pool *pool, **p;
struct permit *permit;
struct permit **permit_head;
pool = new_pool ("parse_pool_statement");
if (!pool)
error ("no memory for pool.");
if (!parse_lbrace (cfile))
return;
do {
switch (peek_token (&val, cfile)) {
case RANGE:
next_token (&val, cfile);
parse_address_range (cfile, group, type, pool);
break;
case ALLOW:
permit_head = &pool -> permit_list;
get_permit:
permit = new_permit ("parse_pool_statement");
if (!permit)
error ("no memory for permit");
next_token (&val, cfile);
token = next_token (&val, cfile);
switch (token) {
case UNKNOWN:
permit -> type = permit_unknown_clients;
get_clients:
if (next_token (&val, cfile) != CLIENTS) {
parse_warn ("expecting \"hosts\"");
skip_to_semi (cfile);
free_permit (permit,
"parse_pool_statement");
continue;
}
break;
case KNOWN:
permit -> type = permit_known_clients;
goto get_clients;
case AUTHENTICATED:
permit -> type = permit_authenticated_clients;
goto get_clients;
case UNAUTHENTICATED:
permit -> type =
permit_unauthenticated_clients;
goto get_clients;
case ALL:
permit -> type = permit_all_clients;
goto get_clients;
break;
case DYNAMIC:
permit -> type = permit_dynamic_bootp_clients;
if (next_token (&val, cfile) != BOOTP) {
parse_warn ("expecting \"bootp\"");
skip_to_semi (cfile);
free_permit (permit,
"parse_pool_statement");
continue;
}
goto get_clients;
case MEMBERS:
if (next_token (&val, cfile) != OF) {
parse_warn ("expecting \"of\"");
skip_to_semi (cfile);
free_permit (permit,
"parse_pool_statement");
continue;
}
if (next_token (&val, cfile) != STRING) {
parse_warn ("expecting class name.");
skip_to_semi (cfile);
free_permit (permit,
"parse_pool_statement");
continue;
}
permit -> type = permit_class;
permit -> class = find_class (val);
if (!permit -> class)
parse_warn ("no such class: %s", val);
default:
parse_warn ("expecting permit type.");
skip_to_semi (cfile);
break;
}
while (*permit_head)
permit_head = &((*permit_head) -> next);
*permit_head = permit;
break;
case DENY:
permit_head = &pool -> prohibit_list;
goto get_permit;
case RBRACE:
next_token (&val, cfile);
done = 1;
break;
default:
parse_warn ("expecting address range or permit list.");
skip_to_semi (cfile);
break;
}
} while (!done);
if (type == SUBNET_DECL)
pool -> shared_network = group -> subnet -> shared_network;
else
pool -> shared_network = group -> shared_network;
p = &pool -> shared_network -> pools;
for (; *p; p = &((*p) -> next))
;
*p = pool;
}
/* allow-deny-keyword :== BOOTP
| BOOTING
| DYNAMIC_BOOTP
| UNKNOWN_CLIENTS */
int parse_allow_deny (oc, cfile, flag)
struct option_cache **oc;
FILE *cfile;
int flag;
{
enum dhcp_token token;
char *val;
char rf = flag;
struct expression *data = (struct expression *)0;
int status;
if (!make_const_data (&data, &rf, 1, 0, 1))
return 0;
token = next_token (&val, cfile);
switch (token) {
case BOOTP:
status = option_cache (oc, (struct data_string *)0, data,
&server_options [SV_ALLOW_BOOTP]);
break;
case BOOTING:
status = option_cache (oc, (struct data_string *)0, data,
&server_options [SV_ALLOW_BOOTING]);
break;
case DYNAMIC_BOOTP:
status = option_cache (oc, (struct data_string *)0, data,
&server_options [SV_DYNAMIC_BOOTP]);
break;
case UNKNOWN_CLIENTS:
status = (option_cache
(oc, (struct data_string *)0, data,
&server_options [SV_BOOT_UNKNOWN_CLIENTS]));
break;
default:
parse_warn ("expecting allow/deny key");
skip_to_semi (cfile);
return 0;
}
parse_semi (cfile);
return status;
}
/* boolean :== ON SEMI | OFF SEMI | TRUE SEMI | FALSE SEMI */
int parse_boolean (cfile)
FILE *cfile;
{
enum dhcp_token token;
char *val;
int rv;
token = next_token (&val, cfile);
if (!strcasecmp (val, "true")
|| !strcasecmp (val, "on"))
rv = 1;
else if (!strcasecmp (val, "false")
|| !strcasecmp (val, "off"))
rv = 0;
else {
parse_warn ("boolean value (true/false/on/off) expected");
skip_to_semi (cfile);
return 0;
}
parse_semi (cfile);
return rv;
}
1996-08-27 09:40:17 +00:00
/* Expect a left brace; if there isn't one, skip over the rest of the
statement and return zero; otherwise, return 1. */
int parse_lbrace (cfile)
FILE *cfile;
{
enum dhcp_token token;
1996-08-27 09:40:17 +00:00
char *val;
token = next_token (&val, cfile);
if (token != LBRACE) {
parse_warn ("expecting left brace.");
skip_to_semi (cfile);
return 0;
}
return 1;
1995-11-29 07:40:04 +00:00
}
1996-08-27 09:40:17 +00:00
/* host-declaration :== hostname RBRACE parameters declarations LBRACE */
1995-11-29 07:40:04 +00:00
void parse_host_declaration (cfile, group)
1995-11-29 07:40:04 +00:00
FILE *cfile;
1996-08-27 09:40:17 +00:00
struct group *group;
1995-11-29 07:40:04 +00:00
{
char *val;
enum dhcp_token token;
1996-08-27 09:40:17 +00:00
struct host_decl *host;
1998-03-17 06:20:51 +00:00
char *name;
int declaration = 0;
1996-08-27 09:40:17 +00:00
1998-03-17 06:20:51 +00:00
token = peek_token (&val, cfile);
if (token != LBRACE) {
name = parse_host_name (cfile);
if (!name)
return;
} else {
name = (char *)0;
}
1996-08-27 09:40:17 +00:00
host = (struct host_decl *)dmalloc (sizeof (struct host_decl),
"parse_host_declaration");
1996-08-27 09:40:17 +00:00
if (!host)
error ("can't allocate host decl struct %s.", name);
host -> name = name;
host -> group = clone_group (group, "parse_host_declaration");
1996-08-27 09:40:17 +00:00
if (!parse_lbrace (cfile))
return;
1995-11-29 07:40:04 +00:00
do {
token = peek_token (&val, cfile);
1996-08-27 09:40:17 +00:00
if (token == RBRACE) {
1995-11-29 07:40:04 +00:00
token = next_token (&val, cfile);
break;
}
if (token == EOF) {
token = next_token (&val, cfile);
parse_warn ("unexpected end of file");
break;
}
declaration = parse_statement (cfile, host -> group,
HOST_DECL, host,
declaration);
1995-11-29 07:40:04 +00:00
} while (1);
1996-08-27 09:40:17 +00:00
enter_host (host);
1995-11-29 07:40:04 +00:00
}
/* class-declaration :== STRING LBRACE parameters declarations RBRACE
*/
struct class *parse_class_declaration (cfile, group, type)
FILE *cfile;
1996-08-27 09:40:17 +00:00
struct group *group;
int type;
{
char *val;
enum dhcp_token token;
struct class *class = (struct class *)0, *pc;
1996-12-31 02:01:28 +00:00
int declaration = 0;
int lose;
struct data_string data;
char *name;
struct executable_statement *stmt = (struct executable_statement *)0;
struct expression *expr;
int new = 1;
token = next_token (&val, cfile);
if (token != STRING) {
parse_warn ("Expecting class name");
skip_to_semi (cfile);
return (struct class *)0;
}
/* See if there's already a class with the specified name. */
pc = (struct class *)find_class (val);
/* If this isn't a subclass, we're updating an existing class. */
if (pc && type != 0 && type != 1 && type != 3) {
class = pc;
new = 0;
pc = (struct class *)0;
}
/* If this _is_ a subclass, there _must_ be a class with the
same name. */
if (!pc && (type == 0 || type == 1 || type == 3)) {
parse_warn ("no class named %s", val);
skip_to_semi (cfile);
return (struct class *)0;
}
/* The old vendor-class and user-class declarations had an implicit
match. We don't do the implicit match anymore. Instead, for
backward compatibility, we have an implicit-vendor-class and an
implicit-user-class. vendor-class and user-class declarations
are turned into subclasses of the implicit classes, and the
spawn expression of the implicit classes extracts the contents of
the vendor class or user class. */
if (type == 0 || type == 1) {
data.len = strlen (val);
data.buffer = (struct buffer *)0;
if (!buffer_allocate (&data.buffer,
data.len + 1, "parse_class_declaration"))
error ("no memoy for class name.");
data.data = &data.buffer -> data [0];
data.terminated = 1;
name = type ? "implicit-vendor-class" : "implicit-user-class";
} else if (type == 2) {
if (!(name = dmalloc (strlen (val) + 1,
"parse_class_declaration")))
error ("No memory for class name %s.", val);
strcpy (name, val);
} else {
name = (char *)0;
}
/* If this is a straight subclass, parse the hash string. */
if (type == 3) {
token = peek_token (&val, cfile);
if (token == STRING) {
token = next_token (&val, cfile);
data.len = strlen (val);
data.buffer = (struct buffer *)0;
if (!buffer_allocate (&data.buffer, data.len + 1,
"parse_class_declaration"))
return (struct class *)0;
data.terminated = 1;
data.data = &data.buffer -> data [0];
strcpy (data.data, val);
} else if (token == NUMBER_OR_NAME || token == NUMBER) {
memset (&data, 0, sizeof data);
if (!parse_cshl (&data, cfile))
return (struct class *)0;
}
}
/* See if there's already a class in the hash table matching the
hash data. */
if (type == 0 || type == 1 || type == 3)
class = ((struct class *)
hash_lookup (pc -> hash, data.data, data.len));
/* If we didn't find an existing class, allocate a new one. */
if (!class) {
/* Allocate the class structure... */
class = (struct class *)dmalloc (sizeof (struct class),
"parse_class_declaration");
if (!class)
error ("No memory for class %s.", val);
memset (class, 0, sizeof *class);
if (pc) {
class -> group = pc -> group;
class -> group = pc -> group;
class -> superclass = pc;
class -> lease_limit = pc -> lease_limit;
if (class -> lease_limit) {
class -> billed_leases =
dmalloc (class -> lease_limit *
sizeof (struct lease *),
"check_collection");
if (!class -> billed_leases)
error ("no memory for billed leases");
memset (class -> billed_leases, 0,
(class -> lease_limit *
sizeof class -> billed_leases));
}
data_string_copy (&class -> hash_string, &data,
"check_collection");
if (!pc -> hash)
pc -> hash = new_hash ();
add_hash (pc -> hash,
class -> hash_string.data,
class -> hash_string.len,
(unsigned char *)class);
} else {
class -> group =
clone_group (group, "parse_class_declaration");
}
/* If this is an implicit vendor or user class, add a
statement that causes the vendor or user class ID to
be sent back in the reply. */
if (type == 0 || type == 1) {
stmt = ((struct executable_statement *)
dmalloc (sizeof (struct executable_statement),
"implicit user/vendor class"));
if (!stmt)
error ("no memory for class statement.");
memset (stmt, 0, sizeof *stmt);
stmt -> op = supersede_option_statement;
if (option_cache_allocate (&stmt -> data.option,
"parse_class_statement")) {
stmt -> data.option -> data = data;
stmt -> data.option -> option =
dhcp_universe.options
[type
? DHO_DHCP_CLASS_IDENTIFIER
: DHO_DHCP_USER_CLASS_ID];
}
class -> statements = stmt;
}
/* Save the name, if there is one. */
class -> name = name;
}
1996-08-27 09:40:17 +00:00
if (type == 0 || type == 1 || type == 3)
data_string_forget (&data, "check_collection");
/* Spawned classes don't have their own settings. */
if (class -> superclass) {
parse_semi (cfile);
return class;
}
1996-08-27 09:40:17 +00:00
if (!parse_lbrace (cfile))
return (struct class *)0;
do {
token = peek_token (&val, cfile);
1996-08-27 09:40:17 +00:00
if (token == RBRACE) {
token = next_token (&val, cfile);
break;
} else if (token == EOF) {
token = next_token (&val, cfile);
parse_warn ("unexpected end of file");
break;
} else if (token == MATCH) {
if (pc) {
parse_warn ("invalid match in subclass.");
skip_to_semi (cfile);
break;
}
if (class -> expr) {
parse_warn ("can't override match.");
skip_to_semi (cfile);
break;
}
token = next_token (&val, cfile);
token = next_token (&val, cfile);
if (token != IF) {
parse_warn ("expecting if after match");
skip_to_semi (cfile);
break;
}
parse_boolean_expression (&class -> expr, cfile,
&lose);
if (lose)
break;
#if defined (DEBUG_EXPRESSION_PARSE)
print_expression ("class match", class -> expr);
#endif
parse_semi (cfile);
} else if (token == SPAWN) {
if (pc) {
parse_warn ("invalid spawn in subclass.");
skip_to_semi (cfile);
break;
}
if (class -> spawn) {
parse_warn ("can't override spawn.");
skip_to_semi (cfile);
break;
}
token = next_token (&val, cfile);
token = next_token (&val, cfile);
if (token != WITH) {
parse_warn ("expecting with after spawn");
skip_to_semi (cfile);
break;
}
parse_data_expression (&class -> spawn, cfile, &lose);
if (lose)
break;
#if defined (DEBUG_EXPRESSION_PARSE)
print_expression ("class match", class -> spawn);
#endif
parse_semi (cfile);
} else if (token == LEASE) {
next_token (&val, cfile);
token = next_token (&val, cfile);
if (token != LIMIT) {
parse_warn ("expecting \"limit\"");
if (token != SEMI)
skip_to_semi (cfile);
break;
}
token = next_token (&val, cfile);
if (token != NUMBER) {
parse_warn ("expecting a number");
if (token != SEMI)
skip_to_semi (cfile);
break;
}
class -> lease_limit = atoi (val);
class -> billed_leases =
dmalloc (class -> lease_limit *
sizeof (struct lease *),
"check_collection");
if (!class -> billed_leases)
error ("no memory for billed leases.");
memset (class -> billed_leases, 0,
(class -> lease_limit *
sizeof class -> billed_leases));
have_billing_classes = 1;
parse_semi (cfile);
} else {
declaration = parse_statement (cfile, class -> group,
CLASS_DECL,
(struct host_decl *)0,
declaration);
}
} while (1);
if (type == 2 && new) {
if (!collections -> classes)
collections -> classes = class;
else {
struct class *cp;
for (cp = collections -> classes;
cp -> nic; cp = cp -> nic)
;
cp -> nic = class;
}
}
return class;
}
/* shared-network-declaration :==
hostname LBRACE declarations parameters RBRACE */
void parse_shared_net_declaration (cfile, group)
FILE *cfile;
1996-08-27 09:40:17 +00:00
struct group *group;
{
char *val;
enum dhcp_token token;
struct shared_network *share;
char *name;
int declaration = 0;
share = new_shared_network ("parse_shared_net_declaration");
if (!share)
error ("No memory for shared subnet");
1998-11-09 02:46:58 +00:00
share -> pools = (struct pool *)0;
share -> next = (struct shared_network *)0;
1996-06-01 02:01:07 +00:00
share -> interface = (struct interface_info *)0;
share -> group = clone_group (group, "parse_shared_net_declaration");
1996-08-27 09:40:17 +00:00
share -> group -> shared_network = share;
/* Get the name of the shared network... */
1996-08-27 09:40:17 +00:00
token = peek_token (&val, cfile);
if (token == STRING) {
token = next_token (&val, cfile);
if (val [0] == 0) {
parse_warn ("zero-length shared network name");
val = "<no-name-given>";
}
name = malloc (strlen (val) + 1);
if (!name)
error ("no memory for shared network name");
strcpy (name, val);
} else {
name = parse_host_name (cfile);
if (!name)
return;
}
share -> name = name;
1996-08-27 09:40:17 +00:00
if (!parse_lbrace (cfile))
return;
do {
1996-08-27 09:40:17 +00:00
token = peek_token (&val, cfile);
if (token == RBRACE) {
token = next_token (&val, cfile);
if (!share -> subnets) {
parse_warn ("empty shared-network decl");
return;
}
enter_shared_network (share);
return;
} else if (token == EOF) {
token = next_token (&val, cfile);
parse_warn ("unexpected end of file");
break;
}
declaration = parse_statement (cfile, share -> group,
SHARED_NET_DECL,
(struct host_decl *)0,
declaration);
} while (1);
}
/* subnet-declaration :==
net NETMASK netmask RBRACE parameters declarations LBRACE */
void parse_subnet_declaration (cfile, share)
FILE *cfile;
struct shared_network *share;
{
char *val;
enum dhcp_token token;
struct subnet *subnet, *t, *u;
1996-08-27 09:40:17 +00:00
struct iaddr iaddr;
unsigned char addr [4];
int len = sizeof addr;
int declaration = 0;
subnet = new_subnet ("parse_subnet_declaration");
if (!subnet)
error ("No memory for new subnet");
subnet -> shared_network = share;
1996-08-27 09:40:17 +00:00
subnet -> group = clone_group (share -> group,
"parse_subnet_declaration");
1996-08-27 09:40:17 +00:00
subnet -> group -> subnet = subnet;
/* Get the network number... */
1996-08-27 09:40:17 +00:00
if (!parse_numeric_aggregate (cfile, addr, &len, DOT, 10, 8))
return;
memcpy (iaddr.iabuf, addr, len);
iaddr.len = len;
subnet -> net = iaddr;
token = next_token (&val, cfile);
if (token != NETMASK) {
parse_warn ("Expecting netmask");
skip_to_semi (cfile);
1996-08-27 09:40:17 +00:00
return;
}
/* Get the netmask... */
1996-08-27 09:40:17 +00:00
if (!parse_numeric_aggregate (cfile, addr, &len, DOT, 10, 8))
return;
memcpy (iaddr.iabuf, addr, len);
iaddr.len = len;
subnet -> netmask = iaddr;
enter_subnet (subnet);
1996-08-27 09:40:17 +00:00
if (!parse_lbrace (cfile))
return;
do {
token = peek_token (&val, cfile);
1996-08-27 09:40:17 +00:00
if (token == RBRACE) {
token = next_token (&val, cfile);
break;
} else if (token == EOF) {
token = next_token (&val, cfile);
parse_warn ("unexpected end of file");
break;
1996-08-27 09:40:17 +00:00
}
declaration = parse_statement (cfile, subnet -> group,
SUBNET_DECL,
(struct host_decl *)0,
declaration);
} while (1);
/* Add the subnet to the list of subnets in this shared net. */
1996-08-27 09:40:17 +00:00
if (!share -> subnets)
share -> subnets = subnet;
else {
u = (struct subnet *)0;
1996-08-27 09:40:17 +00:00
for (t = share -> subnets;
t -> next_sibling; t = t -> next_sibling) {
if (subnet_inner_than (subnet, t, 0)) {
if (u)
u -> next_sibling = subnet;
else
share -> subnets = subnet;
subnet -> next_sibling = t;
return;
}
u = t;
}
t -> next_sibling = subnet;
1996-08-27 09:40:17 +00:00
}
}
/* group-declaration :== RBRACE parameters declarations LBRACE */
1996-08-27 09:40:17 +00:00
void parse_group_declaration (cfile, group)
FILE *cfile;
1996-08-27 09:40:17 +00:00
struct group *group;
{
char *val;
enum dhcp_token token;
1996-08-27 09:40:17 +00:00
struct group *g;
int declaration = 0;
g = clone_group (group, "parse_group_declaration");
1996-08-27 09:40:17 +00:00
if (!parse_lbrace (cfile))
return;
1995-11-29 07:40:04 +00:00
1996-08-27 09:40:17 +00:00
do {
token = peek_token (&val, cfile);
if (token == RBRACE) {
token = next_token (&val, cfile);
1996-08-27 09:40:17 +00:00
break;
} else if (token == EOF) {
token = next_token (&val, cfile);
parse_warn ("unexpected end of file");
break;
}
declaration = parse_statement (cfile, g, GROUP_DECL,
(struct host_decl *)0,
declaration);
1996-08-27 09:40:17 +00:00
} while (1);
1995-11-29 07:40:04 +00:00
}
/* fixed-addr-parameter :== ip-addrs-or-hostnames SEMI
ip-addrs-or-hostnames :== ip-addr-or-hostname
| ip-addrs-or-hostnames ip-addr-or-hostname */
1995-11-29 07:40:04 +00:00
int parse_fixed_addr_param (oc, cfile)
struct option_cache **oc;
1995-11-29 07:40:04 +00:00
FILE *cfile;
{
char *val;
enum dhcp_token token;
struct expression *expr = (struct expression *)0;
struct expression *tmp, *new;
int status;
do {
tmp = (struct expression *)0;
if (parse_ip_addr_or_hostname (&tmp, cfile, 1)) {
if (expr) {
new = (struct expression *)0;
status = make_concat (&new, expr, tmp);
expression_dereference
(&expr, "parse_fixed_addr_param");
expression_dereference
(&tmp, "parse_fixed_addr_param");
if (status)
return 0;
expr = new;
} else
expr = tmp;
} else {
if (expr)
expression_dereference
(&expr, "parse_fixed_addr_param");
return 0;
}
token = peek_token (&val, cfile);
if (token == COMMA)
token = next_token (&val, cfile);
} while (token == COMMA);
1996-08-27 09:40:17 +00:00
if (!parse_semi (cfile)) {
if (expr)
expression_dereference (&expr,
"parse_fixed_addr_param");
return 0;
}
status = option_cache (oc, (struct data_string *)0, expr,
(struct option *)0);
expression_dereference (&expr, "parse_fixed_addr_param");
return status;
1995-11-29 07:40:04 +00:00
}
/* timestamp :== date
1995-11-29 07:40:04 +00:00
Timestamps are actually not used in dhcpd.conf, which is a static file,
but rather in the database file and the journal file. (Okay, actually
they're not even used there yet). */
1995-11-29 07:40:04 +00:00
1996-08-27 09:40:17 +00:00
TIME parse_timestamp (cfile)
1995-11-29 07:40:04 +00:00
FILE *cfile;
{
TIME rv;
1996-08-27 09:40:17 +00:00
rv = parse_date (cfile);
return rv;
1995-11-29 07:40:04 +00:00
}
/* lease_declaration :== LEASE ip_address LBRACE lease_parameters RBRACE
lease_parameters :== <nil>
| lease_parameter
| lease_parameters lease_parameter
lease_parameter :== STARTS date
| ENDS date
| TIMESTAMP date
| HARDWARE hardware-parameter
| UID hex_numbers SEMI
| HOSTNAME hostname SEMI
| CLIENT_HOSTNAME hostname SEMI
| CLASS identifier SEMI
| DYNAMIC_BOOTP SEMI */
struct lease *parse_lease_declaration (cfile)
1995-11-29 07:40:04 +00:00
FILE *cfile;
{
char *val;
enum dhcp_token token;
1995-11-29 07:40:04 +00:00
unsigned char addr [4];
int len = sizeof addr;
int seenmask = 0;
int seenbit;
char tbuf [32];
static struct lease lease;
/* Zap the lease structure... */
memset (&lease, 0, sizeof lease);
1995-11-29 07:40:04 +00:00
/* Get the address for which the lease has been issued. */
1996-08-27 09:40:17 +00:00
if (!parse_numeric_aggregate (cfile, addr, &len, DOT, 10, 8))
return (struct lease *)0;
memcpy (lease.ip_addr.iabuf, addr, len);
lease.ip_addr.len = len;
1995-11-29 07:40:04 +00:00
1996-08-27 09:40:17 +00:00
if (!parse_lbrace (cfile))
return (struct lease *)0;
1995-11-29 07:40:04 +00:00
do {
token = next_token (&val, cfile);
1996-08-27 09:40:17 +00:00
if (token == RBRACE)
1995-11-29 07:40:04 +00:00
break;
else if (token == EOF) {
parse_warn ("unexpected end of file");
break;
}
strncpy (tbuf, val, sizeof tbuf);
1995-11-29 07:40:04 +00:00
tbuf [(sizeof tbuf) - 1] = 0;
/* Parse any of the times associated with the lease. */
if (token == STARTS || token == ENDS || token == TIMESTAMP) {
TIME t;
1996-08-27 09:40:17 +00:00
t = parse_date (cfile);
1995-11-29 07:40:04 +00:00
switch (token) {
case STARTS:
seenbit = 1;
lease.starts = t;
break;
case ENDS:
seenbit = 2;
lease.ends = t;
break;
case TIMESTAMP:
seenbit = 4;
lease.timestamp = t;
break;
default:
/*NOTREACHED*/
seenbit = 0;
break;
1995-11-29 07:40:04 +00:00
}
} else {
switch (token) {
/* Colon-seperated hexadecimal octets... */
case UID:
seenbit = 8;
token = peek_token (&val, cfile);
if (token == STRING) {
token = next_token (&val, cfile);
lease.uid_len = strlen (val) + 1;
lease.uid = (unsigned char *)
malloc (lease.uid_len);
1996-09-09 07:04:29 +00:00
if (!lease.uid) {
warn ("no space for uid");
return (struct lease *)0;
}
memcpy (lease.uid, val, lease.uid_len);
} else {
lease.uid_len = 0;
lease.uid = parse_numeric_aggregate
1996-08-27 09:40:17 +00:00
(cfile, (unsigned char *)0,
&lease.uid_len, ':', 16, 8);
1996-09-09 07:04:29 +00:00
if (!lease.uid) {
warn ("no space for uid");
1996-08-27 09:40:17 +00:00
return (struct lease *)0;
1996-09-09 07:04:29 +00:00
}
if (lease.uid_len == 0) {
1996-09-09 07:04:29 +00:00
lease.uid = (unsigned char *)0;
parse_warn ("zero-length uid");
seenbit = 0;
break;
}
}
1995-11-29 07:40:04 +00:00
if (!lease.uid) {
error ("No memory for lease uid");
}
break;
case CLASS:
seenbit = 32;
token = next_token (&val, cfile);
if (!is_identifier (token)) {
if (token != SEMI)
skip_to_semi (cfile);
1996-08-27 09:40:17 +00:00
return (struct lease *)0;
1995-11-29 07:40:04 +00:00
}
/* for now, we aren't using this. */
break;
case HARDWARE:
seenbit = 64;
parse_hardware_param (cfile,
1996-08-27 09:40:17 +00:00
&lease.hardware_addr);
1995-11-29 07:40:04 +00:00
break;
case DYNAMIC_BOOTP:
seenbit = 128;
lease.flags |= BOOTP_LEASE;
break;
1997-03-06 19:29:39 +00:00
case ABANDONED:
seenbit = 256;
lease.flags |= ABANDONED_LEASE;
break;
case HOSTNAME:
seenbit = 512;
1997-10-27 20:22:40 +00:00
token = peek_token (&val, cfile);
if (token == STRING)
lease.hostname = parse_string (cfile);
else
lease.hostname =
parse_host_name (cfile);
if (!lease.hostname) {
seenbit = 0;
return (struct lease *)0;
}
break;
case CLIENT_HOSTNAME:
seenbit = 1024;
token = peek_token (&val, cfile);
if (token == STRING)
lease.client_hostname =
parse_string (cfile);
else
lease.client_hostname =
parse_host_name (cfile);
break;
case BILLING:
seenbit = 2048;
token = next_token (&val, cfile);
if (token == CLASS) {
token = next_token (&val, cfile);
if (token != STRING) {
parse_warn
("expecting string");
if (token != SEMI)
skip_to_semi (cfile);
token = BILLING;
break;
}
lease.billing_class = find_class (val);
if (!lease.billing_class)
parse_warn ("unknown class %s",
val);
parse_semi (cfile);
} else if (token == SUBCLASS) {
lease.billing_class =
parse_class_declaration
(cfile, (struct group *)0, 3);
} else {
parse_warn ("expecting \"class\"");
if (token != SEMI)
skip_to_semi (cfile);
}
token = BILLING;
break;
1995-11-29 07:40:04 +00:00
default:
1996-08-27 09:40:17 +00:00
skip_to_semi (cfile);
seenbit = 0;
1996-08-27 09:40:17 +00:00
return (struct lease *)0;
}
if (token != HARDWARE && token != STRING
&& token != BILLING) {
1996-08-27 09:40:17 +00:00
token = next_token (&val, cfile);
if (token != SEMI) {
parse_warn ("semicolon expected.");
skip_to_semi (cfile);
return (struct lease *)0;
}
1995-11-29 07:40:04 +00:00
}
}
if (seenmask & seenbit) {
parse_warn ("Too many %s parameters in lease %s\n",
tbuf, piaddr (lease.ip_addr));
1995-11-29 07:40:04 +00:00
} else
seenmask |= seenbit;
1996-08-27 09:40:17 +00:00
1995-11-29 07:40:04 +00:00
} while (1);
return &lease;
}
/* address-range-declaration :== ip-address ip-address SEMI
| DYNAMIC_BOOTP ip-address ip-address SEMI */
1995-11-29 07:40:04 +00:00
1998-11-09 02:46:58 +00:00
void parse_address_range (cfile, group, type, pool)
1995-11-29 07:40:04 +00:00
FILE *cfile;
1998-11-09 02:46:58 +00:00
struct group *group;
int type;
struct pool *pool;
1995-11-29 07:40:04 +00:00
{
1998-11-09 02:46:58 +00:00
struct iaddr low, high, net;
1995-11-29 07:40:04 +00:00
unsigned char addr [4];
int len = sizeof addr;
enum dhcp_token token;
char *val;
int dynamic = 0;
1998-11-09 02:46:58 +00:00
struct subnet *subnet;
struct shared_network *share;
struct pool *p;
if ((token = peek_token (&val, cfile)) == DYNAMIC_BOOTP) {
token = next_token (&val, cfile);
dynamic = 1;
}
1995-11-29 07:40:04 +00:00
/* Get the bottom address in the range... */
1996-08-27 09:40:17 +00:00
if (!parse_numeric_aggregate (cfile, addr, &len, DOT, 10, 8))
return;
memcpy (low.iabuf, addr, len);
low.len = len;
1995-11-29 07:40:04 +00:00
/* Only one address? */
token = peek_token (&val, cfile);
if (token == SEMI)
high = low;
else {
1995-11-29 07:40:04 +00:00
/* Get the top address in the range... */
if (!parse_numeric_aggregate (cfile, addr, &len, DOT, 10, 8))
return;
memcpy (high.iabuf, addr, len);
high.len = len;
}
1995-11-29 07:40:04 +00:00
1996-08-27 09:40:17 +00:00
token = next_token (&val, cfile);
if (token != SEMI) {
parse_warn ("semicolon expected.");
skip_to_semi (cfile);
return;
}
1998-11-09 02:46:58 +00:00
if (type == SUBNET_DECL) {
subnet = group -> subnet;
share = subnet -> shared_network;
} else {
share = group -> shared_network;
for (subnet = share -> subnets;
subnet; subnet = subnet -> next_sibling) {
net = subnet_number (low, subnet -> netmask);
if (addr_eq (low, subnet -> net))
break;
}
if (!subnet) {
parse_warn ("address range not on network %s",
group -> shared_network -> name);
return;
}
}
if (!pool) {
struct pool *last;
/* If we're permitting dynamic bootp for this range,
then look for a pool with an empty prohibit list and
a permit list with one entry which permits dynamic
bootp. */
for (pool = share -> pools; pool; pool = pool -> next) {
if ((!dynamic &&
!pool -> permit_list && !pool -> prohibit_list) ||
(dynamic &&
!pool -> prohibit_list &&
pool -> permit_list &&
!pool -> permit_list -> next &&
(pool -> permit_list -> type ==
permit_dynamic_bootp_clients))) {
break;
}
last = pool;
}
/* If we didn't get a pool, make one. */
if (!pool) {
pool = new_pool ("parse_address_range");
if (!pool)
error ("no memory for ad-hoc pool.");
if (dynamic) {
pool -> permit_list =
new_permit ("parse_address_range");
if (!pool -> permit_list)
error ("no memory for ad-hoc permit.");
pool -> permit_list -> type =
permit_dynamic_bootp_clients;
}
if (share -> pools)
last -> next = pool;
else
share -> pools = pool;
}
}
1995-11-29 07:40:04 +00:00
/* Create the new address range... */
1998-11-09 02:46:58 +00:00
new_address_range (low, high, subnet, pool);
1995-11-29 07:40:04 +00:00
}