svn commit: samba r17397 - in branches/SAMBA_4_0/source/lib/ldb/common: .

abartlet at samba.org abartlet at samba.org
Fri Aug 4 10:27:14 GMT 2006


Author: abartlet
Date: 2006-08-04 10:27:14 +0000 (Fri, 04 Aug 2006)
New Revision: 17397

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

Log:
Add const, and use a more local memory context.

Andrew Bartlett

Modified:
   branches/SAMBA_4_0/source/lib/ldb/common/ldb_modules.c


Changeset:
Modified: branches/SAMBA_4_0/source/lib/ldb/common/ldb_modules.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/common/ldb_modules.c	2006-08-04 07:00:53 UTC (rev 17396)
+++ branches/SAMBA_4_0/source/lib/ldb/common/ldb_modules.c	2006-08-04 10:27:14 UTC (rev 17397)
@@ -73,19 +73,20 @@
 /* modules are called in inverse order on the stack.
    Lets place them as an admin would think the right order is.
    Modules order is important */
-static char **ldb_modules_list_from_string(struct ldb_context *ldb, const char *string)
+static const char **ldb_modules_list_from_string(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, const char *string)
 {
 	char **modules = NULL;
+	const char **m;
 	char *modstr, *p;
 	int i;
 
 	/* spaces not admitted */
-	modstr = talloc_strdup_no_spaces(ldb, string);
+	modstr = talloc_strdup_no_spaces(mem_ctx, string);
 	if ( ! modstr) {
 		return NULL;
 	}
 
-	modules = talloc_realloc(ldb, modules, char *, 2);
+	modules = talloc_realloc(mem_ctx, modules, char *, 2);
 	if ( ! modules ) {
 		ldb_debug(ldb, LDB_DEBUG_FATAL, "Out of Memory in ldb_modules_list_from_string()\n");
 		talloc_free(modstr);
@@ -100,7 +101,7 @@
 		modules[i] = p;
 
 		i++;
-		modules = talloc_realloc(ldb, modules, char *, i + 2);
+		modules = talloc_realloc(mem_ctx, modules, char *, i + 2);
 		if ( ! modules ) {
 			ldb_debug(ldb, LDB_DEBUG_FATAL, "Out of Memory in ldb_modules_list_from_string()\n");
 			return NULL;
@@ -111,7 +112,9 @@
 
 	modules[i + 1] = NULL;
 
-	return modules;
+	m = (const char **)modules;
+
+	return m;
 }
 
 static struct ops_list_entry {
@@ -235,16 +238,21 @@
 
 int ldb_load_modules(struct ldb_context *ldb, const char *options[])
 {
-	char **modules = NULL;
+	const char **modules = NULL;
 	struct ldb_module *module;
 	int i;
+	TALLOC_CTX *mem_ctx = talloc_new(ldb);
+	if (!mem_ctx) {
+		return LDB_ERR_OPERATIONS_ERROR;
+	}
+
 	/* find out which modules we are requested to activate */
 
 	/* check if we have a custom module list passd as ldb option */
 	if (options) {
 		for (i = 0; options[i] != NULL; i++) {
 			if (strncmp(options[i], LDB_MODULE_PREFIX, LDB_MODULE_PREFIX_LEN) == 0) {
-				modules = ldb_modules_list_from_string(ldb, &options[i][LDB_MODULE_PREFIX_LEN]);
+				modules = ldb_modules_list_from_string(ldb, mem_ctx, &options[i][LDB_MODULE_PREFIX_LEN]);
 			}
 		}
 	}
@@ -253,11 +261,12 @@
 	if ((modules == NULL) && (strcmp("ldap", ldb->modules->ops->name) != 0)) { 
 		int ret;
 		const char * const attrs[] = { "@LIST" , NULL};
-		struct ldb_result *res = NULL;
+		struct ldb_result *res;
 		struct ldb_dn *mods;
 
-		mods = ldb_dn_explode(ldb, "@MODULES");
+		mods = ldb_dn_explode(mem_ctx, "@MODULES");
 		if (mods == NULL) {
+			talloc_free(mem_ctx);
 			return -1;
 		}
 
@@ -268,20 +277,21 @@
 		} else {
 			if (ret != LDB_SUCCESS) {
 				ldb_debug(ldb, LDB_DEBUG_FATAL, "ldb error (%s) occurred searching for modules, bailing out\n", ldb_errstring(ldb));
+				talloc_free(mem_ctx);
 				return -1;
 			}
 			if (res->count > 1) {
 				ldb_debug(ldb, LDB_DEBUG_FATAL, "Too many records found (%d), bailing out\n", res->count);
 				talloc_free(res);
+				talloc_free(mem_ctx);
 				return -1;
 			}
 
-			modules = ldb_modules_list_from_string(ldb, 
+			modules = ldb_modules_list_from_string(ldb, mem_ctx,
 							       (const char *)res->msgs[0]->elements[0].values[0].data);
 
+			talloc_free(res);
 		}
-
-		talloc_free(res);
 	}
 
 	if (modules != NULL) {



More information about the samba-cvs mailing list