s4/drs: Move making of partial-binary-oid to a separate function
authorKamen Mazdrashki <kamen.mazdrashki@postpath.com>
Fri, 23 Oct 2009 21:48:14 +0000 (00:48 +0300)
committerStefan Metzmacher <metze@samba.org>
Fri, 6 Nov 2009 13:05:37 +0000 (14:05 +0100)
Signed-off-by: Stefan Metzmacher <metze@samba.org>
source4/dsdb/schema/schema_prefixmap.c

index 08e51559d6a50bdfe60f63f425aaf5c216a244da..6943ee0217eb5d2d59ed5ed259ca9e2ae9940db6 100644 (file)
@@ -131,41 +131,66 @@ static WERROR _dsdb_schema_pfm_add_entry(struct dsdb_schema_prefixmap *pfm, DATA
 
 
 /**
- * Make ATTID for given OID
+ * Make partial binary OID for supplied 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)
+static WERROR _dsdb_pfm_make_binary_oid(const char *full_oid, TALLOC_CTX *mem_ctx,
+                                       DATA_BLOB *_bin_oid, uint32_t *_last_subid)
 {
-       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;
+       uint32_t last_subid;
+       const char *oid_subid;
 
        /* make last sub-identifier value */
-       last_subid = strrchr(oid, '.');
-       if (!last_subid) {
+       oid_subid = strrchr(full_oid, '.');
+       if (!oid_subid) {
                return WERR_INVALID_PARAMETER;
        }
-       last_subid++;
-       last_value = strtoul(last_subid, NULL, 10);
+       oid_subid++;
+       last_subid = strtoul(oid_subid, NULL, 10);
 
        /* encode oid in BER format */
-       if (!ber_write_OID_String(pfm, &bin_oid, oid)) {
+       if (!ber_write_OID_String(mem_ctx, _bin_oid, full_oid)) {
                return WERR_INTERNAL_ERROR;
        }
 
        /* get the prefix of the OID */
-       if (last_value < 128) {
-               bin_oid.length -= 1;
+       if (last_subid < 128) {
+               _bin_oid->length -= 1;
        } else {
-               bin_oid.length -= 2;
+               _bin_oid->length -= 2;
        }
 
+       /* return last_value if requested */
+       if (_last_subid) {
+               *_last_subid = last_subid;
+       }
+
+       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)
+{
+       WERROR werr;
+       uint32_t i;
+       uint32_t lo_word, hi_word;
+       uint32_t last_value;
+       DATA_BLOB bin_oid;
+       struct dsdb_schema_prefixmap_oid *pfm_entry;
+
+       if (!pfm) {
+               return WERR_INVALID_PARAMETER;
+       }
+       if (!oid) {
+               return WERR_INVALID_PARAMETER;
+       }
+
+       werr = _dsdb_pfm_make_binary_oid(oid, pfm, &bin_oid, &last_value);
+       W_ERROR_NOT_OK_RETURN(werr);
+
        /* search the prefix in the prefix table, if none found, add
         * one entry for new prefix.
         */
@@ -182,7 +207,7 @@ WERROR dsdb_schema_pfm_make_attid(struct dsdb_schema_prefixmap *pfm, const char
        /* add entry in no entry exists */
        if (!pfm_entry) {
                uint32_t idx;
-               WERROR werr = _dsdb_schema_pfm_add_entry(pfm, bin_oid, &idx);
+               werr = _dsdb_schema_pfm_add_entry(pfm, bin_oid, &idx);
                W_ERROR_NOT_OK_RETURN(werr);
 
                pfm_entry = &pfm->prefixes[idx];