s3-libsmb Use 'resolv:hosts file' as a DNS emulation when specified.
authorAndrew Bartlett <abartlet@samba.org>
Tue, 26 Apr 2011 02:08:22 +0000 (12:08 +1000)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 26 Apr 2011 08:18:55 +0000 (18:18 +1000)
This allows make test to operate without making real DNS calls.

Andrew Bartlett

source3/libads/dns.c
source3/libsmb/namequery.c

index 113e63710bd2100821518e06093b74e28dd9c0c8..152003941b52bac16b55f3a5b6aca36d938ae772 100644 (file)
@@ -401,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 */
 
@@ -590,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 */
 
index 752b4b1eb9f117bc23211c2c1758dc96cb48b06f..16669c0532ab72b4b64ab32e660f5506c34a2750 100644 (file)
@@ -1738,6 +1738,7 @@ static NTSTATUS resolve_hosts(const char *name, int name_type,
        struct addrinfo *res = NULL;
        int ret = -1;
        int i = 0;
+       const char *dns_hosts_file;
 
        if ( name_type != 0x20 && name_type != 0x0) {
                DEBUG(5, ("resolve_hosts: not appropriate "
@@ -1762,6 +1763,32 @@ static NTSTATUS resolve_hosts(const char *name, int name_type,
        hints.ai_family = AF_INET;
 #endif
 
+       dns_hosts_file = lp_parm_const_string(-1, "resolv", "host file", NULL);
+       if (dns_hosts_file) {
+               struct sockaddr_storage *ss_list;
+               NTSTATUS status;
+               TALLOC_CTX *ctx = talloc_stackframe();
+               if (!ctx) {
+                       return NT_STATUS_NO_MEMORY;
+               }
+
+               status = resolve_dns_hosts_file_as_sockaddr(dns_hosts_file, name, false,
+                                                           ctx, &ss_list, return_count);
+               if (NT_STATUS_IS_OK(status)) {
+                       if (convert_ss2service(return_iplist,
+                                              ss_list,
+                                              *return_count)) {
+                               talloc_free(ctx);
+                               return NT_STATUS_OK;
+                       } else {
+                               talloc_free(ctx);
+                               return NT_STATUS_NO_MEMORY;
+                       }
+               }
+               talloc_free(ctx);
+               return NT_STATUS_UNSUCCESSFUL;
+       }
+
        ret = getaddrinfo(name,
                        NULL,
                        &hints,