s4:dsdb Add 'dsdb_flags' to dsdb_module_search() to enable often-used features
authorAndrew Bartlett <abartlet@samba.org>
Mon, 16 Nov 2009 07:32:17 +0000 (18:32 +1100)
committerAndrew Bartlett <abartlet@samba.org>
Mon, 16 Nov 2009 23:38:01 +0000 (10:38 +1100)
These flags, also on dsdb_module_search_dn() allow us to add commonly
set controls to this pre-packaged blocking search, without rebuilding
the whole function in each caller.

Andrew Bartlett

source4/dsdb/samdb/ldb_modules/extended_dn_store.c
source4/dsdb/samdb/ldb_modules/naming_fsmo.c
source4/dsdb/samdb/ldb_modules/partition_init.c
source4/dsdb/samdb/ldb_modules/pdc_fsmo.c
source4/dsdb/samdb/ldb_modules/util.c
source4/dsdb/samdb/ldb_modules/util.h
source4/setup/provision_configuration_references.ldif [moved from source4/setup/provision_configuration_basedn_modify.ldif with 100% similarity]

index 557acf2d82dbd2a5f2a800b479c10dbbd58c298e..3a531c00a5a1f9c95a7049d5b45cc49f4f1abc17 100644 (file)
@@ -42,7 +42,7 @@
 #include "librpc/gen_ndr/ndr_misc.h"
 #include "dsdb/samdb/samdb.h"
 #include "libcli/security/security.h"
-
+#include "dsdb/samdb/ldb_modules/util.h"
 #include <time.h>
 
 struct extended_dn_replace_list {
@@ -275,9 +275,8 @@ static int extended_store_replace(struct extended_dn_context *ac,
                return ret;
        }
 
-       ret = ldb_request_add_control(os->search_req,
-                                     DSDB_CONTROL_DN_STORAGE_FORMAT_OID,
-                                     true, NULL);
+       ret = dsdb_module_search_handle_flags(ac->module, os->search_req, 
+                                             DSDB_SEARCH_SHOW_DELETED|DSDB_SEARCH_SHOW_DN_IN_STORAGE_FORMAT);
        if (ret != LDB_SUCCESS) {
                talloc_free(os);
                return ret;
index 15cad259ce8eea2173062fa69f115e1708130089..3a10a604ec60af1b31d9e0043f08b9d0a198f920 100644 (file)
@@ -67,8 +67,8 @@ static int naming_fsmo_init(struct ldb_module *module)
        ldb_module_set_private(module, naming_fsmo);
 
        ret = dsdb_module_search_dn(module, mem_ctx, &naming_res,
-                                   naming_dn, 
-                                   naming_attrs);
+                                   naming_dn,
+                                   naming_attrs, 0);
        if (ret == LDB_ERR_NO_SUCH_OBJECT) {
                ldb_debug(ldb, LDB_DEBUG_WARNING,
                          "naming_fsmo_init: no partitions dn present: (skip loading of naming contexts details)\n");
index db99b75817014829a0f828500a897f3dc6245061..416648c0acdbae6da8137995a2818c6392a011e8 100644 (file)
@@ -136,7 +136,7 @@ static int partition_reload_metadata(struct ldb_module *module, struct partition
        /* perform search for @PARTITION, looking for module, replicateEntries and ldapBackend */
        ret = dsdb_module_search_dn(module, mem_ctx, &res, 
                                    ldb_dn_new(mem_ctx, ldb, DSDB_PARTITION_DN),
-                                   attrs);
+                                   attrs, 0);
        if (ret != LDB_SUCCESS) {
                return ret;
        }
@@ -493,7 +493,7 @@ int partition_reload_if_required(struct ldb_module *module,
 
                /* Get the 'correct' case of the partition DNs from the database */
                ret = dsdb_module_search_dn(partition->module, data, &dn_res, 
-                                           dn, no_attrs);
+                                           dn, no_attrs, 0);
                if (ret == LDB_SUCCESS) {
                        talloc_free(partition->ctrl->dn);
                        partition->ctrl->dn = talloc_steal(partition->ctrl, dn_res->msgs[0]->dn);
@@ -533,7 +533,7 @@ static int new_partition_set_replicated_metadata(struct ldb_context *ldb,
                struct ldb_request *add_req;
                ret = dsdb_module_search_dn(module, last_req, &replicate_res, 
                                            data->replicate[i],
-                                           NULL);
+                                           NULL, 0);
                if (ret == LDB_ERR_NO_SUCH_OBJECT) {
                        continue;
                }
index 6d814f9334f0e03661ef550898f12433ca331b62..796ecaf7bca7d90af81074d27b66964fb57c8943 100644 (file)
@@ -67,7 +67,7 @@ static int pdc_fsmo_init(struct ldb_module *module)
 
        ret = dsdb_module_search_dn(module, mem_ctx, &pdc_res,
                                    pdc_dn, 
-                                   pdc_attrs);
+                                   pdc_attrs, 0);
        if (ret == LDB_ERR_NO_SUCH_OBJECT) {
                ldb_debug(ldb, LDB_DEBUG_WARNING,
                          "pdc_fsmo_init: no domain object present: (skip loading of domain details)\n");
index 372cad62e21202567d50e0eeace406a83b0fa102..b0f22de2559cc313e5933e0a0cfe5e9658f0baa0 100644 (file)
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
+#include "includes.h"
 #include "ldb.h"
 #include "ldb_module.h"
+#include "dsdb/samdb/ldb_modules/util.h"
+#include "dsdb/samdb/samdb.h"
+
+int dsdb_module_search_handle_flags(struct ldb_module *module, struct ldb_request *req, int dsdb_flags) 
+{
+       int ret;
+       if (dsdb_flags & DSDB_SEARCH_SEARCH_ALL_PARTITIONS) {
+               struct ldb_search_options_control *options;
+               /* Using the phantom root control allows us to search all partitions */
+               options = talloc(req, struct ldb_search_options_control);
+               if (options == NULL) {
+                       ldb_module_oom(module);
+                       return LDB_ERR_OPERATIONS_ERROR;
+               }
+               options->search_options = LDB_SEARCH_OPTION_PHANTOM_ROOT;
+               
+               ret = ldb_request_add_control(req,
+                                             LDB_CONTROL_SEARCH_OPTIONS_OID,
+                                             true, options);
+               if (ret != LDB_SUCCESS) {
+                       return ret;
+               }
+       }
+
+       if (dsdb_flags & DSDB_SEARCH_SHOW_DELETED) {
+               ret = ldb_request_add_control(req, LDB_CONTROL_SHOW_DELETED_OID, true, NULL);
+               if (ret != LDB_SUCCESS) {
+                       return ret;
+               }
+       }
+
+       if (dsdb_flags & DSDB_SEARCH_SHOW_DN_IN_STORAGE_FORMAT) {
+               ret = ldb_request_add_control(req, DSDB_CONTROL_DN_STORAGE_FORMAT_OID, true, NULL);
+               if (ret != LDB_SUCCESS) {
+                       return ret;
+               }
+       }
+
+       if (dsdb_flags & DSDB_SEARCH_SHOW_EXTENDED_DN) {
+               struct ldb_extended_dn_control *extended_ctrl = talloc(req, struct ldb_extended_dn_control);
+               if (!extended_ctrl) {
+                       ldb_module_oom(module);
+                       return LDB_ERR_OPERATIONS_ERROR;
+               }
+               extended_ctrl->type = 1;
+               
+               ret = ldb_request_add_control(req, LDB_CONTROL_EXTENDED_DN_OID, true, extended_ctrl);
+               if (ret != LDB_SUCCESS) {
+                       return ret;
+               }
+       }
+
+       return LDB_SUCCESS;
+}
 
 /*
   search for attrs on one DN, in the modules below
@@ -29,7 +84,8 @@ int dsdb_module_search_dn(struct ldb_module *module,
                          TALLOC_CTX *mem_ctx,
                          struct ldb_result **_res,
                          struct ldb_dn *basedn,
-                         const char * const *attrs)
+                         const char * const *attrs,
+                         int dsdb_flags)
 {
        int ret;
        struct ldb_request *req;
@@ -57,6 +113,12 @@ int dsdb_module_search_dn(struct ldb_module *module,
                return ret;
        }
 
+       ret = dsdb_module_search_handle_flags(module, req, dsdb_flags);
+       if (ret != LDB_SUCCESS) {
+               talloc_free(tmp_ctx);
+               return ret;
+       }
+
        ret = ldb_next_request(module, req);
        if (ret == LDB_SUCCESS) {
                ret = ldb_wait(req->handle, LDB_WAIT_ALL);
@@ -88,6 +150,7 @@ int dsdb_module_search(struct ldb_module *module,
                       struct ldb_result **_res,
                       struct ldb_dn *basedn, enum ldb_scope scope, 
                       const char * const *attrs,
+                      int dsdb_flags, 
                       const char *expression)
 {
        int ret;
@@ -116,6 +179,12 @@ int dsdb_module_search(struct ldb_module *module,
                return ret;
        }
 
+       ret = dsdb_module_search_handle_flags(module, req, dsdb_flags);
+       if (ret != LDB_SUCCESS) {
+               talloc_free(tmp_ctx);
+               return ret;
+       }
+
        ret = ldb_next_request(module, req);
        if (ret == LDB_SUCCESS) {
                ret = ldb_wait(req->handle, LDB_WAIT_ALL);
index 0a1ab83c6db2ec92bc89fddfeb813e6b04579eae..b612c64acc4630c4f3dc6fdf5d23edfde91fa2fd 100644 (file)
@@ -20,3 +20,8 @@
 */
 
 #include "dsdb/samdb/ldb_modules/util_proto.h"
+
+#define DSDB_SEARCH_SEARCH_ALL_PARTITIONS     0x0001
+#define DSDB_SEARCH_SHOW_DELETED              0x0002
+#define DSDB_SEARCH_SHOW_DN_IN_STORAGE_FORMAT 0x0004
+#define DSDB_SEARCH_SHOW_EXTENDED_DN          0x0010