[SCM] Samba Shared Repository - branch master updated

Andrew Bartlett abartlet at samba.org
Wed Oct 21 05:44:20 MDT 2009


The branch, master has been updated
       via  1467e5e... s4-ldb: allow for non-null terminated ldb_val in ldb_dn_from_ldb_val
       via  16a80f1... s4:dsdb Add note explaining about the partition format upgrade
       via  d7cf71d... s4:dsdb Allow loading of old-style partition records
       via  4209cf9... s4:dsdb Make the 'relative path' code in partitions handle tdb://
       via  fa2e04b... s4:ldb_map Fix use-after-free of memory in ldb_map
       via  96ec453... s4:dsdb talloc_steal the backend module to under the partition
       via  937140b... s4:ldb Put ltdb_private under the 'module'
       via  a0a787a... s4:rpc_server Ensure we talloc_free handles when we delete objects
       via  398188f... s4:dsdb Remove potentially confusing 'partition' control from result
       via  bd53628... s4:ldb Add new function to create a cut down list of controls
       via  fcbe616... s4:samr Don't leak the whole user onto the long-term handle
       via  108b834... librpc Make talloc tree in binding tower match the floors
       via  47daa27... s4:epmapper Create a proper talloc tree of endpoint floors
       via  1547477... s4:dsdb Allow creation of new partitions
       via  4c36cac... s4:provision Use schema to casefold partitions on 'upgrade'.
       via  da7c778... s4:dsdb Remove default instanceType from repl_meta_data
       via  c106017... s4:dsdb Remove workaround for two partition head records
       via  96c9bc1... s4:dsdb Use 'partition modified' information to update @REPLCHANGED
       via  d3a5037... s4:repl Pass schema as argument to replmd_update_rpmd()
       via  f545d5f... s4:dsdb In partitions module, tell the caller what partition was used.
       via  17237f1... s4:ldb Add function to add controls to an LDB reply
       via  be5f081... s4:dsdb Load new partitions in a running LDB if metadata changes
       via  6a77165... s4:dsdb Only reload partition metadata on search and transaction start
       via  e62200e... s4:dsdb Reload partition metadata if the main db updates
       via  1803525... s4:provision Test ability to set GUIDs from provision command line
       via  d3b50ec... s4:provison Allow the NTDS guid on the command line (for testing)
       via  fa5ebaa... s4:dsdb Split 'set per-partition metadata' into it's own function
       via  27c28d3... s4:Handle reprovision with existing partitions
       via  ff3b60d... s4:dsdb Don't try and casefold DNs during startup for partition load
       via  129bda5... s4:dsdb Fix partition_create not to return early
       via  b73d584... s4:dsdb Fix tests for samba3sam to pass after partitions module changes
       via  b04bdee... s4:dsdb Be strict in selecting on-disk names for partitions
       via  8ea2a8b... s4:dsdb Set 'notification' after the success of a change.
       via  d4048b2... s4:provision Set @OPTIONS in the provision_init.ldif
       via  c59f008... s4:dsdb Rework modules create new partitions at runtime
      from  9393d94... s4/drs: prefixMap main interface implementation

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 1467e5eaab24b2b5c90ba0dd4e9dad4f321568c3
Author: Andrew Tridgell <tridge at samba.org>
Date:   Wed Oct 21 22:18:16 2009 +1100

    s4-ldb: allow for non-null terminated ldb_val in ldb_dn_from_ldb_val
    
    The strlen() could go past the end of a non-null terminated value

commit 16a80f17425c5de9d0bd52494e3e26a6840cfd7d
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Wed Oct 21 22:28:29 2009 +1100

    s4:dsdb Add note explaining about the partition format upgrade

commit d7cf71d9b6cae19b2f9a215f910b4b6e1474291d
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Wed Oct 21 22:27:22 2009 +1100

    s4:dsdb Allow loading of old-style partition records
    
    This should make upgrades easier

commit 4209cf9860b528f2ac9da175feec8783a35950f9
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Wed Oct 21 18:25:00 2009 +1100

    s4:dsdb Make the 'relative path' code in partitions handle tdb://
    
    The previous code would fail if the caller used tdb:// in the URL for the
    top-level database.
    
    Andrew Bartlett

commit fa2e04b64004f24bcac51a44ce37b8923480b819
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Wed Oct 21 18:23:18 2009 +1100

    s4:ldb_map Fix use-after-free of memory in ldb_map
    
    We need to keep the old 'ares' from the remote server around so we can forward
    it back to the caller.  We can't send the same controls (from the last search
    entry) twice (and it makes no sense anyway).
    
    Andrew Bartlett

commit 96ec45309a367a00234f7c62c2d30c64ae95b680
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Wed Oct 21 16:09:10 2009 +1100

    s4:dsdb talloc_steal the backend module to under the partition

commit 937140bf102a2a92d7822f22f30a9adc19920834
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Wed Oct 21 16:08:24 2009 +1100

    s4:ldb Put ltdb_private under the 'module'
    
    This helps track the memory better, as we can then place it under the partition
    hirarchy.
    
    Andrew Bartlett

commit a0a787ad78a72b1bb9e7f9f7f28d18a4023a666b
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Wed Oct 21 16:07:22 2009 +1100

    s4:rpc_server Ensure we talloc_free handles when we delete objects
    
    If we don't talloc_free the handle, we leak the memory onto the long-term
    context.
    
    Andrew Bartlett

commit 398188fb9b0d81552d0eb3dba9fcf0695ea539ff
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Wed Oct 21 15:21:21 2009 +1100

    s4:dsdb Remove potentially confusing 'partition' control from result
    
    This ensures that the partition control, needed here for repl_meta_data's
    internal work, is not pushed up to other callers.
    
    Andrew Bartlett

commit bd53628c7a7d430878588666372dc73f1a88b7de
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Wed Oct 21 15:20:26 2009 +1100

    s4:ldb Add new function to create a cut down list of controls
    
    This I hope will be useful for removing controls from the ldb_reply
    
    Andrew Bartlett

commit fcbe6163f65ae9e4fce9228434c447ad34943010
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Wed Oct 21 15:18:59 2009 +1100

    s4:samr Don't leak the whole user onto the long-term handle
    
    The user entry is only required for this function, so use
    mem_ctx to hold it.
    
    Andrew Bartlett

commit 108b8344db39f7314a7c4dcaf0fbd020d1b41da3
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Wed Oct 21 15:17:31 2009 +1100

    librpc Make talloc tree in binding tower match the floors
    
    This is mostly cosmetics, but helped me see that these are legitimate stuctures
    when viewed in the talloc tree.
    
    Also don't put the 'ndr' structure on the long-term tree.
    
    Andrew Bartlett

commit 47daa272c04497418594fdec137033e0f342348b
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Wed Oct 21 15:15:48 2009 +1100

    s4:epmapper Create a proper talloc tree of endpoint floors
    
    Andrew Bartlett

commit 154747759e24903106549a341a3fd86624abe6b5
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Tue Oct 20 09:12:26 2009 +1100

    s4:dsdb Allow creation of new partitions
    
    This is a collection of fixes to allow the creation of new partitions,
    as well as adding debugging that may be useful in chasing down future
    failures.
    
    Andrew Bartlett

commit 4c36cac5ad7890d437e15561794c19a3ebd4406b
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Tue Oct 20 09:11:04 2009 +1100

    s4:provision Use schema to casefold partitions on 'upgrade'.
    
    This helps us upgrade from sam.ldb files before the dynamic partitions
    work, and ensures we use the right casefolding functions.
    
    Andrew Bartlett

commit da7c778741ad51bd03af068faedb2204e2a79af5
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Mon Oct 19 12:03:50 2009 +1100

    s4:dsdb Remove default instanceType from repl_meta_data
    
    This is no longer required, as the instancetype module is now above
    repl_meta_data.
    
    Andrew Bartlett

commit c106017f9ae20c5b58a960b83f50f0d95b78868d
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Fri Oct 16 16:25:49 2009 +1100

    s4:dsdb Remove workaround for two partition head records
    
    The problem here has been avoided in repl_meta_data, and so this is no
    longer required.
    
    Andrew Bartlett

commit 96c9bc18d5ebb62c5ac04a193574db149cffe212
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Fri Oct 16 16:20:15 2009 +1100

    s4:dsdb Use 'partition modified' information to update @REPLCHANGED
    
    This major rework of repl_meta_data changes it from using a static
    list of partitions to a dynamic list created from the controls placed
    on returned ldb results.
    
    To process these in one place, the similar but distinct callbacks are
    combined into a single replmd_op_callback(), which handles both the
    'normal operation' and 'inbound replication' case.
    
    This allows new partitions to be created, and replication events for
    these new partitions to be scheduled immediately.
    
    Also in this commit: We no longer specify the target partition for new
    or modified objects - instead we allow the partitions module to use
    the DN as normal.  THis avoids the issue where we would create two
    partition head records.
    
    Andrew Bartlett

commit d3a5037f2aaa0c229f96a2074cf1c84914302dcf
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Fri Oct 16 15:11:28 2009 +1100

    s4:repl Pass schema as argument to replmd_update_rpmd()

commit f545d5fa43ac0f08f69cf3e130a4b7be1d90784f
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Thu Oct 15 10:49:25 2009 +1100

    s4:dsdb In partitions module, tell the caller what partition was used.
    
    This means we don't return any control for modifications to the
    control records in sam.ldb, but do if they modified one of the actual
    data LDB files.
    
    Andrew Bartlett

commit 17237f18f09798c90b2234150d502ccd21eb5880
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Thu Oct 15 10:45:44 2009 +1100

    s4:ldb Add function to add controls to an LDB reply

commit be5f0818ea89f08c5045e44604c9ba7d63ad1e29
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Wed Oct 14 15:16:34 2009 +1100

    s4:dsdb Load new partitions in a running LDB if metadata changes
    
    This allows one instance of LDB to add a partition, and another to use
    it without first closing the database.
    
    Andrew Bartlett

commit 6a77165c8ad3fdf37218e37352859926eca48922
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Wed Oct 14 14:13:52 2009 +1100

    s4:dsdb Only reload partition metadata on search and transaction start
    
    I see no reason to reload it when in a transaction - it can't change
    on us anyway (we possibly need to watch for our own changes to
    @PARTITION however)
    
    Andrew Bartlett

commit e62200e253a393ce0a427ff315267efbd2eaeeea
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Wed Oct 14 12:57:03 2009 +1100

    s4:dsdb Reload partition metadata if the main db updates
    
    This uses the fact that the primary DB does not change often.  Before
    each operation, we see if the sequence number has changed.
    
    Andrew Bartlett

commit 18035251add0e8c39f5fe7976881d6fd32c1bb9a
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Tue Oct 6 14:11:44 2009 +1100

    s4:provision Test ability to set GUIDs from provision command line

commit d3b50ec33fe0aa0b4e845eac176a0438eaa8b5a2
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Tue Oct 13 22:11:34 2009 +1100

    s4:provison Allow the NTDS guid on the command line (for testing)
    
    This allows a blackbox test to confirm this can be set.
    
    Andrew Bartlett

commit fa5ebaa686dc4f66403b5382fdd846d5c85a938b
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Wed Oct 14 11:09:18 2009 +1100

    s4:dsdb Split 'set per-partition metadata' into it's own function
    
    This helps us ensure we always set the metadata, even when we are
    'adding' a partition that is already in our list.  (We *really* don't
    want these getting out of sync, and the extra writes are harmless)
    
    Andrew Bartlett

commit 27c28d34a7bb80d188782fb073ee5f0a657c9be8
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Tue Oct 13 22:10:28 2009 +1100

    s4:Handle reprovision with existing partitions
    
    The issue here is that if we don't put the partitions metadata in the
    database before we wipe it, we won't wipe the partitions contents, and
    so the provision will later fail (entry already exists)
    
    Andrew Bartlett

commit ff3b60d154fe677339ae66bb5994534d9b898d42
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Tue Oct 13 22:09:14 2009 +1100

    s4:dsdb Don't try and casefold DNs during startup for partition load
    
    The issue here is that before we load the schema partition, we may not
    have the correct casefolding rules.  As such, keep things simple and
    use the DN exactly as found in the @PARTITIONS record to find the
    database.
    
    Andrew Bartlett

commit 129bda51f102bd265e8cf099579e6b484f54b739
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Mon Oct 12 23:27:00 2009 +1100

    s4:dsdb Fix partition_create not to return early

commit b73d584a899049442a49d4ce3215678139102ca9
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Mon Oct 12 20:49:23 2009 +1100

    s4:dsdb Fix tests for samba3sam to pass after partitions module changes
    
    This is needed because the new format of the partitions record is a
    casefolded DN, not a DN and file combination.
    
    Andrew Bartlett

commit b04bdee800dd73417f8885348d90c80dbc20d4a1
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Mon Oct 12 16:37:12 2009 +1100

    s4:dsdb Be strict in selecting on-disk names for partitions
    
    I really don't want a cn=foo/../bar in my ldb file name.
    
    Andrew Bartlett

commit 8ea2a8b7858866689c95d6a9d158b392b560e6b5
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Sat Oct 10 09:36:44 2009 +1100

    s4:dsdb Set 'notification' after the success of a change.
    
    This allows the partition to be created before we try and set a
    notification on it.  (perhaps extra work required here for partition
    heads).
    
    Andrew Bartlett

commit d4048b2e1771724d4e155172ff96983149f669e6
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Sat Oct 10 09:26:06 2009 +1100

    s4:provision Set @OPTIONS in the provision_init.ldif
    
    The new partitions code knows to copy these items in when creating a
    new parition, so we can set it from the start.
    
    Andrew Bartlett

commit c59f00805cb06f3cb90d89690e142006658972d3
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Fri Oct 2 10:28:29 2009 +1000

    s4:dsdb Rework modules create new partitions at runtime
    
    This is done by passing an extended operation to the partitions module
    to extend the @PARTITION record and to extend the in-memory list of
    partitions.
    
    This also splits things up into module parts that belong above and below
    repl_meta_data
    
    Also slit the partitions module into two files due to the complexity
    of the code
    
    Andrew Barltett

-----------------------------------------------------------------------

Summary of changes:
 librpc/rpc/binding.c                              |   24 +-
 source4/dsdb/samdb/ldb_modules/config.mk          |   15 +-
 source4/dsdb/samdb/ldb_modules/instancetype.c     |   37 +-
 source4/dsdb/samdb/ldb_modules/new_partition.c    |  189 ++++++
 source4/dsdb/samdb/ldb_modules/partition.c        |  459 +++----------
 source4/dsdb/samdb/ldb_modules/partition.h        |   63 ++
 source4/dsdb/samdb/ldb_modules/partition_init.c   |  741 +++++++++++++++++++++
 source4/dsdb/samdb/ldb_modules/repl_meta_data.c   |  589 ++++++-----------
 source4/dsdb/samdb/ldb_modules/tests/samba3sam.py |   22 +-
 source4/dsdb/samdb/samdb.c                        |    3 +
 source4/dsdb/samdb/samdb.h                        |    8 +
 source4/lib/ldb/common/ldb_controls.c             |   75 +++
 source4/lib/ldb/common/ldb_dn.c                   |    2 +-
 source4/lib/ldb/include/ldb_module.h              |   17 +
 source4/lib/ldb/ldb_map/ldb_map_outbound.c        |    9 +-
 source4/lib/ldb/ldb_map/ldb_map_private.h         |    3 +
 source4/lib/ldb/ldb_tdb/ldb_tdb.c                 |    1 +
 source4/partition-upgrade.txt                     |   21 +
 source4/rpc_server/epmapper/rpc_epmapper.c        |    2 +-
 source4/rpc_server/samr/dcesrv_samr.c             |    7 +-
 source4/scripting/python/samba/provision.py       |   62 ++-
 source4/setup/provision                           |    3 +
 source4/setup/provision_init.ldif                 |    3 +
 source4/setup/provision_options.ldif              |    3 -
 source4/setup/provision_partitions.ldif           |    5 +-
 source4/setup/schema_samba4.ldif                  |    1 +
 source4/setup/tests/blackbox_provision.sh         |    1 +
 27 files changed, 1560 insertions(+), 805 deletions(-)
 create mode 100644 source4/dsdb/samdb/ldb_modules/new_partition.c
 create mode 100644 source4/dsdb/samdb/ldb_modules/partition.h
 create mode 100644 source4/dsdb/samdb/ldb_modules/partition_init.c
 create mode 100644 source4/partition-upgrade.txt
 delete mode 100644 source4/setup/provision_options.ldif


Changeset truncated at 500 lines:

diff --git a/librpc/rpc/binding.c b/librpc/rpc/binding.c
index d773b8b..7344714 100644
--- a/librpc/rpc/binding.c
+++ b/librpc/rpc/binding.c
@@ -403,6 +403,7 @@ _PUBLIC_ NTSTATUS dcerpc_floor_get_lhs_data(const struct epm_floor *epm_floor,
 
 static DATA_BLOB dcerpc_floor_pack_lhs_data(TALLOC_CTX *mem_ctx, const struct ndr_syntax_id *syntax)
 {
+	DATA_BLOB blob;
 	struct ndr_push *ndr = ndr_push_init_ctx(mem_ctx, NULL);
 
 	ndr->flags |= LIBNDR_FLAG_NOALIGN;
@@ -410,7 +411,10 @@ static DATA_BLOB dcerpc_floor_pack_lhs_data(TALLOC_CTX *mem_ctx, const struct nd
 	ndr_push_GUID(ndr, NDR_SCALARS | NDR_BUFFERS, &syntax->uuid);
 	ndr_push_uint16(ndr, NDR_SCALARS, syntax->if_version);
 
-	return ndr_push_blob(ndr);
+	blob = ndr_push_blob(ndr);
+	talloc_steal(mem_ctx, blob.data);
+	talloc_free(ndr);
+	return blob;
 }
 
 const char *dcerpc_floor_get_rhs_data(TALLOC_CTX *mem_ctx, struct epm_floor *epm_floor)
@@ -691,29 +695,29 @@ _PUBLIC_ NTSTATUS dcerpc_binding_build_tower(TALLOC_CTX *mem_ctx,
 	/* Floor 0 */
 	tower->floors[0].lhs.protocol = EPM_PROTOCOL_UUID;
 
-	tower->floors[0].lhs.lhs_data = dcerpc_floor_pack_lhs_data(mem_ctx, &binding->object);
+	tower->floors[0].lhs.lhs_data = dcerpc_floor_pack_lhs_data(tower->floors, &binding->object);
 
-	tower->floors[0].rhs.uuid.unknown = data_blob_talloc_zero(mem_ctx, 2);
+	tower->floors[0].rhs.uuid.unknown = data_blob_talloc_zero(tower->floors, 2);
 
 	/* Floor 1 */
 	tower->floors[1].lhs.protocol = EPM_PROTOCOL_UUID;
 
-	tower->floors[1].lhs.lhs_data = dcerpc_floor_pack_lhs_data(mem_ctx, 
+	tower->floors[1].lhs.lhs_data = dcerpc_floor_pack_lhs_data(tower->floors, 
 								&ndr_transfer_syntax);
 
-	tower->floors[1].rhs.uuid.unknown = data_blob_talloc_zero(mem_ctx, 2);
+	tower->floors[1].rhs.uuid.unknown = data_blob_talloc_zero(tower->floors, 2);
 
 	/* Floor 2 to num_protocols */
 	for (i = 0; i < num_protocols; i++) {
 		tower->floors[2 + i].lhs.protocol = protseq[i];
-		tower->floors[2 + i].lhs.lhs_data = data_blob_talloc(mem_ctx, NULL, 0);
+		tower->floors[2 + i].lhs.lhs_data = data_blob_talloc(tower->floors, NULL, 0);
 		ZERO_STRUCT(tower->floors[2 + i].rhs);
-		dcerpc_floor_set_rhs_data(mem_ctx, &tower->floors[2 + i], "");
+		dcerpc_floor_set_rhs_data(tower->floors, &tower->floors[2 + i], "");
 	}
 
 	/* The 4th floor contains the endpoint */
 	if (num_protocols >= 2 && binding->endpoint) {
-		status = dcerpc_floor_set_rhs_data(mem_ctx, &tower->floors[3], binding->endpoint);
+		status = dcerpc_floor_set_rhs_data(tower->floors, &tower->floors[3], binding->endpoint);
 		if (NT_STATUS_IS_ERR(status)) {
 			return status;
 		}
@@ -722,7 +726,7 @@ _PUBLIC_ NTSTATUS dcerpc_binding_build_tower(TALLOC_CTX *mem_ctx,
 	/* The 5th contains the network address */
 	if (num_protocols >= 3 && binding->host) {
 		if (is_ipaddress(binding->host)) {
-			status = dcerpc_floor_set_rhs_data(mem_ctx, &tower->floors[4], 
+			status = dcerpc_floor_set_rhs_data(tower->floors, &tower->floors[4], 
 							   binding->host);
 		} else {
 			/* note that we don't attempt to resolve the
@@ -730,7 +734,7 @@ _PUBLIC_ NTSTATUS dcerpc_binding_build_tower(TALLOC_CTX *mem_ctx,
 			   are in the client code, and want to put in
 			   a wildcard all-zeros IP for the server to
 			   fill in */
-			status = dcerpc_floor_set_rhs_data(mem_ctx, &tower->floors[4], 
+			status = dcerpc_floor_set_rhs_data(tower->floors, &tower->floors[4], 
 							   "0.0.0.0");
 		}
 		if (NT_STATUS_IS_ERR(status)) {
diff --git a/source4/dsdb/samdb/ldb_modules/config.mk b/source4/dsdb/samdb/ldb_modules/config.mk
index ea4e722..40e37a4 100644
--- a/source4/dsdb/samdb/ldb_modules/config.mk
+++ b/source4/dsdb/samdb/ldb_modules/config.mk
@@ -235,7 +235,20 @@ INIT_FUNCTION = LDB_MODULE(partition)
 # End MODULE ldb_partition
 ################################################
 
-ldb_partition_OBJ_FILES = $(dsdbsrcdir)/samdb/ldb_modules/partition.o
+ldb_partition_OBJ_FILES = $(dsdbsrcdir)/samdb/ldb_modules/partition.o \
+			  $(dsdbsrcdir)/samdb/ldb_modules/partition_init.o
+$(eval $(call proto_header_template,$(dsdbsrcdir)/samdb/ldb_modules/partition_proto.h,$(ldb_partition_OBJ_FILES:.o=.c)))
+
+################################################
+# Start MODULE ldb_partition
+[MODULE::ldb_new_partition]
+SUBSYSTEM = LIBLDB
+PRIVATE_DEPENDENCIES = LIBTALLOC LIBEVENTS SAMDB DSDB_MODULE_HELPERS
+INIT_FUNCTION = LDB_MODULE(new_partition)
+# End MODULE ldb_partition
+################################################
+
+ldb_new_partition_OBJ_FILES = $(dsdbsrcdir)/samdb/ldb_modules/new_partition.o 
 
 ################################################
 # Start MODULE ldb_update_kt
diff --git a/source4/dsdb/samdb/ldb_modules/instancetype.c b/source4/dsdb/samdb/ldb_modules/instancetype.c
index 201ed04..b17f40e 100644
--- a/source4/dsdb/samdb/ldb_modules/instancetype.c
+++ b/source4/dsdb/samdb/ldb_modules/instancetype.c
@@ -31,6 +31,7 @@
  */
 
 #include "includes.h"
+#include "ldb.h"
 #include "ldb_module.h"
 #include "librpc/gen_ndr/ndr_misc.h"
 #include "dsdb/samdb/samdb.h"
@@ -39,9 +40,10 @@
 struct it_context {
 	struct ldb_module *module;
 	struct ldb_request *req;
+	struct ldb_request *add_req;
 };
 
-static int it_callback(struct ldb_request *req, struct ldb_reply *ares)
+static int it_add_callback(struct ldb_request *req, struct ldb_reply *ares)
 {
 	struct ldb_context *ldb;
 	struct it_context *ac;
@@ -53,6 +55,7 @@ static int it_callback(struct ldb_request *req, struct ldb_reply *ares)
 		return ldb_module_done(ac->req, NULL, NULL,
 					LDB_ERR_OPERATIONS_ERROR);
 	}
+
 	if (ares->error != LDB_SUCCESS) {
 		return ldb_module_done(ac->req, ares->controls,
 					ares->response, ares->error);
@@ -64,8 +67,10 @@ static int it_callback(struct ldb_request *req, struct ldb_reply *ares)
 					LDB_ERR_OPERATIONS_ERROR);
 	}
 
+	/* Add the boilerplate entries */
+
 	return ldb_module_done(ac->req, ares->controls,
-					ares->response, ares->error);
+			       ares->response, ares->error);
 }
 
 /* add_record: add instancetype attribute */
@@ -89,14 +94,32 @@ static int instancetype_add(struct ldb_module *module, struct ldb_request *req)
 
 	if (ldb_msg_find_element(req->op.add.message, "instanceType")) {
 		unsigned int instanceType = ldb_msg_find_attr_as_uint(req->op.add.message, "instanceType", 0);
+		if (!(instanceType & INSTANCE_TYPE_IS_NC_HEAD)) {
+			return ldb_next_request(module, req);		
+		}
 
-		if (instanceType & INSTANCE_TYPE_IS_NC_HEAD) {
-			/* Do something in future */
+		/* Forward the 'add' to the modules below, but if it
+		 * succeeds, then we might need to add the boilerplate
+		 * entries (lost+found, deleted objects) */
+		ac = talloc(req, struct it_context);
+		if (ac == NULL) {
+			return LDB_ERR_OPERATIONS_ERROR;
+		}
+		ac->module = module;
+		ac->req = req;
+		
+		ret = ldb_build_add_req(&ac->add_req, ldb_module_get_ctx(ac->module), ac,
+					ac->req->op.add.message,
+					ac->req->controls,
+					ac, it_add_callback,
+					ac->req);
+		
+		if (ret != LDB_SUCCESS) {
+			return ret;
 		}
 		
-		/* TODO: we need to validate and possibly create a new
-		   partition */
-		return ldb_next_request(module, req);		
+		/* Do the original add */
+		return ldb_next_request(ac->module, ac->add_req);
 	}
 
 	/* we have to copy the message as the caller might have it as a const */
diff --git a/source4/dsdb/samdb/ldb_modules/new_partition.c b/source4/dsdb/samdb/ldb_modules/new_partition.c
new file mode 100644
index 0000000..c497d97
--- /dev/null
+++ b/source4/dsdb/samdb/ldb_modules/new_partition.c
@@ -0,0 +1,189 @@
+/* 
+   ldb database library
+
+   Copyright (C) Simo Sorce  2004-2008
+   Copyright (C) Andrew Bartlett <abartlet at samba.org> 2005
+   Copyright (C) Andrew Tridgell 2005
+   Copyright (C) Stefan Metzmacher <metze at samba.org> 2007
+
+   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
+   (at your option) any later version.
+   
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+   
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/*
+ *  Name: ldb
+ *
+ *  Component: ldb instancetype module
+ *
+ *  Description: add an instanceType onto every new record
+ *
+ *  Author: Andrew Bartlett
+ */
+
+#include "includes.h"
+#include "ldb.h"
+#include "ldb_module.h"
+#include "librpc/gen_ndr/ndr_misc.h"
+#include "dsdb/samdb/samdb.h"
+#include "../libds/common/flags.h"
+
+struct np_context {
+	struct ldb_module *module;
+	struct ldb_request *req;
+	struct ldb_request *search_req;
+	struct ldb_request *part_add;
+};
+
+static int np_part_mod_callback(struct ldb_request *req, struct ldb_reply *ares)
+{
+	struct ldb_context *ldb;
+	struct np_context *ac;
+
+	ac = talloc_get_type(req->context, struct np_context);
+	ldb = ldb_module_get_ctx(ac->module);
+
+	if (!ares) {
+		return ldb_module_done(ac->req, NULL, NULL,
+					LDB_ERR_OPERATIONS_ERROR);
+	}
+
+	/* We just want to update the @PARTITIONS record if the value does not exist */
+	if (ares->error != LDB_SUCCESS && ares->error != LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS) {
+		return ldb_module_done(ac->req, ares->controls,
+					ares->response, ares->error);
+	}
+
+	if (ares->type != LDB_REPLY_DONE) {
+		ldb_set_errstring(ldb, "Invalid reply type!");
+		return ldb_module_done(ac->req, NULL, NULL,
+					LDB_ERR_OPERATIONS_ERROR);
+	}
+
+	ldb_reset_err_string(ldb);
+
+	/* Do the original add */
+	return ldb_next_request(ac->module, ac->req);
+}
+
+static int np_part_search_callback(struct ldb_request *req, struct ldb_reply *ares)
+{
+	struct ldb_context *ldb;
+	struct np_context *ac;
+	struct dsdb_create_partition_exop *ex_op;
+	int ret;
+
+	ac = talloc_get_type(req->context, struct np_context);
+	ldb = ldb_module_get_ctx(ac->module);
+
+	if (!ares) {
+		return ldb_module_done(ac->req, NULL, NULL,
+					LDB_ERR_OPERATIONS_ERROR);
+	}
+
+	/* If this already exists, we really don't want to create a
+	 * partition - it would allow a duplicate entry to be
+	 * created */
+	if (ares->error != LDB_ERR_NO_SUCH_OBJECT) {
+		if (ares->error == LDB_SUCCESS) {
+			return ldb_module_done(ac->req, ares->controls,
+					       ares->response, LDB_ERR_ENTRY_ALREADY_EXISTS);
+		} else {
+			return ldb_module_done(ac->req, ares->controls,
+					       ares->response, ares->error);
+		}
+	}
+
+	if (ares->type != LDB_REPLY_DONE) {
+		ldb_set_errstring(ldb, "Invalid reply type - we must not get a result here!");
+		return ldb_module_done(ac->req, NULL, NULL,
+					LDB_ERR_OPERATIONS_ERROR);
+	}
+
+	ldb_reset_err_string(ldb);
+
+	/* Now that we know it does not exist, we can try and create the partition */
+	ex_op = talloc(ac, struct dsdb_create_partition_exop);
+	if (ex_op == NULL) {
+		ldb_oom(ldb);
+		return LDB_ERR_OPERATIONS_ERROR;
+	}
+	
+	ex_op->new_dn = ac->req->op.add.message->dn;
+	
+	ret = ldb_build_extended_req(&ac->part_add, 
+				     ldb, ac, DSDB_EXTENDED_CREATE_PARTITION_OID, ex_op, 
+				     NULL, ac, np_part_mod_callback, req);
+	
+	if (ret != LDB_SUCCESS) {
+		return ret;
+	}
+	
+	return ldb_next_request(ac->module, ac->part_add);
+}
+
+/* add_record: add instancetype attribute */
+static int new_partition_add(struct ldb_module *module, struct ldb_request *req)
+{
+	struct ldb_context *ldb;
+	struct ldb_request *down_req;
+	struct np_context *ac;
+	int ret;
+
+	ldb = ldb_module_get_ctx(module);
+
+	ldb_debug(ldb, LDB_DEBUG_TRACE, "instancetype_add_record\n");
+
+	/* do not manipulate our control entries */
+	if (ldb_dn_is_special(req->op.add.message->dn)) {
+		return ldb_next_request(module, req);
+	}
+
+	if (!ldb_msg_find_element(req->op.add.message, "instanceType")) {
+		return ldb_next_request(module, req);		
+	} else {
+		const char *no_attrs[] = { NULL };
+		unsigned int instanceType = ldb_msg_find_attr_as_uint(req->op.add.message, "instanceType", 0);
+		if (!(instanceType & INSTANCE_TYPE_IS_NC_HEAD)) {
+			return ldb_next_request(module, req);		
+		}
+
+		/* Create an @PARTITIONS record for this partition -
+		 * by asking the partitions module to do so via an
+		 * extended operation, after first checking if the
+		 * record already exists */
+		ac = talloc(req, struct np_context);
+		if (ac == NULL) {
+			return LDB_ERR_OPERATIONS_ERROR;
+		}
+		ac->module = module;
+		ac->req = req;
+		
+		ret = ldb_build_search_req(&ac->search_req, ldb, ac, req->op.add.message->dn, 
+					   LDB_SCOPE_BASE, NULL, no_attrs, req->controls, ac, 
+					   np_part_search_callback,
+					   req);
+		if (ret != LDB_SUCCESS) {
+			return ret;
+		}
+		
+		return ldb_next_request(module, ac->search_req);
+	}
+
+	/* go on with the call chain */
+	return ldb_next_request(module, down_req);
+}
+
+_PUBLIC_ const struct ldb_module_ops ldb_new_partition_module_ops = {
+	.name          = "new_partition",
+	.add           = new_partition_add,
+};
diff --git a/source4/dsdb/samdb/ldb_modules/partition.c b/source4/dsdb/samdb/ldb_modules/partition.c
index c5bbdf8..779b8b5 100644
--- a/source4/dsdb/samdb/ldb_modules/partition.c
+++ b/source4/dsdb/samdb/ldb_modules/partition.c
@@ -29,22 +29,7 @@
  *  Author: Stefan Metzmacher
  */
 
-#include "includes.h"
-#include "lib/ldb/include/ldb.h"
-#include "lib/ldb/include/ldb_errors.h"
-#include "lib/ldb/include/ldb_module.h"
-#include "lib/ldb/include/ldb_private.h"
-#include "dsdb/samdb/samdb.h"
-
-struct dsdb_partition {
-	struct ldb_module *module;
-	struct dsdb_control_current_partition *ctrl;
-};
-
-struct partition_private_data {
-	struct dsdb_partition **partitions;
-	struct ldb_dn **replicate;
-};
+#include "dsdb/samdb/ldb_modules/partition.h"
 
 struct part_request {
 	struct ldb_module *module;
@@ -77,24 +62,11 @@ static struct partition_context *partition_init_ctx(struct ldb_module *module, s
 	return ac;
 }
 
-#define PARTITION_FIND_OP_NOERROR(module, op) do { \
-        while (module && module->ops->op == NULL) module = module->next; \
-} while (0)
-
-#define PARTITION_FIND_OP(module, op) do { \
-	PARTITION_FIND_OP_NOERROR(module, op); \
-        if (module == NULL) { \
-                ldb_asprintf_errstring(ldb_module_get_ctx(module), \
-			"Unable to find backend operation for " #op ); \
-                return LDB_ERR_OPERATIONS_ERROR; \
-        } \
-} while (0)
-
 /*
  *    helper functions to call the next module in chain
  *    */
 
-static int partition_request(struct ldb_module *module, struct ldb_request *request)
+int partition_request(struct ldb_module *module, struct ldb_request *request)
 {
 	int ret;
 	switch (request->operation) {
@@ -186,8 +158,9 @@ static int partition_req_callback(struct ldb_request *req,
 	struct partition_context *ac;
 	struct ldb_module *module;
 	struct ldb_request *nreq;
-	int ret, i;
+	int ret;
 	struct partition_private_data *data;
+	struct ldb_control *partition_ctrl;
 
 	ac = talloc_get_type(req->context, struct partition_context);
 	data = talloc_get_type(ac->module->private_data, struct partition_private_data);
@@ -197,6 +170,21 @@ static int partition_req_callback(struct ldb_request *req,
 					LDB_ERR_OPERATIONS_ERROR);
 	}
 
+	partition_ctrl = ldb_request_get_control(req, DSDB_CONTROL_CURRENT_PARTITION_OID);
+	if (partition_ctrl && (ac->num_requests == 1 || ares->type == LDB_REPLY_ENTRY)) {
+		/* If we didn't fan this request out to mulitple partitions,
+		 * or this is an individual search result, we can
+		 * deterministily tell the caller what partition this was
+		 * written to (repl_meta_data likes to know) */
+			ret = ldb_reply_add_control(ares,
+						    DSDB_CONTROL_CURRENT_PARTITION_OID,
+						    false, partition_ctrl->data);
+			if (ret != LDB_SUCCESS) {
+				return ldb_module_done(ac->req, NULL, NULL,
+						       ret);
+			}
+	}
+
 	if (ares->error != LDB_SUCCESS && !ac->got_success) {
 		return ldb_module_done(ac->req, ares->controls,
 					ares->response, ares->error);
@@ -215,21 +203,6 @@ 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);
 
@@ -440,7 +413,7 @@ static int partition_replicate(struct ldb_module *module, struct ldb_request *re
 	if (!data || !data->partitions) {
 		return ldb_next_request(module, req);
 	}
-	
+
 	if (req->operation != LDB_SEARCH) {
 		/* Is this a special DN, we need to replicate to every backend? */
 		for (i=0; data->replicate && data->replicate[i]; i++) {


-- 
Samba Shared Repository


More information about the samba-cvs mailing list