s4:dns_server: map LDB_ERR_NO_SUCH_OBJECT to WERR_DNS_ERROR_NAME_DOES_NOT_EXIST
authorStefan Metzmacher <metze@samba.org>
Thu, 31 Jul 2014 06:19:50 +0000 (08:19 +0200)
committerStefan Metzmacher <metze@samba.org>
Tue, 10 Mar 2015 09:55:41 +0000 (10:55 +0100)
This is the correct fix for commit 8b24c43b382740106474e26dec59e1419ba77306
and Bug: https://bugzilla.samba.org/show_bug.cgi?id=9559

With this change we have a consistent behavior between internal server
and the bind dlz module. We keep a dangling LDAP object without
dnsRecord attribute arround forever. This will be fixed in the following
commits.

Bug: https://bugzilla.samba.org/show_bug.cgi?id=10749

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
(cherry picked from commit d0f424a23dc915d9fce625438d2bd63519757cba)

source4/dns_server/dns_update.c
source4/dns_server/dns_utils.c

index 8be3564ee982818c49d4dd5376538f303101d530..d2d90a589f5d65a430ceab1281b096d85ea12761 100644 (file)
@@ -79,6 +79,9 @@ static WERROR check_one_prerequisite(struct dns_server *dns,
                        /*
                         */
                        werror = dns_lookup_records(dns, mem_ctx, dn, &ans, &acount);
+                       if (W_ERROR_EQUAL(werror, WERR_DNS_ERROR_NAME_DOES_NOT_EXIST)) {
+                               return DNS_ERR(NAME_ERROR);
+                       }
                        W_ERROR_NOT_OK_RETURN(werror);
 
                        if (acount == 0) {
@@ -88,6 +91,9 @@ static WERROR check_one_prerequisite(struct dns_server *dns,
                        /*
                         */
                        werror = dns_lookup_records(dns, mem_ctx, dn, &ans, &acount);
+                       if (W_ERROR_EQUAL(werror, WERR_DNS_ERROR_NAME_DOES_NOT_EXIST)) {
+                               return DNS_ERR(NXRRSET);
+                       }
                        if (W_ERROR_EQUAL(werror, DNS_ERR(NAME_ERROR))) {
                                return DNS_ERR(NXRRSET);
                        }
@@ -128,10 +134,11 @@ static WERROR check_one_prerequisite(struct dns_server *dns,
                        /*
                         */
                        werror = dns_lookup_records(dns, mem_ctx, dn, &ans, &acount);
+                       if (W_ERROR_EQUAL(werror, WERR_DNS_ERROR_NAME_DOES_NOT_EXIST)) {
+                               werror = WERR_OK;
+                       }
                        if (W_ERROR_EQUAL(werror, DNS_ERR(NAME_ERROR))) {
                                werror = WERR_OK;
-                               ans = NULL;
-                               acount = 0;
                        }
 
                        for (i = 0; i < acount; i++) {
@@ -160,6 +167,9 @@ static WERROR check_one_prerequisite(struct dns_server *dns,
        *final_result = false;
 
        werror = dns_lookup_records(dns, mem_ctx, dn, &ans, &acount);
+       if (W_ERROR_EQUAL(werror, WERR_DNS_ERROR_NAME_DOES_NOT_EXIST)) {
+               return DNS_ERR(NXRRSET);
+       }
        if (W_ERROR_EQUAL(werror, DNS_ERR(NAME_ERROR))) {
                return DNS_ERR(NXRRSET);
        }
@@ -418,12 +428,13 @@ static WERROR handle_one_update(struct dns_server *dns,
        W_ERROR_NOT_OK_RETURN(werror);
 
        werror = dns_lookup_records(dns, mem_ctx, dn, &recs, &rcount);
-       if (W_ERROR_EQUAL(werror, DNS_ERR(NAME_ERROR))) {
-               recs = NULL;
-               rcount = 0;
+       if (W_ERROR_EQUAL(werror, WERR_DNS_ERROR_NAME_DOES_NOT_EXIST)) {
                needs_add = true;
                werror = WERR_OK;
        }
+       if (W_ERROR_EQUAL(werror, DNS_ERR(NAME_ERROR))) {
+               werror = WERR_OK;
+       }
        W_ERROR_NOT_OK_RETURN(werror);
 
        if (update->rr_class == zone->question_class) {
index 052c6268c5a25c4f33d7828c9a5bd3032a139986..f8dd6d10f07946962536b62af52e78ff0dbdd6d7 100644 (file)
@@ -191,8 +191,14 @@ WERROR dns_lookup_records(struct dns_server *dns,
        struct ldb_message *msg = NULL;
        struct dnsp_DnssrvRpcRecord *recs;
 
+       *records = NULL;
+       *rec_count = 0;
+
        ret = dsdb_search_one(dns->samdb, mem_ctx, &msg, dn,
                              LDB_SCOPE_BASE, attrs, 0, "%s", "(objectClass=dnsNode)");
+       if (ret == LDB_ERR_NO_SUCH_OBJECT) {
+               return WERR_DNS_ERROR_NAME_DOES_NOT_EXIST;
+       }
        if (ret != LDB_SUCCESS) {
                /* TODO: we need to check if there's a glue record we need to
                 * create a referral to */
@@ -201,8 +207,6 @@ WERROR dns_lookup_records(struct dns_server *dns,
 
        el = ldb_msg_find_element(msg, attrs[0]);
        if (el == NULL) {
-               *records = NULL;
-               *rec_count = 0;
                return DNS_ERR(NAME_ERROR);
        }
 
@@ -273,13 +277,8 @@ WERROR dns_replace_records(struct dns_server *dns,
                if (needs_add) {
                        return WERR_OK;
                }
-               /* No entries left, delete the dnsNode object */
-               ret = ldb_delete(dns->samdb, msg->dn);
-               if (ret != LDB_SUCCESS) {
-                       DEBUG(0, ("Deleting record failed; %d\n", ret));
-                       return DNS_ERR(SERVER_FAILURE);
-               }
-               return WERR_OK;
+               /* TODO: Delete object? */
+               el->flags = LDB_FLAG_MOD_DELETE;
        }
 
        if (needs_add) {