#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"
int errors = 0;
int i;
struct binding *b;
+ char *s;
if (counting)
++count;
}
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) {
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)) {
- 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 {
+ s = quotify_buf (b -> value -> value.data.data,
+ b -> value -> value.data.len, MDL);
+ if (s) {
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);
}
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;