svn commit: samba r13839 - in branches/SAMBA_4_0/source: lib/ldb lib/ldb/common lib/ldb/include lib/ldb/ldb_ildap lib/ldb/ldb_ldap lib/ldb/ldb_sqlite3 lib/ldb/ldb_tdb torture

jelmer at samba.org jelmer at samba.org
Sun Mar 5 16:05:28 GMT 2006


Author: jelmer
Date: 2006-03-05 16:05:26 +0000 (Sun, 05 Mar 2006)
New Revision: 13839

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

Log:
Use registration mechanism for backends as well (in the same sense
my previous patch added it for modules). This is the next step towards 
LDB backends and modules as run-time loadable .so files.

Modified:
   branches/SAMBA_4_0/source/lib/ldb/common/ldb.c
   branches/SAMBA_4_0/source/lib/ldb/common/ldb_modules.c
   branches/SAMBA_4_0/source/lib/ldb/config.mk
   branches/SAMBA_4_0/source/lib/ldb/include/ldb_private.h
   branches/SAMBA_4_0/source/lib/ldb/ldb_ildap/ldb_ildap.c
   branches/SAMBA_4_0/source/lib/ldb/ldb_ldap/ldb_ldap.c
   branches/SAMBA_4_0/source/lib/ldb/ldb_sqlite3/ldb_sqlite3.c
   branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_tdb.c
   branches/SAMBA_4_0/source/torture/torture.c


Changeset:
Modified: branches/SAMBA_4_0/source/lib/ldb/common/ldb.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/common/ldb.c	2006-03-05 07:41:19 UTC (rev 13838)
+++ branches/SAMBA_4_0/source/lib/ldb/common/ldb.c	2006-03-05 16:05:26 UTC (rev 13839)
@@ -55,6 +55,40 @@
 	return ldb;
 }
 
+static struct ldb_backend {
+	const char *name;
+	ldb_connect_fn connect_fn;
+	struct ldb_backend *prev, *next;
+} *ldb_backends = NULL;
+/*
+ register a new ldb backend
+*/
+int ldb_register_backend(const char *url_prefix, ldb_connect_fn connectfn)
+{
+	struct ldb_backend *backend = talloc(talloc_autofree_context(), struct ldb_backend);
+
+	/* Maybe check for duplicity here later on? */
+
+	backend->name = talloc_strdup(backend, url_prefix);
+	backend->connect_fn = connectfn;
+	DLIST_ADD(ldb_backends, backend);
+
+	return LDB_SUCCESS;
+}
+
+static ldb_connect_fn ldb_find_backend(const char *url)
+{
+	struct ldb_backend *backend;
+
+	for (backend = ldb_backends; backend; backend = backend->next) {
+		if (strncmp(backend->name, url, strlen(backend->name)) == 0) {
+			return backend->connect_fn;
+		}
+	}
+
+	return NULL;
+}
+
 /* 
  connect to a database. The URL can either be one of the following forms
    ldb://path
@@ -68,31 +102,22 @@
 int ldb_connect(struct ldb_context *ldb, const char *url, unsigned int flags, const char *options[])
 {
 	int ret;
+	ldb_connect_fn fn;
 
-	if (strncmp(url, "tdb:", 4) == 0 ||
-	    strchr(url, ':') == NULL) {
-		ret = ltdb_connect(ldb, url, flags, options);
+	if (strchr(url, ':') != NULL) {
+		fn = ldb_find_backend(url);
+	} else {
+		/* Default to tdb */
+		fn = ldb_find_backend("tdb:");
 	}
 
-#if HAVE_ILDAP
-	else if (strncmp(url, "ldap", 4) == 0) {
-		ret = ildb_connect(ldb, url, flags, options);
-	}
-#elif HAVE_LDAP
-	else if (strncmp(url, "ldap", 4) == 0) {
-		ret = lldb_connect(ldb, url, flags, options);
-	}
-#endif
-#if HAVE_SQLITE3
-	else if (strncmp(url, "sqlite:", 7) == 0) {
-                ret = lsqlite3_connect(ldb, url, flags, options);
-	}
-#endif
-	else {
+	if (fn == NULL) {
 		ldb_debug(ldb, LDB_DEBUG_FATAL, "Unable to find backend for '%s'\n", url);
 		return LDB_ERR_OTHER;
 	}
 
+	ret = fn(ldb, url, flags, options);
+
 	if (ret != LDB_SUCCESS) {
 		ldb_debug(ldb, LDB_DEBUG_ERROR, "Failed to connect to '%s'\n", url);
 		return ret;

Modified: branches/SAMBA_4_0/source/lib/ldb/common/ldb_modules.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/common/ldb_modules.c	2006-03-05 07:41:19 UTC (rev 13838)
+++ branches/SAMBA_4_0/source/lib/ldb/common/ldb_modules.c	2006-03-05 16:05:26 UTC (rev 13839)
@@ -126,10 +126,24 @@
 	return NULL;
 }
 
-	
+#ifdef HAVE_LDAP
+#define LDAP_INIT ldb_ldap_init,
+#else
+#define LDAP_INIT
+#endif
+
+#ifdef HAVE_SQLITE3
+#define SQLITE3_INIT ldb_sqlite3_init,
+#else
+#define SQLITE3_INIT
+#endif
+
 #ifndef STATIC_LIBLDB_MODULES
 #define STATIC_LIBLDB_MODULES \
 	{	\
+		LDAP_INIT \
+		SQLITE3_INIT \
+		ldb_tdb_init, 	\
 		ldb_schema_init,	\
 		ldb_operational_init,	\
 		ldb_rdn_name_init,	\

Modified: branches/SAMBA_4_0/source/lib/ldb/config.mk
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/config.mk	2006-03-05 07:41:19 UTC (rev 13838)
+++ branches/SAMBA_4_0/source/lib/ldb/config.mk	2006-03-05 16:05:26 UTC (rev 13839)
@@ -80,6 +80,7 @@
 [MODULE::libldb_ildap]
 SUBSYSTEM = LIBLDB
 OUTPUT_TYPE = MERGEDOBJ
+INIT_FUNCTION = ldb_ildap_init
 OBJ_FILES = \
 		ldb_ildap/ldb_ildap.o
 REQUIRED_SUBSYSTEMS = \
@@ -112,6 +113,7 @@
 [MODULE::libldb_sqlite3]
 SUBSYSTEM = LIBLDB
 OUTPUT_TYPE = MERGEDOBJ
+INIT_FUNCTION = ldb_sqlite3_init
 OBJ_FILES = \
 		ldb_sqlite3/ldb_sqlite3.o
 REQUIRED_SUBSYSTEMS = \
@@ -124,6 +126,7 @@
 # Start MODULE libldb_tdb
 [MODULE::libldb_tdb]
 SUBSYSTEM = LIBLDB
+INIT_FUNCTION = ldb_tdb_init
 OUTPUT_TYPE = MERGEDOBJ
 OBJ_FILES = \
 		ldb_tdb/ldb_tdb.o \

Modified: branches/SAMBA_4_0/source/lib/ldb/include/ldb_private.h
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/include/ldb_private.h	2006-03-05 07:41:19 UTC (rev 13838)
+++ branches/SAMBA_4_0/source/lib/ldb/include/ldb_private.h	2006-03-05 16:05:26 UTC (rev 13839)
@@ -64,6 +64,7 @@
 	int (*async_wait)(struct ldb_module *, struct ldb_async_handle *, enum ldb_async_wait_type);
 };
 
+typedef int (*ldb_connect_fn) (struct ldb_context *ldb, const char *url, unsigned int flags, const char *options[]);
 
 /*
   schema related information needed for matching rules
@@ -133,6 +134,7 @@
 void ldb_reset_err_string(struct ldb_context *ldb);
 
 int ldb_register_module(const struct ldb_module_ops *);
+int ldb_register_backend(const char *url_prefix, ldb_connect_fn);
 
 /* The following definitions come from lib/ldb/common/ldb_debug.c  */
 void ldb_debug(struct ldb_context *ldb, enum ldb_debug_level level, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
@@ -142,27 +144,16 @@
 /* The following definitions come from lib/ldb/common/ldb_ldif.c  */
 int ldb_should_b64_encode(const struct ldb_val *val);
 
-int ltdb_connect(struct ldb_context *ldb, const char *url, 
-		 unsigned int flags, 
-		 const char *options[]);
-int lldb_connect(struct ldb_context *ldb, const char *url, 
-		 unsigned int flags, 
-		 const char *options[]);
-int ildb_connect(struct ldb_context *ldb,
-		 const char *url, 
-		 unsigned int flags, 
-		 const char *options[]);
-int lsqlite3_connect(struct ldb_context *ldb,
-		     const char *url, 
-		     unsigned int flags, 
-		     const char *options[]);
-
 int ldb_objectclass_init(void);
 int ldb_operational_init(void);
 int ldb_paged_results_init(void);
 int ldb_rdn_name_init(void);
 int ldb_schema_init(void);
 int ldb_sort_init(void);
+int ldb_ldap_init(void);
+int ldb_ildap_init(void);
+int ldb_tdb_init(void);
+int ldb_sqlite3_init(void);
 
 int ldb_match_msg(struct ldb_context *ldb,
 		  struct ldb_message *msg,

Modified: branches/SAMBA_4_0/source/lib/ldb/ldb_ildap/ldb_ildap.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/ldb_ildap/ldb_ildap.c	2006-03-05 07:41:19 UTC (rev 13838)
+++ branches/SAMBA_4_0/source/lib/ldb/ldb_ildap/ldb_ildap.c	2006-03-05 16:05:26 UTC (rev 13839)
@@ -987,7 +987,7 @@
 /*
   connect to the database
 */
-int ildb_connect(struct ldb_context *ldb, const char *url, 
+static int ildb_connect(struct ldb_context *ldb, const char *url, 
 		 unsigned int flags, const char *options[])
 {
 	struct ildb_private *ildb = NULL;
@@ -1065,3 +1065,7 @@
 	return -1;
 }
 
+int ldb_ildap_init(void)
+{
+	return ldb_register_backend("ldap", ildb_connect);
+}

Modified: branches/SAMBA_4_0/source/lib/ldb/ldb_ldap/ldb_ldap.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/ldb_ldap/ldb_ldap.c	2006-03-05 07:41:19 UTC (rev 13838)
+++ branches/SAMBA_4_0/source/lib/ldb/ldb_ldap/ldb_ldap.c	2006-03-05 16:05:26 UTC (rev 13839)
@@ -1042,7 +1042,7 @@
 /*
   connect to the database
 */
-int lldb_connect(struct ldb_context *ldb,
+static int lldb_connect(struct ldb_context *ldb,
 		 const char *url, 
 		 unsigned int flags, 
 		 const char *options[])
@@ -1093,3 +1093,7 @@
 	return -1;
 }
 
+int ldb_ldap_init(void)
+{
+	return ldb_register_backend("ldap", lldb_connect);
+}

Modified: branches/SAMBA_4_0/source/lib/ldb/ldb_sqlite3/ldb_sqlite3.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/ldb_sqlite3/ldb_sqlite3.c	2006-03-05 07:41:19 UTC (rev 13838)
+++ branches/SAMBA_4_0/source/lib/ldb/ldb_sqlite3/ldb_sqlite3.c	2006-03-05 16:05:26 UTC (rev 13839)
@@ -2070,7 +2070,7 @@
 /*
  * connect to the database
  */
-int lsqlite3_connect(struct ldb_context *ldb,
+static int lsqlite3_connect(struct ldb_context *ldb,
 		     const char *url, 
 		     unsigned int flags, 
 		     const char *options[])
@@ -2137,3 +2137,7 @@
 	return -1;
 }
 
+int ldb_sqlite3_init(void)
+{
+	return ldb_register_backend("sqlite3", lsqlite3_connect);
+}

Modified: branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_tdb.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_tdb.c	2006-03-05 07:41:19 UTC (rev 13838)
+++ branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_tdb.c	2006-03-05 16:05:26 UTC (rev 13839)
@@ -1033,7 +1033,7 @@
 /*
   connect to the database
 */
-int ltdb_connect(struct ldb_context *ldb, const char *url, 
+static int ltdb_connect(struct ldb_context *ldb, const char *url, 
 		 unsigned int flags, const char *options[])
 {
 	const char *path;
@@ -1094,3 +1094,8 @@
 
 	return 0;
 }
+
+int ldb_tdb_init(void)
+{
+	return ldb_register_backend("tdb:", ltdb_connect);
+}

Modified: branches/SAMBA_4_0/source/torture/torture.c
===================================================================
--- branches/SAMBA_4_0/source/torture/torture.c	2006-03-05 07:41:19 UTC (rev 13838)
+++ branches/SAMBA_4_0/source/torture/torture.c	2006-03-05 16:05:26 UTC (rev 13839)
@@ -26,6 +26,7 @@
 #include "system/filesys.h"
 #include "libcli/raw/ioctl.h"
 #include "libcli/libcli.h"
+#include "lib/ldb/include/ldb.h"
 #include "librpc/rpc/dcerpc_table.h"
 
 #include "torture/basic/proto.h"
@@ -2632,6 +2633,8 @@
 		alarm(max_runtime);
 	}
 
+	ldb_global_init();
+
 	dcerpc_init();
 
 	dcerpc_table_init();



More information about the samba-cvs mailing list