svn commit: samba r16972 - in branches/SAMBA_4_0/source: dsdb/samdb/ldb_modules ldap_server lib/ldb/common lib/ldb/include lib/ldb/modules

abartlet at samba.org abartlet at samba.org
Wed Jul 12 04:59:42 GMT 2006


Author: abartlet
Date: 2006-07-12 04:59:41 +0000 (Wed, 12 Jul 2006)
New Revision: 16972

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=16972

Log:
Replace the sequence_number function pointer in ldb with the ldb flags.

The function pointer was meant to be unused, this patch fixes
partition.c to use ldb_sequence_number().  (No backend provided the
pointer any more).

Set the flags onto the ldb structure, so that all backends opened by
the partitions module inherit the flags.

Set the read-ony flag when accessed as the global catalog

Modify the LDAP server to track that this query is for the global
catalog (by incoming port), and set a opqaue pointer.

Next step is to read that opaque pointer in the partitions module.

Andrew Bartlett


Modified:
   branches/SAMBA_4_0/source/dsdb/samdb/ldb_modules/partition.c
   branches/SAMBA_4_0/source/ldap_server/ldap_backend.c
   branches/SAMBA_4_0/source/ldap_server/ldap_server.c
   branches/SAMBA_4_0/source/ldap_server/ldap_server.h
   branches/SAMBA_4_0/source/lib/ldb/common/ldb.c
   branches/SAMBA_4_0/source/lib/ldb/include/ldb_private.h
   branches/SAMBA_4_0/source/lib/ldb/modules/operational.c


Changeset:
Modified: branches/SAMBA_4_0/source/dsdb/samdb/ldb_modules/partition.c
===================================================================
--- branches/SAMBA_4_0/source/dsdb/samdb/ldb_modules/partition.c	2006-07-12 03:20:53 UTC (rev 16971)
+++ branches/SAMBA_4_0/source/dsdb/samdb/ldb_modules/partition.c	2006-07-12 04:59:41 UTC (rev 16972)
@@ -363,7 +363,7 @@
 		}
 
 		data->partitions[i]->backend = private_path(data->partitions[i], p);
-		ret = ldb_connect_backend(module->ldb, data->partitions[i]->backend, 0, NULL, &data->partitions[i]->module);
+		ret = ldb_connect_backend(module->ldb, data->partitions[i]->backend, NULL, &data->partitions[i]->module);
 		if (ret != LDB_SUCCESS) {
 			return ret;
 		}

Modified: branches/SAMBA_4_0/source/ldap_server/ldap_backend.c
===================================================================
--- branches/SAMBA_4_0/source/ldap_server/ldap_backend.c	2006-07-12 03:20:53 UTC (rev 16971)
+++ branches/SAMBA_4_0/source/ldap_server/ldap_backend.c	2006-07-12 04:59:41 UTC (rev 16972)
@@ -24,7 +24,7 @@
 #include "libcli/ldap/ldap.h"
 #include "lib/ldb/include/ldb.h"
 #include "lib/ldb/include/ldb_errors.h"
-#include "dsdb/samdb/samdb.h"
+#include "lib/db_wrap.h"
 
 #define VALID_DN_SYNTAX(dn,i) do {\
 	if (!(dn)) {\
@@ -49,12 +49,17 @@
 */
 NTSTATUS ldapsrv_backend_Init(struct ldapsrv_connection *conn) 
 {
-	conn->ldb = samdb_connect(conn, conn->session_info);
+	conn->ldb = ldb_wrap_connect(conn, lp_sam_url(), conn->session_info,
+				     NULL, conn->global_catalog ? LDB_FLG_RDONLY : 0, NULL);
 	if (conn->ldb == NULL) {
 		return NT_STATUS_INTERNAL_DB_CORRUPTION;
 	}
 	ldb_set_opaque(conn->ldb, "server_credentials", conn->server_credentials);
 
+	if (conn->global_catalog) {
+		ldb_set_opaque(conn->ldb, "global_catalog", (void *)(-1));
+	}
+
 	return NT_STATUS_OK;
 }
 

Modified: branches/SAMBA_4_0/source/ldap_server/ldap_server.c
===================================================================
--- branches/SAMBA_4_0/source/ldap_server/ldap_server.c	2006-07-12 03:20:53 UTC (rev 16971)
+++ branches/SAMBA_4_0/source/ldap_server/ldap_server.c	2006-07-12 04:59:41 UTC (rev 16972)
@@ -433,6 +433,8 @@
 			ldapsrv_terminate_connection(conn, "ldapsrv_accept: tls_init_server() failed");
 			return;
 		}
+	} else if (port == 3268) /* Global catalog */ {
+		conn->global_catalog = True;
 	}
 	conn->packet = packet_init(conn);
 	if (conn->packet == NULL) {

Modified: branches/SAMBA_4_0/source/ldap_server/ldap_server.h
===================================================================
--- branches/SAMBA_4_0/source/ldap_server/ldap_server.h	2006-07-12 03:20:53 UTC (rev 16971)
+++ branches/SAMBA_4_0/source/ldap_server/ldap_server.h	2006-07-12 04:59:41 UTC (rev 16972)
@@ -32,6 +32,8 @@
 	/* are we using gensec wrapping? */
 	BOOL enable_wrap;
 
+	BOOL global_catalog;
+
 	struct packet_context *packet;
 
 	struct {

Modified: branches/SAMBA_4_0/source/lib/ldb/common/ldb.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/common/ldb.c	2006-07-12 03:20:53 UTC (rev 16971)
+++ branches/SAMBA_4_0/source/lib/ldb/common/ldb.c	2006-07-12 04:59:41 UTC (rev 16972)
@@ -103,7 +103,7 @@
   This allows modules to get at only the backend module, for example where a module 
   may wish to direct certain requests at a particular backend.
 */
-int ldb_connect_backend(struct ldb_context *ldb, const char *url, unsigned int flags, const char *options[],
+int ldb_connect_backend(struct ldb_context *ldb, const char *url, const char *options[],
 			struct ldb_module **backend_module)
 {
 	int ret;
@@ -132,7 +132,7 @@
 		return LDB_ERR_OTHER;
 	}
 
-	ret = fn(ldb, url, flags, options, backend_module);
+	ret = fn(ldb, url, ldb->flags, options, backend_module);
 
 	if (ret != LDB_SUCCESS) {
 		ldb_debug(ldb, LDB_DEBUG_ERROR, "Failed to connect to '%s'\n", url);
@@ -156,7 +156,9 @@
 {
 	int ret;
 
-	ret = ldb_connect_backend(ldb, url, flags, options, &ldb->modules);
+	ldb->flags = flags;
+
+	ret = ldb_connect_backend(ldb, url, options, &ldb->modules);
 	if (ret != LDB_SUCCESS) {
 		return ret;
 	}
@@ -701,7 +703,7 @@
 
 
 /*
-  rename a record in the database
+  return the global sequence number
 */
 int ldb_sequence_number(struct ldb_context *ldb, uint64_t *seq_num)
 {

Modified: branches/SAMBA_4_0/source/lib/ldb/include/ldb_private.h
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/include/ldb_private.h	2006-07-12 03:20:53 UTC (rev 16971)
+++ branches/SAMBA_4_0/source/lib/ldb/include/ldb_private.h	2006-07-12 04:59:41 UTC (rev 16972)
@@ -117,8 +117,7 @@
 
 	int default_timeout;
 
-	/* a backend supplied highestCommittedUSN function */
-	uint64_t (*sequence_number)(struct ldb_context *);
+	unsigned int flags;
 };
 
 #ifndef ARRAY_SIZE
@@ -132,7 +131,7 @@
 
 /* The following definitions come from lib/ldb/common/ldb.c  */
 
-int ldb_connect_backend(struct ldb_context *ldb, const char *url, unsigned int flags, const char *options[],
+int ldb_connect_backend(struct ldb_context *ldb, const char *url, const char *options[],
 			struct ldb_module **backend_module);
 
 /* The following definitions come from lib/ldb/common/ldb_modules.c  */

Modified: branches/SAMBA_4_0/source/lib/ldb/modules/operational.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/modules/operational.c	2006-07-12 03:20:53 UTC (rev 16971)
+++ branches/SAMBA_4_0/source/lib/ldb/modules/operational.c	2006-07-12 04:59:41 UTC (rev 16972)
@@ -349,6 +349,7 @@
 	struct ldb_request *down_req;
 	struct ldb_message *msg;
 	time_t t = time(NULL);
+	uint64_t seq_num;
 	int ret;
 
 	if (ldb_dn_is_special(req->op.add.message->dn)) {
@@ -373,9 +374,9 @@
 		return LDB_ERR_OPERATIONS_ERROR;
 	}
 
-	/* see if the backend can give us the USN */
-	if (module->ldb->sequence_number != NULL) {
-		uint64_t seq_num = module->ldb->sequence_number(module->ldb);
+	/* Get a sequence number from the backend */
+	ret = ldb_sequence_number(module->ldb, &seq_num);
+	if (ret == LDB_SUCCESS) {
 		if (add_uint64_element(msg, "uSNCreated", seq_num) != 0 ||
 		    add_uint64_element(msg, "uSNChanged", seq_num) != 0) {
 			talloc_free(down_req);
@@ -405,6 +406,7 @@
 	struct ldb_request *down_req;
 	struct ldb_message *msg;
 	time_t t = time(NULL);
+	uint64_t seq_num;
 	int ret;
 
 	if (ldb_dn_is_special(req->op.mod.message->dn)) {
@@ -428,12 +430,15 @@
 		return LDB_ERR_OPERATIONS_ERROR;
 	}
 
-	/* update the records USN if possible */
-	if (module->ldb->sequence_number != NULL &&
-	    add_uint64_element(msg, "uSNChanged", 
-			       module->ldb->sequence_number(module->ldb)) != 0) {
-		talloc_free(down_req);
-		return -1;
+	/* Get a sequence number from the backend */
+	ret = ldb_sequence_number(module->ldb, &seq_num);
+	if (ret == LDB_SUCCESS) {
+		/* update the records USN if possible */
+		if (add_uint64_element(msg, "uSNChanged", 
+				       seq_num) != 0) {
+			talloc_free(down_req);
+			return -1;
+		}
 	}
 	
 	ldb_set_timeout_from_prev_req(module->ldb, req, down_req);



More information about the samba-cvs mailing list