summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source4/dsdb/samdb/ldb_modules/schema_fsmo.c105
-rw-r--r--source4/dsdb/schema/schema_init.c108
-rw-r--r--source4/lib/ldb/config.mk27
-rw-r--r--source4/utils/ad2oLschema.1.xml87
-rw-r--r--source4/utils/ad2oLschema.c (renamed from source4/lib/ldb/tools/ad2oLschema.c)100
-rw-r--r--source4/utils/config.mk28
-rw-r--r--source4/utils/oLschema2ldif.1.xml79
-rw-r--r--source4/utils/oLschema2ldif.c (renamed from source4/lib/ldb/tools/oLschema2ldif.c)2
-rw-r--r--source4/utils/schema_convert.c (renamed from source4/lib/ldb/tools/convert.c)2
-rw-r--r--source4/utils/schema_convert.h (renamed from source4/lib/ldb/tools/convert.h)0
10 files changed, 364 insertions, 174 deletions
diff --git a/source4/dsdb/samdb/ldb_modules/schema_fsmo.c b/source4/dsdb/samdb/ldb_modules/schema_fsmo.c
index 01108605ec..6f65c199ba 100644
--- a/source4/dsdb/samdb/ldb_modules/schema_fsmo.c
+++ b/source4/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/source4/dsdb/schema/schema_init.c b/source4/dsdb/schema/schema_init.c
index f71c14a95d..826f91b5f0 100644
--- a/source4/dsdb/schema/schema_init.c
+++ b/source4/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/source4/lib/ldb/config.mk b/source4/lib/ldb/config.mk
index 6821c058f2..fe3b71d1d5 100644
--- a/source4/lib/ldb/config.mk
+++ b/source4/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/source4/utils/ad2oLschema.1.xml b/source4/utils/ad2oLschema.1.xml
new file mode 100644
index 0000000000..6ae8996477
--- /dev/null
+++ b/source4/utils/ad2oLschema.1.xml
@@ -0,0 +1,87 @@
+<?xml version="1.0" encoding="iso-8859-1"?>
+<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
+<refentry id="ad2oLschema.1">
+
+<refmeta>
+ <refentrytitle>ad2oLschema</refentrytitle>
+ <manvolnum>1</manvolnum>
+</refmeta>
+
+
+<refnamediv>
+ <refname>ad2oLschema</refname>
+ <refpurpose>Converts AC-like LDAP schemas to OpenLDAP
+ compatible schema files</refpurpose>
+</refnamediv>
+
+<refsynopsisdiv>
+ <cmdsynopsis>
+ <command>ad2oLschema</command>
+ <arg choice="opt">-I INPUT-FILE</arg>
+ <arg choice="opt">-O OUTPUT-FILE</arg>
+ </cmdsynopsis>
+</refsynopsisdiv>
+
+<refsect1>
+ <title>DESCRIPTION</title>
+
+ <para>ad2oLschema is a simple tool that converts AD-like LDIF
+ schema files into OpenLDAP schema files.</para>
+</refsect1>
+
+
+<refsect1>
+ <title>OPTIONS</title>
+
+ <variablelist>
+ <varlistentry>
+ <term>-H url</term>
+ <listitem><para>URL to an LDB or LDAP server with an AD schema to read. </para></listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>-I input-file</term> <listitem><para>AD schema
+ to read. If neither this nor -H is specified, the
+ schema file will be read from standard input.
+ </para></listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>-O output-file</term>
+ <listitem><para>File to write OpenLDAP version of schema to.
+ </para></listitem>
+ </varlistentry>
+ </variablelist>
+</refsect1>
+
+<refsect1>
+ <title>VERSION</title>
+
+ <para>This man page is correct for version 4.0 of the Samba suite.</para>
+</refsect1>
+
+<refsect1>
+ <title>SEE ALSO</title>
+
+ <para>ldb(7), ldbmodify, ldbdel, ldif(5)</para>
+
+</refsect1>
+
+<refsect1>
+ <title>AUTHOR</title>
+
+ <para> ldb was written by
+ <ulink url="http://samba.org/~tridge/">Andrew Tridgell</ulink>.
+ ad2oLschema was written by <ulink
+ url="http://samba.org/~abartlet/">Andrew Bartlett</ulink>.
+ </para>
+
+ <para>
+If you wish to report a problem or make a suggestion then please see
+the <ulink url="http://ldb.samba.org/"/> web site for
+current contact and maintainer information.
+ </para>
+
+</refsect1>
+
+</refentry>
diff --git a/source4/lib/ldb/tools/ad2oLschema.c b/source4/utils/ad2oLschema.c
index df6fc91688..879b1a7213 100644
--- a/source4/lib/ldb/tools/ad2oLschema.c
+++ b/source4/utils/ad2oLschema.c
@@ -34,10 +34,11 @@
#include "includes.h"
#include "ldb_includes.h"
#include "system/locale.h"
-#include "tools/cmdline.h"
-#include "tools/convert.h"
+#include "lib/ldb/tools/cmdline.h"
+#include "utils/schema_convert.h"
#include "param/param.h"
#include "lib/cmdline/popt_common.h"
+#include "dsdb/samdb/samdb.h"
struct schema_conv {
int count;
@@ -70,25 +71,12 @@ 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);
+ NULL, attrs_res);
if (ret != LDB_SUCCESS) {
printf("Search failed: %s\n", ldb_errstring(ldb));
return LDB_ERR_OPERATIONS_ERROR;
@@ -97,21 +85,6 @@ static int fetch_attrs_schema(struct ldb_context *ldb, struct ldb_dn *schemadn,
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,
@@ -125,7 +98,7 @@ static int fetch_oc_recursive(struct ldb_context *ldb, struct ldb_dn *schemadn,
"lDAPDisplayname", NULL);
ret = ldb_search_exp_fmt(ldb, mem_ctx, &res,
- schemadn, LDB_SCOPE_SUBTREE, oc_attrs,
+ schemadn, LDB_SCOPE_SUBTREE, NULL,
"(&(&(objectClass=classSchema)(subClassOf=%s))(!(lDAPDisplayName=%s)))",
name, name);
if (ret != LDB_SUCCESS) {
@@ -167,7 +140,7 @@ static int fetch_objectclass_schema(struct ldb_context *ldb, struct ldb_dn *sche
/* Downlaod 'top' */
ret = ldb_search(ldb, schemadn, LDB_SCOPE_SUBTREE,
"(&(objectClass=classSchema)(lDAPDisplayName=top))",
- oc_attrs, &top_res);
+ NULL, &top_res);
if (ret != LDB_SUCCESS) {
printf("Search failed: %s\n", ldb_errstring(ldb));
return LDB_ERR_OPERATIONS_ERROR;
@@ -195,15 +168,15 @@ static int fetch_objectclass_schema(struct ldb_context *ldb, struct ldb_dn *sche
return ret;
}
-static struct ldb_dn *find_schema_dn(struct ldb_context *ldb, TALLOC_CTX *mem_ctx)
+static struct ldb_dn *find_schema_dn(struct ldb_context *ldb, TALLOC_CTX *mem_ctx,
+ struct ldb_result **schema_res)
{
const char *rootdse_attrs[] = {"schemaNamingContext", NULL};
- const char *no_attrs[] = { NULL };
struct ldb_dn *schemadn;
struct ldb_dn *basedn = ldb_dn_new(mem_ctx, ldb, NULL);
struct ldb_result *rootdse_res;
- struct ldb_result *schema_res;
int ldb_ret;
+
if (!basedn) {
return NULL;
}
@@ -213,21 +186,20 @@ static struct ldb_dn *find_schema_dn(struct ldb_context *ldb, TALLOC_CTX *mem_ct
if (ldb_ret != LDB_SUCCESS) {
ldb_ret = ldb_search(ldb, basedn, LDB_SCOPE_SUBTREE,
"(&(objectClass=dMD)(cn=Schema))",
- no_attrs, &schema_res);
+ NULL, schema_res);
if (ldb_ret) {
printf("cn=Schema Search failed: %s\n", ldb_errstring(ldb));
return NULL;
}
- talloc_steal(mem_ctx, schema_res);
+ talloc_steal(mem_ctx, *schema_res);
- if (schema_res->count != 1) {
+ if ((*schema_res)->count != 1) {
printf("Failed to find rootDSE");
return NULL;
}
- schemadn = talloc_steal(mem_ctx, schema_res->msgs[0]->dn);
- talloc_free(schema_res);
+ schemadn = talloc_steal(mem_ctx, (*schema_res)->msgs[0]->dn);
return schemadn;
}
@@ -245,6 +217,20 @@ static struct ldb_dn *find_schema_dn(struct ldb_context *ldb, TALLOC_CTX *mem_ct
return NULL;
}
+ ldb_ret = ldb_search(ldb, schemadn, LDB_SCOPE_BASE,
+ "(&(objectClass=dMD)(cn=Schema))",
+ NULL, schema_res);
+ if (ldb_ret) {
+ printf("cn=Schema Search failed: %s\n", ldb_errstring(ldb));
+ return NULL;
+ }
+
+ talloc_steal(mem_ctx, *schema_res);
+
+ if ((*schema_res)->count != 1) {
+ printf("Failed to find rootDSE");
+ return NULL;
+ }
talloc_free(rootdse_res);
return schemadn;
}
@@ -281,7 +267,7 @@ static bool find_aux_classes(TALLOC_CTX *mem_ctx, struct ldb_context *ldb, struc
for (i=0; aux_class && i < aux_class->num_values; i++) {
ret = ldb_search_exp_fmt(ldb, mem_ctx, &res,
- schema_dn, LDB_SCOPE_SUBTREE, oc_attrs,
+ schema_dn, LDB_SCOPE_SUBTREE, NULL,
"(&(objectClass=classSchema)(lDAPDisplayName=%s))",
aux_class->values[i].data);
if (ret != LDB_SUCCESS) {
@@ -346,9 +332,11 @@ static struct schema_conv process_convert(struct ldb_context *ldb, enum convert_
char *new_attr;
} *attr_map = NULL;
int num_attr_maps = 0;
- struct ldb_result *attrs_res, *objectclasses_res;
+ struct ldb_result *schema_res, *attrs_res, *objectclasses_res;
struct ldb_dn *schemadn;
struct schema_conv ret;
+ struct dsdb_schema *schema;
+ char *error_string;
int ldb_ret, i;
@@ -401,7 +389,7 @@ static struct schema_conv process_convert(struct ldb_context *ldb, enum convert_
}
}
- schemadn = find_schema_dn(ldb, mem_ctx);
+ schemadn = find_schema_dn(ldb, mem_ctx, &schema_res);
if (!schemadn) {
printf("Failed to find schema DN: %s\n", ldb_errstring(ldb));
ret.failures = 1;
@@ -414,7 +402,24 @@ static struct schema_conv process_convert(struct ldb_context *ldb, enum convert_
ret.failures = 1;
return ret;
}
+
+
+ ldb_ret = fetch_objectclass_schema(ldb, schemadn, mem_ctx, &objectclasses_res);
+ if (ldb_ret != LDB_SUCCESS) {
+ printf("Failed to fetch objectClass schema elements: %s\n", ldb_errstring(ldb));
+ ret.failures = 1;
+ return ret;
+ }
+ ldb_ret = dsdb_schema_from_ldb_results(mem_ctx, ldb,
+ lp_iconv_convenience(cmdline_lp_ctx),
+ schema_res, attrs_res, objectclasses_res, &schema, &error_string);
+ if (ldb_ret != LDB_SUCCESS) {
+ printf("Failed to load schema: %s\n", error_string);
+ ret.failures = 1;
+ return ret;
+ }
+
switch (target) {
case TARGET_OPENLDAP:
break;
@@ -534,13 +539,6 @@ static struct schema_conv process_convert(struct ldb_context *ldb, enum convert_
ret.count++;
}
- ldb_ret = fetch_objectclass_schema(ldb, schemadn, mem_ctx, &objectclasses_res);
- if (ldb_ret != LDB_SUCCESS) {
- printf("Failed to fetch objectClass schema elements: %s\n", ldb_errstring(ldb));
- ret.failures = 1;
- return ret;
- }
-
for (i=0; i < objectclasses_res->count; i++) {
struct ldb_message *msg = objectclasses_res->msgs[i];
const char *name = ldb_msg_find_attr_as_string(msg, "lDAPDisplayName", NULL);
diff --git a/source4/utils/config.mk b/source4/utils/config.mk
index d47b36ea7c..61565807d2 100644
--- a/source4/utils/config.mk
+++ b/source4/utils/config.mk
@@ -94,3 +94,31 @@ PRIVATE_DEPENDENCIES = \
#################################
testparm_OBJ_FILES = $(utilssrcdir)/testparm.o
+
+################################################
+# Start BINARY oLschema2ldif
+[BINARY::oLschema2ldif]
+INSTALLDIR = BINDIR
+PRIVATE_DEPENDENCIES = \
+ LIBLDB_CMDLINE
+# End BINARY oLschema2ldif
+################################################
+
+
+oLschema2ldif_OBJ_FILES = $(addprefix $(utilssrcdir)/, schema_convert.o oLschema2ldif.o)
+
+MANPAGES += $(utilssrcdir)/man/oLschema2ldif.1
+
+################################################
+# Start BINARY ad2oLschema
+[BINARY::ad2oLschema]
+INSTALLDIR = BINDIR
+PRIVATE_DEPENDENCIES = \
+ LIBLDB_CMDLINE SAMDB
+# End BINARY ad2oLschema
+################################################
+
+ad2oLschema_OBJ_FILES = $(addprefix $(utilssrcdir)/, schema_convert.o ad2oLschema.o)
+
+MANPAGES += $(utilssrcdir)/man/ad2oLschema.1
+
diff --git a/source4/utils/oLschema2ldif.1.xml b/source4/utils/oLschema2ldif.1.xml
new file mode 100644
index 0000000000..b1e681be4e
--- /dev/null
+++ b/source4/utils/oLschema2ldif.1.xml
@@ -0,0 +1,79 @@
+<?xml version="1.0" encoding="iso-8859-1"?>
+<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
+<refentry id="oLschema2ldif.1">
+
+<refmeta>
+ <refentrytitle>oLschema2ldif</refentrytitle>
+ <manvolnum>1</manvolnum>
+</refmeta>
+
+
+<refnamediv>
+ <refname>oLschema2ldif</refname>
+ <refpurpose>Converts LDAP schema's to LDB-compatible LDIF</refpurpose>
+</refnamediv>
+
+<refsynopsisdiv>
+ <cmdsynopsis>
+ <command>oLschema2ldif</command>
+ <arg choice="opt">-I INPUT-FILE</arg>
+ <arg choice="opt">-O OUTPUT-FILE</arg>
+ </cmdsynopsis>
+</refsynopsisdiv>
+
+<refsect1>
+ <title>DESCRIPTION</title>
+
+ <para>oLschema2ldif is a simple tool that converts standard OpenLDAP schema files to a LDIF format that is understood by LDB.</para>
+</refsect1>
+
+
+<refsect1>
+ <title>OPTIONS</title>
+
+ <variablelist>
+ <varlistentry>
+ <term>-I input-file</term>
+ <listitem><para>OpenLDAP schema to read. If none are specified,
+the schema file will be read from standard input.
+ </para></listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>-O output-file</term>
+ <listitem><para>File to write ldif version of schema to.
+ </para></listitem>
+ </varlistentry>
+ </variablelist>
+</refsect1>
+
+<refsect1>
+ <title>VERSION</title>
+
+ <para>This man page is correct for version 4.0 of the Samba suite.</para>
+</refsect1>
+
+<refsect1>
+ <title>SEE ALSO</title>
+
+ <para>ldb(7), ldbmodify, ldbdel, ldif(5)</para>
+
+</refsect1>
+
+<refsect1>
+ <title>AUTHOR</title>
+
+ <para> ldb was written by
+ <ulink url="http://samba.org/~tridge/">Andrew Tridgell</ulink>.
+ oLschema2ldif was written by <ulink url="mailto:idra@samba.org">Simo Sorce</ulink>.
+ </para>
+
+ <para>
+If you wish to report a problem or make a suggestion then please see
+the <ulink url="http://ldb.samba.org/"/> web site for
+current contact and maintainer information.
+ </para>
+
+</refsect1>
+
+</refentry>
diff --git a/source4/lib/ldb/tools/oLschema2ldif.c b/source4/utils/oLschema2ldif.c
index 3c31f37c55..b501b75529 100644
--- a/source4/lib/ldb/tools/oLschema2ldif.c
+++ b/source4/utils/oLschema2ldif.c
@@ -33,7 +33,7 @@
#include "ldb_includes.h"
#include "tools/cmdline.h"
-#include "tools/convert.h"
+#include "utils/schema_convert.h"
#define SCHEMA_UNKNOWN 0
#define SCHEMA_NAME 1
diff --git a/source4/lib/ldb/tools/convert.c b/source4/utils/schema_convert.c
index 5a5cf2a94c..a5d38451d4 100644
--- a/source4/lib/ldb/tools/convert.c
+++ b/source4/utils/schema_convert.c
@@ -21,7 +21,7 @@
License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
-#include "convert.h"
+#include "schema_convert.h"
#include "ldb_includes.h"
/* Shared map for converting syntax between formats */
diff --git a/source4/lib/ldb/tools/convert.h b/source4/utils/schema_convert.h
index de379343a6..de379343a6 100644
--- a/source4/lib/ldb/tools/convert.h
+++ b/source4/utils/schema_convert.h