s4:utils/oLschema2ldif.c - remove (now) unused variables
[ira/wip.git] / source4 / utils / oLschema2ldif.c
index 6c4e6a9c80afd8f2a9f48ff2075fc090ead39a2f..077987a7d092bf00d84ef8930ab9f0568492e11d 100644 (file)
  */
 
 #include "includes.h"
-#include "ldb_includes.h"
+#include "ldb.h"
 #include "tools/cmdline.h"
 #include "dsdb/samdb/samdb.h"
+#include "../lib/crypto/sha256.h"
+#include "../librpc/gen_ndr/ndr_misc.h"
 
 #define SCHEMA_UNKNOWN 0
 #define SCHEMA_NAME 1
@@ -336,6 +338,14 @@ static struct ldb_message *process_entry(TALLOC_CTX *mem_ctx, const char *entry)
         char *c, *s;
         int n;
 
+       SHA256_CTX sha256_context;
+       uint8_t digest[SHA256_DIGEST_LENGTH];
+
+       struct GUID guid;
+
+       bool isAttribute = false;
+       bool single_valued = false;
+
        ctx = talloc_new(mem_ctx);
        msg = ldb_msg_new(ctx);
 
@@ -351,6 +361,7 @@ static struct ldb_message *process_entry(TALLOC_CTX *mem_ctx, const char *entry)
                if (strncmp(c, "attributetype", 13) == 0) {
                        c += 13;
                        MSG_ADD_STRING("objectClass", "attributeSchema");
+                       isAttribute = true;
                        break;
                }
                goto failed;
@@ -374,7 +385,22 @@ static struct ldb_message *process_entry(TALLOC_CTX *mem_ctx, const char *entry)
        /* get attributeID */
        n = strcspn(c, " \t");
        s = talloc_strndup(msg, c, n);
-       MSG_ADD_STRING("attributeID", s);
+       if (isAttribute) {
+               MSG_ADD_STRING("attributeID", s);
+       } else {
+               MSG_ADD_STRING("governsID", s);
+       }
+
+       SHA256_Init(&sha256_context);
+       SHA256_Update(&sha256_context, (uint8_t*)s, strlen(s));
+       SHA256_Final(digest, &sha256_context);
+
+       memcpy(&guid, digest, sizeof(struct GUID));
+
+       if (dsdb_msg_add_guid(msg, &guid, "schemaIdGuid") != 0) {
+               goto failed;
+       }
+
        c += n;
        c = skip_spaces(c);     
 
@@ -416,7 +442,7 @@ static struct ldb_message *process_entry(TALLOC_CTX *mem_ctx, const char *entry)
                        break;
 
                case SCHEMA_SINGLE_VALUE:
-                       MSG_ADD_STRING("isSingleValued", "TRUE");
+                       single_valued = true;
                        break;
 
                case SCHEMA_EQUALITY:
@@ -433,12 +459,23 @@ static struct ldb_message *process_entry(TALLOC_CTX *mem_ctx, const char *entry)
 
                case SCHEMA_SYNTAX:
                {
-                       const struct dsdb_syntax *map = 
-                               find_syntax_map_by_standard_oid(token->value);
+                       char *syntax_oid;
+                       const struct dsdb_syntax *map;
+                       char *oMSyntax;
+
+                       n = strcspn(token->value, "{");
+                       syntax_oid = talloc_strndup(ctx, token->value, n);
+
+                       map = find_syntax_map_by_standard_oid(syntax_oid);
                        if (!map) {
                                break;
                        }
+
                        MSG_ADD_STRING("attributeSyntax", map->attributeSyntax_oid);
+
+                       oMSyntax = talloc_asprintf(msg, "%d", map->oMSyntax);
+                       MSG_ADD_STRING("oMSyntax", oMSyntax);
+
                        break;
                }
                case SCHEMA_DESC:
@@ -450,6 +487,12 @@ static struct ldb_message *process_entry(TALLOC_CTX *mem_ctx, const char *entry)
                }
        }
 
+       if (isAttribute) {
+               MSG_ADD_STRING("isSingleValued", single_valued ? "TRUE" : "FALSE");
+       } else {
+               MSG_ADD_STRING("defaultObjectCategory", ldb_dn_get_linearized(msg->dn));
+       }
+
        talloc_steal(mem_ctx, msg);
        talloc_free(ctx);
        return msg;