2013-09-04 13:53:02 +10:00
|
|
|
/*
|
|
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
2021-06-03 08:37:05 +02:00
|
|
|
*
|
2013-09-04 13:53:02 +10: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
|
|
|
*
|
2013-09-04 13:53:02 +10:00
|
|
|
* See the COPYRIGHT file distributed with this work for additional
|
2014-06-13 06:27:43 +05:30
|
|
|
* information regarding copyright ownership.
|
2013-09-04 13:53:02 +10:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*! \file */
|
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
#include <stdbool.h>
|
2013-09-04 13:53:02 +10:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2018-08-07 16:46:53 +02:00
|
|
|
#include <isc/attributes.h>
|
2013-09-04 13:53:02 +10:00
|
|
|
#include <isc/buffer.h>
|
|
|
|
#include <isc/commandline.h>
|
|
|
|
#include <isc/hash.h>
|
2025-02-04 13:17:31 +01:00
|
|
|
#include <isc/lib.h>
|
2024-08-14 13:25:50 +02:00
|
|
|
#include <isc/log.h>
|
2013-09-04 13:53:02 +10:00
|
|
|
#include <isc/mem.h>
|
2021-10-04 17:14:53 +02:00
|
|
|
#include <isc/result.h>
|
2013-09-04 13:53:02 +10:00
|
|
|
#include <isc/string.h>
|
|
|
|
#include <isc/util.h>
|
|
|
|
|
|
|
|
#include <dns/callbacks.h>
|
|
|
|
#include <dns/db.h>
|
|
|
|
#include <dns/dbiterator.h>
|
|
|
|
#include <dns/ds.h>
|
|
|
|
#include <dns/fixedname.h>
|
|
|
|
#include <dns/keyvalues.h>
|
2025-02-04 13:17:31 +01:00
|
|
|
#include <dns/lib.h>
|
2013-09-04 13:53:02 +10:00
|
|
|
#include <dns/master.h>
|
|
|
|
#include <dns/name.h>
|
|
|
|
#include <dns/rdata.h>
|
|
|
|
#include <dns/rdataclass.h>
|
|
|
|
#include <dns/rdataset.h>
|
|
|
|
#include <dns/rdatasetiter.h>
|
|
|
|
#include <dns/rdatatype.h>
|
|
|
|
|
|
|
|
#include <dst/dst.h>
|
|
|
|
|
|
|
|
#include "dnssectool.h"
|
|
|
|
|
|
|
|
static dns_rdataclass_t rdclass;
|
|
|
|
static dns_fixedname_t fixed;
|
|
|
|
static dns_name_t *name = NULL;
|
2018-04-17 08:29:14 -07:00
|
|
|
static bool setpub = false, setdel = false;
|
|
|
|
static bool setttl = false;
|
2013-09-04 13:53:02 +10:00
|
|
|
static isc_stdtime_t pub = 0, del = 0;
|
2013-11-13 12:01:09 +11:00
|
|
|
static dns_ttl_t ttl = 0;
|
2015-11-05 12:09:48 +11:00
|
|
|
static isc_stdtime_t syncadd = 0, syncdel = 0;
|
2018-04-17 08:29:14 -07:00
|
|
|
static bool setsyncadd = false;
|
|
|
|
static bool setsyncdel = false;
|
2013-09-04 13:53:02 +10:00
|
|
|
|
|
|
|
static isc_result_t
|
|
|
|
initname(char *setname) {
|
|
|
|
isc_result_t result;
|
|
|
|
isc_buffer_t buf;
|
|
|
|
|
2018-03-28 14:38:09 +02:00
|
|
|
name = dns_fixedname_initname(&fixed);
|
2013-09-04 13:53:02 +10:00
|
|
|
|
|
|
|
isc_buffer_init(&buf, setname, strlen(setname));
|
|
|
|
isc_buffer_add(&buf, strlen(setname));
|
2025-02-22 00:11:38 -08:00
|
|
|
result = dns_name_fromtext(name, &buf, dns_rootname, 0);
|
2013-09-04 13:53:02 +10:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
db_load_from_stream(dns_db_t *db, FILE *fp) {
|
|
|
|
isc_result_t result;
|
|
|
|
dns_rdatacallbacks_t callbacks;
|
|
|
|
|
|
|
|
dns_rdatacallbacks_init(&callbacks);
|
|
|
|
result = dns_db_beginload(db, &callbacks);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
fatal("dns_db_beginload failed: %s", isc_result_totext(result));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2013-09-04 13:53:02 +10:00
|
|
|
|
|
|
|
result = dns_master_loadstream(fp, name, name, rdclass, 0, &callbacks,
|
2025-07-15 12:56:04 +02:00
|
|
|
isc_g_mctx);
|
2013-09-04 13:53:02 +10:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
fatal("can't load from input: %s", isc_result_totext(result));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2013-09-04 13:53:02 +10:00
|
|
|
|
|
|
|
result = dns_db_endload(db, &callbacks);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
fatal("dns_db_endload failed: %s", isc_result_totext(result));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2013-09-04 13:53:02 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
|
|
|
loadset(const char *filename, dns_rdataset_t *rdataset) {
|
|
|
|
isc_result_t result;
|
|
|
|
dns_db_t *db = NULL;
|
|
|
|
dns_dbnode_t *node = NULL;
|
|
|
|
char setname[DNS_NAME_FORMATSIZE];
|
|
|
|
|
|
|
|
dns_name_format(name, setname, sizeof(setname));
|
|
|
|
|
2025-07-15 12:56:04 +02:00
|
|
|
result = dns_db_create(isc_g_mctx, ZONEDB_DEFAULT, name,
|
|
|
|
dns_dbtype_zone, rdclass, 0, NULL, &db);
|
2013-09-04 13:53:02 +10:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
fatal("can't create database");
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2013-09-04 13:53:02 +10:00
|
|
|
|
|
|
|
if (strcmp(filename, "-") == 0) {
|
|
|
|
db_load_from_stream(db, stdin);
|
|
|
|
filename = "input";
|
|
|
|
} else {
|
2018-04-03 13:22:09 +02:00
|
|
|
result = dns_db_load(db, filename, dns_masterformat_text,
|
|
|
|
DNS_MASTER_NOTTL);
|
2013-09-04 13:53:02 +10:00
|
|
|
if (result != ISC_R_SUCCESS && result != DNS_R_SEENINCLUDE) {
|
|
|
|
fatal("can't load %s: %s", filename,
|
|
|
|
isc_result_totext(result));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2013-09-04 13:53:02 +10:00
|
|
|
}
|
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
result = dns_db_findnode(db, name, false, &node);
|
2013-09-04 13:53:02 +10:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
fatal("can't find %s node in %s", setname, filename);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2013-09-04 13:53:02 +10:00
|
|
|
|
|
|
|
result = dns_db_findrdataset(db, node, NULL, dns_rdatatype_dnskey, 0, 0,
|
|
|
|
rdataset, NULL);
|
|
|
|
|
|
|
|
if (result == ISC_R_NOTFOUND) {
|
|
|
|
fatal("no DNSKEY RR for %s in %s", setname, filename);
|
|
|
|
} else if (result != ISC_R_SUCCESS) {
|
|
|
|
fatal("dns_db_findrdataset");
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2013-09-04 13:53:02 +10:00
|
|
|
|
|
|
|
if (node != NULL) {
|
Decouple database and node lifetimes by adding node-specific vtables
All databases in the codebase follow the same structure: a database is
an associative container from DNS names to nodes, and each node is an
associative container from RR types to RR data.
Each database implementation (qpzone, qpcache, sdlz, builtin, dyndb) has
its own corresponding node type (qpznode, qpcnode, etc). However, some
code needs to work with nodes generically regardless of their specific
type - for example, to acquire locks, manage references, or
register/unregister slabs from the heap.
Currently, these generic node operations are implemented as methods in
the database vtable, which creates problematic coupling between database
and node lifetimes. If a node outlives its parent database, the node
destructor will destroy all RR data, and each RR data destructor will
try to unregister from heaps by calling a virtual function from the
database vtable. Since the database was already freed, this causes a
crash.
This commit breaks the coupling by standardizing the layout of all
database nodes, adding a dedicated vtable for node operations, and
moving node-specific methods from the database vtable to the node
vtable.
2025-06-05 11:51:29 +02:00
|
|
|
dns_db_detachnode(&node);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2013-09-04 13:53:02 +10:00
|
|
|
if (db != NULL) {
|
|
|
|
dns_db_detach(&db);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2013-09-04 13:53:02 +10:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
loadkey(char *filename, unsigned char *key_buf, unsigned int key_buf_size,
|
|
|
|
dns_rdata_t *rdata) {
|
|
|
|
isc_result_t result;
|
|
|
|
dst_key_t *key = NULL;
|
|
|
|
isc_buffer_t keyb;
|
|
|
|
isc_region_t r;
|
|
|
|
|
|
|
|
dns_rdata_init(rdata);
|
|
|
|
|
|
|
|
isc_buffer_init(&keyb, key_buf, key_buf_size);
|
|
|
|
|
2025-07-15 12:56:04 +02:00
|
|
|
result = dst_key_fromnamedfile(filename, NULL, DST_TYPE_PUBLIC,
|
|
|
|
isc_g_mctx, &key);
|
2013-09-04 13:53:02 +10:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
fatal("invalid keyfile name %s: %s", filename,
|
|
|
|
isc_result_totext(result));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2013-09-04 13:53:02 +10:00
|
|
|
|
|
|
|
if (verbose > 2) {
|
|
|
|
char keystr[DST_KEY_FORMATSIZE];
|
|
|
|
|
|
|
|
dst_key_format(key, keystr, sizeof(keystr));
|
2025-05-28 22:43:38 +02:00
|
|
|
fprintf(stderr, "%s: %s\n", isc_commandline_progname, keystr);
|
2013-09-04 13:53:02 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
result = dst_key_todns(key, &keyb);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
fatal("can't decode key");
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2013-09-04 13:53:02 +10:00
|
|
|
|
|
|
|
isc_buffer_usedregion(&keyb, &r);
|
|
|
|
dns_rdata_fromregion(rdata, dst_key_class(key), dns_rdatatype_dnskey,
|
|
|
|
&r);
|
|
|
|
|
|
|
|
rdclass = dst_key_class(key);
|
|
|
|
|
2018-03-28 14:38:09 +02:00
|
|
|
name = dns_fixedname_initname(&fixed);
|
2021-05-21 17:20:44 -07:00
|
|
|
dns_name_copy(dst_key_name(key), name);
|
2013-09-04 13:53:02 +10:00
|
|
|
|
|
|
|
dst_key_free(&key);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
emit(const char *dir, dns_rdata_t *rdata) {
|
|
|
|
isc_result_t result;
|
|
|
|
char keystr[DST_KEY_FORMATSIZE];
|
2013-11-13 12:01:09 +11:00
|
|
|
char pubname[1024];
|
|
|
|
char priname[1024];
|
2013-09-04 13:53:02 +10:00
|
|
|
isc_buffer_t buf;
|
2013-11-13 12:01:09 +11:00
|
|
|
dst_key_t *key = NULL, *tmp = NULL;
|
2013-09-04 13:53:02 +10:00
|
|
|
|
|
|
|
isc_buffer_init(&buf, rdata->data, rdata->length);
|
|
|
|
isc_buffer_add(&buf, rdata->length);
|
2025-07-15 12:56:04 +02:00
|
|
|
result = dst_key_fromdns(name, rdclass, &buf, isc_g_mctx, &key);
|
2013-09-04 13:53:02 +10:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
fatal("dst_key_fromdns: %s", isc_result_totext(result));
|
|
|
|
}
|
|
|
|
|
2013-11-13 12:01:09 +11:00
|
|
|
isc_buffer_init(&buf, pubname, sizeof(pubname));
|
2013-09-04 13:53:02 +10:00
|
|
|
result = dst_key_buildfilename(key, DST_TYPE_PUBLIC, dir, &buf);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
fatal("Failed to build public key filename: %s",
|
|
|
|
isc_result_totext(result));
|
|
|
|
}
|
2013-11-13 12:01:09 +11:00
|
|
|
isc_buffer_init(&buf, priname, sizeof(priname));
|
|
|
|
result = dst_key_buildfilename(key, DST_TYPE_PRIVATE, dir, &buf);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
fatal("Failed to build private key filename: %s",
|
|
|
|
isc_result_totext(result));
|
|
|
|
}
|
|
|
|
|
|
|
|
result = dst_key_fromfile(
|
|
|
|
dst_key_name(key), dst_key_id(key), dst_key_alg(key),
|
2025-07-15 12:56:04 +02:00
|
|
|
DST_TYPE_PUBLIC | DST_TYPE_PRIVATE, dir, isc_g_mctx, &tmp);
|
2013-11-13 12:01:09 +11:00
|
|
|
if (result == ISC_R_SUCCESS) {
|
|
|
|
if (dst_key_isprivate(tmp) && !dst_key_isexternal(tmp)) {
|
|
|
|
fatal("Private key already exists in %s", priname);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2013-11-13 12:01:09 +11:00
|
|
|
dst_key_free(&tmp);
|
|
|
|
}
|
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
dst_key_setexternal(key, true);
|
2013-11-13 12:01:09 +11:00
|
|
|
if (setpub) {
|
|
|
|
dst_key_settime(key, DST_TIME_PUBLISH, pub);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2013-11-13 12:01:09 +11:00
|
|
|
if (setdel) {
|
|
|
|
dst_key_settime(key, DST_TIME_DELETE, del);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2015-11-05 12:09:48 +11:00
|
|
|
if (setsyncadd) {
|
|
|
|
dst_key_settime(key, DST_TIME_SYNCPUBLISH, syncadd);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2015-11-05 12:09:48 +11:00
|
|
|
if (setsyncdel) {
|
|
|
|
dst_key_settime(key, DST_TIME_SYNCDELETE, syncdel);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2015-11-05 12:09:48 +11:00
|
|
|
|
2013-11-13 12:01:09 +11:00
|
|
|
if (setttl) {
|
|
|
|
dst_key_setttl(key, ttl);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2013-09-04 13:53:02 +10:00
|
|
|
|
|
|
|
result = dst_key_tofile(key, DST_TYPE_PUBLIC | DST_TYPE_PRIVATE, dir);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
dst_key_format(key, keystr, sizeof(keystr));
|
|
|
|
fatal("Failed to write key %s: %s", keystr,
|
|
|
|
isc_result_totext(result));
|
|
|
|
}
|
2013-11-13 12:01:09 +11:00
|
|
|
printf("%s\n", pubname);
|
2013-09-04 13:53:02 +10:00
|
|
|
|
|
|
|
isc_buffer_clear(&buf);
|
|
|
|
result = dst_key_buildfilename(key, DST_TYPE_PRIVATE, dir, &buf);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
fatal("Failed to build private key filename: %s",
|
|
|
|
isc_result_totext(result));
|
|
|
|
}
|
2013-11-13 12:01:09 +11:00
|
|
|
printf("%s\n", priname);
|
2013-09-04 13:53:02 +10:00
|
|
|
dst_key_free(&key);
|
|
|
|
}
|
|
|
|
|
2024-07-11 16:15:40 +03:00
|
|
|
ISC_NORETURN static void
|
2018-08-07 16:46:53 +02:00
|
|
|
usage(void);
|
2013-09-04 13:53:02 +10:00
|
|
|
|
|
|
|
static void
|
|
|
|
usage(void) {
|
|
|
|
fprintf(stderr, "Usage:\n");
|
2025-05-28 22:43:38 +02:00
|
|
|
fprintf(stderr, " %s options [-K dir] keyfile\n\n",
|
|
|
|
isc_commandline_progname);
|
|
|
|
fprintf(stderr, " %s options -f file [keyname]\n\n",
|
|
|
|
isc_commandline_progname);
|
2018-08-07 16:46:53 +02:00
|
|
|
fprintf(stderr, "Version: %s\n", PACKAGE_VERSION);
|
2013-09-04 13:53:02 +10:00
|
|
|
fprintf(stderr, "Options:\n");
|
2013-11-13 12:01:09 +11:00
|
|
|
fprintf(stderr, " -f file: read key from zone file\n");
|
2013-09-04 13:53:02 +10:00
|
|
|
fprintf(stderr, " -K <directory>: directory in which to store "
|
2013-11-13 12:01:09 +11:00
|
|
|
"the key files\n");
|
|
|
|
fprintf(stderr, " -L ttl: set default key TTL\n");
|
|
|
|
fprintf(stderr, " -v <verbose level>\n");
|
2014-06-13 06:27:43 +05:30
|
|
|
fprintf(stderr, " -V: print version information\n");
|
2013-11-13 12:01:09 +11:00
|
|
|
fprintf(stderr, " -h: print usage and exit\n");
|
|
|
|
fprintf(stderr, "Timing options:\n");
|
|
|
|
fprintf(stderr, " -P date/[+-]offset/none: set/unset key "
|
|
|
|
"publication date\n");
|
2015-11-05 12:09:48 +11:00
|
|
|
fprintf(stderr, " -P sync date/[+-]offset/none: set/unset "
|
|
|
|
"CDS and CDNSKEY publication date\n");
|
2013-11-13 12:01:09 +11:00
|
|
|
fprintf(stderr, " -D date/[+-]offset/none: set/unset key "
|
|
|
|
"deletion date\n");
|
2015-11-05 12:09:48 +11:00
|
|
|
fprintf(stderr, " -D sync date/[+-]offset/none: set/unset "
|
|
|
|
"CDS and CDNSKEY deletion date\n");
|
2013-09-04 13:53:02 +10:00
|
|
|
|
2024-02-07 14:50:38 +01:00
|
|
|
exit(EXIT_FAILURE);
|
2013-09-04 13:53:02 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv) {
|
|
|
|
char *classname = NULL;
|
|
|
|
char *filename = NULL, *dir = NULL, *namestr;
|
2025-03-21 23:32:27 -07:00
|
|
|
char *endp = NULL;
|
2013-09-04 13:53:02 +10:00
|
|
|
int ch;
|
|
|
|
isc_result_t result;
|
|
|
|
dns_rdataset_t rdataset;
|
2023-03-30 21:13:41 +02:00
|
|
|
isc_stdtime_t now = isc_stdtime_now();
|
2013-09-04 13:53:02 +10:00
|
|
|
|
|
|
|
if (argc == 1) {
|
|
|
|
usage();
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2013-09-04 13:53:02 +10:00
|
|
|
|
2025-05-28 22:43:38 +02:00
|
|
|
isc_commandline_init(argc, argv);
|
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
isc_commandline_errprint = false;
|
2013-09-04 13:53:02 +10:00
|
|
|
|
2014-06-13 06:27:43 +05:30
|
|
|
#define CMDLINE_FLAGS "D:f:hK:L:P:v:V"
|
2013-11-13 12:01:09 +11:00
|
|
|
while ((ch = isc_commandline_parse(argc, argv, CMDLINE_FLAGS)) != -1) {
|
2013-09-04 13:53:02 +10:00
|
|
|
switch (ch) {
|
|
|
|
case 'D':
|
2015-11-05 12:09:48 +11:00
|
|
|
/* -Dsync ? */
|
|
|
|
if (isoptarg("sync", argv, usage)) {
|
|
|
|
if (setsyncdel) {
|
|
|
|
fatal("-D sync specified more than "
|
|
|
|
"once");
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2015-11-05 12:09:48 +11:00
|
|
|
|
|
|
|
syncdel = strtotime(isc_commandline_argument,
|
|
|
|
now, now, &setsyncdel);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* -Ddnskey ? */
|
|
|
|
(void)isoptarg("dnskey", argv, usage);
|
2013-09-04 13:53:02 +10:00
|
|
|
if (setdel) {
|
|
|
|
fatal("-D specified more than once");
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2013-09-04 13:53:02 +10:00
|
|
|
|
2014-02-06 15:59:14 -08:00
|
|
|
del = strtotime(isc_commandline_argument, now, now,
|
|
|
|
&setdel);
|
2013-09-04 13:53:02 +10:00
|
|
|
break;
|
|
|
|
case 'K':
|
|
|
|
dir = isc_commandline_argument;
|
|
|
|
if (strlen(dir) == 0U) {
|
|
|
|
fatal("directory must be non-empty string");
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2013-09-04 13:53:02 +10:00
|
|
|
break;
|
2013-11-13 12:01:09 +11:00
|
|
|
case 'L':
|
2014-02-06 15:59:14 -08:00
|
|
|
ttl = strtottl(isc_commandline_argument);
|
2018-04-17 08:29:14 -07:00
|
|
|
setttl = true;
|
2013-11-13 12:01:09 +11:00
|
|
|
break;
|
2013-09-04 13:53:02 +10:00
|
|
|
case 'P':
|
2015-11-05 12:09:48 +11:00
|
|
|
/* -Psync ? */
|
|
|
|
if (isoptarg("sync", argv, usage)) {
|
|
|
|
if (setsyncadd) {
|
|
|
|
fatal("-P sync specified more than "
|
|
|
|
"once");
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2015-11-05 12:09:48 +11:00
|
|
|
|
|
|
|
syncadd = strtotime(isc_commandline_argument,
|
|
|
|
now, now, &setsyncadd);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* -Pdnskey ? */
|
|
|
|
(void)isoptarg("dnskey", argv, usage);
|
2013-09-04 13:53:02 +10:00
|
|
|
if (setpub) {
|
|
|
|
fatal("-P specified more than once");
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2013-09-04 13:53:02 +10:00
|
|
|
|
2014-02-06 15:59:14 -08:00
|
|
|
pub = strtotime(isc_commandline_argument, now, now,
|
|
|
|
&setpub);
|
2013-09-04 13:53:02 +10:00
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
filename = isc_commandline_argument;
|
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
verbose = strtol(isc_commandline_argument, &endp, 0);
|
|
|
|
if (*endp != '\0') {
|
|
|
|
fatal("-v must be followed by a number");
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2013-09-04 13:53:02 +10:00
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
if (isc_commandline_option != '?') {
|
|
|
|
fprintf(stderr, "%s: invalid argument -%c\n",
|
2025-05-28 22:43:38 +02:00
|
|
|
isc_commandline_progname,
|
|
|
|
isc_commandline_option);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2021-10-11 12:09:16 +02:00
|
|
|
FALLTHROUGH;
|
2013-09-04 13:53:02 +10:00
|
|
|
case 'h':
|
2014-06-13 06:27:43 +05:30
|
|
|
/* Does not return. */
|
2013-09-04 13:53:02 +10:00
|
|
|
usage();
|
|
|
|
|
2014-06-13 06:27:43 +05:30
|
|
|
case 'V':
|
|
|
|
/* Does not return. */
|
2025-05-28 22:43:38 +02:00
|
|
|
version(isc_commandline_progname);
|
2014-06-13 06:27:43 +05:30
|
|
|
|
2013-09-04 13:53:02 +10:00
|
|
|
default:
|
2025-05-28 22:43:38 +02:00
|
|
|
fprintf(stderr, "%s: unhandled option -%c\n",
|
|
|
|
isc_commandline_progname,
|
2013-09-04 13:53:02 +10:00
|
|
|
isc_commandline_option);
|
2024-02-07 14:50:38 +01:00
|
|
|
exit(EXIT_FAILURE);
|
2013-09-04 13:53:02 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rdclass = strtoclass(classname);
|
|
|
|
|
|
|
|
if (argc < isc_commandline_index + 1 && filename == NULL) {
|
|
|
|
fatal("the key file name was not specified");
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2013-09-04 13:53:02 +10:00
|
|
|
if (argc > isc_commandline_index + 1) {
|
|
|
|
fatal("extraneous arguments");
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2013-09-04 13:53:02 +10:00
|
|
|
|
2024-08-13 18:20:26 +02:00
|
|
|
setup_logging();
|
2013-09-04 13:53:02 +10:00
|
|
|
|
|
|
|
dns_rdataset_init(&rdataset);
|
|
|
|
|
|
|
|
if (filename != NULL) {
|
2013-11-13 12:01:09 +11:00
|
|
|
if (argc < isc_commandline_index + 1) {
|
|
|
|
/* using filename as zone name */
|
2013-09-04 13:53:02 +10:00
|
|
|
namestr = filename;
|
|
|
|
} else {
|
|
|
|
namestr = argv[isc_commandline_index];
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2013-09-04 13:53:02 +10:00
|
|
|
|
|
|
|
result = initname(namestr);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
fatal("could not initialize name %s", namestr);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2013-09-04 13:53:02 +10:00
|
|
|
|
|
|
|
result = loadset(filename, &rdataset);
|
|
|
|
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
fatal("could not load DNSKEY set: %s\n",
|
|
|
|
isc_result_totext(result));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2013-09-04 13:53:02 +10:00
|
|
|
|
2025-03-21 23:32:27 -07:00
|
|
|
DNS_RDATASET_FOREACH (&rdataset) {
|
|
|
|
dns_rdata_t rdata = DNS_RDATA_INIT;
|
2013-09-04 13:53:02 +10:00
|
|
|
dns_rdataset_current(&rdataset, &rdata);
|
|
|
|
emit(dir, &rdata);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
unsigned char key_buf[DST_KEY_MAXSIZE];
|
2025-03-21 23:32:27 -07:00
|
|
|
dns_rdata_t rdata = DNS_RDATA_INIT;
|
2013-09-04 13:53:02 +10:00
|
|
|
|
|
|
|
loadkey(argv[isc_commandline_index], key_buf, DST_KEY_MAXSIZE,
|
|
|
|
&rdata);
|
|
|
|
|
|
|
|
emit(dir, &rdata);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dns_rdataset_isassociated(&rdataset)) {
|
|
|
|
dns_rdataset_disassociate(&rdataset);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2013-09-04 13:53:02 +10:00
|
|
|
if (verbose > 10) {
|
2025-07-15 12:56:04 +02:00
|
|
|
isc_mem_stats(isc_g_mctx, stdout);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2013-09-04 13:53:02 +10:00
|
|
|
|
|
|
|
fflush(stdout);
|
|
|
|
if (ferror(stdout)) {
|
|
|
|
fprintf(stderr, "write error\n");
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2013-09-04 13:53:02 +10:00
|
|
|
}
|