s4-dsdb: use ldb_operr() in the dsdb code
[samba.git] / source4 / dsdb / samdb / ldb_modules / extended_dn_in.c
index e6b0220242b6e499f89d587c103cd70c4011d391..74417d2bbf13aaebcbb76e278824a48dcf196666 100644 (file)
 #include "ldb/include/ldb_errors.h"
 #include "ldb/include/ldb_module.h"
 
+/*
+  TODO: if relax is not set then we need to reject the fancy RMD_* and
+  DELETED extended DN codes
+ */
+
 /* search */
 struct extended_search_context {
        struct ldb_module *module;
@@ -151,7 +156,7 @@ static int extended_base_callback(struct ldb_request *req, struct ldb_reply *are
 
                if (!ac->basedn) {
                        const char *str = talloc_asprintf(req, "Base-DN '%s' not found",
-                                                         ldb_dn_get_linearized(ac->req->op.search.base));
+                                                         ldb_dn_get_extended_linearized(req, ac->req->op.search.base, 1));
                        ldb_set_errstring(ldb_module_get_ctx(ac->module), str);
                        return ldb_module_done(ac->req, NULL, NULL,
                                               LDB_ERR_NO_SUCH_OBJECT);
@@ -255,6 +260,7 @@ static int extended_dn_in_fix(struct ldb_module *module, struct ldb_request *req
                "wellKnownObjects",
                NULL
        };
+       bool all_partitions = false;
 
        if (!ldb_dn_has_extended(dn)) {
                /* Move along there isn't anything to see here */
@@ -268,26 +274,24 @@ static int extended_dn_in_fix(struct ldb_module *module, struct ldb_request *req
                wkguid_val = ldb_dn_get_extended_component(dn, "WKGUID");
 
                if (sid_val) {
-                       /* TODO: do a search over all partitions */
+                       all_partitions = true;
                        base_dn = ldb_get_default_basedn(ldb_module_get_ctx(module));
                        base_dn_filter = talloc_asprintf(req, "(objectSid=%s)", 
                                                         ldb_binary_encode(req, *sid_val));
                        if (!base_dn_filter) {
-                               ldb_oom(ldb_module_get_ctx(module));
-                               return LDB_ERR_OPERATIONS_ERROR;
+                               return ldb_oom(ldb_module_get_ctx(module));
                        }
                        base_dn_scope = LDB_SCOPE_SUBTREE;
                        base_dn_attrs = no_attr;
 
                } else if (guid_val) {
 
-                       /* TODO: do a search over all partitions */
+                       all_partitions = true;
                        base_dn = ldb_get_default_basedn(ldb_module_get_ctx(module));
                        base_dn_filter = talloc_asprintf(req, "(objectGUID=%s)", 
                                                         ldb_binary_encode(req, *guid_val));
                        if (!base_dn_filter) {
-                               ldb_oom(ldb_module_get_ctx(module));
-                               return LDB_ERR_OPERATIONS_ERROR;
+                               return ldb_oom(ldb_module_get_ctx(module));
                        }
                        base_dn_scope = LDB_SCOPE_SUBTREE;
                        base_dn_attrs = no_attr;
@@ -310,8 +314,7 @@ static int extended_dn_in_fix(struct ldb_module *module, struct ldb_request *req
 
                        wellknown_object = talloc_asprintf(req, "B:32:%s:", wkguid_dup);
                        if (!wellknown_object) {
-                               ldb_oom(ldb_module_get_ctx(module));
-                               return LDB_ERR_OPERATIONS_ERROR;
+                               return ldb_oom(ldb_module_get_ctx(module));
                        }
 
                        tail_str = p;
@@ -319,13 +322,11 @@ static int extended_dn_in_fix(struct ldb_module *module, struct ldb_request *req
                        base_dn = ldb_dn_new(req, ldb_module_get_ctx(module), tail_str);
                        talloc_free(wkguid_dup);
                        if (!base_dn) {
-                               ldb_oom(ldb_module_get_ctx(module));
-                               return LDB_ERR_OPERATIONS_ERROR;
+                               return ldb_oom(ldb_module_get_ctx(module));
                        }
                        base_dn_filter = talloc_strdup(req, "(objectClass=*)");
                        if (!base_dn_filter) {
-                               ldb_oom(ldb_module_get_ctx(module));
-                               return LDB_ERR_OPERATIONS_ERROR;
+                               return ldb_oom(ldb_module_get_ctx(module));
                        }
                        base_dn_scope = LDB_SCOPE_BASE;
                        base_dn_attrs = wkattr;
@@ -335,8 +336,7 @@ static int extended_dn_in_fix(struct ldb_module *module, struct ldb_request *req
 
                ac = talloc_zero(req, struct extended_search_context);
                if (ac == NULL) {
-                       ldb_oom(ldb_module_get_ctx(module));
-                       return LDB_ERR_OPERATIONS_ERROR;
+                       return ldb_oom(ldb_module_get_ctx(module));
                }
                
                ac->module = module;
@@ -357,7 +357,20 @@ static int extended_dn_in_fix(struct ldb_module *module, struct ldb_request *req
                                           ac, extended_base_callback,
                                           req);
                if (ret != LDB_SUCCESS) {
-                       return LDB_ERR_OPERATIONS_ERROR;
+                       return ldb_operr(ldb_module_get_ctx(module));
+               }
+
+               if (all_partitions) {
+                       struct ldb_search_options_control *control;
+                       control = talloc(down_req, struct ldb_search_options_control);
+                       control->search_options = 2;
+                       ret = ldb_request_add_control(down_req,
+                                                     LDB_CONTROL_SEARCH_OPTIONS_OID,
+                                                     true, control);
+                       if (ret != LDB_SUCCESS) {
+                               ldb_oom(ldb_module_get_ctx(module));
+                               return ret;
+                       }
                }
 
                /* perform the search */