1 /* $NetBSD: makejournal.c,v 1.3 2014/12/10 04:37:53 christos Exp $ */
4 * Copyright (C) 2013 Internet Systems Consortium, Inc. ("ISC")
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
11 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
13 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
22 #include <isc/entropy.h>
29 #include <dns/fixedname.h>
30 #include <dns/journal.h>
33 #include <dns/result.h>
34 #include <dns/types.h>
41 if (result != ISC_R_SUCCESS) \
43 } while (/*CONSTCOND*/0)
45 isc_mem_t
*mctx
= NULL
;
46 isc_log_t
*lctx
= NULL
;
47 isc_entropy_t
*ectx
= NULL
;
49 static isc_boolean_t hash_active
= ISC_FALSE
, dst_active
= ISC_FALSE
;
52 * Logging categories: this needs to match the list in bin/named/log.c.
54 static isc_logcategory_t categories
[] = {
61 { "update-security", 0 },
62 { "query-errors", 0 },
67 loadzone(dns_db_t
**db
, const char *origin
, const char *filename
) {
69 dns_fixedname_t fixed
;
72 dns_fixedname_init(&fixed
);
73 name
= dns_fixedname_name(&fixed
);
75 result
= dns_name_fromstring(name
, origin
, 0, NULL
);
76 if (result
!= ISC_R_SUCCESS
)
79 result
= dns_db_create(mctx
, "rbt", name
, dns_dbtype_zone
,
80 dns_rdataclass_in
, 0, NULL
, db
);
81 if (result
!= ISC_R_SUCCESS
)
84 result
= dns_db_load(*db
, filename
);
89 main(int argc
, char **argv
) {
91 char *origin
, *file1
, *file2
, *journal
;
92 dns_db_t
*old
= NULL
, *new = NULL
;
93 isc_logdestination_t destination
;
94 isc_logconfig_t
*logconfig
= NULL
;
97 printf("usage: %s origin file1 file2 journal\n", argv
[0]);
106 isc_mem_debugging
|= ISC_MEM_DEBUGRECORD
;
107 CHECK(isc_mem_create(0, 0, &mctx
));
108 CHECK(isc_entropy_create(mctx
, &ectx
));
110 CHECK(isc_hash_create(mctx
, ectx
, DNS_NAME_MAXWIRE
));
111 hash_active
= ISC_TRUE
;
113 CHECK(dst_lib_init(mctx
, ectx
, ISC_ENTROPY_BLOCKING
));
114 dst_active
= ISC_TRUE
;
116 CHECK(isc_log_create(mctx
, &lctx
, &logconfig
));
117 isc_log_registercategories(lctx
, categories
);
118 isc_log_setcontext(lctx
);
120 dns_log_setcontext(lctx
);
122 destination
.file
.stream
= stderr
;
123 destination
.file
.name
= NULL
;
124 destination
.file
.versions
= ISC_LOG_ROLLNEVER
;
125 destination
.file
.maximum_size
= 0;
126 CHECK(isc_log_createchannel(logconfig
, "stderr",
127 ISC_LOG_TOFILEDESC
, ISC_LOG_DYNAMIC
,
129 CHECK(isc_log_usechannel(logconfig
, "stderr", NULL
, NULL
));
131 dns_result_register();
133 result
= loadzone(&old
, origin
, file1
);
134 if (result
!= ISC_R_SUCCESS
) {
135 fprintf(stderr
, "Couldn't load %s: ", file1
);
139 result
= loadzone(&new, origin
, file2
);
140 if (result
!= ISC_R_SUCCESS
) {
141 fprintf(stderr
, "Couldn't load %s: ", file2
);
145 result
= dns_db_diff(mctx
, new, NULL
, old
, NULL
, journal
);
148 if (result
!= ISC_R_SUCCESS
)
149 fprintf(stderr
, "%s\n", isc_result_totext(result
));
157 isc_log_destroy(&lctx
);
160 dst_active
= ISC_FALSE
;
164 hash_active
= ISC_FALSE
;
167 isc_entropy_detach(&ectx
);
169 isc_mem_destroy(&mctx
);
171 return(result
!= ISC_R_SUCCESS
? 1 : 0);