libndr: Avoid assigning duplicate versions to symbols
[amitay/samba.git] / source4 / dsdb / schema / schema_convert_to_ol.c
index ebcb7ade59e3f73cb23ae253a14fead094c0d3f7..ebb886da677f0487fb39df73b9a606b4994be895 100644 (file)
@@ -23,6 +23,8 @@
 #include "dsdb/samdb/samdb.h"
 #include "system/locale.h"
 
+#undef strcasecmp
+
 #define SEPERATOR "\n  "
 
 struct attr_map {
@@ -56,12 +58,14 @@ static char *print_schema_recursive(char *append_to_string, struct dsdb_schema *
                const char **must;
                const char **may;
                char *schema_entry = NULL;
-               const char *objectclass_name_as_list[] = {
-                       objectclass->lDAPDisplayName,
-                       NULL
+               struct ldb_val objectclass_name_as_ldb_val = data_blob_string_const(objectclass->lDAPDisplayName);
+               struct ldb_message_element objectclass_name_as_el = {
+                       .name = "objectClass",
+                       .num_values = 1,
+                       .values = &objectclass_name_as_ldb_val
                };
-               int j;
-               int attr_idx;
+               unsigned int j;
+               unsigned int attr_idx;
                
                if (!mem_ctx) {
                        DEBUG(0, ("Failed to create new talloc context\n"));
@@ -89,7 +93,15 @@ static char *print_schema_recursive(char *append_to_string, struct dsdb_schema *
                        }
                }
                
-               may = dsdb_full_attribute_list(mem_ctx, schema, objectclass_name_as_list, DSDB_SCHEMA_ALL_MAY);
+               /* We might have been asked to remap this subClassOf, due to a conflict */
+               for (j=0; subClassOf && attr_map && attr_map[j].old_attr; j++) {
+                       if (strcasecmp(subClassOf, attr_map[j].old_attr) == 0) {
+                               subClassOf =  attr_map[j].new_attr;
+                               break;
+                       }
+               }
+               
+               may = dsdb_full_attribute_list(mem_ctx, schema, &objectclass_name_as_el, DSDB_SCHEMA_ALL_MAY);
 
                for (j=0; may && may[j]; j++) {
                        /* We might have been asked to remap this name, due to a conflict */ 
@@ -101,7 +113,7 @@ static char *print_schema_recursive(char *append_to_string, struct dsdb_schema *
                        }                                               
                }
 
-               must = dsdb_full_attribute_list(mem_ctx, schema, objectclass_name_as_list, DSDB_SCHEMA_ALL_MUST);
+               must = dsdb_full_attribute_list(mem_ctx, schema, &objectclass_name_as_el, DSDB_SCHEMA_ALL_MUST);
 
                for (j=0; must && must[j]; j++) {
                        /* We might have been asked to remap this name, due to a conflict */ 
@@ -124,6 +136,7 @@ static char *print_schema_recursive(char *append_to_string, struct dsdb_schema *
                                                        may,
                                                        NULL);
                if (schema_entry == NULL) {
+                       talloc_free(mem_ctx);
                        DEBUG(0, ("failed to generate schema description for %s\n", name));
                        return NULL;
                }
@@ -135,6 +148,10 @@ static char *print_schema_recursive(char *append_to_string, struct dsdb_schema *
                case TARGET_FEDORA_DS:
                        out = talloc_asprintf_append(out, "objectClasses: %s\n", schema_entry);
                        break;
+               default:
+                       talloc_free(mem_ctx);
+                       DEBUG(0,(__location__ " Wrong type of target %u!", (unsigned)target));
+                       return NULL;
                }
                talloc_free(mem_ctx);
        } while (0);
@@ -173,11 +190,11 @@ char *dsdb_convert_schema_to_openldap(struct ldb_context *ldb, char *target_str,
        char *line;
        char *out;
        const char **attrs_skip = NULL;
-       int num_skip = 0;
+       unsigned int num_skip = 0;
        struct oid_map *oid_map = NULL;
-       int num_oid_maps = 0;
+       unsigned int num_oid_maps = 0;
        struct attr_map *attr_map = NULL;
-       int num_attr_maps = 0;  
+       unsigned int num_attr_maps = 0;
        struct dsdb_attribute *attribute;
        struct dsdb_schema *schema;
        enum dsdb_schema_convert_target target;
@@ -189,11 +206,12 @@ char *dsdb_convert_schema_to_openldap(struct ldb_context *ldb, char *target_str,
        } else if (strcasecmp(target_str, "fedora-ds") == 0) {
                target = TARGET_FEDORA_DS;
        } else {
+               talloc_free(mem_ctx);
                DEBUG(0, ("Invalid target type for schema conversion %s\n", target_str));
                return NULL;
        }
 
-       /* The mappings are line-seperated, and specify details such as OIDs to skip etc */
+       /* The mappings are line-separated, and specify details such as OIDs to skip etc */
        while (1) {
                line = next_line;
                next_line = strchr(line, '\n');
@@ -251,8 +269,9 @@ char *dsdb_convert_schema_to_openldap(struct ldb_context *ldb, char *target_str,
                }
        }
 
-       schema = dsdb_get_schema(ldb);
+       schema = dsdb_get_schema(ldb, mem_ctx);
        if (!schema) {
+               talloc_free(mem_ctx);
                DEBUG(0, ("No schema on ldb to convert!\n"));
                return NULL;
        }
@@ -264,6 +283,10 @@ char *dsdb_convert_schema_to_openldap(struct ldb_context *ldb, char *target_str,
        case TARGET_FEDORA_DS:
                out = talloc_strdup(mem_ctx, "dn: cn=schema\n");
                break;
+       default:
+               talloc_free(mem_ctx);
+               DEBUG(0,(__location__ " Wrong type of target %u!", (unsigned)target));
+               return NULL;
        }
 
        for (attribute=schema->attributes; attribute; attribute = attribute->next) {
@@ -274,7 +297,7 @@ char *dsdb_convert_schema_to_openldap(struct ldb_context *ldb, char *target_str,
                bool single_value = attribute->isSingleValued;
 
                char *schema_entry = NULL;
-               int j;
+               unsigned int j;
 
                /* We have been asked to skip some attributes/objectClasses */
                if (attrs_skip && str_list_check_ci(attrs_skip, name)) {
@@ -329,6 +352,7 @@ char *dsdb_convert_schema_to_openldap(struct ldb_context *ldb, char *target_str,
                                                            false, false);
 
                if (schema_entry == NULL) {
+                       talloc_free(mem_ctx);
                        DEBUG(0, ("failed to generate attribute description for %s\n", name));
                        return NULL;
                }
@@ -340,11 +364,18 @@ char *dsdb_convert_schema_to_openldap(struct ldb_context *ldb, char *target_str,
                case TARGET_FEDORA_DS:
                        out = talloc_asprintf_append(out, "attributeTypes: %s\n", schema_entry);
                        break;
+               default:
+                       talloc_free(mem_ctx);
+                       DEBUG(0,(__location__ " Wrong type of target %u!", (unsigned)target));
+                       return NULL;
                }
        }
 
        out = print_schema_recursive(out, schema, "top", target, attrs_skip, attr_map, oid_map);
 
+       talloc_steal(ldb, out);
+       talloc_free(mem_ctx);
+
        return out;
 }