2
0
mirror of https://gitlab.isc.org/isc-projects/dhcp synced 2025-08-29 13:28:14 +00:00

- Write things that could contain non-printable values as quotable strings

with non-printable values stored as \\ooo.
This commit is contained in:
Ted Lemon 2001-03-15 23:21:25 +00:00
parent d73c240408
commit c0b7fffacd

View File

@ -43,7 +43,7 @@
#ifndef lint
static char copyright[] =
"$Id: db.c,v 1.62 2001/02/15 21:28:25 neild Exp $ Copyright (c) 1995-2000 The Internet Software Consortium. All rights reserved.\n";
"$Id: db.c,v 1.63 2001/03/15 23:21:25 mellon Exp $ Copyright (c) 1995-2000 The Internet Software Consortium. All rights reserved.\n";
#endif /* not lint */
#include "dhcpd.h"
@ -65,6 +65,7 @@ int write_lease (lease)
int errors = 0;
int i;
struct binding *b;
char *s;
if (counting)
++count;
@ -176,25 +177,14 @@ int write_lease (lease)
}
if (lease -> uid_len) {
int i;
if (db_printable_len (lease -> uid,
lease -> uid_len)) {
fprintf (db_file, "\n uid \"%.*s\";",
(int)lease -> uid_len, lease -> uid);
} else {
errno = 0;
fprintf (db_file, "\n uid %2.2x", lease -> uid [0]);
if (errno) {
s = quotify_buf (lease -> uid, lease -> uid_len, MDL);
if (s) {
fprintf (db_file, "\n uid \"%s\";", s);
if (errno)
++errors;
}
for (i = 1; i < lease -> uid_len; i++) {
errno = 0;
fprintf (db_file, ":%2.2x", lease -> uid [i]);
if (errno) {
++errors;
}
}
putc (';', db_file);
}
dfree (s, MDL);
} else
++errors;
}
if (lease -> scope) {
for (b = lease -> scope -> bindings; b; b = b -> next) {
@ -202,52 +192,31 @@ int write_lease (lease)
continue;
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)) {
s = quotify_buf (b -> value -> value.data.data,
b -> value -> value.data.len, MDL);
if (s) {
errno = 0;
fprintf (db_file, "\n set %s = \"%.*s\";",
b -> name,
(int)b -> value -> value.data.len,
b -> value -> value.data.data);
if (errno) {
++errors;
}
} else {
errno = 0;
fprintf (db_file, "\n set %s = ", b -> name);
if (errno) {
fprintf (db_file, "\n set %s = \"%s\";",
b -> name, s);
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);
}
dfree (s, MDL);
} else
++errors;
}
} else if (b -> value -> type == binding_numeric) {
errno = 0;
fprintf (db_file, "\n set %s = %%%ld;",
b -> name, b -> value -> value.intval);
if (errno) {
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) {
if (errno)
++errors;
}
} else if (b -> value -> type == binding_dns) {
log_error ("%s: persistent dns values not supported.",
b -> name);
@ -285,12 +254,15 @@ int write_lease (lease)
}
if (lease -> client_hostname &&
db_printable (lease -> client_hostname)) {
errno = 0;
fprintf (db_file, "\n client-hostname \"%s\";",
lease -> client_hostname);
if (errno) {
s = quotify_string (lease -> client_hostname, MDL);
if (s) {
errno = 0;
fprintf (db_file, "\n client-hostname \"%s\";", s);
if (errno)
++errors;
dfree (s, MDL);
} else
++errors;
}
}
if (lease -> on_expiry) {
errno = 0;