From: Ted Lemon Date: Thu, 15 Mar 2001 23:21:25 +0000 (+0000) Subject: - Write things that could contain non-printable values as quotable strings X-Git-Tag: V3-BETA-2-PATCH-19~7 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c0b7fffacd05740e700dc18c480dfc510bf898aa;p=thirdparty%2Fdhcp.git - Write things that could contain non-printable values as quotable strings with non-printable values stored as \\ooo. --- diff --git a/server/db.c b/server/db.c index f58f044f3..863b93996 100644 --- a/server/db.c +++ b/server/db.c @@ -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)) { - 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); @@ -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;