s4-dsdb: added comments and fixed backlink check in repl_meta_data
authorAndrew Tridgell <tridge@samba.org>
Mon, 15 Aug 2011 06:01:39 +0000 (16:01 +1000)
committerAndrew Tridgell <tridge@samba.org>
Wed, 17 Aug 2011 23:26:59 +0000 (09:26 +1000)
added comments explaining the backlink deletion code, plus fix a use
of a bitwise operation in a boolean expression, and avoid calling
dsdb_functional_level() inside a loop

Pair-Programmed-With: Andrew Bartlett <abartlet@samba.org>

source4/dsdb/samdb/ldb_modules/repl_meta_data.c

index 54741e6f9dd5a97c93a04ab707df0aa33910b9ac..e50e2a06cabd1222ca05a5e2373324a58de82dd9 100644 (file)
@@ -2724,6 +2724,7 @@ static int replmd_delete(struct ldb_module *module, struct ldb_request *req)
                                                OBJECT_TOMBSTONE=4, OBJECT_REMOVED=5 };
        enum deletion_state deletion_state, next_deletion_state;
        bool enabled;
+       int functional_level;
 
        if (ldb_dn_is_special(req->op.del.dn)) {
                return ldb_next_request(module, req);
@@ -2740,6 +2741,8 @@ static int replmd_delete(struct ldb_module *module, struct ldb_request *req)
                return LDB_ERR_OPERATIONS_ERROR;
        }
 
+       functional_level = dsdb_functional_level(ldb);
+
        old_dn = ldb_dn_copy(tmp_ctx, req->op.del.dn);
 
        /* we need the complete msg off disk, so we can work out which
@@ -2940,7 +2943,7 @@ static int replmd_delete(struct ldb_module *module, struct ldb_request *req)
 
                /* we also mark it as recycled, meaning this object can't be
                   recovered (we are stripping its attributes) */
-               if (dsdb_functional_level(ldb) >= DS_DOMAIN_FUNCTION_2008_R2) {
+               if (functional_level >= DS_DOMAIN_FUNCTION_2008_R2) {
                        ret = ldb_msg_add_string(msg, "isRecycled", "TRUE");
                        if (ret != LDB_SUCCESS) {
                                DEBUG(0,(__location__ ": Failed to add isRecycled string to the msg\n"));
@@ -2964,12 +2967,24 @@ static int replmd_delete(struct ldb_module *module, struct ldb_request *req)
                                /* don't remove the rDN */
                                continue;
                        }
-                       if (sa->linkID && sa->linkID & 1) {
+                       if (sa->linkID && (sa->linkID & 1)) {
+                               /*
+                                 we have a backlink in this object
+                                 that needs to be removed. We're not
+                                 allowed to remove it directly
+                                 however, so we instead setup a
+                                 modify to delete the corresponding
+                                 forward link
+                                */
                                ret = replmd_delete_remove_link(module, schema, old_dn, el, sa, req);
                                if (ret != LDB_SUCCESS) {
                                        talloc_free(tmp_ctx);
                                        return LDB_ERR_OPERATIONS_ERROR;
                                }
+                               /* now we continue, which means we
+                                  won't remove this backlink
+                                  directly
+                               */
                                continue;
                        }
                        if (!sa->linkID && ldb_attr_in_list(preserved_attrs, el->name)) {