s4-prefixMap: split dsdb_schema_make_attid() function into read-only and
authorKamen Mazdrashki <kamenim@samba.org>
Tue, 26 Oct 2010 15:33:32 +0000 (18:33 +0300)
committerKamen Mazdrashki <kamenim@samba.org>
Tue, 26 Oct 2010 19:17:41 +0000 (22:17 +0300)
read-write functions.
dsdb_schema_make_attid() may change prefixMap implicitly
and this is not always desired behavior.
The problem was that
(1) callers had no control on this behavior
(2) callers had no way to know wheter prefixMap has been
    changed which can lead to hard to find bugs like
    prefixMap is changed in read operation

source4/dsdb/schema/schema_prefixmap.c

index 86c6b8df8d3d2ad066bf18e47b9053b7556a86fe..18920500d6a39e3804ef2ca6999586c4feaf01c4 100644 (file)
@@ -259,9 +259,14 @@ WERROR dsdb_schema_pfm_find_oid(const struct dsdb_schema_prefixmap *pfm,
 
 /**
  * Make ATTID for given OID
+ * If OID is not in prefixMap, new prefix
+ * may be added depending on 'can_change_pfm' flag
  * 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_schema_pfm_make_attid_impl(struct dsdb_schema_prefixmap *pfm,
+                                             const char *oid,
+                                             bool can_change_pfm,
+                                             uint32_t *attid)
 {
        WERROR werr;
        uint32_t idx;
@@ -287,6 +292,11 @@ WERROR dsdb_schema_pfm_make_attid(struct dsdb_schema_prefixmap *pfm, const char
                /* free memory allocated for bin_oid */
                data_blob_free(&bin_oid);
        } else {
+               /* return error in read-only mode */
+               if (!can_change_pfm) {
+                       return werr;
+               }
+
                /* entry does not exists, add it */
                werr = _dsdb_schema_pfm_add_entry(pfm, bin_oid, &idx);
                W_ERROR_NOT_OK_RETURN(werr);
@@ -309,6 +319,33 @@ WERROR dsdb_schema_pfm_make_attid(struct dsdb_schema_prefixmap *pfm, const char
        return WERR_OK;
 }
 
+/**
+ * Make ATTID for given OID
+ * Reference: [MS-DRSR] section 5.12.2
+ *
+ * Note: This function may change prefixMap if prefix
+ * for supplied 'oid' doesn't exists yet.
+ * It is recommended to be used mostly when caller
+ * want to add new prefixes.
+ * Otherwise dsdb_schema_pfm_attid_from_oid() should be used.
+ */
+WERROR dsdb_schema_pfm_make_attid(struct dsdb_schema_prefixmap *pfm,
+                                 const char *oid,
+                                 uint32_t *attid)
+{
+       return dsdb_schema_pfm_make_attid_impl(pfm, oid, true, attid);
+}
+
+/**
+ * Make ATTID for given OID
+ * Reference: [MS-DRSR] section 5.12.2
+ */
+WERROR dsdb_schema_pfm_attid_from_oid(struct dsdb_schema_prefixmap *pfm,
+                                     const char *oid,
+                                     uint32_t *attid)
+{
+       return dsdb_schema_pfm_make_attid_impl(pfm, oid, false, attid);
+}
 
 /**
  * Make OID for given ATTID.