From a3faed4bfe14192292d7656d673e9fcc52084075 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 15 Aug 2008 12:08:10 +1000 Subject: Paramaterise the seperator in ad2OLschema This will allow me to add a new mode, with the CN=Aggregate schema format automatically generated. Andrew Bartlett (This used to be commit 7d2a890a7077e446e45527847f78bba84d22bc4c) --- source4/utils/ad2oLschema.c | 149 ++++++++++++++++++++++++-------------------- 1 file changed, 82 insertions(+), 67 deletions(-) (limited to 'source4/utils/ad2oLschema.c') diff --git a/source4/utils/ad2oLschema.c b/source4/utils/ad2oLschema.c index 51b03b8e8f..dcc0094ab7 100644 --- a/source4/utils/ad2oLschema.c +++ b/source4/utils/ad2oLschema.c @@ -152,6 +152,7 @@ static struct schema_conv process_convert(struct ldb_context *ldb, enum convert_ struct ldb_dn *schemadn; struct schema_conv ret; struct dsdb_schema *schema; + const char *seperator; char *error_string; int ldb_ret; @@ -223,8 +224,10 @@ static struct schema_conv process_convert(struct ldb_context *ldb, enum convert_ switch (target) { case TARGET_OPENLDAP: + seperator = "\n "; break; case TARGET_FEDORA_DS: + seperator = "\n "; fprintf(out, "dn: cn=schema\n"); break; } @@ -236,7 +239,8 @@ static struct schema_conv process_convert(struct ldb_context *ldb, enum convert_ const char *syntax = attribute->attributeSyntax_oid; bool single_value = attribute->isSingleValued; - const struct syntax_map *map = find_syntax_map_by_ad_oid(syntax); + 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; @@ -254,19 +258,21 @@ static struct schema_conv process_convert(struct ldb_context *ldb, enum convert_ } } - switch (target) { - case TARGET_OPENLDAP: - schema_entry = talloc_asprintf(mem_ctx, - "attributetype (\n" - " %s\n", oid); - break; - case TARGET_FEDORA_DS: - schema_entry = talloc_asprintf(mem_ctx, - "attributeTypes: (\n" - " %s\n", oid); - break; + if (const_map) { + map = *const_map; + + /* 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; + break; + } + } + + map_p = ↦ } - IF_NULL_FAIL_RET(schema_entry); /* We might have been asked to remap this name, due to a conflict */ for (j=0; name && attr_map && attr_map[j].old_attr; j++) { @@ -276,53 +282,60 @@ static struct schema_conv process_convert(struct ldb_context *ldb, enum convert_ } } + switch (target) { + case TARGET_OPENLDAP: + schema_entry = talloc_asprintf(mem_ctx, + "attributetype ("); + break; + case TARGET_FEDORA_DS: + schema_entry = talloc_asprintf(mem_ctx, + "attributeTypes: ("); + break; + } + IF_NULL_FAIL_RET(schema_entry); + schema_entry = talloc_asprintf_append(schema_entry, - " NAME '%s'\n", name); + "%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 /* If you want to re-enable this, you must first figure out a sane escaping of ' in the description */ schema_entry = talloc_asprintf_append(schema_entry, - " DESC '%s'\n", description); + "DESC '%s' ", description); IF_NULL_FAIL_RET(schema_entry); #endif } - if (map) { - const char *syntax_oid; - if (map->equality) { + if (map_p) { + if (map_p->equality) { schema_entry = talloc_asprintf_append(schema_entry, - " EQUALITY %s\n", map->equality); + "EQUALITY %s%s", map_p->equality, seperator); IF_NULL_FAIL_RET(schema_entry); } - if (map->substring) { + if (map_p->substring) { schema_entry = talloc_asprintf_append(schema_entry, - " SUBSTR %s\n", map->substring); + "SUBSTR %s%s", map_p->substring, seperator); IF_NULL_FAIL_RET(schema_entry); } - syntax_oid = map->Standard_OID; - /* We might have been asked to remap this oid, - * due to a conflict, or lack of - * implementation */ - for (j=0; syntax_oid && oid_map && oid_map[j].old_oid; j++) { - if (strcasecmp(syntax_oid, oid_map[j].old_oid) == 0) { - syntax_oid = oid_map[j].new_oid; - break; - } - } - schema_entry = talloc_asprintf_append(schema_entry, - " SYNTAX %s\n", syntax_oid); - IF_NULL_FAIL_RET(schema_entry); + + syntax = map_p->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\n"); + "SINGLE-VALUE%s", seperator); IF_NULL_FAIL_RET(schema_entry); } schema_entry = talloc_asprintf_append(schema_entry, - " )"); + ")"); switch (target) { case TARGET_OPENLDAP: @@ -357,10 +370,6 @@ static struct schema_conv process_convert(struct ldb_context *ldb, enum convert_ continue; } - may = dsdb_full_attribute_list(mem_ctx, schema, objectclass_name_as_list, DSDB_SCHEMA_ALL_MAY); - - must = dsdb_full_attribute_list(mem_ctx, schema, objectclass_name_as_list, DSDB_SCHEMA_ALL_MUST); - /* We might have been asked to remap this oid, due to a conflict */ for (j=0; oid_map && oid_map[j].old_oid; j++) { if (strcasecmp(oid, oid_map[j].old_oid) == 0) { @@ -369,64 +378,69 @@ static struct schema_conv process_convert(struct ldb_context *ldb, enum convert_ } } + /* We might have been asked to remap this name, due to a conflict */ + for (j=0; name && attr_map && attr_map[j].old_attr; j++) { + if (strcasecmp(name, attr_map[j].old_attr) == 0) { + name = attr_map[j].new_attr; + break; + } + } + + may = dsdb_full_attribute_list(mem_ctx, schema, objectclass_name_as_list, DSDB_SCHEMA_ALL_MAY); + + must = dsdb_full_attribute_list(mem_ctx, schema, objectclass_name_as_list, DSDB_SCHEMA_ALL_MUST); + switch (target) { case TARGET_OPENLDAP: schema_entry = talloc_asprintf(mem_ctx, - "objectclass (\n" - " %s\n", oid); + "objectclass ("); break; case TARGET_FEDORA_DS: schema_entry = talloc_asprintf(mem_ctx, - "objectClasses: (\n" - " %s\n", oid); + "objectClasses: ("); break; } + schema_entry = talloc_asprintf_append(schema_entry, + "%s%s%s", seperator, oid, seperator); + IF_NULL_FAIL_RET(schema_entry); if (!schema_entry) { ret.failures++; break; } - /* We might have been asked to remap this name, due to a conflict */ - for (j=0; name && attr_map && attr_map[j].old_attr; j++) { - if (strcasecmp(name, attr_map[j].old_attr) == 0) { - name = attr_map[j].new_attr; - break; - } - } - schema_entry = talloc_asprintf_append(schema_entry, - " NAME '%s'\n", name); + "NAME '%s'%s", name, seperator); IF_NULL_FAIL_RET(schema_entry); if (!schema_entry) return ret; if (description) { schema_entry = talloc_asprintf_append(schema_entry, - " DESC '%s'\n", description); + "DESC '%s'%s", description, seperator); IF_NULL_FAIL_RET(schema_entry); } if (subClassOf) { schema_entry = talloc_asprintf_append(schema_entry, - " SUP %s\n", subClassOf); + "SUP %s%s", subClassOf, seperator); IF_NULL_FAIL_RET(schema_entry); } switch (objectClassCategory) { case 1: schema_entry = talloc_asprintf_append(schema_entry, - " STRUCTURAL\n"); + "STRUCTURAL%s", seperator); IF_NULL_FAIL_RET(schema_entry); break; case 2: schema_entry = talloc_asprintf_append(schema_entry, - " ABSTRACT\n"); + "ABSTRACT%s", seperator); IF_NULL_FAIL_RET(schema_entry); break; case 3: schema_entry = talloc_asprintf_append(schema_entry, - " AUXILIARY\n"); + "AUXILIARY%s", seperator); IF_NULL_FAIL_RET(schema_entry); break; } @@ -446,17 +460,18 @@ static struct schema_conv process_convert(struct ldb_context *ldb, enum convert_ } \ \ schema_entry = talloc_asprintf_append(schema_entry, \ - " %s", \ + "%s ", \ attr_name); \ IF_NULL_FAIL_RET(schema_entry); \ if (attributes[k+1]) { \ - schema_entry = talloc_asprintf_append(schema_entry, \ - " $"); \ IF_NULL_FAIL_RET(schema_entry); \ if (target == TARGET_OPENLDAP && ((k+1)%5 == 0)) { \ schema_entry = talloc_asprintf_append(schema_entry, \ - "\n "); \ + "$%s ", seperator); \ IF_NULL_FAIL_RET(schema_entry); \ + } else { \ + schema_entry = talloc_asprintf_append(schema_entry, \ + "$ "); \ } \ } \ } \ @@ -464,30 +479,30 @@ static struct schema_conv process_convert(struct ldb_context *ldb, enum convert_ if (must) { schema_entry = talloc_asprintf_append(schema_entry, - " MUST ("); + "MUST ( "); IF_NULL_FAIL_RET(schema_entry); APPEND_ATTRS(must); schema_entry = talloc_asprintf_append(schema_entry, - " )\n"); + ")%s", seperator); IF_NULL_FAIL_RET(schema_entry); } if (may) { schema_entry = talloc_asprintf_append(schema_entry, - " MAY ("); + "MAY ( "); IF_NULL_FAIL_RET(schema_entry); APPEND_ATTRS(may); schema_entry = talloc_asprintf_append(schema_entry, - " )\n"); + ")%s", seperator); IF_NULL_FAIL_RET(schema_entry); } schema_entry = talloc_asprintf_append(schema_entry, - " )"); + ")"); switch (target) { case TARGET_OPENLDAP: -- cgit From e387677f515ee7f2c185069f8c52a3ec783041e2 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 15 Aug 2008 13:18:48 +1000 Subject: Rework generation of the objectClass and attributeType lines. Now that these are subroutines, we can factor them out into a file the CN=Aggregate schema code can also use. Andrew Bartlett (This used to be commit e3591a6a35ddb60398a03a4fa0545cc6158946ef) --- source4/utils/ad2oLschema.c | 378 ++++++++++++++++++++++++-------------------- 1 file changed, 209 insertions(+), 169 deletions(-) (limited to 'source4/utils/ad2oLschema.c') diff --git a/source4/utils/ad2oLschema.c b/source4/utils/ad2oLschema.c index dcc0094ab7..1e6348bc1a 100644 --- a/source4/utils/ad2oLschema.c +++ b/source4/utils/ad2oLschema.c @@ -1,7 +1,7 @@ /* ldb database library - Copyright (C) Andrew Bartlett 2006 + Copyright (C) Andrew Bartlett 2006-2008 ** NOTE! The following LGPL license applies to the ldb ** library. This does NOT imply that all of Samba is released @@ -124,12 +124,176 @@ static struct ldb_dn *find_schema_dn(struct ldb_context *ldb, TALLOC_CTX *mem_ct #define IF_NULL_FAIL_RET(x) do { \ if (!x) { \ - ret.failures++; \ - return ret; \ + 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) { /* Read list of attributes to skip, OIDs to map */ @@ -172,7 +336,10 @@ static struct schema_conv process_convert(struct ldb_context *ldb, enum convert_ } if (isdigit(line[0])) { char *p = strchr(line, ':'); - IF_NULL_FAIL_RET(p); + if (!p) { + ret.failures++; + return ret; + } p[0] = '\0'; p++; oid_map = talloc_realloc(mem_ctx, oid_map, struct oid_map, num_oid_maps + 2); @@ -282,67 +449,19 @@ static struct schema_conv process_convert(struct ldb_context *ldb, enum convert_ } } - switch (target) { - case TARGET_OPENLDAP: - schema_entry = talloc_asprintf(mem_ctx, - "attributetype ("); - break; - case TARGET_FEDORA_DS: - schema_entry = talloc_asprintf(mem_ctx, - "attributeTypes: ("); - break; - } - IF_NULL_FAIL_RET(schema_entry); - - schema_entry = talloc_asprintf_append(schema_entry, - "%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 /* If you want to re-enable this, you must first figure out a sane escaping of ' in the description */ - schema_entry = talloc_asprintf_append(schema_entry, - "DESC '%s' ", description); - IF_NULL_FAIL_RET(schema_entry); -#endif - } + schema_entry = schema_attribute_description(mem_ctx, target, seperator, oid, name, description, map_p, syntax, single_value, false); - if (map_p) { - if (map_p->equality) { - schema_entry = talloc_asprintf_append(schema_entry, - "EQUALITY %s%s", map_p->equality, seperator); - IF_NULL_FAIL_RET(schema_entry); - } - if (map_p->substring) { - schema_entry = talloc_asprintf_append(schema_entry, - "SUBSTR %s%s", map_p->substring, seperator); - IF_NULL_FAIL_RET(schema_entry); - } - - syntax = map_p->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 (schema_entry == NULL) { + ret.failures++; + return ret; } - - schema_entry = talloc_asprintf_append(schema_entry, - ")"); switch (target) { case TARGET_OPENLDAP: - fprintf(out, "%s\n\n", schema_entry); + fprintf(out, "attributetype %s\n\n", schema_entry); break; case TARGET_FEDORA_DS: - fprintf(out, "%s\n", schema_entry); + fprintf(out, "attributeTypes: %s\n", schema_entry); break; } ret.count++; @@ -363,6 +482,7 @@ static struct schema_conv process_convert(struct ldb_context *ldb, enum convert_ NULL }; int j; + int attr_idx; /* We have been asked to skip some attributes/objectClasses */ if (attrs_skip && str_list_check_ci(attrs_skip, name)) { @@ -388,128 +508,48 @@ static struct schema_conv process_convert(struct ldb_context *ldb, enum convert_ may = dsdb_full_attribute_list(mem_ctx, schema, objectclass_name_as_list, DSDB_SCHEMA_ALL_MAY); - must = dsdb_full_attribute_list(mem_ctx, schema, objectclass_name_as_list, DSDB_SCHEMA_ALL_MUST); - - switch (target) { - case TARGET_OPENLDAP: - schema_entry = talloc_asprintf(mem_ctx, - "objectclass ("); - break; - case TARGET_FEDORA_DS: - schema_entry = talloc_asprintf(mem_ctx, - "objectClasses: ("); - break; - } - schema_entry = talloc_asprintf_append(schema_entry, - "%s%s%s", seperator, oid, seperator); - - IF_NULL_FAIL_RET(schema_entry); - if (!schema_entry) { - ret.failures++; - break; + for (j=0; may && may[j]; j++) { + /* We might have been asked to remap this name, due to a conflict */ + for (attr_idx=0; attr_map && attr_map[attr_idx].old_attr; attr_idx++) { + if (strcasecmp(may[j], attr_map[attr_idx].old_attr) == 0) { + may[j] = attr_map[attr_idx].new_attr; + break; + } + } } - schema_entry = talloc_asprintf_append(schema_entry, - "NAME '%s'%s", name, seperator); - IF_NULL_FAIL_RET(schema_entry); - - if (!schema_entry) return ret; - - 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++) { \ - int attr_idx; \ - const char *attr_name = attributes[k]; \ - /* We might have been asked to remap this name, due to a conflict */ \ - for (attr_idx=0; attr_name && attr_map && attr_map[attr_idx].old_attr; attr_idx++) { \ - if (strcasecmp(attr_name, attr_map[attr_idx].old_attr) == 0) { \ - attr_name = attr_map[attr_idx].new_attr; \ - break; \ - } \ - } \ - \ - 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); + must = dsdb_full_attribute_list(mem_ctx, schema, objectclass_name_as_list, DSDB_SCHEMA_ALL_MUST); - schema_entry = talloc_asprintf_append(schema_entry, - ")%s", seperator); - IF_NULL_FAIL_RET(schema_entry); + for (j=0; must && must[j]; j++) { + /* We might have been asked to remap this name, due to a conflict */ + for (attr_idx=0; attr_map && attr_map[attr_idx].old_attr; attr_idx++) { + if (strcasecmp(must[j], attr_map[attr_idx].old_attr) == 0) { + must[j] = attr_map[attr_idx].new_attr; + break; + } + } } - 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 = schema_class_description(mem_ctx, target, + seperator, + oid, + name, + description, + subClassOf, + objectClassCategory, + must, + may); + if (schema_entry == NULL) { + ret.failures++; + return ret; } - schema_entry = talloc_asprintf_append(schema_entry, - ")"); - switch (target) { case TARGET_OPENLDAP: - fprintf(out, "%s\n\n", schema_entry); + fprintf(out, "objectclass %s\n\n", schema_entry); break; case TARGET_FEDORA_DS: - fprintf(out, "%s\n", schema_entry); + fprintf(out, "objectClasses: %s\n", schema_entry); break; } ret.count++; -- cgit From 16112762e70879b50f1dfc49452d6d278bd256cf Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 15 Aug 2008 20:40:57 +1000 Subject: Generate the subSchema in cn=Aggregate This reads the schema from the in-memory structure, when the magic attributes are requested. The code is a modified version of that used in the ad2oLschema tool (now shared). The schema_fsmo module handles the insertion of the generated result. As such, this commit also removes these entries from the setup/schema.ldif Metze's previous stub of this functionality is also removed. Andrew Bartlett (This used to be commit c7c32ec7b42bdf0f7b669644516438c71b364e60) --- source4/utils/ad2oLschema.c | 206 ++++---------------------------------------- 1 file changed, 15 insertions(+), 191 deletions(-) (limited to 'source4/utils/ad2oLschema.c') diff --git a/source4/utils/ad2oLschema.c b/source4/utils/ad2oLschema.c index 1e6348bc1a..ea5b813e8a 100644 --- a/source4/utils/ad2oLschema.c +++ b/source4/utils/ad2oLschema.c @@ -35,7 +35,6 @@ #include "ldb_includes.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" @@ -45,11 +44,6 @@ struct schema_conv { int skipped; int failures; }; - -enum convert_target { - TARGET_OPENLDAP, - TARGET_FEDORA_DS -}; static void usage(void) @@ -122,179 +116,7 @@ static struct ldb_dn *find_schema_dn(struct ldb_context *ldb, TALLOC_CTX *mem_ct } -#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); @@ -404,10 +226,10 @@ static struct schema_conv process_convert(struct ldb_context *ldb, enum convert_ 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; + const struct dsdb_syntax_map *map = find_syntax_map_by_ad_oid(syntax); char *schema_entry = NULL; int j; @@ -425,20 +247,21 @@ static struct schema_conv process_convert(struct ldb_context *ldb, enum convert_ } } - if (const_map) { - map = *const_map; - + if (map) { /* 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 = map->Standard_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 = map->equality; + substring = map->substring; } /* We might have been asked to remap this name, due to a conflict */ @@ -449,7 +272,7 @@ static struct schema_conv process_convert(struct ldb_context *ldb, enum convert_ } } - 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, description, equality, substring, syntax, single_value, false); if (schema_entry == NULL) { ret.failures++; @@ -534,6 +357,7 @@ static struct schema_conv process_convert(struct ldb_context *ldb, enum convert_ seperator, oid, name, + NULL, description, subClassOf, objectClassCategory, @@ -567,7 +391,7 @@ static struct schema_conv process_convert(struct ldb_context *ldb, enum convert_ 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); -- cgit From 46c94dd8b28cbb6fca28f4884b65be034e135fbb Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 18 Aug 2008 10:16:45 +1000 Subject: Merge the two attribute syntax tables. This merges the table once found in the oLschema2ldif tool (and moved many times) with the table used for DRSUAPI. The OpenLDAP schema map has been updated, to ensure that despite a number of attributes being declared as OIDs, they are actually used as strings (as they are actually LDAP class/attribute names). Andrew Bartlett (This used to be commit 61f2958c84beeedcf369ccdc02afed0c8055b108) --- source4/utils/ad2oLschema.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/utils/ad2oLschema.c') diff --git a/source4/utils/ad2oLschema.c b/source4/utils/ad2oLschema.c index ea5b813e8a..e229bd104b 100644 --- a/source4/utils/ad2oLschema.c +++ b/source4/utils/ad2oLschema.c @@ -229,7 +229,7 @@ static struct schema_conv process_convert(struct ldb_context *ldb, enum dsdb_sch const char *equality = NULL, *substring = NULL; bool single_value = attribute->isSingleValued; - const struct dsdb_syntax_map *map = find_syntax_map_by_ad_oid(syntax); + const struct dsdb_syntax *map = find_syntax_map_by_ad_syntax(attribute->oMSyntax); char *schema_entry = NULL; int j; @@ -251,7 +251,7 @@ static struct schema_conv process_convert(struct ldb_context *ldb, enum dsdb_sch /* We might have been asked to remap this oid, * due to a conflict, or lack of * implementation */ - syntax = map->Standard_OID; + syntax = map->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) { -- cgit