s4-dsdb: don't return the partition root objects
[samba.git] / source4 / dsdb / samdb / ldb_modules / partition.c
index e8b55a4e4bb6ecf033d289d1e9c63b7a0eae8a4b..6e86d4c48455310477e7dbd0f9d5986e20b8c861 100644 (file)
@@ -4,10 +4,6 @@
    Copyright (C) Andrew Bartlett <abartlet@samba.org> 2006
    Copyright (C) Stefan Metzmacher <metze@samba.org> 2007
 
-   * NOTICE: this module is NOT released under the GNU LGPL license as
-   * other ldb code. This module is release under the GNU GPL v3 or
-   * later license.
-
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
@@ -165,6 +161,10 @@ static struct dsdb_partition *find_partition(struct partition_private_data *data
                }
        }
 
+       if (dn == NULL) {
+               return NULL;
+       }
+
        /* Look at base DN */
        /* Figure out which partition it is under */
        /* Skip the lot if 'data' isn't here yet (initialisation) */
@@ -186,9 +186,11 @@ static int partition_req_callback(struct ldb_request *req,
        struct partition_context *ac;
        struct ldb_module *module;
        struct ldb_request *nreq;
-       int ret;
+       int ret, i;
+       struct partition_private_data *data;
 
        ac = talloc_get_type(req->context, struct partition_context);
+       data = talloc_get_type(ac->module->private_data, struct partition_private_data);
 
        if (!ares) {
                return ldb_module_done(ac->req, NULL, NULL,
@@ -213,6 +215,22 @@ static int partition_req_callback(struct ldb_request *req,
                        return ldb_module_done(ac->req, NULL, NULL,
                                                LDB_ERR_OPERATIONS_ERROR);
                }
+               for (i=0; data && data->partitions && data->partitions[i]; i++) {
+                       if (ldb_dn_compare(ares->message->dn, data->partitions[i]->ctrl->dn) == 0) {
+                               struct ldb_control *part_control;
+                               /* this is a partition root message - make
+                                  sure it isn't one of our fake root
+                                  entries from a parent partition */
+                               part_control = ldb_request_get_control(req, DSDB_CONTROL_CURRENT_PARTITION_OID);
+                               if (part_control && part_control->data != data->partitions[i]->ctrl) {
+                                       DEBUG(6,(__location__ ": Discarding partition mount object %s\n",
+                                                ldb_dn_get_linearized(ares->message->dn)));
+                                       talloc_free(ares);
+                                       return LDB_SUCCESS;
+                               }
+                       }
+               }
+               
                return ldb_module_send_entry(ac->req, ares->message, ares->controls);
 
        case LDB_REPLY_DONE:
@@ -474,10 +492,10 @@ static int partition_replicate(struct ldb_module *module, struct ldb_request *re
 static int partition_search(struct ldb_module *module, struct ldb_request *req)
 {
        struct ldb_control **saved_controls;
-       
        /* Find backend */
        struct partition_private_data *data = talloc_get_type(module->private_data, 
                                                              struct partition_private_data);
+
        /* issue request */
 
        /* (later) consider if we should be searching multiple
@@ -487,6 +505,17 @@ static int partition_search(struct ldb_module *module, struct ldb_request *req)
        struct ldb_control *domain_scope_control = ldb_request_get_control(req, LDB_CONTROL_DOMAIN_SCOPE_OID);
        
        struct ldb_search_options_control *search_options = NULL;
+       struct dsdb_partition *p;
+       
+       p = find_partition(data, NULL, req);
+       if (p != NULL) {
+               /* the caller specified what partition they want the
+                * search - just pass it on
+                */
+               return ldb_next_request(p->module, req);                
+       }
+
+
        if (search_control) {
                search_options = talloc_get_type(search_control->data, struct ldb_search_options_control);
        }
@@ -767,6 +796,15 @@ static int partition_sequence_number(struct ldb_module *module, struct ldb_reque
        struct ldb_seqnum_result *tseqr;
        struct ldb_extended *ext;
        struct ldb_result *res;
+       struct dsdb_partition *p;
+
+       p = find_partition(data, NULL, req);
+       if (p != NULL) {
+               /* the caller specified what partition they want the
+                * sequence number operation on - just pass it on
+                */
+               return ldb_next_request(p->module, req);                
+       }
 
        seq = talloc_get_type(req->op.extended.data, struct ldb_seqnum_request);