2
0
mirror of https://gitlab.isc.org/isc-projects/dhcp synced 2025-08-29 21:38:10 +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 #ifndef lint
static char copyright[] = 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 */ #endif /* not lint */
#include "dhcpd.h" #include "dhcpd.h"
@ -65,6 +65,7 @@ int write_lease (lease)
int errors = 0; int errors = 0;
int i; int i;
struct binding *b; struct binding *b;
char *s;
if (counting) if (counting)
++count; ++count;
@ -176,25 +177,14 @@ int write_lease (lease)
} }
if (lease -> uid_len) { if (lease -> uid_len) {
int i; int i;
if (db_printable_len (lease -> uid, s = quotify_buf (lease -> uid, lease -> uid_len, MDL);
lease -> uid_len)) { if (s) {
fprintf (db_file, "\n uid \"%.*s\";", fprintf (db_file, "\n uid \"%s\";", s);
(int)lease -> uid_len, lease -> uid); if (errno)
} else {
errno = 0;
fprintf (db_file, "\n uid %2.2x", lease -> uid [0]);
if (errno) {
++errors; ++errors;
} dfree (s, MDL);
for (i = 1; i < lease -> uid_len; i++) { } else
errno = 0; ++errors;
fprintf (db_file, ":%2.2x", lease -> uid [i]);
if (errno) {
++errors;
}
}
putc (';', db_file);
}
} }
if (lease -> scope) { if (lease -> scope) {
for (b = lease -> scope -> bindings; b; b = b -> next) { for (b = lease -> scope -> bindings; b; b = b -> next) {
@ -202,52 +192,31 @@ int write_lease (lease)
continue; continue;
if (b -> value -> type == binding_data) { if (b -> value -> type == binding_data) {
if (b -> value -> value.data.data) { if (b -> value -> value.data.data) {
if (db_printable_len (b -> value -> value.data.data, s = quotify_buf (b -> value -> value.data.data,
b -> value -> value.data.len)) { b -> value -> value.data.len, MDL);
if (s) {
errno = 0; errno = 0;
fprintf (db_file, "\n set %s = \"%.*s\";", fprintf (db_file, "\n set %s = \"%s\";",
b -> name, b -> name, s);
(int)b -> value -> value.data.len, if (errno)
b -> value -> value.data.data);
if (errno) {
++errors;
}
} else {
errno = 0;
fprintf (db_file, "\n set %s = ", b -> name);
if (errno) {
++errors; ++errors;
} dfree (s, MDL);
for (i = 0; i < b -> value -> value.data.len; i++) } else
{ ++errors;
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);
}
} }
} else if (b -> value -> type == binding_numeric) { } else if (b -> value -> type == binding_numeric) {
errno = 0; errno = 0;
fprintf (db_file, "\n set %s = %%%ld;", fprintf (db_file, "\n set %s = %%%ld;",
b -> name, b -> value -> value.intval); b -> name, b -> value -> value.intval);
if (errno) { if (errno)
++errors; ++errors;
}
} else if (b -> value -> type == binding_boolean) { } else if (b -> value -> type == binding_boolean) {
errno = 0; errno = 0;
fprintf (db_file, "\n set %s = %s;", fprintf (db_file, "\n set %s = %s;",
b -> name, b -> name,
b -> value -> value.intval ? "true" : "false"); b -> value -> value.intval ? "true" : "false");
if (errno) { if (errno)
++errors; ++errors;
}
} else if (b -> value -> type == binding_dns) { } else if (b -> value -> type == binding_dns) {
log_error ("%s: persistent dns values not supported.", log_error ("%s: persistent dns values not supported.",
b -> name); b -> name);
@ -285,12 +254,15 @@ int write_lease (lease)
} }
if (lease -> client_hostname && if (lease -> client_hostname &&
db_printable (lease -> client_hostname)) { db_printable (lease -> client_hostname)) {
errno = 0; s = quotify_string (lease -> client_hostname, MDL);
fprintf (db_file, "\n client-hostname \"%s\";", if (s) {
lease -> client_hostname); errno = 0;
if (errno) { fprintf (db_file, "\n client-hostname \"%s\";", s);
if (errno)
++errors;
dfree (s, MDL);
} else
++errors; ++errors;
}
} }
if (lease -> on_expiry) { if (lease -> on_expiry) {
errno = 0; errno = 0;