summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.sbin/dhcpd/confpars.c758
1 files changed, 373 insertions, 385 deletions
diff --git a/usr.sbin/dhcpd/confpars.c b/usr.sbin/dhcpd/confpars.c
index 0e1b5a02452..1b2eb466d8c 100644
--- a/usr.sbin/dhcpd/confpars.c
+++ b/usr.sbin/dhcpd/confpars.c
@@ -49,17 +49,18 @@ static time_t parsed_time;
parameters :== <nil> | parameter | parameters parameter
declarations :== <nil> | declaration | declarations declaration */
-int readconf ()
+int
+readconf(void)
{
FILE *cfile;
char *val;
int token;
int declaration = 0;
- new_parse (path_dhcpd_conf);
+ new_parse(path_dhcpd_conf);
/* Set up the initial dhcp option universe. */
- initialize_universes ();
+ initialize_universes();
/* Set up the global defaults... */
root_group.default_lease_time = 43200; /* 12 hours. */
@@ -70,20 +71,19 @@ int readconf ()
root_group.allow_booting = 1;
root_group.authoritative = 1;
- if ((cfile = fopen (path_dhcpd_conf, "r")) == NULL) {
- error ("Can't open %s: %m", path_dhcpd_conf);
- }
+ if ((cfile = fopen(path_dhcpd_conf, "r")) == NULL)
+ error("Can't open %s: %m", path_dhcpd_conf);
do {
- token = peek_token (&val, cfile);
+ token = peek_token(&val, cfile);
if (token == EOF)
break;
- declaration = parse_statement (cfile, &root_group,
+ declaration = parse_statement(cfile, &root_group,
ROOT_GROUP,
- (struct host_decl *)0,
+ NULL,
declaration);
} while (1);
- token = next_token (&val, cfile); /* Clear the peek buffer */
+ token = next_token(&val, cfile); /* Clear the peek buffer */
fclose(cfile);
return !warnings_occurred;
@@ -92,15 +92,16 @@ int readconf ()
/* lease-file :== lease-declarations EOF
lease-statments :== <nil>
| lease-declaration
- | lease-declarations lease-declaration */
-
-void read_leases ()
+ | lease-declarations lease-declaration
+ */
+void
+read_leases(void)
{
FILE *cfile;
char *val;
int token;
- new_parse (path_dhcpd_db);
+ new_parse(path_dhcpd_db);
/* Open the lease file. If we can't open it, fail. The reason
for this is that although on initial startup, the absence of
@@ -111,27 +112,27 @@ void read_leases ()
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. */
- if ((cfile = fopen (path_dhcpd_db, "r")) == NULL) {
- warn ("Can't open lease database %s: %m -- %s",
+ if ((cfile = fopen(path_dhcpd_db, "r")) == NULL) {
+ warn("Can't open lease database %s: %m -- %s",
path_dhcpd_db,
"check for failed database rewrite attempt!");
- warn ("Please read the dhcpd.leases manual page if you.");
- error ("don't know what to do about this."); }
+ warn("Please read the dhcpd.leases manual page if you.");
+ error("don't know what to do about this."); }
do {
- token = next_token (&val, cfile);
+ token = next_token(&val, cfile);
if (token == EOF)
break;
if (token != LEASE) {
- warn ("Corrupt lease file - possible data loss!");
- skip_to_semi (cfile);
+ warn("Corrupt lease file - possible data loss!");
+ skip_to_semi(cfile);
} else {
struct lease *lease;
- lease = parse_lease_declaration (cfile);
+ lease = parse_lease_declaration(cfile);
if (lease)
- enter_lease (lease);
+ enter_lease(lease);
else
- parse_warn ("possibly corrupt lease file");
+ parse_warn("possibly corrupt lease file");
}
} while (1);
@@ -168,7 +169,7 @@ void read_leases ()
| USER_CLASS class-declaration
| RANGE address-range-declaration */
-int parse_statement (cfile, group, type, host_decl, declaration)
+int parse_statement(cfile, group, type, host_decl, declaration)
FILE *cfile;
struct group *group;
int type;
@@ -183,53 +184,53 @@ int parse_statement (cfile, group, type, host_decl, declaration)
struct tree_cache *cache;
struct hardware hardware;
- switch (next_token (&val, cfile)) {
- case HOST:
+ switch (next_token(&val, cfile)) {
+ case HOST:
if (type != HOST_DECL)
- parse_host_declaration (cfile, group);
+ parse_host_declaration(cfile, group);
else {
- parse_warn ("host declarations not allowed here.");
- skip_to_semi (cfile);
+ parse_warn("host declarations not allowed here.");
+ skip_to_semi(cfile);
}
return 1;
- case GROUP:
+ case GROUP:
if (type != HOST_DECL)
- parse_group_declaration (cfile, group);
+ parse_group_declaration(cfile, group);
else {
- parse_warn ("host declarations not allowed here.");
- skip_to_semi (cfile);
+ parse_warn("host declarations not allowed here.");
+ skip_to_semi(cfile);
}
return 1;
- case TIMESTAMP:
- parsed_time = parse_timestamp (cfile);
+ case TIMESTAMP:
+ parsed_time = parse_timestamp(cfile);
break;
- case SHARED_NETWORK:
+ case SHARED_NETWORK:
if (type == SHARED_NET_DECL ||
type == HOST_DECL ||
type == SUBNET_DECL) {
- parse_warn ("shared-network parameters not %s.",
+ parse_warn("shared-network parameters not %s.",
"allowed here");
- skip_to_semi (cfile);
+ skip_to_semi(cfile);
break;
}
- parse_shared_net_declaration (cfile, group);
+ parse_shared_net_declaration(cfile, group);
return 1;
- case SUBNET:
+ case SUBNET:
if (type == HOST_DECL || type == SUBNET_DECL) {
- parse_warn ("subnet declarations not allowed here.");
- skip_to_semi (cfile);
+ parse_warn("subnet declarations not allowed here.");
+ skip_to_semi(cfile);
return 1;
}
/* If we're in a subnet declaration, just do the parse. */
if (group->shared_network) {
- parse_subnet_declaration (cfile,
- group->shared_network);
+ parse_subnet_declaration(cfile,
+ group->shared_network);
break;
}
@@ -238,11 +239,11 @@ int parse_statement (cfile, group, type, host_decl, declaration)
share = new_shared_network ("parse_statement");
if (!share)
- error ("No memory for shared subnet");
+ error("No memory for shared subnet");
share->group = clone_group (group, "parse_statement:subnet");
share->group->shared_network = share;
- parse_subnet_declaration (cfile, share);
+ parse_subnet_declaration(cfile, share);
/* share->subnets is the subnet we just parsed. */
if (share->subnets) {
@@ -251,10 +252,10 @@ int parse_statement (cfile, group, type, host_decl, declaration)
/* Make the shared network name from network number. */
n = piaddr (share->subnets->net);
- t = malloc (strlen (n) + 1);
+ t = malloc(strlen(n) + 1);
if (!t)
- error ("no memory for subnet name");
- strlcpy (t, n, (strlen(n) + 1));
+ error("no memory for subnet name");
+ strlcpy(t, n, (strlen(n) + 1));
share->name = t;
/* Copy the authoritative parameter from the subnet,
@@ -265,166 +266,166 @@ int parse_statement (cfile, group, type, host_decl, declaration)
}
return 1;
- case VENDOR_CLASS:
- parse_class_declaration (cfile, group, 0);
+ case VENDOR_CLASS:
+ parse_class_declaration(cfile, group, 0);
return 1;
- case USER_CLASS:
- parse_class_declaration (cfile, group, 1);
+ case USER_CLASS:
+ parse_class_declaration(cfile, group, 1);
return 1;
- case DEFAULT_LEASE_TIME:
- parse_lease_time (cfile, &group->default_lease_time);
+ case DEFAULT_LEASE_TIME:
+ parse_lease_time(cfile, &group->default_lease_time);
break;
- case MAX_LEASE_TIME:
- parse_lease_time (cfile, &group->max_lease_time);
+ case MAX_LEASE_TIME:
+ parse_lease_time(cfile, &group->max_lease_time);
break;
- case DYNAMIC_BOOTP_LEASE_CUTOFF:
- group->bootp_lease_cutoff = parse_date (cfile);
+ case DYNAMIC_BOOTP_LEASE_CUTOFF:
+ group->bootp_lease_cutoff = parse_date(cfile);
break;
- case DYNAMIC_BOOTP_LEASE_LENGTH:
- parse_lease_time (cfile, &group->bootp_lease_length);
+ case DYNAMIC_BOOTP_LEASE_LENGTH:
+ parse_lease_time(cfile, &group->bootp_lease_length);
break;
- case BOOT_UNKNOWN_CLIENTS:
+ case BOOT_UNKNOWN_CLIENTS:
if (type == HOST_DECL)
- parse_warn ("boot-unknown-clients not allowed here.");
- group->boot_unknown_clients = parse_boolean (cfile);
+ parse_warn("boot-unknown-clients not allowed here.");
+ group->boot_unknown_clients = parse_boolean(cfile);
break;
- case ONE_LEASE_PER_CLIENT:
+ case ONE_LEASE_PER_CLIENT:
if (type == HOST_DECL)
- parse_warn ("one-lease-per-client not allowed here.");
- group->one_lease_per_client = parse_boolean (cfile);
+ parse_warn("one-lease-per-client not allowed here.");
+ group->one_lease_per_client = parse_boolean(cfile);
break;
- case GET_LEASE_HOSTNAMES:
+ case GET_LEASE_HOSTNAMES:
if (type == HOST_DECL)
- parse_warn ("get-lease-hostnames not allowed here.");
- group->get_lease_hostnames = parse_boolean (cfile);
+ parse_warn("get-lease-hostnames not allowed here.");
+ group->get_lease_hostnames = parse_boolean(cfile);
break;
- case ALWAYS_REPLY_RFC1048:
- group->always_reply_rfc1048 = parse_boolean (cfile);
+ case ALWAYS_REPLY_RFC1048:
+ group->always_reply_rfc1048 = parse_boolean(cfile);
break;
- case USE_HOST_DECL_NAMES:
+ case USE_HOST_DECL_NAMES:
if (type == HOST_DECL)
- parse_warn ("use-host-decl-names not allowed here.");
- group->use_host_decl_names = parse_boolean (cfile);
+ parse_warn("use-host-decl-names not allowed here.");
+ group->use_host_decl_names = parse_boolean(cfile);
break;
- case USE_LEASE_ADDR_FOR_DEFAULT_ROUTE:
+ case USE_LEASE_ADDR_FOR_DEFAULT_ROUTE:
group->use_lease_addr_for_default_route =
- parse_boolean (cfile);
+ parse_boolean(cfile);
break;
- case TOKEN_NOT:
- token = next_token (&val, cfile);
+ case TOKEN_NOT:
+ token = next_token(&val, cfile);
switch (token) {
- case AUTHORITATIVE:
+ case AUTHORITATIVE:
if (type == HOST_DECL)
- parse_warn ("authority makes no sense here.");
+ parse_warn("authority makes no sense here.");
group->authoritative = 0;
- parse_semi (cfile);
+ parse_semi(cfile);
break;
- default:
- parse_warn ("expecting assertion");
- skip_to_semi (cfile);
+ default:
+ parse_warn("expecting assertion");
+ skip_to_semi(cfile);
break;
}
break;
- case AUTHORITATIVE:
+ case AUTHORITATIVE:
if (type == HOST_DECL)
- parse_warn ("authority makes no sense here.");
+ parse_warn("authority makes no sense here.");
group->authoritative = 1;
- parse_semi (cfile);
+ parse_semi(cfile);
break;
- case NEXT_SERVER:
- tree = parse_ip_addr_or_hostname (cfile, 0);
+ case NEXT_SERVER:
+ tree = parse_ip_addr_or_hostname(cfile, 0);
if (!tree)
break;
cache = tree_cache (tree);
if (!tree_evaluate (cache))
- error ("next-server is not known");
+ error("next-server is not known");
group->next_server.len = 4;
- memcpy (group->next_server.iabuf,
+ memcpy(group->next_server.iabuf,
cache->value, group->next_server.len);
- parse_semi (cfile);
+ parse_semi(cfile);
break;
- case OPTION:
- parse_option_param (cfile, group);
+ case OPTION:
+ parse_option_param(cfile, group);
break;
- case SERVER_IDENTIFIER:
- tree = parse_ip_addr_or_hostname (cfile, 0);
+ case SERVER_IDENTIFIER:
+ tree = parse_ip_addr_or_hostname(cfile, 0);
if (!tree)
return declaration;
group->options[DHO_DHCP_SERVER_IDENTIFIER] =
tree_cache (tree);
- token = next_token (&val, cfile);
+ token = next_token(&val, cfile);
break;
- case FILENAME:
- group->filename = parse_string (cfile);
+ case FILENAME:
+ group->filename = parse_string(cfile);
break;
- case SERVER_NAME:
- group->server_name = parse_string (cfile);
+ case SERVER_NAME:
+ group->server_name = parse_string(cfile);
break;
- case HARDWARE:
- parse_hardware_param (cfile, &hardware);
+ case HARDWARE:
+ parse_hardware_param(cfile, &hardware);
if (host_decl)
host_decl->interface = hardware;
else
- parse_warn ("hardware address parameter %s",
+ parse_warn("hardware address parameter %s",
"not allowed here.");
break;
- case FIXED_ADDR:
- cache = parse_fixed_addr_param (cfile);
+ case FIXED_ADDR:
+ cache = parse_fixed_addr_param(cfile);
if (host_decl)
host_decl->fixed_addr = cache;
else
- parse_warn ("fixed-address parameter not %s",
+ parse_warn("fixed-address parameter not %s",
"allowed here.");
break;
- case RANGE:
+ case RANGE:
if (type != SUBNET_DECL || !group->subnet) {
- parse_warn ("range declaration not allowed here.");
- skip_to_semi (cfile);
+ parse_warn("range declaration not allowed here.");
+ skip_to_semi(cfile);
return declaration;
}
- parse_address_range (cfile, group->subnet);
+ parse_address_range(cfile, group->subnet);
return declaration;
- case ALLOW:
- parse_allow_deny (cfile, group, 1);
+ case ALLOW:
+ parse_allow_deny(cfile, group, 1);
break;
- case DENY:
- parse_allow_deny (cfile, group, 0);
+ case DENY:
+ parse_allow_deny(cfile, group, 0);
break;
- default:
+ default:
if (declaration)
- parse_warn ("expecting a declaration.");
+ parse_warn("expecting a declaration.");
else
- parse_warn ("expecting a parameter or declaration.");
- skip_to_semi (cfile);
+ parse_warn("expecting a parameter or declaration.");
+ skip_to_semi(cfile);
return declaration;
}
if (declaration) {
- parse_warn ("parameters not allowed after first declaration.");
+ parse_warn("parameters not allowed after first declaration.");
return 1;
}
@@ -436,7 +437,7 @@ int parse_statement (cfile, group, type, host_decl, declaration)
| DYNAMIC_BOOTP
| UNKNOWN_CLIENTS */
-void parse_allow_deny (cfile, group, flag)
+void parse_allow_deny(cfile, group, flag)
FILE *cfile;
struct group *group;
int flag;
@@ -444,42 +445,42 @@ void parse_allow_deny (cfile, group, flag)
int token;
char *val;
- token = next_token (&val, cfile);
+ token = next_token(&val, cfile);
switch (token) {
- case BOOTP:
+ case BOOTP:
group->allow_bootp = flag;
break;
- case BOOTING:
+ case BOOTING:
group->allow_booting = flag;
break;
- case DYNAMIC_BOOTP:
+ case DYNAMIC_BOOTP:
group->dynamic_bootp = flag;
break;
- case UNKNOWN_CLIENTS:
+ case UNKNOWN_CLIENTS:
group->boot_unknown_clients = flag;
break;
- default:
- parse_warn ("expecting allow/deny key");
- skip_to_semi (cfile);
+ default:
+ parse_warn("expecting allow/deny key");
+ skip_to_semi(cfile);
return;
}
- parse_semi (cfile);
+ parse_semi(cfile);
}
/* boolean :== ON SEMI | OFF SEMI | TRUE SEMI | FALSE SEMI */
-int parse_boolean (cfile)
+int parse_boolean(cfile)
FILE *cfile;
{
int token;
char *val;
int rv;
- token = next_token (&val, cfile);
+ token = next_token(&val, cfile);
if (!strcasecmp (val, "true")
|| !strcasecmp (val, "on"))
rv = 1;
@@ -487,27 +488,27 @@ int parse_boolean (cfile)
|| !strcasecmp (val, "off"))
rv = 0;
else {
- parse_warn ("boolean value (true/false/on/off) expected");
- skip_to_semi (cfile);
+ parse_warn("boolean value (true/false/on/off) expected");
+ skip_to_semi(cfile);
return 0;
}
- parse_semi (cfile);
+ parse_semi(cfile);
return rv;
}
/* 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;
+int
+parse_lbrace(FILE *cfile)
{
int token;
char *val;
- token = next_token (&val, cfile);
+ token = next_token(&val, cfile);
if (token != LBRACE) {
- parse_warn ("expecting left brace.");
- skip_to_semi (cfile);
+ parse_warn("expecting left brace.");
+ skip_to_semi(cfile);
return 0;
}
return 1;
@@ -516,44 +517,43 @@ int parse_lbrace (cfile)
/* host-declaration :== hostname RBRACE parameters declarations LBRACE */
-void parse_host_declaration (cfile, group)
+void parse_host_declaration(cfile, group)
FILE *cfile;
struct group *group;
{
char *val;
int token;
struct host_decl *host;
- char *name = parse_host_name (cfile);
+ char *name = parse_host_name(cfile);
int declaration = 0;
if (!name)
return;
- host = (struct host_decl *)dmalloc (sizeof (struct host_decl),
- "parse_host_declaration");
+ host = (struct host_decl *)dmalloc(sizeof (struct host_decl),
+ "parse_host_declaration");
if (!host)
- error ("can't allocate host decl struct %s.", name);
+ error("can't allocate host decl struct %s.", name);
host->name = name;
host->group = clone_group (group, "parse_host_declaration");
- if (!parse_lbrace (cfile))
+ if (!parse_lbrace(cfile))
return;
do {
- token = peek_token (&val, cfile);
+ token = peek_token(&val, cfile);
if (token == RBRACE) {
- token = next_token (&val, cfile);
+ token = next_token(&val, cfile);
break;
}
if (token == EOF) {
- token = next_token (&val, cfile);
- parse_warn ("unexpected end of file");
+ token = next_token(&val, cfile);
+ parse_warn("unexpected end of file");
break;
}
- declaration = parse_statement (cfile, host->group,
- HOST_DECL, host,
- declaration);
+ declaration = parse_statement(cfile, host->group,
+ HOST_DECL, host, declaration);
} while (1);
if (!host->group->options[DHO_HOST_NAME] &&
@@ -561,9 +561,9 @@ void parse_host_declaration (cfile, group)
host->group->options[DHO_HOST_NAME] =
new_tree_cache ("parse_host_declaration");
if (!host->group->options[DHO_HOST_NAME])
- error ("can't allocate a tree cache for hostname.");
+ error("can't allocate a tree cache for hostname.");
host->group->options[DHO_HOST_NAME]->len =
- strlen (name);
+ strlen(name);
host->group->options[DHO_HOST_NAME]->value =
(unsigned char *)name;
host->group->options[DHO_HOST_NAME]->buf_size =
@@ -571,7 +571,7 @@ void parse_host_declaration (cfile, group)
host->group->options[DHO_HOST_NAME]->timeout =
0xFFFFFFFF;
host->group->options[DHO_HOST_NAME]->tree =
- (struct tree *)0;
+ NULL;
}
enter_host (host);
@@ -580,7 +580,7 @@ void parse_host_declaration (cfile, group)
/* class-declaration :== STRING LBRACE parameters declarations RBRACE
*/
-void parse_class_declaration (cfile, group, type)
+void parse_class_declaration(cfile, group, type)
FILE *cfile;
struct group *group;
int type;
@@ -590,35 +590,33 @@ void parse_class_declaration (cfile, group, type)
struct class *class;
int declaration = 0;
- token = next_token (&val, cfile);
+ token = next_token(&val, cfile);
if (token != STRING) {
- parse_warn ("Expecting class name");
- skip_to_semi (cfile);
+ parse_warn("Expecting class name");
+ skip_to_semi(cfile);
return;
}
class = add_class (type, val);
if (!class)
- error ("No memory for class %s.", val);
+ error("No memory for class %s.", val);
class->group = clone_group (group, "parse_class_declaration");
- if (!parse_lbrace (cfile))
+ if (!parse_lbrace(cfile))
return;
do {
- token = peek_token (&val, cfile);
+ token = peek_token(&val, cfile);
if (token == RBRACE) {
- token = next_token (&val, cfile);
+ token = next_token(&val, cfile);
break;
} else if (token == EOF) {
- token = next_token (&val, cfile);
- parse_warn ("unexpected end of file");
+ token = next_token(&val, cfile);
+ parse_warn("unexpected end of file");
break;
} else {
- declaration = parse_statement (cfile, class->group,
- CLASS_DECL,
- (struct host_decl *)0,
- declaration);
+ declaration = parse_statement(cfile, class->group,
+ CLASS_DECL, NULL, declaration);
}
} while (1);
}
@@ -626,7 +624,7 @@ void parse_class_declaration (cfile, group, type)
/* shared-network-declaration :==
hostname LBRACE declarations parameters RBRACE */
-void parse_shared_net_declaration (cfile, group)
+void parse_shared_net_declaration(cfile, group)
FILE *cfile;
struct group *group;
{
@@ -638,65 +636,63 @@ void parse_shared_net_declaration (cfile, group)
share = new_shared_network ("parse_shared_net_declaration");
if (!share)
- error ("No memory for shared subnet");
- share->leases = (struct lease *)0;
- share->last_lease = (struct lease *)0;
- share->insertion_point = (struct lease *)0;
- share->next = (struct shared_network *)0;
- share->interface = (struct interface_info *)0;
+ error("No memory for shared subnet");
+ share->leases = NULL;
+ share->last_lease = NULL;
+ share->insertion_point = NULL;
+ share->next = NULL;
+ share->interface = NULL;
share->group = clone_group (group, "parse_shared_net_declaration");
share->group->shared_network = share;
/* Get the name of the shared network... */
- token = peek_token (&val, cfile);
+ token = peek_token(&val, cfile);
if (token == STRING) {
- token = next_token (&val, cfile);
+ token = next_token(&val, cfile);
if (val[0] == 0) {
- parse_warn ("zero-length shared network name");
+ parse_warn("zero-length shared network name");
val = "<no-name-given>";
}
- name = malloc (strlen (val) + 1);
+ name = malloc(strlen(val) + 1);
if (!name)
- error ("no memory for shared network name");
- strlcpy (name, val, strlen(val) + 1);
+ error("no memory for shared network name");
+ strlcpy(name, val, strlen(val) + 1);
} else {
- name = parse_host_name (cfile);
+ name = parse_host_name(cfile);
if (!name)
return;
}
share->name = name;
- if (!parse_lbrace (cfile))
+ if (!parse_lbrace(cfile))
return;
do {
- token = peek_token (&val, cfile);
+ token = peek_token(&val, cfile);
if (token == RBRACE) {
- token = next_token (&val, cfile);
+ token = next_token(&val, cfile);
if (!share->subnets) {
- parse_warn ("empty shared-network decl");
+ 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");
+ 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);
+ declaration = parse_statement(cfile, share->group,
+ SHARED_NET_DECL, NULL, declaration);
} while (1);
}
/* subnet-declaration :==
net NETMASK netmask RBRACE parameters declarations LBRACE */
-void parse_subnet_declaration (cfile, share)
+void parse_subnet_declaration(cfile, share)
FILE *cfile;
struct shared_network *share;
{
@@ -708,54 +704,51 @@ void parse_subnet_declaration (cfile, share)
int len = sizeof addr;
int declaration = 0;
- subnet = new_subnet ("parse_subnet_declaration");
+ subnet = new_subnet("parse_subnet_declaration");
if (!subnet)
- error ("No memory for new subnet");
+ error("No memory for new subnet");
subnet->shared_network = share;
- subnet->group = clone_group (share->group,
- "parse_subnet_declaration");
+ subnet->group = clone_group(share->group, "parse_subnet_declaration");
subnet->group->subnet = subnet;
/* Get the network number... */
- if (!parse_numeric_aggregate (cfile, addr, &len, DOT, 10, 8))
+ if (!parse_numeric_aggregate(cfile, addr, &len, DOT, 10, 8))
return;
- memcpy (iaddr.iabuf, addr, len);
+ memcpy(iaddr.iabuf, addr, len);
iaddr.len = len;
subnet->net = iaddr;
- token = next_token (&val, cfile);
+ token = next_token(&val, cfile);
if (token != NETMASK) {
- parse_warn ("Expecting netmask");
- skip_to_semi (cfile);
+ parse_warn("Expecting netmask");
+ skip_to_semi(cfile);
return;
}
/* Get the netmask... */
- if (!parse_numeric_aggregate (cfile, addr, &len, DOT, 10, 8))
+ if (!parse_numeric_aggregate(cfile, addr, &len, DOT, 10, 8))
return;
- memcpy (iaddr.iabuf, addr, len);
+ memcpy(iaddr.iabuf, addr, len);
iaddr.len = len;
subnet->netmask = iaddr;
enter_subnet (subnet);
- if (!parse_lbrace (cfile))
+ if (!parse_lbrace(cfile))
return;
do {
- token = peek_token (&val, cfile);
+ token = peek_token(&val, cfile);
if (token == RBRACE) {
- token = next_token (&val, cfile);
+ token = next_token(&val, cfile);
break;
} else if (token == EOF) {
- token = next_token (&val, cfile);
- parse_warn ("unexpected end of file");
+ token = next_token(&val, cfile);
+ parse_warn("unexpected end of file");
break;
}
- declaration = parse_statement (cfile, subnet->group,
- SUBNET_DECL,
- (struct host_decl *)0,
- declaration);
+ declaration = parse_statement(cfile, subnet->group,
+ SUBNET_DECL, NULL, declaration);
} while (1);
/* If this subnet supports dynamic bootp, flag it so in the
@@ -769,9 +762,9 @@ void parse_subnet_declaration (cfile, share)
if (!share->subnets)
share->subnets = subnet;
else {
- u = (struct subnet *)0;
+ u = NULL;
for (t = share->subnets; t; t = t->next_sibling) {
- if (subnet_inner_than (subnet, t, 0)) {
+ if (subnet_inner_than(subnet, t, 0)) {
if (u)
u->next_sibling = subnet;
else
@@ -787,7 +780,7 @@ void parse_subnet_declaration (cfile, share)
/* group-declaration :== RBRACE parameters declarations LBRACE */
-void parse_group_declaration (cfile, group)
+void parse_group_declaration(cfile, group)
FILE *cfile;
struct group *group;
{
@@ -796,24 +789,23 @@ void parse_group_declaration (cfile, group)
struct group *g;
int declaration = 0;
- g = clone_group (group, "parse_group_declaration");
+ g = clone_group(group, "parse_group_declaration");
- if (!parse_lbrace (cfile))
+ if (!parse_lbrace(cfile))
return;
do {
- token = peek_token (&val, cfile);
+ token = peek_token(&val, cfile);
if (token == RBRACE) {
- token = next_token (&val, cfile);
+ token = next_token(&val, cfile);
break;
} else if (token == EOF) {
- token = next_token (&val, cfile);
- parse_warn ("unexpected end of file");
+ token = next_token(&val, cfile);
+ parse_warn("unexpected end of file");
break;
}
- declaration = parse_statement (cfile, g, GROUP_DECL,
- (struct host_decl *)0,
- declaration);
+ declaration = parse_statement(cfile, g, GROUP_DECL, NULL,
+ declaration);
} while (1);
}
@@ -824,7 +816,7 @@ void parse_group_declaration (cfile, group)
a TREE_LIMIT node to catch hostnames that evaluate to more than
one IP address. */
-struct tree *parse_ip_addr_or_hostname (cfile, uniform)
+struct tree *parse_ip_addr_or_hostname(cfile, uniform)
FILE *cfile;
int uniform;
{
@@ -835,26 +827,26 @@ struct tree *parse_ip_addr_or_hostname (cfile, uniform)
char *name;
struct tree *rv;
- token = peek_token (&val, cfile);
+ token = peek_token(&val, cfile);
if (is_identifier (token)) {
- name = parse_host_name (cfile);
+ name = parse_host_name(cfile);
if (!name)
- return (struct tree *)0;
+ return NULL;
rv = tree_host_lookup (name);
if (!uniform)
rv = tree_limit (rv, 4);
} else if (token == NUMBER) {
- if (!parse_numeric_aggregate (cfile, addr, &len, DOT, 10, 8))
- return (struct tree *)0;
+ if (!parse_numeric_aggregate(cfile, addr, &len, DOT, 10, 8))
+ return NULL;
rv = tree_const (addr, len);
} else {
if (token != RBRACE && token != LBRACE)
- token = next_token (&val, cfile);
- parse_warn ("%s (%d): expecting IP address or hostname",
+ token = next_token(&val, cfile);
+ parse_warn("%s (%d): expecting IP address or hostname",
val, token);
if (token != SEMI)
- skip_to_semi (cfile);
- return (struct tree *)0;
+ skip_to_semi(cfile);
+ return NULL;
}
return rv;
@@ -865,27 +857,27 @@ struct tree *parse_ip_addr_or_hostname (cfile, uniform)
ip-addrs-or-hostnames :== ip-addr-or-hostname
| ip-addrs-or-hostnames ip-addr-or-hostname */
-struct tree_cache *parse_fixed_addr_param (cfile)
+struct tree_cache *parse_fixed_addr_param(cfile)
FILE *cfile;
{
char *val;
int token;
- struct tree *tree = (struct tree *)0;
+ struct tree *tree = NULL;
struct tree *tmp;
do {
- tmp = parse_ip_addr_or_hostname (cfile, 0);
+ tmp = parse_ip_addr_or_hostname(cfile, 0);
if (tree)
tree = tree_concat (tree, tmp);
else
tree = tmp;
- token = peek_token (&val, cfile);
+ token = peek_token(&val, cfile);
if (token == COMMA)
- token = next_token (&val, cfile);
+ token = next_token(&val, cfile);
} while (token == COMMA);
- if (!parse_semi (cfile))
- return (struct tree_cache *)0;
+ if (!parse_semi(cfile))
+ return NULL;
return tree_cache (tree);
}
@@ -896,7 +888,7 @@ struct tree_cache *parse_fixed_addr_param (cfile)
would be painful to come up with BNF for it. However, it always
starts as above and ends in a SEMI. */
-void parse_option_param (cfile, group)
+void parse_option_param(cfile, group)
FILE *cfile;
struct group *group;
{
@@ -907,31 +899,31 @@ void parse_option_param (cfile, group)
char *fmt;
struct universe *universe;
struct option *option;
- struct tree *tree = (struct tree *)0;
+ struct tree *tree = NULL;
struct tree *t;
- token = next_token (&val, cfile);
+ token = next_token(&val, cfile);
if (!is_identifier (token)) {
- parse_warn ("expecting identifier after option keyword.");
+ parse_warn("expecting identifier after option keyword.");
if (token != SEMI)
- skip_to_semi (cfile);
+ skip_to_semi(cfile);
return;
}
- vendor = malloc (strlen (val) + 1);
+ vendor = malloc(strlen(val) + 1);
if (!vendor)
- error ("no memory for vendor token.");
- strlcpy (vendor, val, strlen(val) + 1);
- token = peek_token (&val, cfile);
+ error("no memory for vendor token.");
+ strlcpy(vendor, val, strlen(val) + 1);
+ token = peek_token(&val, cfile);
if (token == DOT) {
/* Go ahead and take the DOT token... */
- token = next_token (&val, cfile);
+ token = next_token(&val, cfile);
/* The next token should be an identifier... */
- token = next_token (&val, cfile);
+ token = next_token(&val, cfile);
if (!is_identifier (token)) {
- parse_warn ("expecting identifier after '.'");
+ parse_warn("expecting identifier after '.'");
if (token != SEMI)
- skip_to_semi (cfile);
+ skip_to_semi(cfile);
return;
}
@@ -943,8 +935,8 @@ void parse_option_param (cfile, group)
/* If it's not there, we can't parse the rest of the
declaration. */
if (!universe) {
- parse_warn ("no vendor named %s.", vendor);
- skip_to_semi (cfile);
+ parse_warn("no vendor named %s.", vendor);
+ skip_to_semi(cfile);
return;
}
} else {
@@ -961,11 +953,11 @@ void parse_option_param (cfile, group)
/* If we didn't get an option structure, it's an undefined option. */
if (!option) {
if (val == vendor)
- parse_warn ("no option named %s", val);
+ parse_warn("no option named %s", val);
else
- parse_warn ("no option named %s for vendor %s",
+ parse_warn("no option named %s for vendor %s",
val, vendor);
- skip_to_semi (cfile);
+ skip_to_semi(cfile);
return;
}
@@ -983,8 +975,8 @@ void parse_option_param (cfile, group)
if (*fmt == 'A')
break;
switch (*fmt) {
- case 'X':
- token = peek_token (&val, cfile);
+ case 'X':
+ token = peek_token(&val, cfile);
if (token == NUMBER_OR_NAME ||
token == NUMBER) {
do {
@@ -1004,78 +996,78 @@ void parse_option_param (cfile, group)
(&val, cfile);
} while (token == COLON);
} else if (token == STRING) {
- token = next_token (&val, cfile);
+ token = next_token(&val, cfile);
tree = tree_concat
(tree,
tree_const ((unsigned char *)
val,
- strlen (val)));
+ strlen(val)));
} else {
- parse_warn ("expecting string %s.",
+ parse_warn("expecting string %s.",
"or hexadecimal data");
- skip_to_semi (cfile);
+ skip_to_semi(cfile);
return;
}
break;
- case 't': /* Text string... */
- token = next_token (&val, cfile);
+ case 't': /* Text string... */
+ token = next_token(&val, cfile);
if (token != STRING
&& !is_identifier (token)) {
- parse_warn ("expecting string.");
+ parse_warn("expecting string.");
if (token != SEMI)
- skip_to_semi (cfile);
+ skip_to_semi(cfile);
return;
}
tree = tree_concat
(tree,
tree_const ((unsigned char *)val,
- strlen (val)));
+ strlen(val)));
break;
- case 'I': /* IP address or hostname. */
- t = parse_ip_addr_or_hostname (cfile, uniform);
+ case 'I': /* IP address or hostname. */
+ t = parse_ip_addr_or_hostname(cfile, uniform);
if (!t)
return;
tree = tree_concat (tree, t);
break;
- case 'L': /* Unsigned 32-bit integer... */
- case 'l': /* Signed 32-bit integer... */
- token = next_token (&val, cfile);
+ case 'L': /* Unsigned 32-bit integer... */
+ case 'l': /* Signed 32-bit integer... */
+ token = next_token(&val, cfile);
if (token != NUMBER) {
need_number:
- parse_warn ("expecting number.");
+ parse_warn("expecting number.");
if (token != SEMI)
- skip_to_semi (cfile);
+ skip_to_semi(cfile);
return;
}
convert_num (buf, val, 0, 32);
tree = tree_concat (tree, tree_const (buf, 4));
break;
- case 's': /* Signed 16-bit integer. */
- case 'S': /* Unsigned 16-bit integer. */
- token = next_token (&val, cfile);
+ case 's': /* Signed 16-bit integer. */
+ case 'S': /* Unsigned 16-bit integer. */
+ token = next_token(&val, cfile);
if (token != NUMBER)
goto need_number;
convert_num (buf, val, 0, 16);
tree = tree_concat (tree, tree_const (buf, 2));
break;
- case 'b': /* Signed 8-bit integer. */
- case 'B': /* Unsigned 8-bit integer. */
- token = next_token (&val, cfile);
+ case 'b': /* Signed 8-bit integer. */
+ case 'B': /* Unsigned 8-bit integer. */
+ token = next_token(&val, cfile);
if (token != NUMBER)
goto need_number;
convert_num (buf, val, 0, 8);
tree = tree_concat (tree, tree_const (buf, 1));
break;
- case 'f': /* Boolean flag. */
- token = next_token (&val, cfile);
+ case 'f': /* Boolean flag. */
+ token = next_token(&val, cfile);
if (!is_identifier (token)) {
- parse_warn ("expecting identifier.");
+ parse_warn("expecting identifier.");
bad_flag:
if (token != SEMI)
- skip_to_semi (cfile);
+ skip_to_semi(cfile);
return;
}
if (!strcasecmp (val, "true")
@@ -1085,32 +1077,32 @@ void parse_option_param (cfile, group)
|| !strcasecmp (val, "off"))
buf[0] = 0;
else {
- parse_warn ("expecting boolean.");
+ parse_warn("expecting boolean.");
goto bad_flag;
}
tree = tree_concat (tree, tree_const (buf, 1));
break;
- default:
- warn ("Bad format %c in parse_option_param.",
+ default:
+ warn("Bad format %c in parse_option_param.",
*fmt);
- skip_to_semi (cfile);
+ skip_to_semi(cfile);
return;
}
}
if (*fmt == 'A') {
- token = peek_token (&val, cfile);
+ token = peek_token(&val, cfile);
if (token == COMMA) {
- token = next_token (&val, cfile);
+ token = next_token(&val, cfile);
continue;
}
break;
}
} while (*fmt == 'A');
- token = next_token (&val, cfile);
+ token = next_token(&val, cfile);
if (token != SEMI) {
- parse_warn ("semicolon expected.");
- skip_to_semi (cfile);
+ parse_warn("semicolon expected.");
+ skip_to_semi(cfile);
return;
}
group->options[option->code] = tree_cache (tree);
@@ -1122,12 +1114,12 @@ void parse_option_param (cfile, group)
but rather in the database file and the journal file. (Okay, actually
they're not even used there yet). */
-time_t parse_timestamp (cfile)
+time_t parse_timestamp(cfile)
FILE *cfile;
{
time_t rv;
- rv = parse_date (cfile);
+ rv = parse_date(cfile);
return rv;
}
@@ -1147,7 +1139,7 @@ time_t parse_timestamp (cfile)
| CLASS identifier SEMI
| DYNAMIC_BOOTP SEMI */
-struct lease *parse_lease_declaration (cfile)
+struct lease *parse_lease_declaration(cfile)
FILE *cfile;
{
char *val;
@@ -1160,48 +1152,48 @@ struct lease *parse_lease_declaration (cfile)
static struct lease lease;
/* Zap the lease structure... */
- memset (&lease, 0, sizeof lease);
+ memset(&lease, 0, sizeof lease);
/* Get the address for which the lease has been issued. */
- if (!parse_numeric_aggregate (cfile, addr, &len, DOT, 10, 8))
- return (struct lease *)0;
- memcpy (lease.ip_addr.iabuf, addr, len);
+ if (!parse_numeric_aggregate(cfile, addr, &len, DOT, 10, 8))
+ return NULL;
+ memcpy(lease.ip_addr.iabuf, addr, len);
lease.ip_addr.len = len;
- if (!parse_lbrace (cfile))
- return (struct lease *)0;
+ if (!parse_lbrace(cfile))
+ return NULL;
do {
- token = next_token (&val, cfile);
+ token = next_token(&val, cfile);
if (token == RBRACE)
break;
else if (token == EOF) {
- parse_warn ("unexpected end of file");
+ parse_warn("unexpected end of file");
break;
}
- strlcpy (tbuf, val, sizeof tbuf);
+ strlcpy(tbuf, val, sizeof tbuf);
/* Parse any of the times associated with the lease. */
if (token == STARTS || token == ENDS || token == TIMESTAMP) {
time_t t;
- t = parse_date (cfile);
+ t = parse_date(cfile);
switch (token) {
- case STARTS:
+ case STARTS:
seenbit = 1;
lease.starts = t;
break;
- case ENDS:
+ case ENDS:
seenbit = 2;
lease.ends = t;
break;
- case TIMESTAMP:
+ case TIMESTAMP:
seenbit = 4;
lease.timestamp = t;
break;
- default:
+ default:
/*NOTREACHED*/
seenbit = 0;
break;
@@ -1209,111 +1201,109 @@ struct lease *parse_lease_declaration (cfile)
} else {
switch (token) {
/* Colon-separated hexadecimal octets... */
- case UID:
+ case UID:
seenbit = 8;
- token = peek_token (&val, cfile);
+ token = peek_token(&val, cfile);
if (token == STRING) {
- token = next_token (&val, cfile);
- lease.uid_len = strlen (val);
+ token = next_token(&val, cfile);
+ lease.uid_len = strlen(val);
lease.uid = (unsigned char *)
- malloc (lease.uid_len);
+ malloc(lease.uid_len);
if (!lease.uid) {
- warn ("no space for uid");
- return (struct lease *)0;
+ warn("no space for uid");
+ return NULL;
}
- memcpy (lease.uid, val, lease.uid_len);
- parse_semi (cfile);
+ memcpy(lease.uid, val, lease.uid_len);
+ parse_semi(cfile);
} else {
lease.uid_len = 0;
- lease.uid = parse_numeric_aggregate
- (cfile, (unsigned char *)0,
- &lease.uid_len, ':', 16, 8);
+ lease.uid = parse_numeric_aggregate(cfile,
+ NULL, &lease.uid_len, ':', 16, 8);
if (!lease.uid) {
- warn ("no space for uid");
- return (struct lease *)0;
+ warn("no space for uid");
+ return NULL;
}
if (lease.uid_len == 0) {
- lease.uid = (unsigned char *)0;
- parse_warn ("zero-length uid");
+ lease.uid = NULL;
+ parse_warn("zero-length uid");
seenbit = 0;
break;
}
}
- if (!lease.uid) {
- error ("No memory for lease uid");
- }
+ if (!lease.uid)
+ error("No memory for lease uid");
break;
- case CLASS:
+ case CLASS:
seenbit = 32;
- token = next_token (&val, cfile);
+ token = next_token(&val, cfile);
if (!is_identifier (token)) {
if (token != SEMI)
- skip_to_semi (cfile);
- return (struct lease *)0;
+ skip_to_semi(cfile);
+ return NULL;
}
/* for now, we aren't using this. */
break;
- case HARDWARE:
+ case HARDWARE:
seenbit = 64;
- parse_hardware_param (cfile,
- &lease.hardware_addr);
+ parse_hardware_param(cfile,
+ &lease.hardware_addr);
break;
- case DYNAMIC_BOOTP:
+ case DYNAMIC_BOOTP:
seenbit = 128;
lease.flags |= BOOTP_LEASE;
break;
- case ABANDONED:
+ case ABANDONED:
seenbit = 256;
lease.flags |= ABANDONED_LEASE;
break;
- case HOSTNAME:
+ case HOSTNAME:
seenbit = 512;
- token = peek_token (&val, cfile);
+ token = peek_token(&val, cfile);
if (token == STRING)
- lease.hostname = parse_string (cfile);
+ lease.hostname = parse_string(cfile);
else
lease.hostname =
- parse_host_name (cfile);
+ parse_host_name(cfile);
if (!lease.hostname) {
seenbit = 0;
- return (struct lease *)0;
+ return NULL;
}
break;
- case CLIENT_HOSTNAME:
+ case CLIENT_HOSTNAME:
seenbit = 1024;
- token = peek_token (&val, cfile);
+ token = peek_token(&val, cfile);
if (token == STRING)
lease.client_hostname =
- parse_string (cfile);
+ parse_string(cfile);
else
lease.client_hostname =
- parse_host_name (cfile);
+ parse_host_name(cfile);
break;
- default:
- skip_to_semi (cfile);
+ default:
+ skip_to_semi(cfile);
seenbit = 0;
- return (struct lease *)0;
+ return NULL;
}
if (token != HARDWARE && token != STRING) {
- token = next_token (&val, cfile);
+ token = next_token(&val, cfile);
if (token != SEMI) {
- parse_warn ("semicolon expected.");
- skip_to_semi (cfile);
- return (struct lease *)0;
+ parse_warn("semicolon expected.");
+ skip_to_semi(cfile);
+ return NULL;
}
}
}
if (seenmask & seenbit) {
- parse_warn ("Too many %s parameters in lease %s\n",
- tbuf, piaddr (lease.ip_addr));
+ parse_warn("Too many %s parameters in lease %s\n",
+ tbuf, piaddr (lease.ip_addr));
} else
seenmask |= seenbit;
@@ -1321,52 +1311,50 @@ struct lease *parse_lease_declaration (cfile)
return &lease;
}
-/* address-range-declaration :== ip-address ip-address SEMI
- | DYNAMIC_BOOTP ip-address ip-address SEMI */
-
-void parse_address_range (cfile, subnet)
- FILE *cfile;
- struct subnet *subnet;
+/*
+ * address-range-declaration :== ip-address ip-address SEMI
+ * | DYNAMIC_BOOTP ip-address ip-address SEMI
+ */
+void
+parse_address_range(FILE *cfile, struct subnet *subnet)
{
struct iaddr low, high;
unsigned char addr[4];
- int len = sizeof addr;
- int token;
+ int len = sizeof addr, token, dynamic = 0;
char *val;
- int dynamic = 0;
- if ((token = peek_token (&val, cfile)) == DYNAMIC_BOOTP) {
- token = next_token (&val, cfile);
+ if ((token = peek_token(&val, cfile)) == DYNAMIC_BOOTP) {
+ token = next_token(&val, cfile);
subnet->group->dynamic_bootp = dynamic = 1;
}
/* Get the bottom address in the range... */
- if (!parse_numeric_aggregate (cfile, addr, &len, DOT, 10, 8))
+ if (!parse_numeric_aggregate(cfile, addr, &len, DOT, 10, 8))
return;
- memcpy (low.iabuf, addr, len);
+ memcpy(low.iabuf, addr, len);
low.len = len;
/* Only one address? */
- token = peek_token (&val, cfile);
+ token = peek_token(&val, cfile);
if (token == SEMI)
high = low;
else {
- /* Get the top address in the range... */
- if (!parse_numeric_aggregate (cfile, addr, &len, DOT, 10, 8))
+ /* Get the top address in the range... */
+ if (!parse_numeric_aggregate(cfile, addr, &len, DOT, 10, 8))
return;
- memcpy (high.iabuf, addr, len);
+ memcpy(high.iabuf, addr, len);
high.len = len;
}
- token = next_token (&val, cfile);
+ token = next_token(&val, cfile);
if (token != SEMI) {
- parse_warn ("semicolon expected.");
- skip_to_semi (cfile);
+ parse_warn("semicolon expected.");
+ skip_to_semi(cfile);
return;
}
/* Create the new address range... */
- new_address_range (low, high, subnet, dynamic);
+ new_address_range(low, high, subnet, dynamic);
}