2
0
mirror of https://gitlab.isc.org/isc-projects/dhcp synced 2025-09-02 07:15:44 +00:00

Handle typed variables.

This commit is contained in:
Ted Lemon
2000-02-05 17:39:24 +00:00
parent 0d0d25d027
commit 11cd757b7d
2 changed files with 126 additions and 48 deletions

View File

@@ -22,7 +22,7 @@
#ifndef lint #ifndef lint
static char copyright[] = static char copyright[] =
"$Id: confpars.c,v 1.101 2000/02/02 17:10:43 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n"; "$Id: confpars.c,v 1.102 2000/02/05 17:39:24 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n";
#endif /* not lint */ #endif /* not lint */
#include "dhcpd.h" #include "dhcpd.h"
@@ -2164,10 +2164,13 @@ struct lease *parse_lease_declaration (cfile)
"name"); "name");
strcpy (binding -> name, val); strcpy (binding -> name, val);
newbinding = 1; newbinding = 1;
} else if (binding -> value.data) { } else if (binding -> value) {
data_string_forget (&binding -> value, MDL); binding_value_dereference (&binding -> value,
MDL);
newbinding = 0; newbinding = 0;
} }
if (!binding_value_allocate (&binding -> value, MDL))
log_fatal ("no memory for binding value.");
if (!noequal) { if (!noequal) {
token = next_token (&val, cfile); token = next_token (&val, cfile);
@@ -2180,38 +2183,79 @@ struct lease *parse_lease_declaration (cfile)
token = peek_token (&val, cfile); token = peek_token (&val, cfile);
if (token == STRING) { if (token == STRING) {
unsigned char *tuid; unsigned char *tuid;
token = next_token (&val, cfile); token = next_token (&val, cfile);
binding -> value.len = strlen (val); /* !! */ binding -> value -> type = binding_data;
binding -> value -> value.data.len = strlen (val);
if (!(buffer_allocate
(&binding -> value -> value.data.buffer,
binding -> value-> value.data.len + 1,
MDL)))
log_fatal ("No memory for binding.");
strcpy ((char *)
(binding -> value ->
value.data.buffer -> data), val);
binding -> value -> value.data.data =
binding -> value -> value.data.buffer -> data;
binding -> value -> value.data.terminated = 1;
} else if (token == NUMBER_OR_NAME) {
binding -> value -> type = binding_data;
s = ((char *)
(parse_numeric_aggregate
(cfile, (unsigned char *)0,
&binding -> value -> value.data.len,
':', 16, 8)));
if (!s) {
binding_value_dereference
(&binding -> value, MDL);
return (struct lease *)0;
}
if (binding -> value -> value.data.len) {
if (!(buffer_allocate if (!(buffer_allocate
(&binding -> value.buffer, (&binding -> value -> value.data.buffer,
binding -> value.len + 1, MDL))) binding -> value -> value.data.len + 1,
MDL)))
log_fatal ("No memory for binding."); log_fatal ("No memory for binding.");
strcpy ((char *) memcpy ((binding -> value ->
binding -> value.buffer -> data, val); value.data.buffer -> data), s,
binding -> value.data = binding -> value -> value.data.len);
binding -> value.buffer -> data; dfree (s, MDL);
binding -> value.terminated = 1; binding -> value -> value.data.data =
binding -> value -> value.data.buffer -> data;
}
} else if (token == PERCENT) {
token = next_token (&val, cfile);
token = next_token (&val, cfile);
if (token != NUMBER) {
parse_warn (cfile,
"expecting decimal number.");
if (token != SEMI)
skip_to_semi (cfile);
binding_value_dereference
(&binding -> value, MDL);
return (struct lease *)0;
}
binding -> value -> type = binding_numeric;
binding -> value -> value.intval = atol (val);
} else if (token == NAME) {
token = next_token (&val, cfile);
binding -> value -> type = binding_boolean;
if (!strcasecmp (val, "true"))
binding -> value -> value.boolean = 1;
else if (!strcasecmp (val, "false"))
binding -> value -> value.boolean = 0;
else
goto badbool;
} else { } else {
s = ((char *) badbool:
(parse_numeric_aggregate parse_warn (cfile,
(cfile, (unsigned char *)0, "expecting a constant value.");
&binding -> value.len, ':', 16, 8))); skip_to_semi (cfile);
if (!s) binding_value_dereference (&binding -> value,
return (struct lease *)0; MDL);
if (binding -> value.len) { return (struct lease *)0;
if (!(buffer_allocate
(&binding -> value.buffer,
binding -> value.len + 1, MDL)))
log_fatal ("No memory for%s.",
" binding");
memcpy (binding -> value.buffer -> data,
s, binding -> value.len);
dfree (s, MDL);
binding -> value.data =
binding -> value.buffer -> data;
}
} }
if (newbinding) { if (newbinding) {
binding -> next = lease.scope.bindings; binding -> next = lease.scope.bindings;
lease.scope.bindings = binding; lease.scope.bindings = binding;

View File

@@ -22,7 +22,7 @@
#ifndef lint #ifndef lint
static char copyright[] = static char copyright[] =
"$Id: db.c,v 1.43 2000/02/01 03:19:56 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n"; "$Id: db.c,v 1.44 2000/02/05 17:38:17 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n";
#endif /* not lint */ #endif /* not lint */
#include "dhcpd.h" #include "dhcpd.h"
@@ -169,31 +169,65 @@ int write_lease (lease)
} }
} }
for (b = lease -> scope.bindings; b; b = b -> next) { for (b = lease -> scope.bindings; b; b = b -> next) {
if (b -> value.data) { if (!b -> value)
if (db_printable_len (b -> value.data, continue;
b -> value.len)) { if (b -> value -> type == binding_data) {
if (b -> value -> value.data.data) {
if (db_printable_len (b -> value -> value.data.data,
b -> value -> value.data.len)) {
errno = 0; errno = 0;
fprintf (db_file, "\n set %s = \"%.*s\";", fprintf (db_file, "\n set %s = \"%.*s\";",
b -> name, b -> name,
(int)b -> value.len, b -> value.data); (int)b -> value -> value.data.len,
} else { b -> value -> value.data.data);
errno = 0;
fprintf (db_file, "\n set %s = ", b -> name);
if (errno) { if (errno) {
++errors; ++errors;
} }
for (i = 0; i < b -> value.len; i++) { } else {
errno = 0; errno = 0;
fprintf (db_file, "%2.2x%s", fprintf (db_file, "\n set %s = ", b -> name);
b -> value.data [i], if (errno) {
i + 1 == b -> value.len ++errors;
? "" : ":");
if (errno) {
++errors;
}
} }
for (i = 0; i < b -> value -> value.data.len; i++)
{
errno = 0;
fprintf (db_file, "%2.2x%s",
b -> value -> value.data.data [i],
i + 1 == b -> value -> value.data.len
? "" : ":");
if (errno) {
++errors;
}
}
errno = 0;
putc (';', db_file); putc (';', db_file);
}
} }
} else if (b -> value -> type == binding_numeric) {
errno = 0;
fprintf (db_file, "\n set %s = %%%ld;",
b -> name, b -> value -> value.intval);
if (errno) {
++errors;
}
} else if (b -> value -> type == binding_boolean) {
errno = 0;
fprintf (db_file, "\n set %s = %s;",
b -> name,
b -> value -> value.intval ? "true" : "false");
if (errno) {
++errors;
}
} else if (b -> value -> type == binding_dns) {
log_error ("%s: persistent dns values not supported.",
b -> name);
} else if (b -> value -> type == binding_function) {
log_error ("%s: persistent functions not supported.",
b -> name);
} else {
log_error ("%s: unknown binding type %d",
b -> name, b -> value -> type);
} }
} }
if (lease -> client_hostname && if (lease -> client_hostname &&