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)
committerKarolin Seeger <kseeger@samba.org>
Mon, 8 Sep 2014 05:49:10 +0000 (07:49 +0200)
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 9edc40bc341dbfa0ab2c3d7a3b237e666883af97..c439d8d27baad023c1f64549f1f2868e879d0ca9 100644 (file)
@@ -82,6 +82,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) {
@@ -91,6 +94,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);
                        }
@@ -131,10 +137,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++) {
@@ -163,6 +170,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);
        }
@@ -421,12 +431,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 86f7e7cd1922aab4b19848bb864abc3673fcb216..14ca2f417384cfd203021df4e102f9368cbf6250 100644 (file)
@@ -194,8 +194,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 */
@@ -204,8 +210,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);
        }
 
@@ -278,13 +282,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) {