*/
#include "includes.h"
-#include "ldb_includes.h"
+#include "ldb.h"
#include "system/locale.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"
int skipped;
int failures;
};
-
-enum convert_target {
- TARGET_OPENLDAP,
- TARGET_FEDORA_DS
-};
static void usage(void)
}
/* Search for rootdse */
- ldb_ret = ldb_search(ldb, basedn, LDB_SCOPE_BASE, NULL, rootdse_attrs, &rootdse_res);
+ ldb_ret = ldb_search(ldb, mem_ctx, &rootdse_res,
+ basedn, LDB_SCOPE_BASE, rootdse_attrs, NULL);
if (ldb_ret != LDB_SUCCESS) {
- ldb_ret = ldb_search(ldb, basedn, LDB_SCOPE_SUBTREE,
- "(&(objectClass=dMD)(cn=Schema))",
- NULL, &schema_res);
+ ldb_ret = ldb_search(ldb, mem_ctx, &schema_res, basedn, LDB_SCOPE_SUBTREE,
+ NULL, "(&(objectClass=dMD)(cn=Schema))");
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) {
talloc_free(schema_res);
printf("Failed to find rootDSE");
}
-#define IF_NULL_FAIL_RET(x) do { \
- if (!x) { \
- return NULL; \
- } \
- } while (0)
-
-
-static char *schema_attribute_description(TALLOC_CTX *mem_ctx,
- enum convert_target target,
- const char *seperator,
- const char *oid,
- const char *name,
- const char *description,
- struct syntax_map *map,
- const char *syntax,
- bool single_value, bool operational)
-{
- char *schema_entry = talloc_asprintf(mem_ctx,
- "(%s%s%s", seperator, oid, seperator);
-
- schema_entry = talloc_asprintf_append(schema_entry,
- "NAME '%s'%s", name, seperator);
- IF_NULL_FAIL_RET(schema_entry);
-
- if (description) {
-#if 0
- /* Need a way to escape ' characters from the description */
- schema_entry = talloc_asprintf_append(schema_entry,
- "DESC '%s'%s", description, seperator);
- IF_NULL_FAIL_RET(schema_entry);
-#endif
- }
-
- if (map) {
- if (map->equality) {
- schema_entry = talloc_asprintf_append(schema_entry,
- "EQUALITY %s%s", map->equality, seperator);
- IF_NULL_FAIL_RET(schema_entry);
- }
- if (map->substring) {
- schema_entry = talloc_asprintf_append(schema_entry,
- "SUBSTR %s%s", map->substring, seperator);
- IF_NULL_FAIL_RET(schema_entry);
- }
-
- syntax = map->Standard_OID;
- }
-
- schema_entry = talloc_asprintf_append(schema_entry,
- "SYNTAX %s%s", syntax, seperator);
- IF_NULL_FAIL_RET(schema_entry);
-
- if (single_value) {
- schema_entry = talloc_asprintf_append(schema_entry,
- "SINGLE-VALUE%s", seperator);
- IF_NULL_FAIL_RET(schema_entry);
- }
-
- if (operational) {
- schema_entry = talloc_asprintf_append(schema_entry,
- "NO-USER-MODIFICATION%s", seperator);
- IF_NULL_FAIL_RET(schema_entry);
- }
-
- schema_entry = talloc_asprintf_append(schema_entry,
- ")");
- return schema_entry;
-}
-
-static char *schema_class_description(TALLOC_CTX *mem_ctx,
- enum convert_target target,
- const char *seperator,
- const char *oid,
- const char *name,
- const char *description,
- const char *subClassOf,
- int objectClassCategory,
- char **must,
- char **may)
-{
- char *schema_entry = talloc_asprintf(mem_ctx,
- "(%s%s%s", seperator, oid, seperator);
-
- IF_NULL_FAIL_RET(schema_entry);
-
- schema_entry = talloc_asprintf_append(schema_entry,
- "NAME '%s'%s", name, seperator);
- IF_NULL_FAIL_RET(schema_entry);
-
- if (description) {
- schema_entry = talloc_asprintf_append(schema_entry,
- "DESC '%s'%s", description, seperator);
- IF_NULL_FAIL_RET(schema_entry);
- }
-
- if (subClassOf) {
- schema_entry = talloc_asprintf_append(schema_entry,
- "SUP %s%s", subClassOf, seperator);
- IF_NULL_FAIL_RET(schema_entry);
- }
-
- switch (objectClassCategory) {
- case 1:
- schema_entry = talloc_asprintf_append(schema_entry,
- "STRUCTURAL%s", seperator);
- IF_NULL_FAIL_RET(schema_entry);
- break;
- case 2:
- schema_entry = talloc_asprintf_append(schema_entry,
- "ABSTRACT%s", seperator);
- IF_NULL_FAIL_RET(schema_entry);
- break;
- case 3:
- schema_entry = talloc_asprintf_append(schema_entry,
- "AUXILIARY%s", seperator);
- IF_NULL_FAIL_RET(schema_entry);
- break;
- }
-
-#define APPEND_ATTRS(attributes) \
- do { \
- int k; \
- for (k=0; attributes && attributes[k]; k++) { \
- const char *attr_name = attributes[k]; \
- \
- schema_entry = talloc_asprintf_append(schema_entry, \
- "%s ", \
- attr_name); \
- IF_NULL_FAIL_RET(schema_entry); \
- if (attributes[k+1]) { \
- IF_NULL_FAIL_RET(schema_entry); \
- if (target == TARGET_OPENLDAP && ((k+1)%5 == 0)) { \
- schema_entry = talloc_asprintf_append(schema_entry, \
- "$%s ", seperator); \
- IF_NULL_FAIL_RET(schema_entry); \
- } else { \
- schema_entry = talloc_asprintf_append(schema_entry, \
- "$ "); \
- } \
- } \
- } \
- } while (0)
-
- if (must) {
- schema_entry = talloc_asprintf_append(schema_entry,
- "MUST ( ");
- IF_NULL_FAIL_RET(schema_entry);
-
- APPEND_ATTRS(must);
-
- schema_entry = talloc_asprintf_append(schema_entry,
- ")%s", seperator);
- IF_NULL_FAIL_RET(schema_entry);
- }
-
- if (may) {
- schema_entry = talloc_asprintf_append(schema_entry,
- "MAY ( ");
- IF_NULL_FAIL_RET(schema_entry);
-
- APPEND_ATTRS(may);
-
- schema_entry = talloc_asprintf_append(schema_entry,
- ")%s", seperator);
- IF_NULL_FAIL_RET(schema_entry);
- }
-
- schema_entry = talloc_asprintf_append(schema_entry,
- ")");
- return schema_entry;
-}
-
-static struct schema_conv process_convert(struct ldb_context *ldb, enum convert_target target, FILE *in, FILE *out)
+static struct schema_conv process_convert(struct ldb_context *ldb, enum dsdb_schema_convert_target target, FILE *in, FILE *out)
{
/* Read list of attributes to skip, OIDs to map */
TALLOC_CTX *mem_ctx = talloc_new(ldb);
for (attribute=schema->attributes; attribute; attribute = attribute->next) {
const char *name = attribute->lDAPDisplayName;
- const char *description = attribute->adminDescription;
const char *oid = attribute->attributeID_oid;
const char *syntax = attribute->attributeSyntax_oid;
+ const char *equality = NULL, *substring = NULL;
bool single_value = attribute->isSingleValued;
- const struct syntax_map *const_map = find_syntax_map_by_ad_oid(syntax);
- struct syntax_map map, *map_p = NULL;
char *schema_entry = NULL;
int j;
}
}
- if (const_map) {
- map = *const_map;
-
+ if (attribute->syntax) {
/* We might have been asked to remap this oid,
* due to a conflict, or lack of
* implementation */
- for (j=0; map.Standard_OID && oid_map && oid_map[j].old_oid; j++) {
- if (strcasecmp(map.Standard_OID, oid_map[j].old_oid) == 0) {
- map.Standard_OID = oid_map[j].new_oid;
+ syntax = attribute->syntax->ldap_oid;
+ /* We might have been asked to remap this oid, due to a conflict */
+ for (j=0; syntax && oid_map && oid_map[j].old_oid; j++) {
+ if (strcasecmp(syntax, oid_map[j].old_oid) == 0) {
+ syntax = oid_map[j].new_oid;
break;
}
}
-
- map_p = ↦
+
+ equality = attribute->syntax->equality;
+ substring = attribute->syntax->substring;
}
/* We might have been asked to remap this name, due to a conflict */
}
}
- schema_entry = schema_attribute_description(mem_ctx, target, seperator, oid, name, description, map_p, syntax, single_value, false);
+ schema_entry = schema_attribute_description(mem_ctx,
+ target,
+ seperator,
+ oid,
+ name,
+ equality,
+ substring,
+ syntax,
+ single_value,
+ false,
+ NULL, NULL,
+ NULL, NULL,
+ false, false);
if (schema_entry == NULL) {
ret.failures++;
/* This is already sorted to have 'top' and similar classes first */
for (objectclass=schema->classes; objectclass; objectclass = objectclass->next) {
const char *name = objectclass->lDAPDisplayName;
- const char *description = objectclass->adminDescription;
const char *oid = objectclass->governsID_oid;
const char *subClassOf = objectclass->subClassOf;
int objectClassCategory = objectclass->objectClassCategory;
- char **must;
- char **may;
+ const char **must;
+ const char **may;
char *schema_entry = NULL;
const char *objectclass_name_as_list[] = {
objectclass->lDAPDisplayName,
seperator,
oid,
name,
- description,
+ NULL,
subClassOf,
objectClassCategory,
must,
- may);
+ may,
+ NULL);
if (schema_entry == NULL) {
ret.failures++;
return ret;
struct ldb_context *ldb;
struct schema_conv ret;
const char *target_str;
- enum convert_target target;
+ enum dsdb_schema_convert_target target;
ctx = talloc_new(NULL);
ldb = ldb_init(ctx, NULL);