repl_meta_data: Print more detail into the LDB error string, not just DEBUG()
authorAndrew Bartlett <abartlet@samba.org>
Thu, 24 Sep 2015 02:08:37 +0000 (14:08 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Mon, 26 Oct 2015 04:11:21 +0000 (05:11 +0100)
Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
source4/dsdb/samdb/ldb_modules/repl_meta_data.c

index 3310d307b01109eca6ad8d55d7187adf9c1d7d9d..3e4880e131c2391a0b11a11304cfa622c4f0ec27 100644 (file)
@@ -3159,16 +3159,17 @@ static int replmd_delete_internals(struct ldb_module *module, struct ldb_request
                                            ldb_dn_escape_value(tmp_ctx, *rdn_value),
                                            GUID_string(tmp_ctx, &guid));
                if (!retb) {
-                       DEBUG(0,(__location__ ": Unable to add a formatted child to dn: %s",
-                                ldb_dn_get_linearized(new_dn)));
+                       ldb_asprintf_errstring(ldb, __location__
+                                              ": Unable to add a formatted child to dn: %s",
+                                              ldb_dn_get_linearized(new_dn));
                        talloc_free(tmp_ctx);
                        return LDB_ERR_OPERATIONS_ERROR;
                }
 
                ret = ldb_msg_add_string(msg, "isDeleted", "TRUE");
                if (ret != LDB_SUCCESS) {
-                       DEBUG(0,(__location__ ": Failed to add isDeleted string to the msg\n"));
-                       ldb_module_oom(module);
+                       ldb_asprintf_errstring(ldb, __location__
+                                              ": Failed to add isDeleted string to the msg");
                        talloc_free(tmp_ctx);
                        return ret;
                }
@@ -3182,8 +3183,9 @@ static int replmd_delete_internals(struct ldb_module *module, struct ldb_request
                struct ldb_dn *rdn = ldb_dn_copy(tmp_ctx, old_dn);
                retb = ldb_dn_remove_base_components(rdn, ldb_dn_get_comp_num(rdn) - 1);
                if (!retb) {
-                       DEBUG(0,(__location__ ": Unable to add a prepare rdn of %s",
-                                ldb_dn_get_linearized(rdn)));
+                       ldb_asprintf_errstring(ldb, __location__
+                                              ": Unable to add a prepare rdn of %s",
+                                              ldb_dn_get_linearized(rdn));
                        talloc_free(tmp_ctx);
                        return LDB_ERR_OPERATIONS_ERROR;
                }
@@ -3191,9 +3193,10 @@ static int replmd_delete_internals(struct ldb_module *module, struct ldb_request
 
                retb = ldb_dn_add_child(new_dn, rdn);
                if (!retb) {
-                       DEBUG(0,(__location__ ": Unable to add rdn %s to base dn: %s",
-                                ldb_dn_get_linearized(rdn),
-                                ldb_dn_get_linearized(new_dn)));
+                       ldb_asprintf_errstring(ldb, __location__
+                                              ": Unable to add rdn %s to base dn: %s",
+                                              ldb_dn_get_linearized(rdn),
+                                              ldb_dn_get_linearized(new_dn));
                        talloc_free(tmp_ctx);
                        return LDB_ERR_OPERATIONS_ERROR;
                }
@@ -3217,29 +3220,48 @@ static int replmd_delete_internals(struct ldb_module *module, struct ldb_request
         */
 
        if (deletion_state == OBJECT_NOT_DELETED) {
+               struct ldb_dn *parent_dn = ldb_dn_get_parent(tmp_ctx, old_dn);
+               char *parent_dn_str = NULL;
+
                /* we need the storage form of the parent GUID */
                ret = dsdb_module_search_dn(module, tmp_ctx, &parent_res,
-                                           ldb_dn_get_parent(tmp_ctx, old_dn), NULL,
+                                           parent_dn, NULL,
                                            DSDB_FLAG_NEXT_MODULE |
                                            DSDB_SEARCH_SHOW_DN_IN_STORAGE_FORMAT |
                                            DSDB_SEARCH_REVEAL_INTERNALS|
                                            DSDB_SEARCH_SHOW_RECYCLED, req);
                if (ret != LDB_SUCCESS) {
                        ldb_asprintf_errstring(ldb_module_get_ctx(module),
-                                              "repmd_delete: Failed to %s %s, because we failed to find it's parent (%s): %s",
+                                              "repmd_delete: Failed to %s %s, "
+                                              "because we failed to find it's parent (%s): %s",
                                               re_delete ? "re-delete" : "delete",
                                               ldb_dn_get_linearized(old_dn),
-                                              ldb_dn_get_linearized(ldb_dn_get_parent(tmp_ctx, old_dn)),
+                                              ldb_dn_get_linearized(parent_dn),
                                               ldb_errstring(ldb_module_get_ctx(module)));
                        talloc_free(tmp_ctx);
                        return ret;
                }
 
+               /*
+                * Now we can use the DB version,
+                * it will have the extended DN info in it
+                */
+               parent_dn = parent_res->msgs[0]->dn;
+               parent_dn_str = ldb_dn_get_extended_linearized(tmp_ctx,
+                                                              parent_dn,
+                                                              1);
+               if (parent_dn_str == NULL) {
+                       talloc_free(tmp_ctx);
+                       return ldb_module_oom(module);
+               }
+
                ret = ldb_msg_add_steal_string(msg, "lastKnownParent",
-                                                  ldb_dn_get_extended_linearized(tmp_ctx, parent_res->msgs[0]->dn, 1));
+                                              parent_dn_str);
                if (ret != LDB_SUCCESS) {
-                       DEBUG(0,(__location__ ": Failed to add lastKnownParent string to the msg\n"));
-                       ldb_module_oom(module);
+                       ldb_asprintf_errstring(ldb, __location__
+                                              ": Failed to add lastKnownParent "
+                                              "string when deleting %s",
+                                              ldb_dn_get_linearized(old_dn));
                        talloc_free(tmp_ctx);
                        return ret;
                }
@@ -3248,8 +3270,10 @@ static int replmd_delete_internals(struct ldb_module *module, struct ldb_request
                if (next_deletion_state == OBJECT_DELETED) {
                        ret = ldb_msg_add_value(msg, "msDS-LastKnownRDN", rdn_value, NULL);
                        if (ret != LDB_SUCCESS) {
-                               DEBUG(0,(__location__ ": Failed to add msDS-LastKnownRDN string to the msg\n"));
-                               ldb_module_oom(module);
+                               ldb_asprintf_errstring(ldb, __location__
+                                                      ": Failed to add msDS-LastKnownRDN "
+                                                      "string when deleting %s",
+                                                      ldb_dn_get_linearized(old_dn));
                                talloc_free(tmp_ctx);
                                return ret;
                        }
@@ -3316,6 +3340,14 @@ static int replmd_delete_internals(struct ldb_module *module, struct ldb_request
                                 */
                                ret = replmd_delete_remove_link(module, schema, old_dn, el, sa, req);
                                if (ret != LDB_SUCCESS) {
+                                       const char *old_dn_str
+                                               = ldb_dn_get_linearized(old_dn);
+                                       ldb_asprintf_errstring(ldb,
+                                                              __location__
+                                                              ": Failed to remove backlink of "
+                                                              "%s when deleting %s",
+                                                              el->name,
+                                                              old_dn_str);
                                        talloc_free(tmp_ctx);
                                        return LDB_ERR_OPERATIONS_ERROR;
                                }