dns: use unix_to_dns_timestamp almost everywhere
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Thu, 11 Mar 2021 02:58:37 +0000 (15:58 +1300)
committerJeremy Allison <jra@samba.org>
Mon, 29 Mar 2021 23:20:37 +0000 (23:20 +0000)
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 <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Jeremy Allison <jra@samba.org>
source4/dns_server/dlz_bind9.c
source4/dns_server/dns_update.c
source4/dns_server/dnsserver_common.c
source4/dsdb/kcc/scavenge_dns_records.c

index 687313b0a78e94c08ee1f720d08eda11dde81313..6f729f46561f6a92dca7323df68dfb4784320fac 100644 (file)
@@ -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));
                }
        }
 
index 529ee7894a331fadf403215a3316d28fe68405d1..d1e7825bf07c5f0c2aad3e5fde52353c4c51f722 100644 (file)
@@ -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 */
index 6142d2af406787a64c643ca3680cc73ef114cf62..bc0f8ad6c234e6e7abd260894f22a694d14e49a7 100644 (file)
@@ -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;
index 8e916cf7b0626e0f6e4cb011ef3759258f5ef6e5..7504d3ac53610947e8028b378ae701b61c9846af 100644 (file)
@@ -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(&current_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 =