#ifndef lint
static char copyright[] =
-"$Id: db.c,v 1.80 2007/06/05 23:28:43 each Exp $ Copyright (c) 2004-2007 Internet Systems Consortium. All rights reserved.\n";
+"$Id: db.c,v 1.81 2007/06/06 23:07:17 each Exp $ Copyright (c) 2004-2007 Internet Systems Consortium. All rights reserved.\n";
#endif /* not lint */
#include "dhcpd.h"
fprintf(db_file, "\n cltt %s", tval) < 0))
++errors;
- fprintf (db_file, "\n binding state %s;",
+ if (fprintf (db_file, "\n binding state %s;",
((lease -> binding_state > 0 &&
lease -> binding_state <= FTS_LAST)
? binding_state_names [lease -> binding_state - 1]
- : "abandoned"));
+ : "abandoned")) < 0)
+ ++errors;
if (lease -> binding_state != lease -> next_binding_state)
- fprintf (db_file, "\n next binding state %s;",
+ if (fprintf (db_file, "\n next binding state %s;",
((lease -> next_binding_state > 0 &&
lease -> next_binding_state <= FTS_LAST)
? (binding_state_names
[lease -> next_binding_state - 1])
- : "abandoned"));
+ : "abandoned")) < 0)
+ ++errors;
if (lease->flags & RESERVED_LEASE)
- fprintf(db_file, "\n reserved;");
+ if (fprintf(db_file, "\n reserved;") < 0)
+ ++errors;
+
if (lease->flags & BOOTP_LEASE)
- fprintf(db_file, "\n dynamic-bootp;");
+ if (fprintf(db_file, "\n dynamic-bootp;") < 0)
+ ++errors;
/* If this lease is billed to a class and is still valid,
write it out. */
print_hw_addr (lease -> hardware_addr.hbuf [0],
lease -> hardware_addr.hlen - 1,
&lease -> hardware_addr.hbuf [1]));
- if (errno) {
+ if (errno)
++errors;
- }
}
if (lease -> uid_len) {
int i;
fprintf (db_file, "\n on expiry%s {",
lease -> on_expiry == lease -> on_release
? " or release" : "");
- if (errno)
- ++errors;
write_statements (db_file, lease -> on_expiry, 4);
/* XXX */
fprintf (db_file, "\n }");
+ if (errno)
+ ++errors;
}
if (lease -> on_release && lease -> on_release != lease -> on_expiry) {
errno = 0;
fprintf (db_file, "\n on release {");
- if (errno)
- ++errors;
write_statements (db_file, lease -> on_release, 4);
/* XXX */
fprintf (db_file, "\n }");
+ if (errno)
+ ++errors;
}
+
errno = 0;
fputs ("\n}\n", db_file);
- if (errno) {
+ if (errno)
++errors;
- }
- if (errors)
+
+ if (errors) {
log_info ("write_lease: unable to write lease %s",
piaddr (lease -> ip_addr));
- if (errors)
lease_file_is_corrupt = 1;
+ }
+
return !errors;
}
if (counting)
++count;
- errno = 0;
+ errno = 0;
fprintf (db_file, "host %s {", host -> name);
- if (errno) {
+ if (errno)
++errors;
- }
if (host -> flags & HOST_DECL_DYNAMIC) {
errno = 0;
print_hw_addr (host -> interface.hbuf [0],
host -> interface.hlen - 1,
&host -> interface.hbuf [1]));
- if (errno) {
+ if (errno)
++errors;
- }
}
if (host -> client_identifier.len) {
int i;
fprintf (db_file, "\n uid \"%.*s\";",
(int)host -> client_identifier.len,
host -> client_identifier.data);
+ if (errno)
+ ++errors;
} else {
fprintf (db_file,
"\n uid %2.2x",
host -> client_identifier.data [0]);
- if (errno) {
+ if (errno)
++errors;
- }
for (i = 1;
i < host -> client_identifier.len; i++) {
errno = 0;
fprintf (db_file, ":%2.2x",
host ->
client_identifier.data [i]);
- if (errno) {
+ if (errno)
++errors;
- }
}
- putc (';', db_file);
+
+ errno = 0;
+ fputc (';', db_file);
+ if (errno)
+ ++errors;
}
}
errno = 0;
fprintf (db_file, "\n fixed-address ");
- if (errno) {
+ if (errno)
++errors;
- }
for (i = 0; i < ip_addrs.len - 3; i += 4) {
+
errno = 0;
fprintf (db_file, "%u.%u.%u.%u%s",
ip_addrs.data [i] & 0xff,
ip_addrs.data [i + 2] & 0xff,
ip_addrs.data [i + 3] & 0xff,
i + 7 < ip_addrs.len ? "," : "");
- if (errno) {
+ if (errno)
++errors;
- }
}
+
errno = 0;
fputc (';', db_file);
- if (errno) {
+ if (errno)
++errors;
- }
}
if (host -> named_group) {
errno = 0;
fprintf (db_file, "\n group \"%s\";",
host -> named_group -> name);
- if (errno) {
+ if (errno)
++errors;
- }
}
if (host -> group &&
errno = 0;
write_statements (db_file,
host -> group -> statements, 8);
- if (errno) {
+ if (errno)
++errors;
- }
}
}
errno = 0;
fputs ("\n}\n", db_file);
- if (errno) {
+ if (errno)
++errors;
- }
+
if (errors) {
log_info ("write_host: unable to write host %s",
host -> name);
lease_file_is_corrupt = 1;
}
+
return !errors;
}
if (counting)
++count;
- errno = 0;
+ errno = 0;
fprintf (db_file, "group %s {", group -> name);
- if (errno) {
+ if (errno)
++errors;
- }
if (group -> flags & GROUP_OBJECT_DYNAMIC) {
errno = 0;
errno = 0;
write_statements (db_file,
group -> group -> statements, 8);
- if (errno) {
+ if (errno)
++errors;
- }
}
}
errno = 0;
fputs ("\n}\n", db_file);
- if (errno) {
+ if (errno)
++errors;
- }
+
if (errors) {
log_info ("write_group: unable to write group %s",
group -> name);
lease_file_is_corrupt = 1;
}
+
return !errors;
}
if (fprintf(db_file, " ends %s", tval) < 0) {
goto error_exit;
}
- if (fprintf(db_file, "\n }\n") < 0) goto error_exit;
+ if (fprintf(db_file, "\n }\n") < 0)
+ goto error_exit;
}
- if (fprintf(db_file, "}\n\n") < 0) goto error_exit;
+ if (fprintf(db_file, "}\n\n") < 0)
+ goto error_exit;
fflush(db_file);
return 1;
if (errno)
++errors;
}
+
+ errno = 0;
fprintf (db_file, "\n}\n");
if (errno)
++errors;
lease_file_is_corrupt = 1;
return 0;
}
+
return 1;
}
if (class->expr != 0) {
if (fprintf(db_file, " match if ") <= 0)
return ISC_R_IOERROR;
+
+ errno = 0;
write_expression(db_file, class->expr, 5, 5, 0);
+ if (errno)
+ return ISC_R_IOERROR;
+
if (fprintf(db_file, ";\n") <= 0)
return ISC_R_IOERROR;
}
return ISC_R_IOERROR;
}
+ errno = 0;
write_expression(db_file, class->submatch, 5, 5, 0);
+ if (errno)
+ return ISC_R_IOERROR;
+
if (fprintf(db_file, ";\n") <= 0)
return ISC_R_IOERROR;
}
if (class->statements != 0) {
+ errno = 0;
write_statements(db_file, class->statements, 8);
+ if (errno)
+ return ISC_R_IOERROR;
}
/* XXXJAB this isn't right, but classes read in off the
leases file don't get the root group assigned to them
(due to clone_group() call). */
- if (class->group != 0 && class->group->authoritative != 0)
+ if (class->group != 0 && class->group->authoritative != 0) {
+ errno = 0;
write_statements(db_file, class->group->statements, 8);
+ if (errno)
+ return ISC_R_IOERROR;
+ }
if (fprintf(db_file, "}\n\n") <= 0)
return ISC_R_IOERROR;
return !errno;
}
- errno = 0;
- fprintf (db_file, "\n billing subclass \"%s\"",
- class -> superclass -> name);
- if (errno)
+ if (fprintf(db_file, "\n billing subclass \"%s\"",
+ class -> superclass -> name) < 0)
++errors;
- print_hash_string(db_file, class);
- fprintf(db_file, ";");
+ if (!print_hash_string(db_file, class))
+ ++errors;
+
+ if (fprintf(db_file, ";") < 0)
+ ++errors;
class -> dirty = !errors;
if (errors)
lease_file_is_corrupt = 1;
+
return !errors;
}
errno = 0;
fprintf (db_file, "# The format of this file is documented in the %s",
"dhcpd.leases(5) manual page.\n");
- if (errno != 0)
+ if (errno)
goto fail;
+
fprintf (db_file, "# This lease file was written by isc-dhcp-%s\n\n",
PACKAGE_VERSION);
- if (errno != 0)
+ if (errno)
goto fail;
/* At this point we have a new lease file that, so far, could not