From 0fc2427224c2826e5ee0b09631ae77d0b08b5ba9 Mon Sep 17 00:00:00 2001 From: Kamen Mazdrashki Date: Tue, 26 Oct 2010 18:33:32 +0300 Subject: [PATCH] s4-prefixMap: split dsdb_schema_make_attid() function into read-only and 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 | 39 +++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/source4/dsdb/schema/schema_prefixmap.c b/source4/dsdb/schema/schema_prefixmap.c index 86c6b8df8d3d..18920500d6a3 100644 --- a/source4/dsdb/schema/schema_prefixmap.c +++ b/source4/dsdb/schema/schema_prefixmap.c @@ -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. -- 2.34.1