[SCM] Samba Shared Repository - branch v4-0-test updated - release-4-0-0alpha4-185-gb4e7063

Andrew Bartlett abartlet at samba.org
Wed Jul 2 11:48:32 GMT 2008


The branch, v4-0-test has been updated
       via  b4e7063058ac8587c526dd9133aee345e99f8ef8 (commit)
       via  c7704805b9a3541e4c8768278c8289b0aa6ed5e3 (commit)
      from  3da6f7f95d7c04cff49fa2312f94c059686d11e4 (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v4-0-test


- Log -----------------------------------------------------------------
commit b4e7063058ac8587c526dd9133aee345e99f8ef8
Merge: c7704805b9a3541e4c8768278c8289b0aa6ed5e3 3da6f7f95d7c04cff49fa2312f94c059686d11e4
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Wed Jul 2 21:47:21 2008 +1000

    Merge branch 'v4-0-test' of ssh://git.samba.org/data/git/samba into 4-0-local

commit c7704805b9a3541e4c8768278c8289b0aa6ed5e3
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Wed Jul 2 21:30:08 2008 +1000

    Move ad2oLschema and oLschema2ldif into Samba4, out of LDB
    
    LDB does not know about nor process the AD schema, so it makes no
    sense to have this tool there.  I've been changing it anyway, to use a
    common schema manipulation library, and will enhance these links in
    the future.
    
    Andrew Bartlett

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

Summary of changes:
 source/dsdb/samdb/ldb_modules/schema_fsmo.c |  105 +----
 source/dsdb/schema/schema_init.c            |  108 ++++
 source/lib/ldb/config.mk                    |   27 -
 source/lib/ldb/tools/ad2oLschema.c          |  800 ---------------------------
 source/lib/ldb/tools/convert.c              |  173 ------
 source/lib/ldb/tools/convert.h              |   10 -
 source/lib/ldb/tools/oLschema2ldif.c        |  603 --------------------
 source/utils/ad2oLschema.1.xml              |   87 +++
 source/utils/ad2oLschema.c                  |  798 ++++++++++++++++++++++++++
 source/utils/config.mk                      |   28 +
 source/utils/oLschema2ldif.1.xml            |   79 +++
 source/utils/oLschema2ldif.c                |  603 ++++++++++++++++++++
 source/utils/schema_convert.c               |  173 ++++++
 source/utils/schema_convert.h               |   10 +
 14 files changed, 1897 insertions(+), 1707 deletions(-)
 delete mode 100644 source/lib/ldb/tools/ad2oLschema.c
 delete mode 100644 source/lib/ldb/tools/convert.c
 delete mode 100644 source/lib/ldb/tools/convert.h
 delete mode 100644 source/lib/ldb/tools/oLschema2ldif.c
 create mode 100644 source/utils/ad2oLschema.1.xml
 create mode 100644 source/utils/ad2oLschema.c
 create mode 100644 source/utils/oLschema2ldif.1.xml
 create mode 100644 source/utils/oLschema2ldif.c
 create mode 100644 source/utils/schema_convert.c
 create mode 100644 source/utils/schema_convert.h


Changeset truncated at 500 lines:

diff --git a/source/dsdb/samdb/ldb_modules/schema_fsmo.c b/source/dsdb/samdb/ldb_modules/schema_fsmo.c
index 0110860..6f65c19 100644
--- a/source/dsdb/samdb/ldb_modules/schema_fsmo.c
+++ b/source/dsdb/samdb/ldb_modules/schema_fsmo.c
@@ -34,17 +34,13 @@
 
 static int schema_fsmo_init(struct ldb_module *module)
 {
-	WERROR status;
 	TALLOC_CTX *mem_ctx;
 	struct ldb_dn *schema_dn;
 	struct dsdb_schema *schema;
 	struct ldb_result *schema_res;
-	const struct ldb_val *prefix_val;
-	const struct ldb_val *info_val;
-	struct ldb_val info_val_default;
 	struct ldb_result *a_res;
 	struct ldb_result *c_res;
-	uint32_t i;
+	char *error_string = NULL;
 	int ret;
 	static const char *schema_attrs[] = {
 		"prefixMap",
@@ -71,12 +67,6 @@ static int schema_fsmo_init(struct ldb_module *module)
 		return LDB_ERR_OPERATIONS_ERROR;
 	}
 
-	schema = dsdb_new_schema(mem_ctx, lp_iconv_convenience(ldb_get_opaque(module->ldb, "loadparm")));
-	if (!schema) {
-		ldb_oom(module->ldb);
-		return LDB_ERR_OPERATIONS_ERROR;
-	}
-
 	/*
 	 * setup the prefix mappings and schema info
 	 */
@@ -111,33 +101,6 @@ static int schema_fsmo_init(struct ldb_module *module)
 		return LDB_ERR_CONSTRAINT_VIOLATION;
 	}
 
-	prefix_val = ldb_msg_find_ldb_val(schema_res->msgs[0], "prefixMap");
-	if (!prefix_val) {
-		ldb_debug_set(module->ldb, LDB_DEBUG_FATAL,
-			      "schema_fsmo_init: no prefixMap attribute found");
-		talloc_free(mem_ctx);
-		return LDB_ERR_CONSTRAINT_VIOLATION;
-	}
-	info_val = ldb_msg_find_ldb_val(schema_res->msgs[0], "schemaInfo");
-	if (!info_val) {
-		info_val_default = strhex_to_data_blob("FF0000000000000000000000000000000000000000");
-		if (!info_val_default.data) {
-			ldb_oom(module->ldb);
-			return LDB_ERR_OPERATIONS_ERROR;
-		}
-		talloc_steal(mem_ctx, info_val_default.data);
-		info_val = &info_val_default;
-	}
-
-	status = dsdb_load_oid_mappings_ldb(schema, prefix_val, info_val);
-	if (!W_ERROR_IS_OK(status)) {
-		ldb_debug_set(module->ldb, LDB_DEBUG_FATAL,
-			      "schema_fsmo_init: failed to load oid mappings: %s",
-			      win_errstr(status));
-		talloc_free(mem_ctx);
-		return LDB_ERR_CONSTRAINT_VIOLATION;
-	}
-
 	/*
 	 * load the attribute definitions
 	 */
@@ -154,29 +117,6 @@ static int schema_fsmo_init(struct ldb_module *module)
 	}
 	talloc_steal(mem_ctx, a_res);
 
-	for (i=0; i < a_res->count; i++) {
-		struct dsdb_attribute *sa;
-
-		sa = talloc_zero(schema, struct dsdb_attribute);
-		if (!sa) {
-			ldb_oom(module->ldb);
-			return LDB_ERR_OPERATIONS_ERROR;
-		}
-
-		status = dsdb_attribute_from_ldb(schema, a_res->msgs[i], sa, sa);
-		if (!W_ERROR_IS_OK(status)) {
-			ldb_debug_set(module->ldb, LDB_DEBUG_FATAL,
-				      "schema_fsmo_init: failed to load attriute definition: %s:%s",
-				      ldb_dn_get_linearized(a_res->msgs[i]->dn),
-				      win_errstr(status));
-			talloc_free(mem_ctx);
-			return LDB_ERR_CONSTRAINT_VIOLATION;
-		}
-
-		DLIST_ADD_END(schema->attributes, sa, struct dsdb_attribute *);
-	}
-	talloc_free(a_res);
-
 	/*
 	 * load the objectClass definitions
 	 */
@@ -193,36 +133,17 @@ static int schema_fsmo_init(struct ldb_module *module)
 	}
 	talloc_steal(mem_ctx, c_res);
 
-	for (i=0; i < c_res->count; i++) {
-		struct dsdb_class *sc;
-
-		sc = talloc_zero(schema, struct dsdb_class);
-		if (!sc) {
-			ldb_oom(module->ldb);
-			return LDB_ERR_OPERATIONS_ERROR;
-		}
-
-		status = dsdb_class_from_ldb(schema, c_res->msgs[i], sc, sc);
-		if (!W_ERROR_IS_OK(status)) {
-			ldb_debug_set(module->ldb, LDB_DEBUG_FATAL,
-				      "schema_fsmo_init: failed to load class definition: %s:%s",
-				      ldb_dn_get_linearized(c_res->msgs[i]->dn),
-				      win_errstr(status));
-			talloc_free(mem_ctx);
-			return LDB_ERR_CONSTRAINT_VIOLATION;
-		}
-
-		DLIST_ADD_END(schema->classes, sc, struct dsdb_class *);
-	}
-	talloc_free(c_res);
-
-	schema->fsmo.master_dn = ldb_msg_find_attr_as_dn(module->ldb, schema, schema_res->msgs[0], "fSMORoleOwner");
-	if (ldb_dn_compare(samdb_ntds_settings_dn(module->ldb), schema->fsmo.master_dn) == 0) {
-		schema->fsmo.we_are_master = true;
-	} else {
-		schema->fsmo.we_are_master = false;
+	ret = dsdb_schema_from_ldb_results(mem_ctx, module->ldb,
+					   lp_iconv_convenience(ldb_get_opaque(module->ldb, "loadparm")),
+					   schema_res, a_res, c_res, &schema, &error_string);
+	if (ret != LDB_SUCCESS) {
+		ldb_asprintf_errstring(module->ldb, 
+				       "schema_fsmo_init: dsdb_schema load failed: %s",
+				       error_string);
+		talloc_free(mem_ctx);
+		return ret;
 	}
-
+	
 	/* dsdb_set_schema() steal schema into the ldb_context */
 	ret = dsdb_set_schema(module->ldb, schema);
 	if (ret != LDB_SUCCESS) {
@@ -233,10 +154,6 @@ static int schema_fsmo_init(struct ldb_module *module)
 		return ret;
 	}
 
-	ldb_debug(module->ldb, LDB_DEBUG_TRACE,
-			  "schema_fsmo_init: we are master: %s\n",
-			  (schema->fsmo.we_are_master?"yes":"no"));
-
 	talloc_free(mem_ctx);
 	return ldb_next_init(module);
 }
diff --git a/source/dsdb/schema/schema_init.c b/source/dsdb/schema/schema_init.c
index f71c14a..826f91b 100644
--- a/source/dsdb/schema/schema_init.c
+++ b/source/dsdb/schema/schema_init.c
@@ -563,6 +563,114 @@ WERROR dsdb_class_from_ldb(const struct dsdb_schema *schema,
 	return WERR_OK;
 }
 
+#define dsdb_oom(error_string, mem_ctx) *error_string = talloc_asprintf(mem_ctx, "dsdb out of memory at %s:%d\n", __FILE__, __LINE__)
+
+int dsdb_schema_from_ldb_results(TALLOC_CTX *mem_ctx, struct ldb_context *ldb,
+				 struct smb_iconv_convenience *iconv_convenience, 
+				 struct ldb_result *schema_res,
+				 struct ldb_result *attrs_res, struct ldb_result *objectclass_res, 
+				 struct dsdb_schema **schema_out,
+				 char **error_string)
+{
+	WERROR status;
+	uint32_t i;
+	const struct ldb_val *prefix_val;
+	const struct ldb_val *info_val;
+	struct ldb_val info_val_default;
+	struct dsdb_schema *schema;
+
+	schema = dsdb_new_schema(mem_ctx, iconv_convenience);
+	if (!schema) {
+		dsdb_oom(error_string, mem_ctx);
+		return LDB_ERR_OPERATIONS_ERROR;
+	}
+
+	prefix_val = ldb_msg_find_ldb_val(schema_res->msgs[0], "prefixMap");
+	if (!prefix_val) {
+		*error_string = talloc_asprintf(mem_ctx, 
+						"schema_fsmo_init: no prefixMap attribute found");
+		talloc_free(mem_ctx);
+		return LDB_ERR_CONSTRAINT_VIOLATION;
+	}
+	info_val = ldb_msg_find_ldb_val(schema_res->msgs[0], "schemaInfo");
+	if (!info_val) {
+		info_val_default = strhex_to_data_blob("FF0000000000000000000000000000000000000000");
+		if (!info_val_default.data) {
+			dsdb_oom(error_string, mem_ctx);
+			return LDB_ERR_OPERATIONS_ERROR;
+		}
+		talloc_steal(mem_ctx, info_val_default.data);
+		info_val = &info_val_default;
+	}
+
+	status = dsdb_load_oid_mappings_ldb(schema, prefix_val, info_val);
+	if (!W_ERROR_IS_OK(status)) {
+		*error_string = talloc_asprintf(mem_ctx, 
+			      "schema_fsmo_init: failed to load oid mappings: %s",
+			      win_errstr(status));
+		talloc_free(mem_ctx);
+		return LDB_ERR_CONSTRAINT_VIOLATION;
+	}
+
+	for (i=0; i < attrs_res->count; i++) {
+		struct dsdb_attribute *sa;
+
+		sa = talloc_zero(schema, struct dsdb_attribute);
+		if (!sa) {
+			dsdb_oom(error_string, mem_ctx);
+			return LDB_ERR_OPERATIONS_ERROR;
+		}
+
+		status = dsdb_attribute_from_ldb(schema, attrs_res->msgs[i], sa, sa);
+		if (!W_ERROR_IS_OK(status)) {
+			*error_string = talloc_asprintf(mem_ctx, 
+				      "schema_fsmo_init: failed to load attriute definition: %s:%s",
+				      ldb_dn_get_linearized(attrs_res->msgs[i]->dn),
+				      win_errstr(status));
+			talloc_free(mem_ctx);
+			return LDB_ERR_CONSTRAINT_VIOLATION;
+		}
+
+		DLIST_ADD_END(schema->attributes, sa, struct dsdb_attribute *);
+	}
+
+	for (i=0; i < objectclass_res->count; i++) {
+		struct dsdb_class *sc;
+
+		sc = talloc_zero(schema, struct dsdb_class);
+		if (!sc) {
+			dsdb_oom(error_string, mem_ctx);
+			return LDB_ERR_OPERATIONS_ERROR;
+		}
+
+		status = dsdb_class_from_ldb(schema, objectclass_res->msgs[i], sc, sc);
+		if (!W_ERROR_IS_OK(status)) {
+			*error_string = talloc_asprintf(mem_ctx, 
+				      "schema_fsmo_init: failed to load class definition: %s:%s",
+				      ldb_dn_get_linearized(objectclass_res->msgs[i]->dn),
+				      win_errstr(status));
+			talloc_free(mem_ctx);
+			return LDB_ERR_CONSTRAINT_VIOLATION;
+		}
+
+		DLIST_ADD_END(schema->classes, sc, struct dsdb_class *);
+	}
+
+	schema->fsmo.master_dn = ldb_msg_find_attr_as_dn(ldb, schema, schema_res->msgs[0], "fSMORoleOwner");
+	if (ldb_dn_compare(samdb_ntds_settings_dn(ldb), schema->fsmo.master_dn) == 0) {
+		schema->fsmo.we_are_master = true;
+	} else {
+		schema->fsmo.we_are_master = false;
+	}
+
+	DEBUG(5, ("schema_fsmo_init: we are master: %s\n",
+		  (schema->fsmo.we_are_master?"yes":"no")));
+
+	*schema_out = schema;
+	return LDB_SUCCESS;
+}
+
+
 static const struct {
 	const char *name;
 	const char *oid;
diff --git a/source/lib/ldb/config.mk b/source/lib/ldb/config.mk
index 6821c05..fe3b71d 100644
--- a/source/lib/ldb/config.mk
+++ b/source/lib/ldb/config.mk
@@ -147,32 +147,5 @@ PRIVATE_DEPENDENCIES = \
 
 ldbtest_OBJ_FILES = $(ldbsrcdir)/tools/ldbtest.o
 
-################################################
-# Start BINARY oLschema2ldif
-[BINARY::oLschema2ldif]
-INSTALLDIR = BINDIR
-PRIVATE_DEPENDENCIES = \
-		LIBLDB_CMDLINE
-# End BINARY oLschema2ldif
-################################################
-
-
-oLschema2ldif_OBJ_FILES = $(addprefix $(ldbsrcdir)/tools/, convert.o oLschema2ldif.o)
-
-MANPAGES += $(ldbsrcdir)/man/oLschema2ldif.1
-
-################################################
-# Start BINARY  ad2oLschema
-[BINARY::ad2oLschema]
-INSTALLDIR = BINDIR
-PRIVATE_DEPENDENCIES = \
-		LIBLDB_CMDLINE
-# End BINARY ad2oLschema
-################################################
-
-ad2oLschema_OBJ_FILES = $(addprefix $(ldbsrcdir)/tools/, convert.o ad2oLschema.o)
-
-MANPAGES += $(ldbsrcdir)/man/ad2oLschema.1
-
 mkinclude tools/config.mk
 mkinclude ldb_ildap/config.mk
diff --git a/source/lib/ldb/tools/ad2oLschema.c b/source/lib/ldb/tools/ad2oLschema.c
deleted file mode 100644
index df6fc91..0000000
--- a/source/lib/ldb/tools/ad2oLschema.c
+++ /dev/null
@@ -1,800 +0,0 @@
-/* 
-   ldb database library
-
-   Copyright (C) Andrew Bartlett 2006
-
-     ** NOTE! The following LGPL license applies to the ldb
-     ** library. This does NOT imply that all of Samba is released
-     ** under the LGPL
-   
-   This library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 3 of the License, or (at your option) any later version.
-
-   This library 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
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with this library; if not, see <http://www.gnu.org/licenses/>.
-*/
-
-/*
- *  Name: ldb
- *
- *  Component: ad2oLschema
- *
- *  Description: utility to convert an AD schema into the format required by OpenLDAP
- *
- *  Author: Andrew Bartlett
- */
-
-#include "includes.h"
-#include "ldb_includes.h"
-#include "system/locale.h"
-#include "tools/cmdline.h"
-#include "tools/convert.h"
-#include "param/param.h"
-#include "lib/cmdline/popt_common.h"
-
-struct schema_conv {
-	int count;
-	int skipped;
-	int failures;
-};
-
-enum convert_target {
-	TARGET_OPENLDAP,
-	TARGET_FEDORA_DS
-};
-	
-
-static void usage(void)
-{
-	printf("Usage: ad2oLschema <options>\n");
-	printf("\nConvert AD-like LDIF to OpenLDAP schema format\n\n");
-	printf("Options:\n");
-	printf("  -I inputfile     inputfile of mapped OIDs and skipped attributes/ObjectClasses");
-	printf("  -H url           LDB or LDAP server to read schmea from\n");
-	printf("  -O outputfile    outputfile otherwise STDOUT\n");
-	printf("  -o options       pass options like modules to activate\n");
-	printf("              e.g: -o modules:timestamps\n");
-	printf("\n");
-	printf("Converts records from an AD-like LDIF schema into an openLdap formatted schema\n\n");
-	exit(1);
-}
-
-static int fetch_attrs_schema(struct ldb_context *ldb, struct ldb_dn *schemadn,
-			      TALLOC_CTX *mem_ctx, 
-			      struct ldb_result **attrs_res)
-{
-	TALLOC_CTX *local_ctx = talloc_new(mem_ctx);
-	int ret;
-	const char *attrs[] = {
-		"lDAPDisplayName",
-		"isSingleValued",
-		"attributeID",
-		"attributeSyntax",
-		"description",		
-		NULL
-	};
-
-	if (!local_ctx) {
-		return LDB_ERR_OPERATIONS_ERROR;
-	}
-	
-	/* Downlaod schema */
-	ret = ldb_search(ldb, schemadn, LDB_SCOPE_SUBTREE, 
-			 "objectClass=attributeSchema", 
-			 attrs, attrs_res);
-	if (ret != LDB_SUCCESS) {
-		printf("Search failed: %s\n", ldb_errstring(ldb));
-		return LDB_ERR_OPERATIONS_ERROR;
-	}
-	
-	return ret;
-}
-
-static const char *oc_attrs[] = {
-	"lDAPDisplayName",
-	"mayContain",
-	"mustContain",
-	"systemMayContain",
-	"systemMustContain",
-	"objectClassCategory",
-	"governsID",
-	"description",
-	"subClassOf",
-	"systemAuxiliaryClass",
-	"auxiliaryClass",
-	NULL
-};
-
-static int fetch_oc_recursive(struct ldb_context *ldb, struct ldb_dn *schemadn, 
-			      TALLOC_CTX *mem_ctx, 
-			      struct ldb_result *search_from,
-			      struct ldb_result *res_list)
-{
-	int i;
-	int ret = 0;
-	for (i=0; i < search_from->count; i++) {
-		struct ldb_result *res;
-		const char *name = ldb_msg_find_attr_as_string(search_from->msgs[i], 
-							       "lDAPDisplayname", NULL);
-
-		ret = ldb_search_exp_fmt(ldb, mem_ctx, &res,
-					schemadn, LDB_SCOPE_SUBTREE, oc_attrs,
-					"(&(&(objectClass=classSchema)(subClassOf=%s))(!(lDAPDisplayName=%s)))",
-					name, name);
-		if (ret != LDB_SUCCESS) {
-			printf("Search failed: %s\n", ldb_errstring(ldb));
-			return ret;
-		}
-		
-		res_list->msgs = talloc_realloc(res_list, res_list->msgs, 
-						struct ldb_message *, res_list->count + 2);
-		if (!res_list->msgs) {
-			return LDB_ERR_OPERATIONS_ERROR;
-		}
-		res_list->msgs[res_list->count] = talloc_move(res_list, 
-							      &search_from->msgs[i]);
-		res_list->count++;
-		res_list->msgs[res_list->count] = NULL;
-
-		if (res->count > 0) {
-			ret = fetch_oc_recursive(ldb, schemadn, mem_ctx, res, res_list); 
-		}
-		if (ret != LDB_SUCCESS) {
-			return ret;
-		}
-	}
-	return ret;
-}
-
-static int fetch_objectclass_schema(struct ldb_context *ldb, struct ldb_dn *schemadn, 
-				    TALLOC_CTX *mem_ctx, 
-				    struct ldb_result **objectclasses_res)
-{
-	TALLOC_CTX *local_ctx = talloc_new(mem_ctx);
-	struct ldb_result *top_res, *ret_res;
-	int ret;
-	if (!local_ctx) {
-		return LDB_ERR_OPERATIONS_ERROR;
-	}
-	
-	/* Downlaod 'top' */
-	ret = ldb_search(ldb, schemadn, LDB_SCOPE_SUBTREE, 
-			 "(&(objectClass=classSchema)(lDAPDisplayName=top))", 
-			 oc_attrs, &top_res);
-	if (ret != LDB_SUCCESS) {
-		printf("Search failed: %s\n", ldb_errstring(ldb));
-		return LDB_ERR_OPERATIONS_ERROR;
-	}
-
-	talloc_steal(local_ctx, top_res);
-
-	if (top_res->count != 1) {
-		return LDB_ERR_OPERATIONS_ERROR;
-	}


-- 
Samba Shared Repository


More information about the samba-cvs mailing list