s4/drs: Implement binary-oid-lookup into prefixMap
authorKamen Mazdrashki <kamen.mazdrashki@postpath.com>
Fri, 23 Oct 2009 21:48:55 +0000 (00:48 +0300)
committerStefan Metzmacher <metze@samba.org>
Fri, 6 Nov 2009 13:05:38 +0000 (14:05 +0100)
Signed-off-by: Stefan Metzmacher <metze@samba.org>
source4/dsdb/schema/schema_prefixmap.c

index 6943ee0217eb5d2d59ed5ed259ca9e2ae9940db6..b20aecef686d61f4be15f8bd7b6b353d31383633 100644 (file)
@@ -168,6 +168,31 @@ static WERROR _dsdb_pfm_make_binary_oid(const char *full_oid, TALLOC_CTX *mem_ct
        return WERR_OK;
 }
 
+/**
+ * Lookup partial-binary-oid in prefixMap
+ */
+WERROR dsdb_schema_pfm_find_binary_oid(struct dsdb_schema_prefixmap *pfm,
+                                      DATA_BLOB bin_oid,
+                                      uint32_t *_idx)
+{
+       uint32_t i;
+
+       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) {
+                       if (_idx) {
+                               *_idx = i;
+                       }
+                       return WERR_OK;
+               }
+       }
+
+       return WERR_DS_NO_MSDS_INTID;
+}
+
 /**
  * Make ATTID for given OID
  * Reference: [MS-DRSR] section 5.12.2
@@ -175,11 +200,10 @@ static WERROR _dsdb_pfm_make_binary_oid(const char *full_oid, TALLOC_CTX *mem_ct
 WERROR dsdb_schema_pfm_make_attid(struct dsdb_schema_prefixmap *pfm, const char *oid, uint32_t *attid)
 {
        WERROR werr;
-       uint32_t i;
+       uint32_t idx;
        uint32_t lo_word, hi_word;
-       uint32_t last_value;
+       uint32_t last_subid;
        DATA_BLOB bin_oid;
-       struct dsdb_schema_prefixmap_oid *pfm_entry;
 
        if (!pfm) {
                return WERR_INVALID_PARAMETER;
@@ -188,42 +212,30 @@ WERROR dsdb_schema_pfm_make_attid(struct dsdb_schema_prefixmap *pfm, const char
                return WERR_INVALID_PARAMETER;
        }
 
-       werr = _dsdb_pfm_make_binary_oid(oid, pfm, &bin_oid, &last_value);
+       werr = _dsdb_pfm_make_binary_oid(oid, pfm, &bin_oid, &last_subid);
        W_ERROR_NOT_OK_RETURN(werr);
 
        /* 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;
-               werr = _dsdb_schema_pfm_add_entry(pfm, bin_oid, &idx);
-               W_ERROR_NOT_OK_RETURN(werr);
-
-               pfm_entry = &pfm->prefixes[idx];
-       } else {
+       werr = dsdb_schema_pfm_find_binary_oid(pfm, bin_oid, &idx);
+       if (W_ERROR_IS_OK(werr)) {
                /* free memory allocated for bin_oid */
                data_blob_free(&bin_oid);
+       } else {
+               /* entry does not exists, add it */
+               werr = _dsdb_schema_pfm_add_entry(pfm, bin_oid, &idx);
+               W_ERROR_NOT_OK_RETURN(werr);
        }
 
        /* compose the attid */
-       lo_word = last_value % 16384;   /* actually get lower 14 bits: lo_word & 0x3FFF */
-       if (last_value >= 16384) {
+       lo_word = last_subid % 16384;   /* actually get lower 14 bits: lo_word & 0x3FFF */
+       if (last_subid >= 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;
+       hi_word = pfm->prefixes[idx].id;
 
        /* make ATTID:
         * HIWORD is prefixMap id