s3-talloc Change TALLOC_ARRAY() to talloc_array()
[samba.git] / source3 / libads / dns.c
index 8d23ce1eba8a22fad8483ff8e8d5caea57196e69..c1332849bff6bc5988327b844c1880cf87acea60 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "includes.h"
 #include "libads/dns.h"
+#include "../librpc/ndr/libndr.h"
 
 /* AIX resolv.h uses 'class' in struct ns_rr */
 
@@ -297,7 +298,7 @@ static NTSTATUS dns_send_req( TALLOC_CTX *ctx, const char *name, int q_type,
        int resp_len = NS_PACKETSZ;
        static time_t last_dns_check = 0;
        static NTSTATUS last_dns_status = NT_STATUS_OK;
-       time_t now = time(NULL);
+       time_t now = time_mono(NULL);
 
        /* Try to prevent bursts of DNS lookups if the server is down */
 
@@ -327,12 +328,12 @@ static NTSTATUS dns_send_req( TALLOC_CTX *ctx, const char *name, int q_type,
                buf_len = resp_len * sizeof(uint8);
 
                if (buf_len) {
-                       if ((buffer = TALLOC_ARRAY(ctx, uint8, buf_len))
+                       if ((buffer = talloc_array(ctx, uint8, buf_len))
                                        == NULL ) {
                                DEBUG(0,("ads_dns_lookup_srv: "
                                        "talloc() failed!\n"));
                                last_dns_status = NT_STATUS_NO_MEMORY;
-                               last_dns_check = time(NULL);
+                               last_dns_check = time_mono(NULL);
                                return last_dns_status;
                        }
                }
@@ -351,7 +352,7 @@ static NTSTATUS dns_send_req( TALLOC_CTX *ctx, const char *name, int q_type,
                        if (errno == ECONNREFUSED) {
                                last_dns_status = NT_STATUS_CONNECTION_REFUSED;
                        }
-                       last_dns_check = time(NULL);
+                       last_dns_check = time_mono(NULL);
                        return last_dns_status;
                }
 
@@ -365,7 +366,7 @@ static NTSTATUS dns_send_req( TALLOC_CTX *ctx, const char *name, int q_type,
                                        name));
                                TALLOC_FREE( buffer );
                                last_dns_status = NT_STATUS_BUFFER_TOO_SMALL;
-                               last_dns_check = time(NULL);
+                               last_dns_check = time_mono(NULL);
                                return last_dns_status;
                        }
 
@@ -378,7 +379,7 @@ static NTSTATUS dns_send_req( TALLOC_CTX *ctx, const char *name, int q_type,
        *buf = buffer;
        *resp_length = resp_len;
 
-       last_dns_check = time(NULL);
+       last_dns_check = time_mono(NULL);
        last_dns_status = NT_STATUS_OK;
        return last_dns_status;
 }
@@ -400,11 +401,19 @@ static NTSTATUS ads_dns_lookup_srv( TALLOC_CTX *ctx,
        int rrnum;
        int idx = 0;
        NTSTATUS status;
+       const char *dns_hosts_file;
 
        if ( !ctx || !name || !dclist ) {
                return NT_STATUS_INVALID_PARAMETER;
        }
 
+       dns_hosts_file = lp_parm_const_string(-1, "resolv", "host file", NULL);
+       if (dns_hosts_file) {
+               return resolve_dns_hosts_file_as_dns_rr(dns_hosts_file,
+                                                       name, true, ctx,
+                                                       dclist, numdcs);
+       }
+
        /* Send the request.  May have to loop several times in case
           of large replies */
 
@@ -525,13 +534,13 @@ static NTSTATUS ads_dns_lookup_srv( TALLOC_CTX *ctx,
                                /* allocate new memory */
 
                                if (dcs[i].num_ips == 0) {
-                                       if ((dcs[i].ss_s = TALLOC_ARRAY(dcs,
+                                       if ((dcs[i].ss_s = talloc_array(dcs,
                                                struct sockaddr_storage, 1 ))
                                                        == NULL ) {
                                                return NT_STATUS_NO_MEMORY;
                                        }
                                } else {
-                                       if ((tmp_ss_s = TALLOC_REALLOC_ARRAY(dcs,
+                                       if ((tmp_ss_s = talloc_realloc(dcs,
                                                        dcs[i].ss_s,
                                                        struct sockaddr_storage,
                                                        dcs[i].num_ips+1))
@@ -589,11 +598,18 @@ NTSTATUS ads_dns_lookup_ns(TALLOC_CTX *ctx,
        int rrnum;
        int idx = 0;
        NTSTATUS status;
+       const char *dns_hosts_file;
 
        if ( !ctx || !dnsdomain || !nslist ) {
                return NT_STATUS_INVALID_PARAMETER;
        }
 
+       dns_hosts_file = lp_parm_const_string(-1, "resolv", "host file", NULL);
+       if (dns_hosts_file) {
+               DEBUG(1, ("NO 'NS' lookup available when using resolv:host file"));
+               return NT_STATUS_OBJECT_NAME_NOT_FOUND;
+       }
+
        /* Send the request.  May have to loop several times in case
           of large replies */
 
@@ -622,7 +638,7 @@ NTSTATUS ads_dns_lookup_ns(TALLOC_CTX *ctx,
                answer_count));
 
        if (answer_count) {
-               if ((nsarray = TALLOC_ARRAY(ctx, struct dns_rr_ns,
+               if ((nsarray = talloc_array(ctx, struct dns_rr_ns,
                                                answer_count)) == NULL ) {
                        DEBUG(0,("ads_dns_lookup_ns: "
                                "talloc() failure for %d char*'s\n",