dns_server: Do the exact match query first, then do the wildcard lookup
authorAndrew Bartlett <abartlet@samba.org>
Thu, 14 Dec 2017 23:30:50 +0000 (12:30 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 19 Dec 2017 06:19:21 +0000 (07:19 +0100)
The wildcard lookup is SCOPE_ONELEVEL combined with an index on the name
attribute.  This is not as efficient as a base DN lookup, so we try for
that first.

A not-found and wildcard response will still fall back to the ONELEVEL
index.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13191

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
source4/dns_server/dnsserver_common.c

index 3e161f81ac7699599782ab3f53254df99e7959b5..6c7ab8025754e10d84ad4078824ffecb42a06702 100644 (file)
@@ -563,6 +563,20 @@ WERROR dns_common_wildcard_lookup(struct ldb_context *samdb,
                return werr;
        }
 
+       /*
+        * Do a point search first, then fall back to a wildcard
+        * lookup if it does not exist
+        */
+       werr = dns_common_lookup(samdb,
+                                mem_ctx,
+                                dn,
+                                records,
+                                num_records,
+                                NULL);
+       if (!W_ERROR_EQUAL(werr, WERR_DNS_ERROR_NAME_DOES_NOT_EXIST)) {
+               return werr;
+       }
+
        ret = dns_wildcard_lookup(samdb, mem_ctx, dn, &msg);
        if (ret == LDB_ERR_OPERATIONS_ERROR) {
                return DNS_ERR(SERVER_FAILURE);