From: Matthijs Mekking Date: Mon, 4 Nov 2019 10:12:26 +0000 (+0100) Subject: Add dst_key_copy_metadata function. X-Git-Tag: v9.15.6~26^2~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1211c348bbe0695672dec18cb9597c1a4b11bdb3;p=thirdparty%2Fbind9.git Add dst_key_copy_metadata function. When updating DNSSEC keys we would like to be able to copy the metadata from one key to another. --- diff --git a/lib/dns/dst_api.c b/lib/dns/dst_api.c index cfa4bbcda63..06e9c611ada 100644 --- a/lib/dns/dst_api.c +++ b/lib/dns/dst_api.c @@ -2587,3 +2587,52 @@ dst_key_is_removed(dst_key_t *key, isc_stdtime_t now, isc_stdtime_t *remove) return state_ok && time_ok; } + +void +dst_key_copy_metadata(dst_key_t *to, dst_key_t *from) +{ + dst_key_state_t state; + isc_stdtime_t when; + uint32_t num; + bool yesno; + isc_result_t result; + + REQUIRE(VALID_KEY(to)); + REQUIRE(VALID_KEY(from)); + + for (int i = 0; i < DST_MAX_TIMES+1; i++) { + result = dst_key_gettime(from, i, &when); + if (result == ISC_R_SUCCESS) { + dst_key_settime(to, i, when); + } else { + dst_key_unsettime(to, i); + } + } + + for (int i = 0; i < DST_MAX_NUMERIC+1; i++) { + result = dst_key_getnum(from, i, &num); + if (result == ISC_R_SUCCESS) { + dst_key_setnum(to, i, num); + } else { + dst_key_unsetnum(to, i); + } + } + + for (int i = 0; i < DST_MAX_BOOLEAN+1; i++) { + result = dst_key_getbool(from, i, &yesno); + if (result == ISC_R_SUCCESS) { + dst_key_setbool(to, i, yesno); + } else { + dst_key_unsetnum(to, i); + } + } + + for (int i = 0; i < DST_MAX_KEYSTATES+1; i++) { + result = dst_key_getstate(from, i, &state); + if (result == ISC_R_SUCCESS) { + dst_key_setstate(to, i, state); + } else { + dst_key_unsetstate(to, i); + } + } +} diff --git a/lib/dns/include/dst/dst.h b/lib/dns/include/dst/dst.h index febadabae76..afa20686239 100644 --- a/lib/dns/include/dst/dst.h +++ b/lib/dns/include/dst/dst.h @@ -1166,6 +1166,16 @@ dst_key_is_removed(dst_key_t *key, isc_stdtime_t now, isc_stdtime_t *remove); * 'key' to be valid. */ +void +dst_key_copy_metadata(dst_key_t *to, dst_key_t *from); +/*%< + * Copy key metadata from one key to another. + * + * Requires: + * 'to' and 'from' to be valid. + */ + + ISC_LANG_ENDDECLS #endif /* DST_DST_H */ diff --git a/lib/dns/win32/libdns.def.in b/lib/dns/win32/libdns.def.in index c127aba804d..2d90054b6b9 100644 --- a/lib/dns/win32/libdns.def.in +++ b/lib/dns/win32/libdns.def.in @@ -1405,6 +1405,7 @@ dst_key_attach dst_key_buildfilename dst_key_buildinternal dst_key_class +dst_key_copy_metadata dst_key_compare dst_key_computesecret dst_key_dump