2000-10-16 20:42:03 +00:00
|
|
|
/*
|
2015-05-23 14:21:51 +02:00
|
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
2000-10-16 20:42:03 +00:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
2021-06-03 08:37:05 +02:00
|
|
|
*
|
2000-10-16 20:42:03 +00:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
2018-02-23 09:53:12 +01:00
|
|
|
*
|
2000-10-16 20:42:03 +00:00
|
|
|
* See the COPYRIGHT file distributed with this work for additional
|
|
|
|
* information regarding copyright ownership.
|
|
|
|
*/
|
|
|
|
|
2005-04-27 04:57:32 +00:00
|
|
|
/*! \file */
|
2006-08-24 00:17:54 +00:00
|
|
|
|
2000-10-02 20:13:47 +00:00
|
|
|
#include <stdlib.h>
|
2020-02-12 13:59:18 +01:00
|
|
|
|
allow dns_journal_rollforward() to read old journal files
when the 'max-ixfr-ratio' option was added, journal transaction
headers were revised to include a count of RR's in each transaction.
this made it impossible to read old journal files after an upgrade.
this branch restores the ability to read version 1 transaction
headers. when rolling forward, printing journal contents, if
the wrong transaction header format is found, we can switch.
when dns_journal_rollforward() detects a version 1 transaction
header, it returns DNS_R_RECOVERABLE. this triggers zone_postload()
to force a rewrite of the journal file in the new format, and
also to schedule a dump of the zone database with minimal delay.
journal repair is done by dns_journal_compact(), which rewrites
the entire journal, ignoring 'max-journal-size'. journal size is
corrected later.
newly created journal files now have "BIND LOG V9.2" in their headers
instead of "BIND LOG V9". files with the new version string cannot be
read using the old transaction header format. note that this means
newly created journal files will be rejected by older versions of named.
named-journalprint now takes a "-x" option, causing it to print
transaction header information before each delta, including its
format version.
2021-02-19 15:04:50 -08:00
|
|
|
#include <isc/commandline.h>
|
2025-02-04 13:17:31 +01:00
|
|
|
#include <isc/lib.h>
|
2008-09-25 02:01:45 +00:00
|
|
|
#include <isc/log.h>
|
2000-10-02 20:13:47 +00:00
|
|
|
#include <isc/mem.h>
|
2021-10-04 17:14:53 +02:00
|
|
|
#include <isc/result.h>
|
2000-10-02 20:13:47 +00:00
|
|
|
#include <isc/util.h>
|
|
|
|
|
|
|
|
#include <dns/journal.h>
|
2025-02-04 13:17:31 +01:00
|
|
|
#include <dns/lib.h>
|
2000-10-02 20:13:47 +00:00
|
|
|
#include <dns/types.h>
|
|
|
|
|
allow dns_journal_rollforward() to read old journal files
when the 'max-ixfr-ratio' option was added, journal transaction
headers were revised to include a count of RR's in each transaction.
this made it impossible to read old journal files after an upgrade.
this branch restores the ability to read version 1 transaction
headers. when rolling forward, printing journal contents, if
the wrong transaction header format is found, we can switch.
when dns_journal_rollforward() detects a version 1 transaction
header, it returns DNS_R_RECOVERABLE. this triggers zone_postload()
to force a rewrite of the journal file in the new format, and
also to schedule a dump of the zone database with minimal delay.
journal repair is done by dns_journal_compact(), which rewrites
the entire journal, ignoring 'max-journal-size'. journal size is
corrected later.
newly created journal files now have "BIND LOG V9.2" in their headers
instead of "BIND LOG V9". files with the new version string cannot be
read using the old transaction header format. note that this means
newly created journal files will be rejected by older versions of named.
named-journalprint now takes a "-x" option, causing it to print
transaction header information before each delta, including its
format version.
2021-02-19 15:04:50 -08:00
|
|
|
static void
|
|
|
|
usage(void) {
|
2025-05-28 22:43:38 +02:00
|
|
|
fprintf(stderr, "Usage: %s [-dux] journal\n", isc_commandline_progname);
|
2024-02-07 14:50:38 +01:00
|
|
|
exit(EXIT_FAILURE);
|
allow dns_journal_rollforward() to read old journal files
when the 'max-ixfr-ratio' option was added, journal transaction
headers were revised to include a count of RR's in each transaction.
this made it impossible to read old journal files after an upgrade.
this branch restores the ability to read version 1 transaction
headers. when rolling forward, printing journal contents, if
the wrong transaction header format is found, we can switch.
when dns_journal_rollforward() detects a version 1 transaction
header, it returns DNS_R_RECOVERABLE. this triggers zone_postload()
to force a rewrite of the journal file in the new format, and
also to schedule a dump of the zone database with minimal delay.
journal repair is done by dns_journal_compact(), which rewrites
the entire journal, ignoring 'max-journal-size'. journal size is
corrected later.
newly created journal files now have "BIND LOG V9.2" in their headers
instead of "BIND LOG V9". files with the new version string cannot be
read using the old transaction header format. note that this means
newly created journal files will be rejected by older versions of named.
named-journalprint now takes a "-x" option, causing it to print
transaction header information before each delta, including its
format version.
2021-02-19 15:04:50 -08:00
|
|
|
}
|
|
|
|
|
2008-09-25 02:01:45 +00:00
|
|
|
/*
|
|
|
|
* Setup logging to use stderr.
|
|
|
|
*/
|
2024-08-13 18:20:26 +02:00
|
|
|
static void
|
|
|
|
setup_logging(FILE *errout) {
|
2024-08-14 14:38:07 +02:00
|
|
|
isc_logconfig_t *logconfig = isc_logconfig_get();
|
|
|
|
isc_log_createandusechannel(
|
|
|
|
logconfig, "default_stderr", ISC_LOG_TOFILEDESC,
|
|
|
|
ISC_LOG_DYNAMIC, ISC_LOGDESTINATION_FILE(errout), 0,
|
|
|
|
ISC_LOGCATEGORY_DEFAULT, ISC_LOGMODULE_DEFAULT);
|
2008-09-25 02:01:45 +00:00
|
|
|
}
|
|
|
|
|
2000-10-02 20:13:47 +00:00
|
|
|
int
|
|
|
|
main(int argc, char **argv) {
|
|
|
|
char *file;
|
2008-09-25 02:01:45 +00:00
|
|
|
isc_result_t result;
|
allow dns_journal_rollforward() to read old journal files
when the 'max-ixfr-ratio' option was added, journal transaction
headers were revised to include a count of RR's in each transaction.
this made it impossible to read old journal files after an upgrade.
this branch restores the ability to read version 1 transaction
headers. when rolling forward, printing journal contents, if
the wrong transaction header format is found, we can switch.
when dns_journal_rollforward() detects a version 1 transaction
header, it returns DNS_R_RECOVERABLE. this triggers zone_postload()
to force a rewrite of the journal file in the new format, and
also to schedule a dump of the zone database with minimal delay.
journal repair is done by dns_journal_compact(), which rewrites
the entire journal, ignoring 'max-journal-size'. journal size is
corrected later.
newly created journal files now have "BIND LOG V9.2" in their headers
instead of "BIND LOG V9". files with the new version string cannot be
read using the old transaction header format. note that this means
newly created journal files will be rejected by older versions of named.
named-journalprint now takes a "-x" option, causing it to print
transaction header information before each delta, including its
format version.
2021-02-19 15:04:50 -08:00
|
|
|
uint32_t flags = 0U;
|
2021-03-04 10:43:00 +01:00
|
|
|
int ch;
|
2021-05-04 17:20:26 +10:00
|
|
|
bool compact = false;
|
2021-03-03 17:07:15 +11:00
|
|
|
bool downgrade = false;
|
|
|
|
bool upgrade = false;
|
2021-05-04 17:20:26 +10:00
|
|
|
unsigned int serial = 0;
|
|
|
|
char *endp = NULL;
|
2000-10-02 20:13:47 +00:00
|
|
|
|
2025-05-28 22:43:38 +02:00
|
|
|
isc_commandline_init(argc, argv);
|
|
|
|
|
2021-05-04 17:20:26 +10:00
|
|
|
while ((ch = isc_commandline_parse(argc, argv, "c:dux")) != -1) {
|
allow dns_journal_rollforward() to read old journal files
when the 'max-ixfr-ratio' option was added, journal transaction
headers were revised to include a count of RR's in each transaction.
this made it impossible to read old journal files after an upgrade.
this branch restores the ability to read version 1 transaction
headers. when rolling forward, printing journal contents, if
the wrong transaction header format is found, we can switch.
when dns_journal_rollforward() detects a version 1 transaction
header, it returns DNS_R_RECOVERABLE. this triggers zone_postload()
to force a rewrite of the journal file in the new format, and
also to schedule a dump of the zone database with minimal delay.
journal repair is done by dns_journal_compact(), which rewrites
the entire journal, ignoring 'max-journal-size'. journal size is
corrected later.
newly created journal files now have "BIND LOG V9.2" in their headers
instead of "BIND LOG V9". files with the new version string cannot be
read using the old transaction header format. note that this means
newly created journal files will be rejected by older versions of named.
named-journalprint now takes a "-x" option, causing it to print
transaction header information before each delta, including its
format version.
2021-02-19 15:04:50 -08:00
|
|
|
switch (ch) {
|
2021-05-04 17:20:26 +10:00
|
|
|
case 'c':
|
|
|
|
compact = true;
|
|
|
|
serial = strtoul(isc_commandline_argument, &endp, 0);
|
|
|
|
if (endp == isc_commandline_argument || *endp != 0) {
|
|
|
|
fprintf(stderr, "invalid serial: %s\n",
|
|
|
|
isc_commandline_argument);
|
2024-02-07 14:50:38 +01:00
|
|
|
exit(EXIT_FAILURE);
|
2021-05-04 17:20:26 +10:00
|
|
|
}
|
|
|
|
break;
|
2021-03-03 17:07:15 +11:00
|
|
|
case 'd':
|
|
|
|
downgrade = true;
|
|
|
|
break;
|
|
|
|
case 'u':
|
|
|
|
upgrade = true;
|
|
|
|
break;
|
allow dns_journal_rollforward() to read old journal files
when the 'max-ixfr-ratio' option was added, journal transaction
headers were revised to include a count of RR's in each transaction.
this made it impossible to read old journal files after an upgrade.
this branch restores the ability to read version 1 transaction
headers. when rolling forward, printing journal contents, if
the wrong transaction header format is found, we can switch.
when dns_journal_rollforward() detects a version 1 transaction
header, it returns DNS_R_RECOVERABLE. this triggers zone_postload()
to force a rewrite of the journal file in the new format, and
also to schedule a dump of the zone database with minimal delay.
journal repair is done by dns_journal_compact(), which rewrites
the entire journal, ignoring 'max-journal-size'. journal size is
corrected later.
newly created journal files now have "BIND LOG V9.2" in their headers
instead of "BIND LOG V9". files with the new version string cannot be
read using the old transaction header format. note that this means
newly created journal files will be rejected by older versions of named.
named-journalprint now takes a "-x" option, causing it to print
transaction header information before each delta, including its
format version.
2021-02-19 15:04:50 -08:00
|
|
|
case 'x':
|
|
|
|
flags |= DNS_JOURNAL_PRINTXHDR;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}
|
2000-10-02 20:13:47 +00:00
|
|
|
}
|
|
|
|
|
allow dns_journal_rollforward() to read old journal files
when the 'max-ixfr-ratio' option was added, journal transaction
headers were revised to include a count of RR's in each transaction.
this made it impossible to read old journal files after an upgrade.
this branch restores the ability to read version 1 transaction
headers. when rolling forward, printing journal contents, if
the wrong transaction header format is found, we can switch.
when dns_journal_rollforward() detects a version 1 transaction
header, it returns DNS_R_RECOVERABLE. this triggers zone_postload()
to force a rewrite of the journal file in the new format, and
also to schedule a dump of the zone database with minimal delay.
journal repair is done by dns_journal_compact(), which rewrites
the entire journal, ignoring 'max-journal-size'. journal size is
corrected later.
newly created journal files now have "BIND LOG V9.2" in their headers
instead of "BIND LOG V9". files with the new version string cannot be
read using the old transaction header format. note that this means
newly created journal files will be rejected by older versions of named.
named-journalprint now takes a "-x" option, causing it to print
transaction header information before each delta, including its
format version.
2021-02-19 15:04:50 -08:00
|
|
|
argc -= isc_commandline_index;
|
|
|
|
argv += isc_commandline_index;
|
|
|
|
|
|
|
|
if (argc != 1) {
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
file = argv[0];
|
2000-10-02 20:13:47 +00:00
|
|
|
|
2024-08-13 18:20:26 +02:00
|
|
|
setup_logging(stderr);
|
2000-10-02 20:13:47 +00:00
|
|
|
|
2021-03-03 17:07:15 +11:00
|
|
|
if (upgrade) {
|
|
|
|
flags = DNS_JOURNAL_COMPACTALL;
|
2025-07-15 12:56:04 +02:00
|
|
|
result = dns_journal_compact(isc_g_mctx, file, 0, flags, 0);
|
2021-03-03 17:07:15 +11:00
|
|
|
} else if (downgrade) {
|
|
|
|
flags = DNS_JOURNAL_COMPACTALL | DNS_JOURNAL_VERSION1;
|
2025-07-15 12:56:04 +02:00
|
|
|
result = dns_journal_compact(isc_g_mctx, file, 0, flags, 0);
|
2021-05-04 17:20:26 +10:00
|
|
|
} else if (compact) {
|
|
|
|
flags = 0;
|
2025-07-15 12:56:04 +02:00
|
|
|
result = dns_journal_compact(isc_g_mctx, file, serial, flags,
|
|
|
|
0);
|
2021-03-03 17:07:15 +11:00
|
|
|
} else {
|
2025-07-15 12:56:04 +02:00
|
|
|
result = dns_journal_print(isc_g_mctx, flags, file, stdout);
|
2021-03-03 17:07:15 +11:00
|
|
|
if (result == DNS_R_NOJOURNAL) {
|
2021-10-04 17:14:53 +02:00
|
|
|
fprintf(stderr, "%s\n", isc_result_totext(result));
|
2021-03-03 17:07:15 +11:00
|
|
|
}
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2025-07-24 08:06:04 +02:00
|
|
|
|
2008-09-25 02:01:45 +00:00
|
|
|
return result != ISC_R_SUCCESS ? 1 : 0;
|
2000-10-02 20:13:47 +00:00
|
|
|
}
|