#define _XOPEN_SOURCE 600
#include <fcntl.h>
#include <errno.h>
+#include <err.h>
#include <ctype.h>
#include "dhcpd-pools.h"
else if (strstr(line, "binding state active")) {
leases[num_leases] = htonl(inp.s_addr);
num_leases++;
+ if (leasesmallocsize < num_leases) {
+ errx(EXIT_FAILURE, "parse_leases: running out of lease memory, report a bug");
+ }
sw_active_lease = 1;
} else if (strstr(line, " binding state free")) {
touches[num_touches] = htonl(inp.s_addr);
num_touches++;
+ if (touchesmallocsize < num_touches) {
+ errx(EXIT_FAILURE, "parse_leases: running out of touch memory, report a bug");
+ }
} else if (strstr(line, " binding state backup")) {
if (num_backups == 0) {
backups =
}
backups[num_backups] = htonl(inp.s_addr);
num_backups++;
+ if (backupsmallocsize < num_backups) {
+ errx(EXIT_FAILURE, "parse_leases: running out of backup IPs memory, report a bug");
+ }
}
/* FIXME: move to output.c and use FILE *outfile */
("<active_lease>\n\t<ip>%s</ip>\n\t<macaddress>%s</macaddress>\n</active_lease>\n",
ipstring, macstring);
}
-
- if ((leasesmallocsize < num_leases) ||
- (touchesmallocsize < num_touches) ||
- (backupsmallocsize < num_backups)) {
- printf("WARNING: running out of memory\n");
- printf("\tlease/touch/backup = %lu/%lu/%lu\n",
- leasesmallocsize, touchesmallocsize,
- backupsmallocsize);
- printf("\tlease/touch/backup = %lu/%lu/%lu\n",
- num_leases, num_touches, num_backups);
- printf
- ("Code should realloc() and init new memory, but no time to write that now!\n");
- exit(EXIT_FAILURE);
- }
}
-
return 0;
}
/* dhcpd.conf interesting words */
int is_interesting_config_clause(char *s)
{
- if (strstr(s, "shared-network")) {
- return 1;
- } else if (strstr(s, "range")) {
+ if (strstr(s, "range")) {
return 3;
+ } else if (strstr(s, "shared-network")) {
+ return 1;
} else if (strstr(s, "include")) {
return 4;
} else {
i = 0;
switch (argument) {
- case 0:
- /* printf ("nothing interesting: %s\n", word); */
+ case 2:
+ /* printf ("range 2nd ip: %s\n", word); */
+ range_p = ranges + num_ranges;
+ inet_aton(word, &inp);
argument = 0;
+ range_p->last_ip = htonl(inp.s_addr) + 1;
+ range_p->count = 0;
+ range_p->touched = 0;
+ range_p->backups = 0;
+ range_p->shared_net = shared_p;
+ num_ranges++;
+ if (RANGES < num_ranges) {
+ eprintf
+ ("parse_config: Range space full! Increase RANGES and recompile.");
+ exit(EXIT_FAILURE);
+ }
+ newclause = true;
+ break;
+ case 3:
+ /* printf ("range 1nd ip: %s\n", word); */
+ range_p = ranges + num_ranges;
+ if (!(inet_aton(word, &inp))) {
+ /* word was not ip, try again */
+ break;
+ }
+ range_p->first_ip = htonl(inp.s_addr) - 1;
+ argument = 2;
break;
case 1:
/* printf ("shared-network named: %s\n", word); */
argument = 0;
braces_shared = braces;
break;
- case 2:
- /* printf ("range 2nd ip: %s\n", word); */
- range_p = ranges + num_ranges;
- inet_aton(word, &inp);
- argument = 0;
- range_p->last_ip = htonl(inp.s_addr) + 1;
- range_p->count = 0;
- range_p->touched = 0;
- range_p->backups = 0;
- range_p->shared_net = shared_p;
- num_ranges++;
- if (RANGES < num_ranges) {
- eprintf
- ("parse_config: Range space full! Increase RANGES and recompile.");
- exit(EXIT_FAILURE);
- }
- newclause = true;
- break;
- case 3:
- /* printf ("range 1nd ip: %s\n", word); */
- range_p = ranges + num_ranges;
- if (!(inet_aton(word, &inp))) {
- /* word was not ip, try again */
- break;
- }
- range_p->first_ip = htonl(inp.s_addr) - 1;
- argument = 2;
- break;
case 4:
/* printf ("include file: %s\n", word); */
argument = 0;
shared_p);
newclause = true;
break;
+ case 0:
+ /* printf ("nothing interesting: %s\n", word); */
+ argument = 0;
+ break;
default:
eprintf
("parse_config: This cannot happen, report a bug!");