s4:dsdb/schema: add a function to generate the "extendedAttributeInfo" values
authorStefan Metzmacher <metze@samba.org>
Fri, 14 Nov 2008 07:49:06 +0000 (08:49 +0100)
committerStefan Metzmacher <metze@samba.org>
Sun, 16 Nov 2008 15:37:27 +0000 (16:37 +0100)
metze

source4/dsdb/schema/schema_description.c
source4/utils/ad2oLschema.c

index 9e162f28b19177061dde56590cdf3a640638a488..754ce43615ce33921f0c72dcf82961e043e1d2ed 100644 (file)
@@ -20,6 +20,7 @@
 */
 #include "includes.h"
 #include "dsdb/samdb/samdb.h"
+#include "librpc/ndr/libndr.h"
 
 #define IF_NULL_FAIL_RET(x) do {     \
                if (!x) {               \
@@ -36,7 +37,12 @@ char *schema_attribute_description(TALLOC_CTX *mem_ctx,
                                          const char *equality, 
                                          const char *substring, 
                                          const char *syntax,
-                                         bool single_value, bool operational)
+                                         bool single_value, bool operational,
+                                         uint32_t *range_lower,
+                                         uint32_t *range_upper,
+                                         const char *property_guid,
+                                         const char *property_set_guid,
+                                         bool indexed, bool system_only)
 {
        char *schema_entry = talloc_asprintf(mem_ctx, 
                                             "(%s%s%s", seperator, oid, seperator);
@@ -55,11 +61,13 @@ char *schema_attribute_description(TALLOC_CTX *mem_ctx,
                                                      "SUBSTR %s%s", substring, seperator);
                IF_NULL_FAIL_RET(schema_entry);
        }
-       
-       schema_entry = talloc_asprintf_append(schema_entry, 
-                                             "SYNTAX %s%s", syntax, seperator);
-       IF_NULL_FAIL_RET(schema_entry);
-       
+
+       if (syntax) {
+               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);
@@ -71,7 +79,47 @@ char *schema_attribute_description(TALLOC_CTX *mem_ctx,
                                                      "NO-USER-MODIFICATION%s", seperator);
                IF_NULL_FAIL_RET(schema_entry);
        }
-       
+
+       if (range_lower) {
+               schema_entry = talloc_asprintf_append(schema_entry,
+                                                     "RANGE-LOWER '%u'%s",
+                                                     *range_lower, seperator);
+               IF_NULL_FAIL_RET(schema_entry);
+       }
+
+       if (range_upper) {
+               schema_entry = talloc_asprintf_append(schema_entry,
+                                                     "RANGE-UPPER '%u'%s",
+                                                     *range_upper, seperator);
+               IF_NULL_FAIL_RET(schema_entry);
+       }
+
+       if (property_guid) {
+               schema_entry = talloc_asprintf_append(schema_entry,
+                                                     "PROPERTY-GUID '%s'%s",
+                                                     property_guid, seperator);
+               IF_NULL_FAIL_RET(schema_entry);
+       }
+
+       if (property_set_guid) {
+               schema_entry = talloc_asprintf_append(schema_entry,
+                                                     "PROPERTY-SET-GUID '%s'%s",
+                                                     property_set_guid, seperator);
+               IF_NULL_FAIL_RET(schema_entry);
+       }
+
+       if (indexed) {
+               schema_entry = talloc_asprintf_append(schema_entry,
+                                                     "INDEXED%s", seperator);
+               IF_NULL_FAIL_RET(schema_entry);
+       }
+
+       if (system_only) {
+               schema_entry = talloc_asprintf_append(schema_entry,
+                                                     "SYSTEM-ONLY%s", seperator);
+               IF_NULL_FAIL_RET(schema_entry);
+       }
+
        schema_entry = talloc_asprintf_append(schema_entry, 
                                              ")");
        return schema_entry;
@@ -94,6 +142,34 @@ char *schema_attribute_to_description(TALLOC_CTX *mem_ctx, const struct dsdb_att
                                               attribute->lDAPDisplayName,
                                               NULL, NULL, talloc_asprintf(tmp_ctx, "'%s'", syntax),
                                               attribute->isSingleValued,
+                                              attribute->systemOnly,/* TODO: is this correct? */
+                                              NULL, NULL, NULL, NULL,
+                                              false, false);
+       talloc_free(tmp_ctx);
+       return schema_description;
+}
+
+char *schema_attribute_to_extendedInfo(TALLOC_CTX *mem_ctx, const struct dsdb_attribute *attribute)
+{
+       char *schema_description;
+       TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
+       if (!tmp_ctx) {
+               return NULL;
+       }
+
+       schema_description
+               = schema_attribute_description(mem_ctx,
+                                              TARGET_AD_SCHEMA_SUBENTRY,
+                                              " ",
+                                              attribute->attributeID_oid,
+                                              attribute->lDAPDisplayName,
+                                              NULL, NULL, NULL,
+                                              false, false,
+                                              attribute->rangeLower,
+                                              attribute->rangeUpper,
+                                              GUID_hexstring(tmp_ctx, &attribute->schemaIDGUID),
+                                              GUID_hexstring(tmp_ctx, &attribute->attributeSecurityGUID),
+                                              (attribute->searchFlags & SEARCH_FLAG_ATTINDEX),
                                               attribute->systemOnly);
        talloc_free(tmp_ctx);
        return schema_description;
index c579112b45ddf0c50580632de9c2935f6e735bf9..c1e74cb3a220f04dccf98a4ecaf2d947c1f0fefd 100644 (file)
@@ -278,7 +278,10 @@ static struct schema_conv process_convert(struct ldb_context *ldb, enum dsdb_sch
                                                            substring, 
                                                            syntax, 
                                                            single_value, 
-                                                           false);
+                                                           false,
+                                                           NULL, NULL,
+                                                           NULL, NULL,
+                                                           false, false);
 
                if (schema_entry == NULL) {
                        ret.failures++;