1995-11-29 07:40:04 +00:00
|
|
|
/* confpars.c
|
|
|
|
|
|
|
|
Parser for dhcpd config file... */
|
|
|
|
|
|
|
|
/*
|
1999-03-16 05:50:46 +00:00
|
|
|
* Copyright (c) 1996-1999 Internet Software Consortium.
|
|
|
|
* Use is subject to license terms which appear in the file named
|
|
|
|
* ISC-LICENSE that should have accompanied this file when you
|
|
|
|
* received it. If a file named ISC-LICENSE did not accompany this
|
|
|
|
* file, or you are not sure the one you have is correct, you may
|
|
|
|
* obtain an applicable copy of the license at:
|
1995-11-29 07:40:04 +00:00
|
|
|
*
|
1999-03-16 05:50:46 +00:00
|
|
|
* http://www.isc.org/isc-license-1.0.html.
|
1995-11-29 07:40:04 +00:00
|
|
|
*
|
1999-03-16 05:50:46 +00:00
|
|
|
* This file is part of the ISC DHCP distribution. The documentation
|
|
|
|
* associated with this file is listed in the file DOCUMENTATION,
|
|
|
|
* included in the top-level directory of this release.
|
1995-11-29 07:40:04 +00:00
|
|
|
*
|
1999-03-16 05:50:46 +00:00
|
|
|
* Support and other services are available for ISC products - see
|
|
|
|
* http://www.isc.org for more information.
|
1995-11-29 07:40:04 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef lint
|
|
|
|
static char copyright[] =
|
1999-03-26 19:19:46 +00:00
|
|
|
"$Id: confpars.c,v 1.67 1999/03/26 19:19:45 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;
|
|
|
|
|
1996-08-29 09:14:39 +00:00
|
|
|
/* conf-file :== parameters declarations EOF
|
|
|
|
parameters :== <nil> | parameter | parameters parameter
|
|
|
|
declarations :== <nil> | declaration | declarations declaration */
|
1995-11-29 07:40:04 +00:00
|
|
|
|
1996-08-29 09:49:53 +00:00
|
|
|
int readconf ()
|
1995-11-29 07:40:04 +00:00
|
|
|
{
|
|
|
|
FILE *cfile;
|
|
|
|
char *val;
|
1998-11-06 00:16:52 +00:00
|
|
|
enum dhcp_token token;
|
1996-08-29 09:14:39 +00:00
|
|
|
int declaration = 0;
|
1995-11-29 07:40:04 +00:00
|
|
|
|
1996-09-02 21:16:25 +00:00
|
|
|
new_parse (path_dhcpd_conf);
|
1996-05-23 22:20:26 +00:00
|
|
|
|
1995-11-29 07:40:04 +00:00
|
|
|
/* Set up the initial dhcp option universe. */
|
|
|
|
initialize_universes ();
|
|
|
|
|
1999-02-14 19:08:51 +00:00
|
|
|
root_group.authoritative = 0;
|
|
|
|
|
1996-09-02 21:16:25 +00:00
|
|
|
if ((cfile = fopen (path_dhcpd_conf, "r")) == NULL)
|
1999-02-24 17:56:53 +00:00
|
|
|
log_fatal ("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;
|
1996-08-29 09:14:39 +00:00
|
|
|
declaration = parse_statement (cfile, &root_group,
|
1998-06-25 03:51:59 +00:00
|
|
|
ROOT_GROUP,
|
|
|
|
(struct host_decl *)0,
|
|
|
|
declaration);
|
1995-11-29 07:40:04 +00:00
|
|
|
} while (1);
|
1996-08-29 09:49:53 +00:00
|
|
|
token = next_token (&val, cfile); /* Clear the peek buffer */
|
|
|
|
|
|
|
|
return !warnings_occurred;
|
1996-03-02 05:13:36 +00:00
|
|
|
}
|
|
|
|
|
1996-08-29 09:14:39 +00:00
|
|
|
/* lease-file :== lease-declarations EOF
|
1996-08-28 01:28:27 +00:00
|
|
|
lease-statments :== <nil>
|
1996-08-29 09:14:39 +00:00
|
|
|
| lease-declaration
|
|
|
|
| lease-declarations lease-declaration */
|
1996-08-28 01:28:27 +00:00
|
|
|
|
1996-05-16 07:12:57 +00:00
|
|
|
void read_leases ()
|
1996-03-02 05:13:36 +00:00
|
|
|
{
|
|
|
|
FILE *cfile;
|
|
|
|
char *val;
|
1998-11-06 00:16:52 +00:00
|
|
|
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. */
|
1999-03-26 19:19:46 +00:00
|
|
|
if ((cfile = fopen (path_dhcpd_db, "r")) == NULL) {
|
|
|
|
log_error ("Can't open lease database %s: %m -- %s",
|
|
|
|
path_dhcpd_db,
|
|
|
|
"check for failed database rewrite attempt!");
|
|
|
|
log_error ("Please read the dhcpd.leases manual page if you");
|
|
|
|
log_fatal ("don't know what to do about this.");
|
|
|
|
}
|
|
|
|
|
1996-03-02 05:13:36 +00:00
|
|
|
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!");
|
1996-03-02 05:13:36 +00:00
|
|
|
skip_to_semi (cfile);
|
|
|
|
} else {
|
1996-08-27 09:40:17 +00:00
|
|
|
struct lease *lease;
|
1996-08-29 09:14:39 +00:00
|
|
|
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
|
1996-05-22 07:18:11 +00:00
|
|
|
parse_warn ("possibly corrupt lease file");
|
1996-03-02 05:13:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} while (1);
|
1995-11-29 07:40:04 +00:00
|
|
|
}
|
|
|
|
|
1996-08-29 09:14:39 +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
|
1996-08-29 09:14:39 +00:00
|
|
|
| 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
|
1997-02-22 08:41:01 +00:00
|
|
|
| ALLOW allow-deny-keyword
|
|
|
|
| DENY allow-deny-keyword
|
1998-04-09 04:38:24 +00:00
|
|
|
| USE_LEASE_ADDR_FOR_DEFAULT_ROUTE boolean
|
1999-02-14 19:08:51 +00:00
|
|
|
| AUTHORITATIVE
|
|
|
|
| NOT AUTHORITATIVE
|
1999-02-25 23:30:43 +00:00
|
|
|
| AUTH_KEY key-id key-value
|
1996-08-29 09:14:39 +00:00
|
|
|
|
|
|
|
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;
|
1996-08-29 09:14:39 +00:00
|
|
|
int declaration;
|
1995-11-29 07:40:04 +00:00
|
|
|
{
|
1998-11-06 00:16:52 +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;
|
1998-06-25 03:51:59 +00:00
|
|
|
struct expression *expr;
|
|
|
|
struct data_string data;
|
1996-08-27 09:40:17 +00:00
|
|
|
struct hardware hardware;
|
1998-06-25 03:51:59 +00:00
|
|
|
struct executable_statement *et, *ep;
|
|
|
|
struct option *option;
|
|
|
|
struct option_cache *cache;
|
|
|
|
int lose;
|
1999-02-25 23:30:43 +00:00
|
|
|
struct data_string key_id;
|
1995-11-29 07:40:04 +00:00
|
|
|
|
1998-06-25 03:51:59 +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)) {
|
|
|
|
if (type == HOST_DECL)
|
|
|
|
data_string_copy (&host_decl -> auth_key_id,
|
|
|
|
&key_id, "parse_statement");
|
|
|
|
data_string_forget (&key_id, "parse_statement");
|
|
|
|
}
|
|
|
|
break;
|
1995-11-29 07:40:04 +00:00
|
|
|
case HOST:
|
1998-06-25 03:51:59 +00:00
|
|
|
next_token (&val, cfile);
|
|
|
|
if (type != HOST_DECL && type != CLASS_DECL)
|
1996-08-29 09:14:39 +00:00
|
|
|
parse_host_declaration (cfile, group);
|
1996-08-27 09:40:17 +00:00
|
|
|
else {
|
1996-08-29 09:14:39 +00:00
|
|
|
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:
|
1998-06-25 03:51:59 +00:00
|
|
|
next_token (&val, cfile);
|
|
|
|
if (type != HOST_DECL && type != CLASS_DECL)
|
1996-08-29 09:14:39 +00:00
|
|
|
parse_group_declaration (cfile, group);
|
1996-08-27 09:40:17 +00:00
|
|
|
else {
|
1996-08-29 09:14:39 +00:00
|
|
|
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:
|
1998-06-25 03:51:59 +00:00
|
|
|
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
|
|
|
|
1996-05-22 07:18:11 +00:00
|
|
|
case SHARED_NETWORK:
|
1998-06-25 03:51:59 +00:00
|
|
|
next_token (&val, cfile);
|
1996-08-29 09:14:39 +00:00
|
|
|
if (type == SHARED_NET_DECL ||
|
|
|
|
type == HOST_DECL ||
|
1998-06-25 03:51:59 +00:00
|
|
|
type == SUBNET_DECL ||
|
|
|
|
type == CLASS_DECL) {
|
1996-08-29 09:14:39 +00:00
|
|
|
parse_warn ("shared-network parameters not %s.",
|
1996-08-27 09:40:17 +00:00
|
|
|
"allowed here");
|
|
|
|
skip_to_semi (cfile);
|
|
|
|
break;
|
1996-05-22 07:18:11 +00:00
|
|
|
}
|
1996-08-27 09:40:17 +00:00
|
|
|
|
1996-08-29 09:14:39 +00:00
|
|
|
parse_shared_net_declaration (cfile, group);
|
1996-08-27 09:40:17 +00:00
|
|
|
return 1;
|
|
|
|
|
1996-02-21 15:16:18 +00:00
|
|
|
case SUBNET:
|
1998-06-25 03:51:59 +00:00
|
|
|
next_token (&val, cfile);
|
|
|
|
if (type == HOST_DECL || type == SUBNET_DECL ||
|
|
|
|
type == CLASS_DECL) {
|
1996-08-29 09:14:39 +00:00
|
|
|
parse_warn ("subnet declarations not allowed here.");
|
1996-08-27 09:40:17 +00:00
|
|
|
skip_to_semi (cfile);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1996-08-29 09:14:39 +00:00
|
|
|
/* If we're in a subnet declaration, just do the parse. */
|
1996-08-27 09:40:17 +00:00
|
|
|
if (group -> shared_network) {
|
1996-08-29 09:14:39 +00:00
|
|
|
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)
|
1999-02-24 17:56:53 +00:00
|
|
|
log_fatal ("No memory for shared subnet");
|
1996-08-27 09:40:17 +00:00
|
|
|
share -> group = clone_group (group, "parse_statement:subnet");
|
|
|
|
share -> group -> shared_network = share;
|
|
|
|
|
1996-08-29 09:14:39 +00:00
|
|
|
parse_subnet_declaration (cfile, share);
|
1999-02-14 19:08:51 +00:00
|
|
|
|
|
|
|
/* share -> subnets is the subnet we just parsed. */
|
1996-08-27 09:40:17 +00:00
|
|
|
if (share -> subnets) {
|
|
|
|
share -> interface =
|
|
|
|
share -> subnets -> interface;
|
|
|
|
|
1999-02-14 19:08:51 +00:00
|
|
|
/* 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);
|
1996-05-22 07:18:11 +00:00
|
|
|
if (!t)
|
1999-02-24 17:56:53 +00:00
|
|
|
log_fatal ("no memory for subnet name");
|
1996-05-22 07:18:11 +00:00
|
|
|
strcpy (t, n);
|
|
|
|
share -> name = t;
|
1999-02-14 19:08:51 +00:00
|
|
|
|
|
|
|
/* Copy the authoritative parameter from the subnet,
|
|
|
|
since there is no opportunity to declare it here. */
|
|
|
|
share -> group -> authoritative =
|
|
|
|
share -> subnets -> group -> authoritative;
|
1996-05-22 07:18:11 +00:00
|
|
|
enter_shared_network (share);
|
1995-11-29 07:40:04 +00:00
|
|
|
}
|
1996-08-27 09:40:17 +00:00
|
|
|
return 1;
|
|
|
|
|
1996-02-29 18:08:45 +00:00
|
|
|
case VENDOR_CLASS:
|
1998-06-25 03:51:59 +00:00
|
|
|
next_token (&val, cfile);
|
|
|
|
if (type == CLASS_DECL) {
|
|
|
|
parse_warn ("class declarations not allowed here.");
|
|
|
|
skip_to_semi (cfile);
|
|
|
|
break;
|
|
|
|
}
|
1996-08-29 09:14:39 +00:00
|
|
|
parse_class_declaration (cfile, group, 0);
|
1996-08-27 09:40:17 +00:00
|
|
|
return 1;
|
|
|
|
|
1996-02-29 18:08:45 +00:00
|
|
|
case USER_CLASS:
|
1998-06-25 03:51:59 +00:00
|
|
|
next_token (&val, cfile);
|
|
|
|
if (type == CLASS_DECL) {
|
|
|
|
parse_warn ("class declarations not allowed here.");
|
|
|
|
skip_to_semi (cfile);
|
|
|
|
break;
|
|
|
|
}
|
1996-08-29 09:14:39 +00:00
|
|
|
parse_class_declaration (cfile, group, 1);
|
1996-08-27 09:40:17 +00:00
|
|
|
return 1;
|
1996-05-22 07:18:11 +00:00
|
|
|
|
1998-06-25 03:51:59 +00:00
|
|
|
case CLASS:
|
|
|
|
next_token (&val, cfile);
|
|
|
|
if (type == CLASS_DECL) {
|
|
|
|
parse_warn ("class declarations not allowed here.");
|
1998-04-09 04:38:24 +00:00
|
|
|
skip_to_semi (cfile);
|
1998-06-25 03:51:59 +00:00
|
|
|
break;
|
1998-04-09 04:38:24 +00:00
|
|
|
}
|
1998-06-25 03:51:59 +00:00
|
|
|
parse_class_declaration (cfile, group, 2);
|
|
|
|
return 1;
|
1998-04-09 04:38:24 +00:00
|
|
|
|
1998-06-25 03:51:59 +00:00
|
|
|
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;
|
|
|
|
}
|
1998-06-25 03:51:59 +00:00
|
|
|
parse_class_declaration (cfile, group, 3);
|
|
|
|
return 1;
|
1996-08-27 09:40:17 +00:00
|
|
|
|
|
|
|
case HARDWARE:
|
1998-06-25 03:51:59 +00:00
|
|
|
next_token (&val, cfile);
|
1996-08-29 09:14:39 +00:00
|
|
|
parse_hardware_param (cfile, &hardware);
|
1996-08-27 09:40:17 +00:00
|
|
|
if (host_decl)
|
|
|
|
host_decl -> interface = hardware;
|
|
|
|
else
|
1996-08-29 09:14:39 +00:00
|
|
|
parse_warn ("hardware address parameter %s",
|
1996-08-27 09:40:17 +00:00
|
|
|
"not allowed here.");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FIXED_ADDR:
|
1998-06-25 03:51:59 +00:00
|
|
|
next_token (&val, cfile);
|
1998-11-06 00:16:52 +00:00
|
|
|
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;
|
1998-11-06 00:16:52 +00:00
|
|
|
else {
|
1996-08-29 09:14:39 +00:00
|
|
|
parse_warn ("fixed-address parameter not %s",
|
1996-08-27 09:40:17 +00:00
|
|
|
"allowed here.");
|
1998-11-06 00:16:52 +00:00
|
|
|
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");
|
|
|
|
}
|
1999-02-25 23:30:43 +00:00
|
|
|
if (type == POOL_DECL) {
|
|
|
|
parse_warn ("pool declared within pool.");
|
|
|
|
}
|
1998-11-09 02:46:58 +00:00
|
|
|
parse_pool_statement (cfile, group, type);
|
|
|
|
return declaration;
|
|
|
|
|
1996-08-27 09:40:17 +00:00
|
|
|
case RANGE:
|
1998-06-25 03:51:59 +00:00
|
|
|
next_token (&val, cfile);
|
1996-08-29 09:14:39 +00:00
|
|
|
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);
|
1996-08-29 09:14:39 +00:00
|
|
|
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);
|
1996-08-29 09:14:39 +00:00
|
|
|
return declaration;
|
1996-08-27 09:40:17 +00:00
|
|
|
|
1997-02-22 08:41:01 +00:00
|
|
|
case ALLOW:
|
|
|
|
case DENY:
|
1998-06-25 03:51:59 +00:00
|
|
|
token = next_token (&val, cfile);
|
1998-11-06 00:16:52 +00:00
|
|
|
cache = (struct option_cache *)0;
|
|
|
|
if (!parse_allow_deny (&cache, cfile,
|
|
|
|
token == ALLOW ? 1 : 0))
|
|
|
|
return declaration;
|
1998-06-25 03:51:59 +00:00
|
|
|
et = (struct executable_statement *)dmalloc (sizeof *et,
|
|
|
|
"allow/deny");
|
|
|
|
if (!et)
|
1999-02-24 17:56:53 +00:00
|
|
|
log_fatal ("no memory for %s statement",
|
1998-06-25 03:51:59 +00:00
|
|
|
token == ALLOW ? "allow" : "deny");
|
|
|
|
memset (et, 0, sizeof *et);
|
|
|
|
et -> op = supersede_option_statement;
|
|
|
|
et -> data.option = cache;
|
|
|
|
goto insert_statement;
|
1997-02-22 08:41:01 +00:00
|
|
|
|
1999-02-14 19:08:51 +00:00
|
|
|
case TOKEN_NOT:
|
1999-02-23 19:07:14 +00:00
|
|
|
token = next_token (&val, cfile);
|
1999-02-14 19:08:51 +00:00
|
|
|
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);
|
1999-02-14 19:08:51 +00:00
|
|
|
group -> authoritative = 1;
|
|
|
|
authoritative:
|
1999-02-23 19:07:14 +00:00
|
|
|
if (type == HOST_DECL)
|
|
|
|
parse_warn ("authority makes no sense here.");
|
1999-02-14 19:08:51 +00:00
|
|
|
parse_semi (cfile);
|
|
|
|
break;
|
|
|
|
|
1999-03-25 22:05:19 +00:00
|
|
|
/* "server-identifier" is a special hack, equivalent to
|
|
|
|
"option dhcp-server-identifier". */
|
|
|
|
case SERVER_IDENTIFIER:
|
|
|
|
option = dhcp_universe.options [DHO_DHCP_SERVER_IDENTIFIER];
|
|
|
|
token = next_token (&val, cfile);
|
|
|
|
goto finish_option;
|
|
|
|
|
1998-11-06 00:16:52 +00:00
|
|
|
case OPTION:
|
|
|
|
token = next_token (&val, cfile);
|
1999-03-25 22:05:19 +00:00
|
|
|
option = parse_option_name (cfile, 1);
|
1998-11-06 00:16:52 +00:00
|
|
|
if (option) {
|
1999-03-25 22:05:19 +00:00
|
|
|
token = peek_token (&val, cfile);
|
|
|
|
if (token == CODE) {
|
|
|
|
if (type != ROOT_GROUP) {
|
|
|
|
parse_warn ("option definitions%s%s",
|
|
|
|
" may not currently be",
|
|
|
|
" scoped.");
|
|
|
|
skip_to_semi (cfile);
|
|
|
|
free_option (option,
|
|
|
|
"parse_statement");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
next_token (&val, cfile);
|
|
|
|
if (!parse_option_code_definition (cfile,
|
|
|
|
option))
|
|
|
|
free_option (option,
|
|
|
|
"parse_statement");
|
|
|
|
return declaration;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If this wasn't an option code definition, don't
|
|
|
|
allow an unknown option. */
|
|
|
|
if (option -> code == -1) {
|
|
|
|
parse_warn ("unknown option %s.%s",
|
|
|
|
option -> universe -> name,
|
|
|
|
option -> name);
|
|
|
|
skip_to_semi (cfile);
|
|
|
|
free_option (option, "parse_statement");
|
|
|
|
return declaration;
|
|
|
|
}
|
|
|
|
|
|
|
|
finish_option:
|
1998-11-06 00:16:52 +00:00
|
|
|
et = parse_option_statement
|
|
|
|
(cfile, 1, option,
|
|
|
|
supersede_option_statement);
|
|
|
|
if (!et)
|
|
|
|
return declaration;
|
|
|
|
goto insert_statement;
|
|
|
|
} else
|
|
|
|
return declaration;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
1999-02-14 19:08:51 +00:00
|
|
|
#if defined (FAILOVER_PROTOCOL)
|
|
|
|
case FAILOVER:
|
|
|
|
parse_failover_peer (cfile, group, type);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
1995-11-29 07:40:04 +00:00
|
|
|
default:
|
1998-06-25 03:51:59 +00:00
|
|
|
et = (struct executable_statement *)0;
|
|
|
|
if (is_identifier (token)) {
|
|
|
|
option = ((struct option *)
|
|
|
|
hash_lookup (server_universe.hash,
|
|
|
|
(unsigned char *)val, 0));
|
|
|
|
if (option) {
|
1998-11-06 00:16:52 +00:00
|
|
|
token = next_token (&val, cfile);
|
1998-06-25 03:51:59 +00:00
|
|
|
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) {
|
1998-11-06 02:58:17 +00:00
|
|
|
if (!lose) {
|
|
|
|
if (declaration)
|
|
|
|
parse_warn ("expecting a %s.",
|
|
|
|
"declaration");
|
|
|
|
else
|
|
|
|
parse_warn ("expecting a%s%s.",
|
|
|
|
" parameter",
|
|
|
|
" or declaration");
|
|
|
|
skip_to_semi (cfile);
|
|
|
|
}
|
1998-06-25 03:51:59 +00:00
|
|
|
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;
|
|
|
|
|
1998-11-06 00:16:52 +00:00
|
|
|
} else
|
|
|
|
group -> statements = et;
|
|
|
|
return declaration;
|
1995-11-29 07:40:04 +00:00
|
|
|
}
|
1996-05-22 07:18:11 +00:00
|
|
|
|
1996-08-29 09:14:39 +00:00
|
|
|
if (declaration) {
|
|
|
|
parse_warn ("parameters not allowed after first declaration.");
|
1996-08-27 09:40:17 +00:00
|
|
|
return 1;
|
1996-05-22 07:18:11 +00:00
|
|
|
}
|
1996-08-27 09:40:17 +00:00
|
|
|
|
|
|
|
return 0;
|
1995-11-29 07:40:04 +00:00
|
|
|
}
|
|
|
|
|
1999-02-14 19:08:51 +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)
|
1999-02-24 17:56:53 +00:00
|
|
|
log_fatal ("no memory for peer name %s", name);
|
1999-02-14 19:08:51 +00:00
|
|
|
} 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)
|
1999-02-24 17:56:53 +00:00
|
|
|
log_fatal ("no memory for %sfailover peer%s%s.",
|
1999-02-14 19:08:51 +00:00
|
|
|
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;
|
1999-02-25 23:30:43 +00:00
|
|
|
int declaration = 0;
|
1998-11-09 02:46:58 +00:00
|
|
|
|
|
|
|
pool = new_pool ("parse_pool_statement");
|
|
|
|
if (!pool)
|
1999-02-24 17:56:53 +00:00
|
|
|
log_fatal ("no memory for pool.");
|
1998-11-09 02:46:58 +00:00
|
|
|
|
1999-02-25 23:30:43 +00:00
|
|
|
pool -> group = clone_group (group, "parse_pool_statement");
|
|
|
|
|
1998-11-09 02:46:58 +00:00
|
|
|
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)
|
1999-02-24 17:56:53 +00:00
|
|
|
log_fatal ("no memory for permit");
|
1998-11-09 02:46:58 +00:00
|
|
|
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) {
|
1999-02-25 23:30:43 +00:00
|
|
|
parse_warn ("expecting \"clients\"");
|
1998-11-09 02:46:58 +00:00
|
|
|
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;
|
1999-02-25 23:30:43 +00:00
|
|
|
parse_semi (cfile);
|
1998-11-09 02:46:58 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DENY:
|
|
|
|
permit_head = &pool -> prohibit_list;
|
|
|
|
goto get_permit;
|
|
|
|
|
|
|
|
case RBRACE:
|
|
|
|
next_token (&val, cfile);
|
|
|
|
done = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
1999-02-25 23:30:43 +00:00
|
|
|
declaration = parse_statement (cfile, pool -> group,
|
|
|
|
POOL_DECL,
|
|
|
|
(struct host_decl *)0,
|
|
|
|
declaration);
|
1998-11-09 02:46:58 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
1997-02-22 08:41:01 +00:00
|
|
|
/* allow-deny-keyword :== BOOTP
|
|
|
|
| BOOTING
|
|
|
|
| DYNAMIC_BOOTP
|
|
|
|
| UNKNOWN_CLIENTS */
|
|
|
|
|
1998-11-06 00:16:52 +00:00
|
|
|
int parse_allow_deny (oc, cfile, flag)
|
|
|
|
struct option_cache **oc;
|
1997-02-22 08:41:01 +00:00
|
|
|
FILE *cfile;
|
|
|
|
int flag;
|
|
|
|
{
|
1998-11-06 00:16:52 +00:00
|
|
|
enum dhcp_token token;
|
1997-02-22 08:41:01 +00:00
|
|
|
char *val;
|
1999-03-16 06:37:55 +00:00
|
|
|
unsigned char rf = flag;
|
1998-11-06 00:16:52 +00:00
|
|
|
struct expression *data = (struct expression *)0;
|
|
|
|
int status;
|
|
|
|
|
|
|
|
if (!make_const_data (&data, &rf, 1, 0, 1))
|
|
|
|
return 0;
|
1997-02-22 08:41:01 +00:00
|
|
|
|
|
|
|
token = next_token (&val, cfile);
|
|
|
|
switch (token) {
|
|
|
|
case BOOTP:
|
1998-11-06 00:16:52 +00:00
|
|
|
status = option_cache (oc, (struct data_string *)0, data,
|
|
|
|
&server_options [SV_ALLOW_BOOTP]);
|
1997-02-22 08:41:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BOOTING:
|
1998-11-06 00:16:52 +00:00
|
|
|
status = option_cache (oc, (struct data_string *)0, data,
|
|
|
|
&server_options [SV_ALLOW_BOOTING]);
|
1997-02-22 08:41:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DYNAMIC_BOOTP:
|
1998-11-06 00:16:52 +00:00
|
|
|
status = option_cache (oc, (struct data_string *)0, data,
|
|
|
|
&server_options [SV_DYNAMIC_BOOTP]);
|
1997-02-22 08:41:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UNKNOWN_CLIENTS:
|
1998-11-06 00:16:52 +00:00
|
|
|
status = (option_cache
|
|
|
|
(oc, (struct data_string *)0, data,
|
|
|
|
&server_options [SV_BOOT_UNKNOWN_CLIENTS]));
|
1997-02-22 08:41:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
parse_warn ("expecting allow/deny key");
|
|
|
|
skip_to_semi (cfile);
|
1998-11-06 00:16:52 +00:00
|
|
|
return 0;
|
1997-02-22 08:41:01 +00:00
|
|
|
}
|
|
|
|
parse_semi (cfile);
|
1998-11-06 00:16:52 +00:00
|
|
|
return status;
|
1997-02-22 08:41:01 +00:00
|
|
|
}
|
|
|
|
|
1996-08-28 01:28:27 +00:00
|
|
|
/* boolean :== ON SEMI | OFF SEMI | TRUE SEMI | FALSE SEMI */
|
|
|
|
|
|
|
|
int parse_boolean (cfile)
|
|
|
|
FILE *cfile;
|
|
|
|
{
|
1998-11-06 00:16:52 +00:00
|
|
|
enum dhcp_token token;
|
1996-08-28 01:28:27 +00:00
|
|
|
char *val;
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
token = next_token (&val, cfile);
|
|
|
|
if (!strcasecmp (val, "true")
|
|
|
|
|| !strcasecmp (val, "on"))
|
1996-09-13 18:58:20 +00:00
|
|
|
rv = 1;
|
1996-08-28 01:28:27 +00:00
|
|
|
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;
|
|
|
|
{
|
1998-11-06 00:16:52 +00:00
|
|
|
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
|
|
|
|
1996-08-29 09:14:39 +00:00
|
|
|
/* host-declaration :== hostname RBRACE parameters declarations LBRACE */
|
1995-11-29 07:40:04 +00:00
|
|
|
|
1996-08-29 09:14:39 +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;
|
1998-11-06 00:16:52 +00:00
|
|
|
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;
|
1996-08-29 09:14:39 +00:00
|
|
|
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),
|
1996-08-29 09:14:39 +00:00
|
|
|
"parse_host_declaration");
|
1996-08-27 09:40:17 +00:00
|
|
|
if (!host)
|
1999-02-24 17:56:53 +00:00
|
|
|
log_fatal ("can't allocate host decl struct %s.", name);
|
1996-08-27 09:40:17 +00:00
|
|
|
|
|
|
|
host -> name = name;
|
1996-08-29 09:14:39 +00:00
|
|
|
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;
|
|
|
|
}
|
1996-08-28 01:28:27 +00:00
|
|
|
if (token == EOF) {
|
|
|
|
token = next_token (&val, cfile);
|
|
|
|
parse_warn ("unexpected end of file");
|
|
|
|
break;
|
|
|
|
}
|
1996-08-29 09:14:39 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
1996-08-29 09:14:39 +00:00
|
|
|
/* class-declaration :== STRING LBRACE parameters declarations RBRACE
|
1996-02-29 18:08:45 +00:00
|
|
|
*/
|
|
|
|
|
1998-11-11 07:59:53 +00:00
|
|
|
struct class *parse_class_declaration (cfile, group, type)
|
1996-02-29 18:08:45 +00:00
|
|
|
FILE *cfile;
|
1996-08-27 09:40:17 +00:00
|
|
|
struct group *group;
|
1996-02-29 18:08:45 +00:00
|
|
|
int type;
|
|
|
|
{
|
|
|
|
char *val;
|
1998-11-06 00:16:52 +00:00
|
|
|
enum dhcp_token token;
|
1998-11-06 02:58:17 +00:00
|
|
|
struct class *class = (struct class *)0, *pc;
|
1996-12-31 02:01:28 +00:00
|
|
|
int declaration = 0;
|
1998-06-25 03:51:59 +00:00
|
|
|
int lose;
|
|
|
|
struct data_string data;
|
|
|
|
char *name;
|
|
|
|
struct executable_statement *stmt = (struct executable_statement *)0;
|
|
|
|
struct expression *expr;
|
1998-11-06 02:58:17 +00:00
|
|
|
int new = 1;
|
1996-02-29 18:08:45 +00:00
|
|
|
|
|
|
|
token = next_token (&val, cfile);
|
|
|
|
if (token != STRING) {
|
|
|
|
parse_warn ("Expecting class name");
|
|
|
|
skip_to_semi (cfile);
|
1998-11-11 07:59:53 +00:00
|
|
|
return (struct class *)0;
|
1996-02-29 18:08:45 +00:00
|
|
|
}
|
|
|
|
|
1998-06-25 03:51:59 +00:00
|
|
|
/* 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;
|
1998-11-06 02:58:17 +00:00
|
|
|
new = 0;
|
1998-06-25 03:51:59 +00:00
|
|
|
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);
|
1998-11-11 07:59:53 +00:00
|
|
|
return (struct class *)0;
|
1998-06-25 03:51:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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
|
1999-03-16 00:56:02 +00:00
|
|
|
submatch expression of the implicit classes extracts the contents of
|
1998-06-25 03:51:59 +00:00
|
|
|
the vendor class or user class. */
|
|
|
|
if (type == 0 || type == 1) {
|
|
|
|
data.len = strlen (val);
|
1998-11-06 00:16:52 +00:00
|
|
|
data.buffer = (struct buffer *)0;
|
|
|
|
if (!buffer_allocate (&data.buffer,
|
|
|
|
data.len + 1, "parse_class_declaration"))
|
1999-02-24 17:56:53 +00:00
|
|
|
log_fatal ("no memoy for class name.");
|
1998-11-06 00:16:52 +00:00
|
|
|
data.data = &data.buffer -> data [0];
|
1998-06-25 03:51:59 +00:00
|
|
|
data.terminated = 1;
|
|
|
|
|
|
|
|
name = type ? "implicit-vendor-class" : "implicit-user-class";
|
|
|
|
} else if (type == 2) {
|
|
|
|
if (!(name = dmalloc (strlen (val) + 1,
|
|
|
|
"parse_class_declaration")))
|
1999-02-24 17:56:53 +00:00
|
|
|
log_fatal ("No memory for class name %s.", val);
|
1998-06-25 03:51:59 +00:00
|
|
|
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);
|
1998-11-06 00:16:52 +00:00
|
|
|
data.buffer = (struct buffer *)0;
|
|
|
|
if (!buffer_allocate (&data.buffer, data.len + 1,
|
|
|
|
"parse_class_declaration"))
|
1998-11-11 07:59:53 +00:00
|
|
|
return (struct class *)0;
|
1998-06-25 03:51:59 +00:00
|
|
|
data.terminated = 1;
|
1998-11-06 00:16:52 +00:00
|
|
|
data.data = &data.buffer -> data [0];
|
1999-03-16 06:37:55 +00:00
|
|
|
strcpy ((char *)data.data, val);
|
1998-06-25 03:51:59 +00:00
|
|
|
} else if (token == NUMBER_OR_NAME || token == NUMBER) {
|
1998-11-06 00:16:52 +00:00
|
|
|
memset (&data, 0, sizeof data);
|
|
|
|
if (!parse_cshl (&data, cfile))
|
1998-11-11 07:59:53 +00:00
|
|
|
return (struct class *)0;
|
1998-06-25 03:51:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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)
|
1999-02-24 17:56:53 +00:00
|
|
|
log_fatal ("No memory for class %s.", val);
|
1998-06-25 03:51:59 +00:00
|
|
|
memset (class, 0, sizeof *class);
|
|
|
|
if (pc) {
|
1998-11-11 07:59:53 +00:00
|
|
|
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)
|
1999-02-24 17:56:53 +00:00
|
|
|
log_fatal ("no memory for billed leases");
|
1998-11-11 07:59:53 +00:00
|
|
|
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 ();
|
1998-06-25 03:51:59 +00:00
|
|
|
add_hash (pc -> hash,
|
1998-11-11 07:59:53 +00:00
|
|
|
class -> hash_string.data,
|
|
|
|
class -> hash_string.len,
|
|
|
|
(unsigned char *)class);
|
1998-06-25 03:51:59 +00:00
|
|
|
} 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)
|
1999-02-24 17:56:53 +00:00
|
|
|
log_fatal ("no memory for class statement.");
|
1998-06-25 03:51:59 +00:00
|
|
|
memset (stmt, 0, sizeof *stmt);
|
|
|
|
stmt -> op = supersede_option_statement;
|
1998-11-06 00:16:52 +00:00
|
|
|
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];
|
|
|
|
}
|
1998-06-25 03:51:59 +00:00
|
|
|
class -> statements = stmt;
|
|
|
|
}
|
1998-11-06 02:58:17 +00:00
|
|
|
|
|
|
|
/* Save the name, if there is one. */
|
|
|
|
class -> name = name;
|
1998-06-25 03:51:59 +00:00
|
|
|
}
|
1996-08-27 09:40:17 +00:00
|
|
|
|
1998-11-11 07:59:53 +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))
|
1998-11-11 07:59:53 +00:00
|
|
|
return (struct class *)0;
|
1996-02-29 18:08:45 +00:00
|
|
|
|
|
|
|
do {
|
|
|
|
token = peek_token (&val, cfile);
|
1996-08-27 09:40:17 +00:00
|
|
|
if (token == RBRACE) {
|
1996-02-29 18:08:45 +00:00
|
|
|
token = next_token (&val, cfile);
|
|
|
|
break;
|
1996-08-28 01:28:27 +00:00
|
|
|
} else if (token == EOF) {
|
|
|
|
token = next_token (&val, cfile);
|
|
|
|
parse_warn ("unexpected end of file");
|
|
|
|
break;
|
1998-06-25 03:51:59 +00:00
|
|
|
} 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);
|
1999-03-16 00:56:02 +00:00
|
|
|
if (token != IF)
|
|
|
|
goto submatch;
|
1998-11-06 00:16:52 +00:00
|
|
|
parse_boolean_expression (&class -> expr, cfile,
|
|
|
|
&lose);
|
1998-06-25 03:51:59 +00:00
|
|
|
if (lose)
|
|
|
|
break;
|
1998-11-06 00:16:52 +00:00
|
|
|
#if defined (DEBUG_EXPRESSION_PARSE)
|
|
|
|
print_expression ("class match", class -> expr);
|
|
|
|
#endif
|
1998-11-06 02:58:17 +00:00
|
|
|
parse_semi (cfile);
|
1998-06-25 03:51:59 +00:00
|
|
|
} else if (token == SPAWN) {
|
|
|
|
if (pc) {
|
|
|
|
parse_warn ("invalid spawn in subclass.");
|
|
|
|
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;
|
|
|
|
}
|
1999-03-16 00:56:02 +00:00
|
|
|
class -> spawning = 1;
|
|
|
|
submatch:
|
|
|
|
if (class -> submatch) {
|
|
|
|
parse_warn ("can't override existing %s.",
|
|
|
|
"submatch/spawn");
|
|
|
|
skip_to_semi (cfile);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
parse_data_expression (&class -> submatch,
|
|
|
|
cfile, &lose);
|
1998-06-25 03:51:59 +00:00
|
|
|
if (lose)
|
|
|
|
break;
|
1998-11-06 00:16:52 +00:00
|
|
|
#if defined (DEBUG_EXPRESSION_PARSE)
|
1999-03-16 00:56:02 +00:00
|
|
|
print_expression ("class submatch",
|
|
|
|
class -> submatch);
|
1998-11-06 00:16:52 +00:00
|
|
|
#endif
|
1998-11-06 02:58:17 +00:00
|
|
|
parse_semi (cfile);
|
1998-11-11 07:59:53 +00:00
|
|
|
} 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)
|
1999-02-24 17:56:53 +00:00
|
|
|
log_fatal ("no memory for billed leases.");
|
1998-11-11 07:59:53 +00:00
|
|
|
memset (class -> billed_leases, 0,
|
|
|
|
(class -> lease_limit *
|
|
|
|
sizeof class -> billed_leases));
|
|
|
|
have_billing_classes = 1;
|
|
|
|
parse_semi (cfile);
|
1996-02-29 18:08:45 +00:00
|
|
|
} else {
|
1996-08-29 09:14:39 +00:00
|
|
|
declaration = parse_statement (cfile, class -> group,
|
|
|
|
CLASS_DECL,
|
|
|
|
(struct host_decl *)0,
|
|
|
|
declaration);
|
1996-02-29 18:08:45 +00:00
|
|
|
}
|
|
|
|
} while (1);
|
1998-11-06 02:58:17 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
1998-11-11 07:59:53 +00:00
|
|
|
return class;
|
1996-02-29 18:08:45 +00:00
|
|
|
}
|
|
|
|
|
1996-08-29 09:14:39 +00:00
|
|
|
/* shared-network-declaration :==
|
|
|
|
hostname LBRACE declarations parameters RBRACE */
|
1996-05-22 07:18:11 +00:00
|
|
|
|
1996-08-29 09:14:39 +00:00
|
|
|
void parse_shared_net_declaration (cfile, group)
|
1996-05-22 07:18:11 +00:00
|
|
|
FILE *cfile;
|
1996-08-27 09:40:17 +00:00
|
|
|
struct group *group;
|
1996-05-22 07:18:11 +00:00
|
|
|
{
|
|
|
|
char *val;
|
1998-11-06 00:16:52 +00:00
|
|
|
enum dhcp_token token;
|
1996-05-22 07:18:11 +00:00
|
|
|
struct shared_network *share;
|
|
|
|
char *name;
|
1996-08-29 09:14:39 +00:00
|
|
|
int declaration = 0;
|
1996-05-22 07:18:11 +00:00
|
|
|
|
1996-08-29 09:14:39 +00:00
|
|
|
share = new_shared_network ("parse_shared_net_declaration");
|
1996-05-22 07:18:11 +00:00
|
|
|
if (!share)
|
1999-02-24 17:56:53 +00:00
|
|
|
log_fatal ("No memory for shared subnet");
|
1998-11-09 02:46:58 +00:00
|
|
|
share -> pools = (struct pool *)0;
|
1996-05-22 07:18:11 +00:00
|
|
|
share -> next = (struct shared_network *)0;
|
1996-06-01 02:01:07 +00:00
|
|
|
share -> interface = (struct interface_info *)0;
|
1996-08-29 09:14:39 +00:00
|
|
|
share -> group = clone_group (group, "parse_shared_net_declaration");
|
1996-08-27 09:40:17 +00:00
|
|
|
share -> group -> shared_network = share;
|
1996-05-22 07:18:11 +00:00
|
|
|
|
|
|
|
/* 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)
|
1999-02-24 17:56:53 +00:00
|
|
|
log_fatal ("no memory for shared network name");
|
1996-08-27 09:40:17 +00:00
|
|
|
strcpy (name, val);
|
|
|
|
} else {
|
|
|
|
name = parse_host_name (cfile);
|
|
|
|
if (!name)
|
|
|
|
return;
|
1996-05-22 07:18:11 +00:00
|
|
|
}
|
|
|
|
share -> name = name;
|
|
|
|
|
1996-08-27 09:40:17 +00:00
|
|
|
if (!parse_lbrace (cfile))
|
|
|
|
return;
|
|
|
|
|
1996-05-22 07:18:11 +00:00
|
|
|
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) {
|
1996-05-22 07:18:11 +00:00
|
|
|
parse_warn ("empty shared-network decl");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
enter_shared_network (share);
|
|
|
|
return;
|
1996-08-28 01:28:27 +00:00
|
|
|
} else if (token == EOF) {
|
|
|
|
token = next_token (&val, cfile);
|
|
|
|
parse_warn ("unexpected end of file");
|
|
|
|
break;
|
1996-05-22 07:18:11 +00:00
|
|
|
}
|
1996-08-28 01:28:27 +00:00
|
|
|
|
1996-08-29 09:14:39 +00:00
|
|
|
declaration = parse_statement (cfile, share -> group,
|
|
|
|
SHARED_NET_DECL,
|
|
|
|
(struct host_decl *)0,
|
|
|
|
declaration);
|
1996-05-22 07:18:11 +00:00
|
|
|
} while (1);
|
|
|
|
}
|
|
|
|
|
1996-08-29 09:14:39 +00:00
|
|
|
/* subnet-declaration :==
|
|
|
|
net NETMASK netmask RBRACE parameters declarations LBRACE */
|
1996-02-21 15:16:18 +00:00
|
|
|
|
1996-08-29 09:14:39 +00:00
|
|
|
void parse_subnet_declaration (cfile, share)
|
1996-02-21 15:16:18 +00:00
|
|
|
FILE *cfile;
|
1996-05-22 07:18:11 +00:00
|
|
|
struct shared_network *share;
|
1996-02-21 15:16:18 +00:00
|
|
|
{
|
|
|
|
char *val;
|
1998-11-06 00:16:52 +00:00
|
|
|
enum dhcp_token token;
|
1999-02-14 19:08:51 +00:00
|
|
|
struct subnet *subnet, *t, *u;
|
1996-08-27 09:40:17 +00:00
|
|
|
struct iaddr iaddr;
|
1996-02-21 15:16:18 +00:00
|
|
|
unsigned char addr [4];
|
|
|
|
int len = sizeof addr;
|
1996-08-29 09:14:39 +00:00
|
|
|
int declaration = 0;
|
1996-02-21 15:16:18 +00:00
|
|
|
|
1996-08-29 09:14:39 +00:00
|
|
|
subnet = new_subnet ("parse_subnet_declaration");
|
1996-02-21 15:16:18 +00:00
|
|
|
if (!subnet)
|
1999-02-24 17:56:53 +00:00
|
|
|
log_fatal ("No memory for new subnet");
|
1996-05-22 07:18:11 +00:00
|
|
|
subnet -> shared_network = share;
|
1996-08-27 09:40:17 +00:00
|
|
|
subnet -> group = clone_group (share -> group,
|
1996-08-29 09:14:39 +00:00
|
|
|
"parse_subnet_declaration");
|
1996-08-27 09:40:17 +00:00
|
|
|
subnet -> group -> subnet = subnet;
|
1996-02-21 15:16:18 +00:00
|
|
|
|
|
|
|
/* 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;
|
1996-02-21 15:16:18 +00:00
|
|
|
|
|
|
|
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;
|
1996-02-21 15:16:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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;
|
1996-02-21 15:16:18 +00:00
|
|
|
|
|
|
|
enter_subnet (subnet);
|
|
|
|
|
1996-08-27 09:40:17 +00:00
|
|
|
if (!parse_lbrace (cfile))
|
|
|
|
return;
|
|
|
|
|
1996-02-21 15:16:18 +00:00
|
|
|
do {
|
|
|
|
token = peek_token (&val, cfile);
|
1996-08-27 09:40:17 +00:00
|
|
|
if (token == RBRACE) {
|
|
|
|
token = next_token (&val, cfile);
|
1996-02-21 15:16:18 +00:00
|
|
|
break;
|
1996-08-28 01:28:27 +00:00
|
|
|
} else if (token == EOF) {
|
|
|
|
token = next_token (&val, cfile);
|
|
|
|
parse_warn ("unexpected end of file");
|
|
|
|
break;
|
1996-08-27 09:40:17 +00:00
|
|
|
}
|
1996-08-29 09:14:39 +00:00
|
|
|
declaration = parse_statement (cfile, subnet -> group,
|
|
|
|
SUBNET_DECL,
|
|
|
|
(struct host_decl *)0,
|
|
|
|
declaration);
|
1996-02-21 15:16:18 +00:00
|
|
|
} while (1);
|
1996-05-22 07:18:11 +00:00
|
|
|
|
1996-08-30 23:39:37 +00:00
|
|
|
/* 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 {
|
1999-02-14 19:08:51 +00:00
|
|
|
u = (struct subnet *)0;
|
1996-08-27 09:40:17 +00:00
|
|
|
for (t = share -> subnets;
|
1999-02-14 19:08:51 +00:00
|
|
|
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;
|
|
|
|
}
|
1996-08-30 23:39:37 +00:00
|
|
|
t -> next_sibling = subnet;
|
1996-08-27 09:40:17 +00:00
|
|
|
}
|
1996-02-21 15:16:18 +00:00
|
|
|
}
|
|
|
|
|
1996-08-29 09:14:39 +00:00
|
|
|
/* group-declaration :== RBRACE parameters declarations LBRACE */
|
1996-08-27 09:40:17 +00:00
|
|
|
|
1996-08-29 09:14:39 +00:00
|
|
|
void parse_group_declaration (cfile, group)
|
1996-02-21 15:16:18 +00:00
|
|
|
FILE *cfile;
|
1996-08-27 09:40:17 +00:00
|
|
|
struct group *group;
|
1996-02-21 15:16:18 +00:00
|
|
|
{
|
|
|
|
char *val;
|
1998-11-06 00:16:52 +00:00
|
|
|
enum dhcp_token token;
|
1996-08-27 09:40:17 +00:00
|
|
|
struct group *g;
|
1996-08-29 09:14:39 +00:00
|
|
|
int declaration = 0;
|
1996-02-21 15:16:18 +00:00
|
|
|
|
1996-08-29 09:14:39 +00:00
|
|
|
g = clone_group (group, "parse_group_declaration");
|
1996-02-21 15:16:18 +00:00
|
|
|
|
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);
|
1996-08-28 01:28:27 +00:00
|
|
|
if (token == RBRACE) {
|
|
|
|
token = next_token (&val, cfile);
|
1996-08-27 09:40:17 +00:00
|
|
|
break;
|
1996-08-28 01:28:27 +00:00
|
|
|
} else if (token == EOF) {
|
|
|
|
token = next_token (&val, cfile);
|
|
|
|
parse_warn ("unexpected end of file");
|
|
|
|
break;
|
|
|
|
}
|
1996-08-29 09:14:39 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
1996-08-29 09:14:39 +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
|
|
|
|
1998-11-06 00:16:52 +00:00
|
|
|
int parse_fixed_addr_param (oc, cfile)
|
|
|
|
struct option_cache **oc;
|
1995-11-29 07:40:04 +00:00
|
|
|
FILE *cfile;
|
|
|
|
{
|
1996-05-22 07:18:11 +00:00
|
|
|
char *val;
|
1998-11-06 00:16:52 +00:00
|
|
|
enum dhcp_token token;
|
1998-06-25 03:51:59 +00:00
|
|
|
struct expression *expr = (struct expression *)0;
|
1998-11-06 00:16:52 +00:00
|
|
|
struct expression *tmp, *new;
|
|
|
|
int status;
|
1996-05-22 07:18:11 +00:00
|
|
|
|
|
|
|
do {
|
1998-11-06 00:16:52 +00:00
|
|
|
tmp = (struct expression *)0;
|
|
|
|
if (parse_ip_addr_or_hostname (&tmp, cfile, 1)) {
|
1998-11-06 00:31:08 +00:00
|
|
|
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;
|
1998-11-06 00:16:52 +00:00
|
|
|
} else {
|
|
|
|
if (expr)
|
|
|
|
expression_dereference
|
|
|
|
(&expr, "parse_fixed_addr_param");
|
|
|
|
return 0;
|
|
|
|
}
|
1996-05-22 07:18:11 +00:00
|
|
|
token = peek_token (&val, cfile);
|
1996-08-28 01:28:27 +00:00
|
|
|
if (token == COMMA)
|
1996-05-22 07:18:11 +00:00
|
|
|
token = next_token (&val, cfile);
|
|
|
|
} while (token == COMMA);
|
1996-08-27 09:40:17 +00:00
|
|
|
|
1998-11-06 00:16:52 +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
|
|
|
}
|
|
|
|
|
1996-08-28 01:28:27 +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,
|
1996-08-28 01:28:27 +00:00
|
|
|
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;
|
|
|
|
{
|
1996-02-06 20:25:56 +00:00
|
|
|
TIME rv;
|
|
|
|
|
1996-08-27 09:40:17 +00:00
|
|
|
rv = parse_date (cfile);
|
1996-02-06 20:25:56 +00:00
|
|
|
return rv;
|
1995-11-29 07:40:04 +00:00
|
|
|
}
|
|
|
|
|
1996-08-29 09:14:39 +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
|
1997-05-09 08:21:25 +00:00
|
|
|
| HOSTNAME hostname SEMI
|
|
|
|
| CLIENT_HOSTNAME hostname SEMI
|
1996-08-29 09:14:39 +00:00
|
|
|
| CLASS identifier SEMI
|
|
|
|
| DYNAMIC_BOOTP SEMI */
|
|
|
|
|
|
|
|
struct lease *parse_lease_declaration (cfile)
|
1995-11-29 07:40:04 +00:00
|
|
|
FILE *cfile;
|
|
|
|
{
|
|
|
|
char *val;
|
1998-11-06 00:16:52 +00:00
|
|
|
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;
|
|
|
|
|
1996-05-17 23:12:09 +00:00
|
|
|
/* 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;
|
1996-02-06 20:25:56 +00:00
|
|
|
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;
|
1996-08-28 01:28:27 +00:00
|
|
|
else if (token == EOF) {
|
|
|
|
parse_warn ("unexpected end of file");
|
|
|
|
break;
|
|
|
|
}
|
1998-06-25 03:51:59 +00:00
|
|
|
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;
|
1996-05-25 18:37:01 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
/*NOTREACHED*/
|
|
|
|
seenbit = 0;
|
|
|
|
break;
|
1995-11-29 07:40:04 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch (token) {
|
|
|
|
/* Colon-seperated hexadecimal octets... */
|
|
|
|
case UID:
|
|
|
|
seenbit = 8;
|
1996-05-17 23:12:09 +00:00
|
|
|
token = peek_token (&val, cfile);
|
|
|
|
if (token == STRING) {
|
1996-05-19 23:57:22 +00:00
|
|
|
token = next_token (&val, cfile);
|
1996-05-17 23:12:09 +00:00
|
|
|
lease.uid_len = strlen (val) + 1;
|
1996-05-23 22:20:26 +00:00
|
|
|
lease.uid = (unsigned char *)
|
|
|
|
malloc (lease.uid_len);
|
1996-09-09 07:04:29 +00:00
|
|
|
if (!lease.uid) {
|
1999-02-24 17:56:53 +00:00
|
|
|
log_error ("no space for uid");
|
1996-09-09 07:04:29 +00:00
|
|
|
return (struct lease *)0;
|
|
|
|
}
|
1996-05-23 22:20:26 +00:00
|
|
|
memcpy (lease.uid, val, lease.uid_len);
|
1996-05-17 23:12:09 +00:00
|
|
|
} else {
|
1996-05-23 22:20:26 +00:00
|
|
|
lease.uid_len = 0;
|
|
|
|
lease.uid = parse_numeric_aggregate
|
1996-08-27 09:40:17 +00:00
|
|
|
(cfile, (unsigned char *)0,
|
1996-05-17 23:12:09 +00:00
|
|
|
&lease.uid_len, ':', 16, 8);
|
1996-09-09 07:04:29 +00:00
|
|
|
if (!lease.uid) {
|
1999-02-24 17:56:53 +00:00
|
|
|
log_error ("no space for uid");
|
1996-08-27 09:40:17 +00:00
|
|
|
return (struct lease *)0;
|
1996-09-09 07:04:29 +00:00
|
|
|
}
|
1996-05-17 23:12:09 +00:00
|
|
|
if (lease.uid_len == 0) {
|
1996-09-09 07:04:29 +00:00
|
|
|
lease.uid = (unsigned char *)0;
|
1996-05-17 23:12:09 +00:00
|
|
|
parse_warn ("zero-length uid");
|
1996-05-19 23:57:22 +00:00
|
|
|
seenbit = 0;
|
1996-05-17 23:12:09 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1995-11-29 07:40:04 +00:00
|
|
|
if (!lease.uid) {
|
1999-02-24 17:56:53 +00:00
|
|
|
log_fatal ("No memory for lease uid");
|
1995-11-29 07:40:04 +00:00
|
|
|
}
|
|
|
|
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;
|
1996-08-29 09:14:39 +00:00
|
|
|
parse_hardware_param (cfile,
|
1996-08-27 09:40:17 +00:00
|
|
|
&lease.hardware_addr);
|
1995-11-29 07:40:04 +00:00
|
|
|
break;
|
|
|
|
|
1996-05-22 07:18:11 +00:00
|
|
|
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;
|
|
|
|
|
1997-05-09 08:21:25 +00:00
|
|
|
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);
|
1997-05-09 08:21:25 +00:00
|
|
|
if (!lease.hostname) {
|
|
|
|
seenbit = 0;
|
|
|
|
return (struct lease *)0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CLIENT_HOSTNAME:
|
1997-06-03 01:06:10 +00:00
|
|
|
seenbit = 1024;
|
1997-06-10 05:49:15 +00:00
|
|
|
token = peek_token (&val, cfile);
|
|
|
|
if (token == STRING)
|
|
|
|
lease.client_hostname =
|
|
|
|
parse_string (cfile);
|
|
|
|
else
|
|
|
|
lease.client_hostname =
|
|
|
|
parse_host_name (cfile);
|
1997-05-09 08:21:25 +00:00
|
|
|
break;
|
|
|
|
|
1998-11-11 07:59:53 +00:00
|
|
|
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);
|
1996-05-25 18:37:01 +00:00
|
|
|
seenbit = 0;
|
1996-08-27 09:40:17 +00:00
|
|
|
return (struct lease *)0;
|
|
|
|
}
|
|
|
|
|
1998-11-11 07:59:53 +00:00
|
|
|
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) {
|
1996-08-29 09:14:39 +00:00
|
|
|
parse_warn ("Too many %s parameters in lease %s\n",
|
1996-02-06 20:25:56 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
1996-08-29 09:14:39 +00:00
|
|
|
/* 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;
|
1998-11-06 00:16:52 +00:00
|
|
|
enum dhcp_token token;
|
1996-02-06 20:25:56 +00:00
|
|
|
char *val;
|
1996-05-22 07:18:11 +00:00
|
|
|
int dynamic = 0;
|
1998-11-09 02:46:58 +00:00
|
|
|
struct subnet *subnet;
|
|
|
|
struct shared_network *share;
|
|
|
|
struct pool *p;
|
1996-05-22 07:18:11 +00:00
|
|
|
|
|
|
|
if ((token = peek_token (&val, cfile)) == DYNAMIC_BOOTP) {
|
1996-08-28 01:28:27 +00:00
|
|
|
token = next_token (&val, cfile);
|
1998-06-25 03:51:59 +00:00
|
|
|
dynamic = 1;
|
1996-05-22 07:18:11 +00:00
|
|
|
}
|
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;
|
1996-02-06 20:25:56 +00:00
|
|
|
memcpy (low.iabuf, addr, len);
|
|
|
|
low.len = len;
|
1995-11-29 07:40:04 +00:00
|
|
|
|
1996-08-29 09:14:39 +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... */
|
1996-08-29 09:14:39 +00:00
|
|
|
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)
|
1999-02-24 17:56:53 +00:00
|
|
|
log_fatal ("no memory for ad-hoc pool.");
|
1998-11-09 02:46:58 +00:00
|
|
|
if (dynamic) {
|
|
|
|
pool -> permit_list =
|
|
|
|
new_permit ("parse_address_range");
|
|
|
|
if (!pool -> permit_list)
|
1999-02-24 17:56:53 +00:00
|
|
|
log_fatal ("no memory for ad-hoc permit.");
|
1998-11-09 02:46:58 +00:00
|
|
|
pool -> permit_list -> type =
|
|
|
|
permit_dynamic_bootp_clients;
|
|
|
|
}
|
|
|
|
if (share -> pools)
|
|
|
|
last -> next = pool;
|
|
|
|
else
|
|
|
|
share -> pools = pool;
|
1999-03-09 23:43:36 +00:00
|
|
|
pool -> shared_network = share;
|
|
|
|
pool -> group = clone_group (share -> group,
|
|
|
|
"parse_address_range");
|
1998-11-09 02:46:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|