The branch, master has been updated
       via  9393d94... s4/drs: prefixMap main interface implementation
       via  4dc90c0... s4/drs(tort): Unit test for prefixMap implementation.
       via  31168f1... s4/drs(tort): Comment typos fixed in drs_util.c
       via  1ecca31... s4/drs(tort): fixed '==' to '>='
      from  4b6cfbb... s4-lsa: Fix dcesrv_lsa_EnumTrustDom() and avoid infite 
windows client loop.

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 9393d94ad48160d3af665ed7362683b0a59ce72d
Author: Kamen Mazdrashki <[email protected]>
Date:   Sun Oct 18 21:34:21 2009 +0300

    s4/drs: prefixMap main interface implementation
    
    Currenly implemented functions are:
    dsdb_schema_pfm_new(), dsdb_schema_pfm_make_attid()
    and dsdb_schema_pfm_oid_from_attid()

commit 4dc90c0851bdeeb0f10205e4105658d75ff3df6a
Author: Kamen Mazdrashki <[email protected]>
Date:   Sun Oct 18 21:31:37 2009 +0300

    s4/drs(tort): Unit test for prefixMap implementation.
    
    Currenly those tests cover only the main part of the interface,
    i.e. dsdb_schema_pfm_new(), dsdb_schema_pfm_make_attid()
    and dsdb_schema_pfm_oid_from_attid()

commit 31168f1fac4c50c078f106a59c6d1da0134212b2
Author: Kamen Mazdrashki <[email protected]>
Date:   Sun Oct 18 21:28:55 2009 +0300

    s4/drs(tort): Comment typos fixed in drs_util.c

commit 1ecca31caa8c366264e8b15fdb6363a4a5338cde
Author: Kamen Mazdrashki <[email protected]>
Date:   Sun Oct 18 21:28:28 2009 +0300

    s4/drs(tort): fixed '==' to '>='
    
    ATTID is marked as partial by adding 32768.
    Thus the check should be '>= 32768'

-----------------------------------------------------------------------

Summary of changes:
 source4/dsdb/schema/prefixmap.h                |    6 +-
 source4/dsdb/schema/schema.h                   |    2 +
 source4/dsdb/schema/schema_prefixmap.c         |  244 +++++++++++++++++
 source4/torture/drs/drs_util.c                 |    6 +-
 source4/torture/drs/internal/prefixmap_tests.c |  332 +++++++++++++++++++++++-
 5 files changed, 578 insertions(+), 12 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source4/dsdb/schema/prefixmap.h b/source4/dsdb/schema/prefixmap.h
index 7b28c88..816ddcf 100644
--- a/source4/dsdb/schema/prefixmap.h
+++ b/source4/dsdb/schema/prefixmap.h
@@ -26,8 +26,8 @@
  * oid-prefix in prefixmap
  */
 struct dsdb_schema_prefixmap_oid {
-       uint32_t id;
-       DATA_BLOB *bin_oid; /* partial binary-oid prefix */
+       uint32_t  id;
+       DATA_BLOB bin_oid; /* partial binary-oid prefix */
 };
 
 /**
@@ -39,7 +39,5 @@ struct dsdb_schema_prefixmap {
 };
 
 
-#include "dsdb/schema/proto.h"
-
 
 #endif /* _DSDB_PREFIXMAP_H */
diff --git a/source4/dsdb/schema/schema.h b/source4/dsdb/schema/schema.h
index ddd9b37..175e999 100644
--- a/source4/dsdb/schema/schema.h
+++ b/source4/dsdb/schema/schema.h
@@ -22,6 +22,8 @@
 #ifndef _DSDB_SCHEMA_H
 #define _DSDB_SCHEMA_H
 
+#include "prefixmap.h"
+
 struct dsdb_attribute;
 struct dsdb_class;
 struct dsdb_schema;
diff --git a/source4/dsdb/schema/schema_prefixmap.c 
b/source4/dsdb/schema/schema_prefixmap.c
index d24c5ad..8173f89 100644
--- a/source4/dsdb/schema/schema_prefixmap.c
+++ b/source4/dsdb/schema/schema_prefixmap.c
@@ -20,3 +20,247 @@
 */
 
 #include "includes.h"
+#include "dsdb/samdb/samdb.h"
+#include "librpc/gen_ndr/ndr_drsuapi.h"
+#include "librpc/gen_ndr/ndr_drsblobs.h"
+#include "../lib/util/asn1.h"
+
+/**
+ * Initial prefixMap creation according to:
+ * [MS-DRSR] section 5.12.2
+ */
+WERROR dsdb_schema_pfm_new(TALLOC_CTX *mem_ctx, struct dsdb_schema_prefixmap 
**ppfm)
+{
+       uint32_t i;
+       struct dsdb_schema_prefixmap *pfm;
+       const struct {
+               uint32_t        id;
+               const char      *oid_prefix;
+       } pfm_init_data[] = {
+               {.id=0x00000000, .oid_prefix="2.5.4"},
+               {.id=0x00000001, .oid_prefix="2.5.6"},
+               {.id=0x00000002, .oid_prefix="1.2.840.113556.1.2"},
+               {.id=0x00000003, .oid_prefix="1.2.840.113556.1.3"},
+               {.id=0x00000004, .oid_prefix="2.16.840.1.101.2.2.1"},
+               {.id=0x00000005, .oid_prefix="2.16.840.1.101.2.2.3"},
+               {.id=0x00000006, .oid_prefix="2.16.840.1.101.2.1.5"},
+               {.id=0x00000007, .oid_prefix="2.16.840.1.101.2.1.4"},
+               {.id=0x00000008, .oid_prefix="2.5.5"},
+               {.id=0x00000009, .oid_prefix="1.2.840.113556.1.4"},
+               {.id=0x0000000A, .oid_prefix="1.2.840.113556.1.5"},
+               {.id=0x00000013, .oid_prefix="0.9.2342.19200300.100"},
+               {.id=0x00000014, .oid_prefix="2.16.840.1.113730.3"},
+               {.id=0x00000015, .oid_prefix="0.9.2342.19200300.100.1"},
+               {.id=0x00000016, .oid_prefix="2.16.840.1.113730.3.1"},
+               {.id=0x00000017, .oid_prefix="1.2.840.113556.1.5.7000"},
+               {.id=0x00000018, .oid_prefix="2.5.21"},
+               {.id=0x00000019, .oid_prefix="2.5.18"},
+               {.id=0x0000001A, .oid_prefix="2.5.20"},
+       };
+
+       /* allocate mem for prefix map */
+       pfm = talloc_zero(mem_ctx, struct dsdb_schema_prefixmap);
+       W_ERROR_HAVE_NO_MEMORY(pfm);
+
+       pfm->length = ARRAY_SIZE(pfm_init_data);
+       pfm->prefixes = talloc_array(pfm, struct dsdb_schema_prefixmap_oid, 
pfm->length);
+       W_ERROR_HAVE_NO_MEMORY(pfm->prefixes);
+
+       /* build prefixes */
+       for (i = 0; i < pfm->length; i++) {
+               if (!ber_write_partial_OID_String(pfm, 
&pfm->prefixes[i].bin_oid, pfm_init_data[i].oid_prefix)) {
+                       talloc_free(pfm);
+                       return WERR_INTERNAL_ERROR;
+               }
+               pfm->prefixes[i].id = pfm_init_data[i].id;
+       }
+
+       *ppfm = pfm;
+
+       return WERR_OK;
+}
+
+
+/**
+ * Adds oid to prefix map.
+ * On success returns ID for newly added index
+ * or ID of existing entry that matches oid
+ * Reference: [MS-DRSR] section 5.12.2
+ *
+ * \param pfm prefixMap
+ * \param bin_oid OID prefix to be added to prefixMap
+ * \param pfm_id Location where to store prefixMap entry ID
+ */
+static WERROR _dsdb_schema_pfm_add_entry(struct dsdb_schema_prefixmap *pfm, 
DATA_BLOB bin_oid, uint32_t *_idx)
+{
+       uint32_t i;
+       struct dsdb_schema_prefixmap_oid * pfm_entry;
+       struct dsdb_schema_prefixmap_oid * prefixes_new;
+
+       /* dup memory for bin-oid prefix to be added */
+       bin_oid = data_blob_dup_talloc(pfm, &bin_oid);
+       if (!bin_oid.data) {
+               return WERR_NOMEM;
+       }
+
+       /* make room for new entry */
+       prefixes_new = talloc_realloc(pfm, pfm->prefixes, struct 
dsdb_schema_prefixmap_oid, pfm->length + 1);
+       if (!prefixes_new) {
+               talloc_free(bin_oid.data);
+               return WERR_NOMEM;
+       }
+       pfm->prefixes = prefixes_new;
+
+       /* make new unique ID in prefixMap */
+       pfm_entry = &pfm->prefixes[pfm->length];
+       pfm_entry->id = 0;
+       for (i = 0; i < pfm->length; i++) {
+               if (pfm_entry->id < pfm->prefixes[i].id)
+                       pfm_entry->id = pfm->prefixes[i].id;
+       }
+
+       /* add new bin-oid prefix */
+       pfm_entry->id++;
+       pfm_entry->bin_oid = bin_oid;
+
+       *_idx = pfm->length;
+       pfm->length++;
+
+       return WERR_OK;
+}
+
+
+/**
+ * Make ATTID for given OID
+ * Reference: [MS-DRSR] section 5.12.2
+ */
+WERROR dsdb_schema_pfm_make_attid(struct dsdb_schema_prefixmap *pfm, const 
char *oid, uint32_t *attid)
+{
+       uint32_t i;
+       uint32_t lo_word, hi_word;
+       DATA_BLOB bin_oid;
+       const char *last_subid;
+       uint32_t last_value;
+       struct dsdb_schema_prefixmap_oid *pfm_entry;
+
+       if (!pfm)       return WERR_INVALID_PARAMETER;
+       if (!oid)       return WERR_INVALID_PARAMETER;
+
+       /* make last sub-identifier value */
+       last_subid = strrchr(oid, '.');
+       if (!last_subid) {
+               return WERR_INVALID_PARAMETER;
+       }
+       last_subid++;
+       last_value = strtoul(last_subid, NULL, 10);
+
+       /* encode oid in BER format */
+       if (!ber_write_OID_String(NULL, &bin_oid, oid)) {
+               return WERR_INTERNAL_ERROR;
+       }
+
+       /* get the prefix of the OID */
+       if (last_value < 128) {
+               bin_oid.length -= 1;
+       } else {
+               bin_oid.length -= 2;
+       }
+
+       /* search the prefix in the prefix table, if none found, add
+        * one entry for new prefix.
+        */
+       pfm_entry = NULL;
+       for (i = 0; i < pfm->length; i++) {
+               if (pfm->prefixes[i].bin_oid.length != bin_oid.length)
+                       continue;
+
+               if (memcmp(pfm->prefixes[i].bin_oid.data, bin_oid.data, 
bin_oid.length) == 0) {
+                       pfm_entry = &pfm->prefixes[i];
+                       break;
+               }
+       }
+       /* add entry in no entry exists */
+       if (!pfm_entry) {
+               uint32_t idx;
+               WERROR werr = _dsdb_schema_pfm_add_entry(pfm, bin_oid, &idx);
+               W_ERROR_NOT_OK_RETURN(werr);
+
+               pfm_entry = &pfm->prefixes[idx];
+       }
+
+       /* compose the attid */
+       lo_word = last_value % 16384;   /* actually get lower 14 bits: lo_word 
& 0x3FFF */
+       if (last_value >= 16384) {
+               /* mark it so that it is known to not be the whole lastValue
+                * This will raise 16-th bit*/
+               lo_word += 32768;
+       }
+       hi_word = pfm_entry->id;
+
+       /* make ATTID:
+        * HIWORD is prefixMap id
+        * LOWORD is truncated binary-oid */
+       *attid = (hi_word * 65536) + lo_word;
+
+       return WERR_OK;
+}
+
+
+/**
+ * Make OID for given ATTID.
+ * Reference: [MS-DRSR] section 5.12.2
+ */
+WERROR dsdb_schema_pfm_oid_from_attid(struct dsdb_schema_prefixmap *pfm, 
uint32_t attid,
+                                     TALLOC_CTX *mem_ctx, const char **_oid)
+{
+       int i;
+       uint32_t hi_word, lo_word;
+       DATA_BLOB bin_oid = {NULL, 0};
+       struct dsdb_schema_prefixmap_oid *pfm_entry;
+       WERROR werr = WERR_OK;
+
+       /* crack attid value */
+       hi_word = attid >> 16;
+       lo_word = attid & 0xFFFF;
+
+       /* locate corRespoNding prefixMap entry */
+       pfm_entry = NULL;
+       for (i = 0; i < pfm->length; i++) {
+               if (hi_word == pfm->prefixes[i].id) {
+                       pfm_entry = &pfm->prefixes[i];
+                       break;
+               }
+       }
+
+       if (!pfm_entry) {
+               return WERR_INTERNAL_ERROR;
+       }
+
+       /* copy oid prefix making enough room */
+       bin_oid.length = pfm_entry->bin_oid.length + 2;
+       bin_oid.data = talloc_array(mem_ctx, uint8_t, bin_oid.length);
+       W_ERROR_HAVE_NO_MEMORY(bin_oid.data);
+       memcpy(bin_oid.data, pfm_entry->bin_oid.data, 
pfm_entry->bin_oid.length);
+
+       if (lo_word < 128) {
+               bin_oid.length = bin_oid.length - 1;
+               bin_oid.data[bin_oid.length-1] = lo_word;
+       }
+       else {
+               if (lo_word >= 32768) {
+                       lo_word -= 32768;
+               }
+               bin_oid.data[bin_oid.length-2] = (0x80 | ((lo_word>>7) & 0x7f));
+               bin_oid.data[bin_oid.length-1] = lo_word & 0x7f;
+       }
+
+       if (!ber_read_OID_String(mem_ctx, bin_oid, _oid)) {
+               werr = WERR_INTERNAL_ERROR;
+       }
+
+       /* free locally allocated memory */
+       talloc_free(bin_oid.data);
+
+       return werr;
+}
+
diff --git a/source4/torture/drs/drs_util.c b/source4/torture/drs/drs_util.c
index 093fcf8..d1a1497 100644
--- a/source4/torture/drs/drs_util.c
+++ b/source4/torture/drs/drs_util.c
@@ -54,7 +54,7 @@ bool drs_util_oid_from_attid(struct torture_context *tctx,
                        && (*map_entry->oid.binary_oid == 0xFF),
                        "Last entry in Prefix Map is not the special one!");
 
-       /* locate correspoding prefixMap entry */
+       /* locate corresponding prefixMap entry */
        map_entry = NULL;
        for (i = 0; i < prefix_map->num_mappings - 1; i++) {
 
@@ -78,10 +78,10 @@ bool drs_util_oid_from_attid(struct torture_context *tctx,
                bin_oid.data[bin_oid.length-1] = lo_word;
        }
        else {
-               if (lo_word == 32768) {
+               if (lo_word >= 32768) {
                        lo_word -= 32768;
                }
-               bin_oid.data[bin_oid.length-2] = ((lo_word / 128) % 128) + 128; 
// (0x80 | ((lo_word>>7)&0x7f))
+               bin_oid.data[bin_oid.length-2] = ((lo_word / 128) % 128) + 128; 
// (0x80 | ((lo_word>>7) & 0x7f))
                bin_oid.data[bin_oid.length-1] = lo_word % 128; // lo_word & 
0x7f
        }
 
diff --git a/source4/torture/drs/internal/prefixmap_tests.c 
b/source4/torture/drs/internal/prefixmap_tests.c
index 6e6c4aa..54bd661 100644
--- a/source4/torture/drs/internal/prefixmap_tests.c
+++ b/source4/torture/drs/internal/prefixmap_tests.c
@@ -29,31 +29,346 @@
  * Private data to be shared among all test in Test case
  */
 struct drsut_prefixmap_data {
-       struct dsdb_schema_prefixmap *prefixmap;
+       struct dsdb_schema_prefixmap *pfm_new;
+       struct dsdb_schema_prefixmap *pfm_full;
 };
 
+/**
+ * Test-oid data structure
+ */
+struct drsut_pfm_oid_data {
+       uint32_t        id;
+       const char      *bin_oid;
+       const char      *oid_prefix;
+};
+
+/**
+ * Default prefixMap initialization data
+ */
+static const struct drsut_pfm_oid_data _prefixmap_test_new_data[] = {
+       {.id=0x00000000, .bin_oid="5504",                 .oid_prefix="2.5.4"},
+       {.id=0x00000001, .bin_oid="5506",                 .oid_prefix="2.5.6"},
+       {.id=0x00000002, .bin_oid="2A864886F7140102",     
.oid_prefix="1.2.840.113556.1.2"},
+       {.id=0x00000003, .bin_oid="2A864886F7140103",     
.oid_prefix="1.2.840.113556.1.3"},
+       {.id=0x00000004, .bin_oid="6086480165020201",     
.oid_prefix="2.16.840.1.101.2.2.1"},
+       {.id=0x00000005, .bin_oid="6086480165020203",     
.oid_prefix="2.16.840.1.101.2.2.3"},
+       {.id=0x00000006, .bin_oid="6086480165020105",     
.oid_prefix="2.16.840.1.101.2.1.5"},
+       {.id=0x00000007, .bin_oid="6086480165020104",     
.oid_prefix="2.16.840.1.101.2.1.4"},
+       {.id=0x00000008, .bin_oid="5505",                 .oid_prefix="2.5.5"},
+       {.id=0x00000009, .bin_oid="2A864886F7140104",     
.oid_prefix="1.2.840.113556.1.4"},
+       {.id=0x0000000A, .bin_oid="2A864886F7140105",     
.oid_prefix="1.2.840.113556.1.5"},
+       {.id=0x00000013, .bin_oid="0992268993F22C64",     
.oid_prefix="0.9.2342.19200300.100"},
+       {.id=0x00000014, .bin_oid="6086480186F84203",     
.oid_prefix="2.16.840.1.113730.3"},
+       {.id=0x00000015, .bin_oid="0992268993F22C6401",   
.oid_prefix="0.9.2342.19200300.100.1"},
+       {.id=0x00000016, .bin_oid="6086480186F8420301",   
.oid_prefix="2.16.840.1.113730.3.1"},
+       {.id=0x00000017, .bin_oid="2A864886F7140105B658", 
.oid_prefix="1.2.840.113556.1.5.7000"},
+       {.id=0x00000018, .bin_oid="5515",                 .oid_prefix="2.5.21"},
+       {.id=0x00000019, .bin_oid="5512",                 .oid_prefix="2.5.18"},
+       {.id=0x0000001A, .bin_oid="5514",                 .oid_prefix="2.5.20"},
+};
 
 /**
- * Initial prefix map creation function
+ * Data to be used for creating full prefix map for testing
+ */
+static const struct drsut_pfm_oid_data _prefixmap_full_map_data[] = {
+       {.id=0x00000000, .bin_oid="0x5504",                     
.oid_prefix="2.5.4"},
+       {.id=0x00000001, .bin_oid="0x5506",                     
.oid_prefix="2.5.6"},
+       {.id=0x00000002, .bin_oid="0x2A864886F7140102",         
.oid_prefix="1.2.840.113556.1.2"},
+       {.id=0x00000003, .bin_oid="0x2A864886F7140103",         
.oid_prefix="1.2.840.113556.1.3"},
+       {.id=0x00000004, .bin_oid="0x6086480165020201",         
.oid_prefix="2.16.840.1.101.2.2.1"},
+       {.id=0x00000005, .bin_oid="0x6086480165020203",         
.oid_prefix="2.16.840.1.101.2.2.3"},
+       {.id=0x00000006, .bin_oid="0x6086480165020105",         
.oid_prefix="2.16.840.1.101.2.1.5"},
+       {.id=0x00000007, .bin_oid="0x6086480165020104",         
.oid_prefix="2.16.840.1.101.2.1.4"},
+       {.id=0x00000008, .bin_oid="0x5505",                     
.oid_prefix="2.5.5"},
+       {.id=0x00000009, .bin_oid="0x2A864886F7140104",         
.oid_prefix="1.2.840.113556.1.4"},
+       {.id=0x0000000a, .bin_oid="0x2A864886F7140105",         
.oid_prefix="1.2.840.113556.1.5"},
+       {.id=0x00000013, .bin_oid="0x0992268993F22C64",         
.oid_prefix="0.9.2342.19200300.100"},
+       {.id=0x00000014, .bin_oid="0x6086480186F84203",         
.oid_prefix="2.16.840.1.113730.3"},
+       {.id=0x00000015, .bin_oid="0x0992268993F22C6401",       
.oid_prefix="0.9.2342.19200300.100.1"},
+       {.id=0x00000016, .bin_oid="0x6086480186F8420301",       
.oid_prefix="2.16.840.1.113730.3.1"},
+       {.id=0x00000017, .bin_oid="0x2A864886F7140105B658",     
.oid_prefix="1.2.840.113556.1.5.7000"},
+       {.id=0x00000018, .bin_oid="0x5515",                     
.oid_prefix="2.5.21"},
+       {.id=0x00000019, .bin_oid="0x5512",                     
.oid_prefix="2.5.18"},
+       {.id=0x0000001a, .bin_oid="0x5514",                     
.oid_prefix="2.5.20"},
+       {.id=0x0000000b, .bin_oid="0x2A864886F71401048204",     
.oid_prefix="1.2.840.113556.1.4.260"},
+       {.id=0x0000000c, .bin_oid="0x2A864886F714010538",       
.oid_prefix="1.2.840.113556.1.5.56"},
+       {.id=0x0000000d, .bin_oid="0x2A864886F71401048206",     
.oid_prefix="1.2.840.113556.1.4.262"},
+       {.id=0x0000000e, .bin_oid="0x2A864886F714010539",       
.oid_prefix="1.2.840.113556.1.5.57"},
+       {.id=0x0000000f, .bin_oid="0x2A864886F71401048207",     
.oid_prefix="1.2.840.113556.1.4.263"},
+       {.id=0x00000010, .bin_oid="0x2A864886F71401053A",       
.oid_prefix="1.2.840.113556.1.5.58"},
+       {.id=0x00000011, .bin_oid="0x2A864886F714010549",       
.oid_prefix="1.2.840.113556.1.5.73"},
+       {.id=0x00000012, .bin_oid="0x2A864886F71401048231",     
.oid_prefix="1.2.840.113556.1.4.305"},
+       {.id=0x0000001b, .bin_oid="0x2B060104018B3A6577",       
.oid_prefix="1.3.6.1.4.1.1466.101.119"},
+       {.id=0x0000001c, .bin_oid="0x6086480186F8420302",       
.oid_prefix="2.16.840.1.113730.3.2"},
+       {.id=0x0000001d, .bin_oid="0x2B06010401817A01",         
.oid_prefix="1.3.6.1.4.1.250.1"},
+       {.id=0x0000001e, .bin_oid="0x2A864886F70D0109",         
.oid_prefix="1.2.840.113549.1.9"},
+       {.id=0x0000001f, .bin_oid="0x0992268993F22C6404",       
.oid_prefix="0.9.2342.19200300.100.4"},
+       {.id=0x00000020, .bin_oid="0x2A864886F714010617",       
.oid_prefix="1.2.840.113556.1.6.23"},
+       {.id=0x00000021, .bin_oid="0x2A864886F71401061201",     
.oid_prefix="1.2.840.113556.1.6.18.1"},
+       {.id=0x00000022, .bin_oid="0x2A864886F71401061202",     
.oid_prefix="1.2.840.113556.1.6.18.2"},
+       {.id=0x00000023, .bin_oid="0x2A864886F71401060D03",     
.oid_prefix="1.2.840.113556.1.6.13.3"},
+       {.id=0x00000024, .bin_oid="0x2A864886F71401060D04",     
.oid_prefix="1.2.840.113556.1.6.13.4"},
+       {.id=0x00000025, .bin_oid="0x2B0601010101",             
.oid_prefix="1.3.6.1.1.1.1"},
+       {.id=0x00000026, .bin_oid="0x2B0601010102",             
.oid_prefix="1.3.6.1.1.1.2"},
+       {.id=0x000003ed, .bin_oid="0x2A864886F7140104B65866",   
.oid_prefix="1.2.840.113556.1.4.7000.102"},
+       {.id=0x00000428, .bin_oid="0x2A864886F7140105B6583E",   
.oid_prefix="1.2.840.113556.1.5.7000.62"},
+       {.id=0x0000044c, .bin_oid="0x2A864886F7140104B6586683", 
.oid_prefix="1.2.840.113556.1.4.7000.102:0x83"},
+       {.id=0x0000044f, .bin_oid="0x2A864886F7140104B6586681", 
.oid_prefix="1.2.840.113556.1.4.7000.102:0x81"},
+       {.id=0x0000047d, .bin_oid="0x2A864886F7140105B6583E81", 
.oid_prefix="1.2.840.113556.1.5.7000.62:0x81"},
+       {.id=0x00000561, .bin_oid="0x2A864886F7140105B6583E83", 
.oid_prefix="1.2.840.113556.1.5.7000.62:0x83"},
+       {.id=0x000007d1, .bin_oid="0x2A864886F71401061401",     
.oid_prefix="1.2.840.113556.1.6.20.1"},
+       {.id=0x000007e1, .bin_oid="0x2A864886F71401061402",     
.oid_prefix="1.2.840.113556.1.6.20.2"},
+       {.id=0x00001b86, .bin_oid="0x2A817A",                   
.oid_prefix="1.2.250"},
+       {.id=0x00001c78, .bin_oid="0x2A817A81",                 
.oid_prefix="1.2.250:0x81"},
+       {.id=0x00001c7b, .bin_oid="0x2A817A8180",               
.oid_prefix="1.2.250:0x8180"},
+};
+
+
+/**
+ * OID-to-ATTID mappings to be used for testing
+ */
+static const struct {
+       const char      *oid;
+       uint32_t        id;
+       uint32_t        attid;
+} _prefixmap_test_data[] = {
+       {.oid="2.5.4.0",                .id=0x00000000, .attid=0x000000},
+       {.oid="2.5.4.42",               .id=0x00000000, .attid=0x00002a},
+       {.oid="1.2.840.113556.1.2.1",   .id=0x00000002, .attid=0x020001},
+       {.oid="1.2.840.113556.1.2.13",  .id=0x00000002, .attid=0x02000d},
+       {.oid="1.2.840.113556.1.2.281", .id=0x00000002, .attid=0x020119},
+       {.oid="1.2.840.113556.1.4.125", .id=0x00000009, .attid=0x09007d},
+       {.oid="1.2.840.113556.1.4.146", .id=0x00000009, .attid=0x090092},
+       {.oid="1.2.250.1",              .id=0x00001b86, .attid=0x1b860001},
+       {.oid="1.2.250.130",            .id=0x00001b86, .attid=0x1b860082},
+       {.oid="1.2.250.16386",          .id=0x00001c78, .attid=0x1c788002},
+       {.oid="1.2.250.2097154",        .id=0x00001c7b, .attid=0x1c7b8002},
+};
+
+
+/**
+ * Creates dsdb_schema_prefixmap based on predefined data
  *
  */
-static struct dsdb_schema_prefixmap * _drsut_prefixmap_new(struct 
torture_context *tctx)
+static WERROR _drsut_prefixmap_new(const struct drsut_pfm_oid_data 
*_pfm_init_data, uint32_t count,
+                                  TALLOC_CTX *mem_ctx, struct 
dsdb_schema_prefixmap **_pfm)
+{
+       uint32_t i;
+       struct dsdb_schema_prefixmap *pfm;
+
+       pfm = talloc(mem_ctx, struct dsdb_schema_prefixmap);
+       W_ERROR_HAVE_NO_MEMORY(pfm);
+
+       pfm->length = count;
+       pfm->prefixes = talloc_array(pfm, struct dsdb_schema_prefixmap_oid, 
pfm->length);
+       if (!pfm->prefixes) {
+               talloc_free(pfm);
+               return WERR_NOMEM;
+       }
+
+       for (i = 0; i < pfm->length; i++) {
+               pfm->prefixes[i].id = _pfm_init_data[i].id;
+               pfm->prefixes[i].bin_oid = strhex_to_data_blob(pfm, 
_pfm_init_data[i].bin_oid);
+               if (!pfm->prefixes[i].bin_oid.data) {
+                       talloc_free(pfm);
+                       return WERR_NOMEM;
+               }
+       }
+
+       *_pfm = pfm;
+
+       return WERR_OK;
+}
+
+
+/*
+ * Tests dsdb_schema_pfm_new()
+ */
+static bool torture_drs_unit_pfm_new(struct torture_context *tctx, struct 
drsut_prefixmap_data *priv)
+{
+       int i;
+       WERROR werr;
+       TALLOC_CTX *mem_ctx;
+       struct dsdb_schema_prefixmap *pfm = NULL;
+
+       mem_ctx = talloc_new(priv);
+
+       /* create new prefix map */
+       werr = dsdb_schema_pfm_new(mem_ctx, &pfm);
+       torture_assert_werr_ok(tctx, werr, "dsdb_schema_pfm_new() failed!");
+       torture_assert(tctx, pfm != NULL, "NULL prefixMap created!");
+       torture_assert(tctx, pfm->length > 0, "Empty prefixMap created!");
+       torture_assert(tctx, pfm->prefixes != NULL, "No prefixes for newly 
created prefixMap!");
+
+       /* compare newly created prefixMap with template one */
+       torture_assert(tctx, priv->pfm_new->length == pfm->length,
+                       "Newly created prefixMap differs in length with 
expected one");
+       for (i = 0; i < pfm->length; i++) {


-- 
Samba Shared Repository

Reply via email to