From a32c229b0956f6ed1cf1ad20599539141bbff15d Mon Sep 17 00:00:00 2001 From: Douglas Bagnall Date: Thu, 11 Mar 2021 15:58:37 +1300 Subject: [PATCH] dns: use unix_to_dns_timestamp almost everywhere In places we change NTTIME to uint32_t, because that is what is actually wanted. There is one instance of the calculation that we are not changing, because there are other problems there. Signed-off-by: Douglas Bagnall Reviewed-by: Jeremy Allison --- source4/dns_server/dlz_bind9.c | 6 +----- source4/dns_server/dns_update.c | 6 +----- source4/dns_server/dnsserver_common.c | 6 ++---- source4/dsdb/kcc/scavenge_dns_records.c | 6 ++---- 4 files changed, 6 insertions(+), 18 deletions(-) diff --git a/source4/dns_server/dlz_bind9.c b/source4/dns_server/dlz_bind9.c index 687313b0a78..6f729f46561 100644 --- a/source4/dns_server/dlz_bind9.c +++ b/source4/dns_server/dlz_bind9.c @@ -1908,7 +1908,6 @@ _PUBLIC_ isc_result_t dlz_addrdataset(const char *name, const char *rdatastr, vo uint16_t num_recs = 0; uint16_t first = 0; uint16_t i; - NTTIME t; WERROR werr; if (state->transaction_token != (void*)version) { @@ -1993,10 +1992,7 @@ _PUBLIC_ isc_result_t dlz_addrdataset(const char *name, const char *rdatastr, vo if (dns_name_is_static(recs, num_recs)) { rec->dwTimeStamp = 0; } else { - unix_to_nt_time(&t, time(NULL)); - t /= 10 * 1000 * 1000; /* convert to seconds */ - t /= 3600; /* convert to hours */ - rec->dwTimeStamp = (uint32_t)t; + rec->dwTimeStamp = unix_to_dns_timestamp(time(NULL)); } } diff --git a/source4/dns_server/dns_update.c b/source4/dns_server/dns_update.c index 529ee7894a3..d1e7825bf07 100644 --- a/source4/dns_server/dns_update.c +++ b/source4/dns_server/dns_update.c @@ -302,7 +302,6 @@ static WERROR dns_rr_to_dnsp(TALLOC_CTX *mem_ctx, bool name_is_static) { enum ndr_err_code ndr_err; - NTTIME t; if (rrec->rr_type == DNS_QTYPE_ALL) { return DNS_ERR(FORMAT_ERROR); @@ -316,10 +315,7 @@ static WERROR dns_rr_to_dnsp(TALLOC_CTX *mem_ctx, if (name_is_static) { r->dwTimeStamp = 0; } else { - unix_to_nt_time(&t, time(NULL)); - t /= 10 * 1000 * 1000; - t /= 3600; - r->dwTimeStamp = t; + r->dwTimeStamp = unix_to_dns_timestamp(time(NULL)); } /* If we get QCLASS_ANY, we're done here */ diff --git a/source4/dns_server/dnsserver_common.c b/source4/dns_server/dnsserver_common.c index 6142d2af406..bc0f8ad6c23 100644 --- a/source4/dns_server/dnsserver_common.c +++ b/source4/dns_server/dnsserver_common.c @@ -941,7 +941,7 @@ WERROR dns_common_replace(struct ldb_context *samdb, bool become_tombstoned = false; struct ldb_dn *zone_dn = NULL; struct dnsserver_zoneinfo *zoneinfo = NULL; - NTTIME t; + uint32_t t; msg = ldb_msg_new(mem_ctx); W_ERROR_HAVE_NO_MEMORY(msg); @@ -1015,9 +1015,7 @@ WERROR dns_common_replace(struct ldb_context *samdb, } if (zoneinfo->fAging == 1 && records[i].dwTimeStamp != 0) { - unix_to_nt_time(&t, time(NULL)); - t /= 10 * 1000 * 1000; - t /= 3600; + t = unix_to_dns_timestamp(time(NULL)); if (t - records[i].dwTimeStamp > zoneinfo->dwNoRefreshInterval) { records[i].dwTimeStamp = t; diff --git a/source4/dsdb/kcc/scavenge_dns_records.c b/source4/dsdb/kcc/scavenge_dns_records.c index 8e916cf7b06..7504d3ac536 100644 --- a/source4/dsdb/kcc/scavenge_dns_records.c +++ b/source4/dsdb/kcc/scavenge_dns_records.c @@ -381,7 +381,7 @@ NTSTATUS dns_delete_tombstones(TALLOC_CTX *mem_ctx, struct dns_server_zone *zones = NULL; struct dns_server_zone *z = NULL; int ret, i; - NTTIME current_time; + uint32_t current_time; enum ndr_err_code ndr_err; struct ldb_result *res = NULL; int tombstone_time; @@ -392,9 +392,7 @@ NTSTATUS dns_delete_tombstones(TALLOC_CTX *mem_ctx, const char *attrs[] = {"dnsRecord", "dNSTombstoned", NULL}; rec = talloc_zero(mem_ctx, struct dnsp_DnssrvRpcRecord); - unix_to_nt_time(¤t_time, time(NULL)); - current_time /= 10 * 1000 * 1000; - current_time /= 3600; + current_time = unix_to_dns_timestamp(time(NULL)); lp_ctx = (struct loadparm_context *)ldb_get_opaque(samdb, "loadparm"); tombstone_time =