From: Joseph Sutton Date: Thu, 30 Mar 2023 03:00:59 +0000 (+1300) Subject: s4:dsdb/schema: Add dsdb_attribute_by_cn_ldb_val() X-Git-Tag: talloc-2.4.1~1167 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=652c10a5a3e2e8ac707df7ca4bf474b5ad3be158;p=thirdparty%2Fsamba.git s4:dsdb/schema: Add dsdb_attribute_by_cn_ldb_val() This looks up a schema attribute by its CN, similar to dsdb_class_by_cn_ldb_val(). Signed-off-by: Joseph Sutton Reviewed-by: Andrew Bartlett --- diff --git a/source4/dsdb/schema/schema.h b/source4/dsdb/schema/schema.h index aaa2a9f9275..700f40414c8 100644 --- a/source4/dsdb/schema/schema.h +++ b/source4/dsdb/schema/schema.h @@ -243,6 +243,7 @@ struct dsdb_schema { struct dsdb_attribute **attributes_by_attributeID_id; struct dsdb_attribute **attributes_by_attributeID_oid; struct dsdb_attribute **attributes_by_linkID; + struct dsdb_attribute **attributes_by_cn; uint32_t num_int_id_attr; struct dsdb_attribute **attributes_by_msDS_IntId; diff --git a/source4/dsdb/schema/schema_query.c b/source4/dsdb/schema/schema_query.c index fc34764881c..96c53927f23 100644 --- a/source4/dsdb/schema/schema_query.c +++ b/source4/dsdb/schema/schema_query.c @@ -126,6 +126,16 @@ const struct dsdb_attribute *dsdb_attribute_by_linkID(const struct dsdb_schema * return c; } +const struct dsdb_attribute *dsdb_attribute_by_cn_ldb_val(const struct dsdb_schema *schema, + const struct ldb_val *cn) +{ + struct dsdb_attribute *c; + + BINARY_ARRAY_SEARCH_P(schema->attributes_by_cn, + schema->num_attributes, cn, cn, strcasecmp_with_ldb_val, c); + return c; +} + const struct dsdb_class *dsdb_class_by_governsID_id(const struct dsdb_schema *schema, uint32_t id) { diff --git a/source4/dsdb/schema/schema_set.c b/source4/dsdb/schema/schema_set.c index 090f5468416..d388fecc8c8 100644 --- a/source4/dsdb/schema/schema_set.c +++ b/source4/dsdb/schema/schema_set.c @@ -514,6 +514,10 @@ static int dsdb_compare_attribute_by_linkID(struct dsdb_attribute **a1, struct d { return uint32_cmp((*a1)->linkID, (*a2)->linkID); } +static int dsdb_compare_attribute_by_cn(struct dsdb_attribute **a1, struct dsdb_attribute **a2) +{ + return strcasecmp((*a1)->cn, (*a2)->cn); +} /** * Clean up Classes and Attributes accessor arrays @@ -531,6 +535,7 @@ static void dsdb_sorted_accessors_free(struct dsdb_schema *schema) TALLOC_FREE(schema->attributes_by_msDS_IntId); TALLOC_FREE(schema->attributes_by_attributeID_oid); TALLOC_FREE(schema->attributes_by_linkID); + TALLOC_FREE(schema->attributes_by_cn); } /* @@ -611,11 +616,13 @@ int dsdb_setup_sorted_accessors(struct ldb_context *ldb, struct dsdb_attribute *, num_int_id); schema->attributes_by_attributeID_oid = talloc_array(schema, struct dsdb_attribute *, i); schema->attributes_by_linkID = talloc_array(schema, struct dsdb_attribute *, i); + schema->attributes_by_cn = talloc_array(schema, struct dsdb_attribute *, i); if (schema->attributes_by_lDAPDisplayName == NULL || schema->attributes_by_attributeID_id == NULL || schema->attributes_by_msDS_IntId == NULL || schema->attributes_by_attributeID_oid == NULL || - schema->attributes_by_linkID == NULL) { + schema->attributes_by_linkID == NULL || + schema->attributes_by_cn == NULL) { goto failed; } @@ -625,6 +632,7 @@ int dsdb_setup_sorted_accessors(struct ldb_context *ldb, schema->attributes_by_attributeID_id[i] = a; schema->attributes_by_attributeID_oid[i] = a; schema->attributes_by_linkID[i] = a; + schema->attributes_by_cn[i] = a; /* append attr-by-msDS-IntId values */ if (a->msDS_IntId != 0) { schema->attributes_by_msDS_IntId[num_int_id] = a; @@ -639,6 +647,7 @@ int dsdb_setup_sorted_accessors(struct ldb_context *ldb, TYPESAFE_QSORT(schema->attributes_by_msDS_IntId, schema->num_int_id_attr, dsdb_compare_attribute_by_msDS_IntId); TYPESAFE_QSORT(schema->attributes_by_attributeID_oid, schema->num_attributes, dsdb_compare_attribute_by_attributeID_oid); TYPESAFE_QSORT(schema->attributes_by_linkID, schema->num_attributes, dsdb_compare_attribute_by_linkID); + TYPESAFE_QSORT(schema->attributes_by_cn, schema->num_attributes, dsdb_compare_attribute_by_cn); dsdb_setup_attribute_shortcuts(ldb, schema);