s4:dlz_bind9: let dlz_bind9 use dns_common_lookup() for name lookup
authorStefan Metzmacher <metze@samba.org>
Wed, 30 Jul 2014 06:40:32 +0000 (08:40 +0200)
committerStefan Metzmacher <metze@samba.org>
Wed, 27 Aug 2014 10:55:06 +0000 (12:55 +0200)
Bug: https://bugzilla.samba.org/show_bug.cgi?id=10749

Change-Id: I2632fa0ce120a978f6f400fa5cbf18a7fbbd64a3
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
source4/dns_server/dlz_bind9.c
source4/dns_server/wscript_build

index 83b607025afa482fe7542ab120a46356016e7a18..402de15b4a3f62d22012a934302b712c1f8f904c 100644 (file)
@@ -38,7 +38,7 @@
 #include "lib/cmdline/popt_common.h"
 #include "lib/util/dlinklist.h"
 #include "dlz_minimal.h"
-
+#include "dns_server/dnsserver_common.h"
 
 struct b9_options {
        const char *url;
@@ -808,11 +808,10 @@ static isc_result_t dlz_lookup_types(struct dlz_bind9_data *state,
                                     const char **types)
 {
        TALLOC_CTX *tmp_ctx = talloc_new(state);
-       const char *attrs[] = { "dnsRecord", NULL };
-       int ret = LDB_SUCCESS, i;
-       struct ldb_result *res;
-       struct ldb_message_element *el;
        struct ldb_dn *dn;
+       WERROR werr = WERR_DNS_ERROR_NAME_DOES_NOT_EXIST;
+       struct dnsp_DnssrvRpcRecord *records = NULL;
+       uint16_t num_records = 0, i;
 
        for (i=0; zone_prefixes[i]; i++) {
                dn = ldb_dn_copy(tmp_ctx, ldb_get_default_basedn(state->samdb));
@@ -826,38 +825,21 @@ static isc_result_t dlz_lookup_types(struct dlz_bind9_data *state,
                        return ISC_R_NOMEMORY;
                }
 
-               ret = ldb_search(state->samdb, tmp_ctx, &res, dn, LDB_SCOPE_BASE,
-                                attrs, "objectClass=dnsNode");
-               if (ret == LDB_SUCCESS) {
+               werr = dns_common_lookup(state->samdb, tmp_ctx, dn,
+                                        &records, &num_records, NULL);
+               if (W_ERROR_IS_OK(werr)) {
                        break;
                }
        }
-       if (ret != LDB_SUCCESS || res->count == 0) {
+       if (!W_ERROR_IS_OK(werr)) {
                talloc_free(tmp_ctx);
                return ISC_R_NOTFOUND;
        }
 
-       el = ldb_msg_find_element(res->msgs[0], "dnsRecord");
-       if (el == NULL || el->num_values == 0) {
-               talloc_free(tmp_ctx);
-               return ISC_R_NOTFOUND;
-       }
-
-       for (i=0; i<el->num_values; i++) {
-               struct dnsp_DnssrvRpcRecord rec;
-               enum ndr_err_code ndr_err;
+       for (i=0; i < num_records; i++) {
                isc_result_t result;
 
-               ndr_err = ndr_pull_struct_blob(&el->values[i], tmp_ctx, &rec,
-                                              (ndr_pull_flags_fn_t)ndr_pull_dnsp_DnssrvRpcRecord);
-               if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
-                       state->log(ISC_LOG_ERROR, "samba_dlz: failed to parse dnsRecord for %s",
-                                  ldb_dn_get_linearized(dn));
-                       talloc_free(tmp_ctx);
-                       return ISC_R_FAILURE;
-               }
-
-               result = b9_putrr(state, lookup, &rec, types);
+               result = b9_putrr(state, lookup, &records[i], types);
                if (result != ISC_R_SUCCESS) {
                        talloc_free(tmp_ctx);
                        return result;
@@ -1066,39 +1048,25 @@ _PUBLIC_ void dlz_closeversion(const char *zone, isc_boolean_t commit,
  */
 static bool b9_has_soa(struct dlz_bind9_data *state, struct ldb_dn *dn, const char *zone)
 {
-       const char *attrs[] = { "dnsRecord", NULL };
-       struct ldb_result *res;
-       struct ldb_message_element *el;
        TALLOC_CTX *tmp_ctx = talloc_new(state);
-       int ret, i;
+       WERROR werr;
+       struct dnsp_DnssrvRpcRecord *records = NULL;
+       uint16_t num_records = 0, i;
 
        if (!ldb_dn_add_child_fmt(dn, "DC=@,DC=%s", zone)) {
                talloc_free(tmp_ctx);
                return false;
        }
 
-       ret = ldb_search(state->samdb, tmp_ctx, &res, dn, LDB_SCOPE_BASE,
-                        attrs, "objectClass=dnsNode");
-       if (ret != LDB_SUCCESS) {
-               talloc_free(tmp_ctx);
-               return false;
-       }
-
-       el = ldb_msg_find_element(res->msgs[0], "dnsRecord");
-       if (el == NULL) {
+       werr = dns_common_lookup(state->samdb, tmp_ctx, dn,
+                                &records, &num_records, NULL);
+       if (!W_ERROR_IS_OK(werr)) {
                talloc_free(tmp_ctx);
                return false;
        }
-       for (i=0; i<el->num_values; i++) {
-               struct dnsp_DnssrvRpcRecord rec;
-               enum ndr_err_code ndr_err;
 
-               ndr_err = ndr_pull_struct_blob(&el->values[i], tmp_ctx, &rec,
-                                              (ndr_pull_flags_fn_t)ndr_pull_dnsp_DnssrvRpcRecord);
-               if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
-                       continue;
-               }
-               if (rec.wType == DNS_TYPE_SOA) {
+       for (i=0; i < num_records; i++) {
+               if (records[i].wType == DNS_TYPE_SOA) {
                        talloc_free(tmp_ctx);
                        return true;
                }
index 66e6b7224ddb9609601f7f98a6e3ae73c40325c3..a92ab67a40fd38832f4c9cbb88bc51a9970f9f8d 100644 (file)
@@ -24,7 +24,7 @@ bld.SAMBA_LIBRARY('dlz_bind9',
                   link_name='modules/bind9/dlz_bind9.so',
                   realname='dlz_bind9.so',
                   install_path='${MODULESDIR}/bind9',
-                  deps='samba-hostconfig samdb-common gensec popt',
+                  deps='samba-hostconfig samdb-common gensec popt dnsserver_common',
                   enabled=bld.AD_DC_BUILD_IS_ENABLED())
 
 bld.SAMBA_LIBRARY('dlz_bind9_9',
@@ -34,12 +34,12 @@ bld.SAMBA_LIBRARY('dlz_bind9_9',
                   link_name='modules/bind9/dlz_bind9_9.so',
                   realname='dlz_bind9_9.so',
                   install_path='${MODULESDIR}/bind9',
-                  deps='samba-hostconfig samdb-common gensec popt',
+                  deps='samba-hostconfig samdb-common gensec popt dnsserver_common',
                   enabled=bld.AD_DC_BUILD_IS_ENABLED())
 
 bld.SAMBA_LIBRARY('dlz_bind9_for_torture',
                   source='dlz_bind9.c',
                   cflags='-DBIND_VERSION_9_8',
                   private_library=True,
-                  deps='samba-hostconfig samdb-common gensec popt',
+                  deps='samba-hostconfig samdb-common gensec popt dnsserver_common',
                   enabled=bld.AD_DC_BUILD_IS_ENABLED())