From 5549190b37a2bfc01f5cbff89da47b7ca4bd84fa Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 13 Feb 2010 12:59:43 +1100 Subject: s4-dsdb: use TYPESAFE_QSORT() in dsdb code --- source4/dsdb/common/util.c | 15 +++++---------- source4/dsdb/samdb/ldb_modules/acl.c | 12 +++--------- source4/dsdb/samdb/ldb_modules/kludge_acl.c | 6 ++---- source4/dsdb/samdb/ldb_modules/partition_init.c | 5 +++-- source4/dsdb/samdb/ldb_modules/repl_meta_data.c | 7 +++---- source4/dsdb/schema/schema_query.c | 10 +++------- source4/dsdb/schema/schema_set.c | 25 +++++++++---------------- 7 files changed, 28 insertions(+), 52 deletions(-) (limited to 'source4') diff --git a/source4/dsdb/common/util.c b/source4/dsdb/common/util.c index 8de44726fa..a26ffc26f5 100644 --- a/source4/dsdb/common/util.c +++ b/source4/dsdb/common/util.c @@ -38,6 +38,7 @@ #include "libcli/auth/libcli_auth.h" #include "librpc/gen_ndr/ndr_drsblobs.h" #include "system/locale.h" +#include "lib/util/tsort.h" /* search the sam for the specified attributes in a specific domain, filter on @@ -3160,7 +3161,7 @@ int dsdb_find_nc_root(struct ldb_context *samdb, TALLOC_CTX *mem_ctx, struct ldb } } - qsort(nc_dns, el->num_values, sizeof(nc_dns[0]), (comparison_fn_t)dsdb_dn_compare_ptrs); + TYPESAFE_QSORT(nc_dns, el->num_values, dsdb_dn_compare_ptrs); for (i=0; inum_values; i++) { if (ldb_dn_compare_base(nc_dns[i], dn) == 0) { @@ -3297,9 +3298,7 @@ int dsdb_load_udv_v2(struct ldb_context *samdb, struct ldb_dn *dn, TALLOC_CTX *m ret = dsdb_load_partition_usn(samdb, dn, &highest_usn, NULL); if (ret != LDB_SUCCESS) { /* nothing to add - this can happen after a vampire */ - qsort(*cursors, *count, - sizeof(struct drsuapi_DsReplicaCursor2), - (comparison_fn_t)drsuapi_DsReplicaCursor2_compare); + TYPESAFE_QSORT(*cursors, *count, drsuapi_DsReplicaCursor2_compare); return LDB_SUCCESS; } @@ -3307,9 +3306,7 @@ int dsdb_load_udv_v2(struct ldb_context *samdb, struct ldb_dn *dn, TALLOC_CTX *m if (GUID_equal(our_invocation_id, &(*cursors)[i].source_dsa_invocation_id)) { (*cursors)[i].highest_usn = highest_usn; (*cursors)[i].last_sync_success = timeval_to_nttime(&now); - qsort(*cursors, *count, - sizeof(struct drsuapi_DsReplicaCursor2), - (comparison_fn_t)drsuapi_DsReplicaCursor2_compare); + TYPESAFE_QSORT(*cursors, *count, drsuapi_DsReplicaCursor2_compare); return LDB_SUCCESS; } } @@ -3324,9 +3321,7 @@ int dsdb_load_udv_v2(struct ldb_context *samdb, struct ldb_dn *dn, TALLOC_CTX *m (*cursors)[*count].last_sync_success = timeval_to_nttime(&now); (*count)++; - qsort(*cursors, *count, - sizeof(struct drsuapi_DsReplicaCursor2), - (comparison_fn_t)drsuapi_DsReplicaCursor2_compare); + TYPESAFE_QSORT(*cursors, *count, drsuapi_DsReplicaCursor2_compare); return LDB_SUCCESS; } diff --git a/source4/dsdb/samdb/ldb_modules/acl.c b/source4/dsdb/samdb/ldb_modules/acl.c index 5f50084281..250d62677b 100644 --- a/source4/dsdb/samdb/ldb_modules/acl.c +++ b/source4/dsdb/samdb/ldb_modules/acl.c @@ -39,6 +39,7 @@ #include "librpc/gen_ndr/ndr_security.h" #include "param/param.h" #include "dsdb/samdb/ldb_modules/util.h" +#include "lib/util/tsort.h" struct extended_access_check_attribute { const char *oa_name; @@ -528,11 +529,7 @@ static int acl_childClasses(struct ldb_module *module, } } if (allowedClasses->num_values > 1) { - qsort(allowedClasses->values, - allowedClasses->num_values, - sizeof(*allowedClasses->values), - (comparison_fn_t)data_blob_cmp); - + TYPESAFE_QSORT(allowedClasses->values, allowedClasses->num_values, data_blob_cmp); for (i=1 ; i < allowedClasses->num_values; i++) { struct ldb_val *val1 = &allowedClasses->values[i-1]; struct ldb_val *val2 = &allowedClasses->values[i]; @@ -615,10 +612,7 @@ static int acl_childClassesEffective(struct ldb_module *module, } if (allowedClasses->num_values > 1) { - qsort(allowedClasses->values, - allowedClasses->num_values, - sizeof(*allowedClasses->values), - (comparison_fn_t)data_blob_cmp); + TYPESAFE_QSORT(allowedClasses->values, allowedClasses->num_values, data_blob_cmp); for (i=1 ; i < allowedClasses->num_values; i++) { struct ldb_val *val1 = &allowedClasses->values[i-1]; struct ldb_val *val2 = &allowedClasses->values[i]; diff --git a/source4/dsdb/samdb/ldb_modules/kludge_acl.c b/source4/dsdb/samdb/ldb_modules/kludge_acl.c index 73e135f17d..cc29d26cf0 100644 --- a/source4/dsdb/samdb/ldb_modules/kludge_acl.c +++ b/source4/dsdb/samdb/ldb_modules/kludge_acl.c @@ -36,6 +36,7 @@ #include "libcli/security/security.h" #include "dsdb/samdb/samdb.h" #include "param/param.h" +#include "lib/util/tsort.h" /* Kludge ACL rules: * @@ -174,10 +175,7 @@ static int kludge_acl_childClasses(struct ldb_context *ldb, struct ldb_message * } if (allowedClasses->num_values > 1) { - qsort(allowedClasses->values, - allowedClasses->num_values, - sizeof(*allowedClasses->values), - (comparison_fn_t)data_blob_cmp); + TYPESAFE_QSORT(allowedClasses->values, allowedClasses->num_values, data_blob_cmp); for (i=1 ; i < allowedClasses->num_values; i++) { diff --git a/source4/dsdb/samdb/ldb_modules/partition_init.c b/source4/dsdb/samdb/ldb_modules/partition_init.c index c791c6f6cf..5dcd88a5db 100644 --- a/source4/dsdb/samdb/ldb_modules/partition_init.c +++ b/source4/dsdb/samdb/ldb_modules/partition_init.c @@ -30,6 +30,8 @@ */ #include "dsdb/samdb/ldb_modules/partition.h" +#include "lib/util/tsort.h" + static int partition_sort_compare(const void *v1, const void *v2) { const struct dsdb_partition *p1; @@ -359,8 +361,7 @@ static int add_partition_to_data(struct ldb_context *ldb, struct partition_priva data->partitions[i+1] = NULL; /* Sort again (should use binary insert) */ - qsort(data->partitions, i+1, - sizeof(*data->partitions), partition_sort_compare); + TYPESAFE_QSORT(data->partitions, i+1, partition_sort_compare); ret = partition_register(ldb, partition->ctrl); if (ret != LDB_SUCCESS) { diff --git a/source4/dsdb/samdb/ldb_modules/repl_meta_data.c b/source4/dsdb/samdb/ldb_modules/repl_meta_data.c index 67d7094d4c..9fd2c1e617 100644 --- a/source4/dsdb/samdb/ldb_modules/repl_meta_data.c +++ b/source4/dsdb/samdb/ldb_modules/repl_meta_data.c @@ -48,6 +48,7 @@ #include "dsdb/samdb/ldb_modules/util.h" #include "lib/util/binsearch.h" #include "libcli/security/security.h" +#include "lib/util/tsort.h" #define W2K3_LINKED_ATTRIBUTES 1 @@ -1278,7 +1279,7 @@ static int get_parsed_dns(struct ldb_module *module, TALLOC_CTX *mem_ctx, p->v = v; } - qsort(*pdn, el->num_values, sizeof((*pdn)[0]), (comparison_fn_t)parsed_dn_compare); + TYPESAFE_QSORT(*pdn, el->num_values, parsed_dn_compare); return LDB_SUCCESS; } @@ -3151,9 +3152,7 @@ static int replmd_replicated_uptodate_modify(struct replmd_replicated_request *a /* * sort the cursors */ - qsort(nuv.ctr.ctr2.cursors, nuv.ctr.ctr2.count, - sizeof(struct drsuapi_DsReplicaCursor2), - (comparison_fn_t)drsuapi_DsReplicaCursor2_compare); + TYPESAFE_QSORT(nuv.ctr.ctr2.cursors, nuv.ctr.ctr2.count, drsuapi_DsReplicaCursor2_compare); /* * create the change ldb_message diff --git a/source4/dsdb/schema/schema_query.c b/source4/dsdb/schema/schema_query.c index 4e11e50c17..ff54488251 100644 --- a/source4/dsdb/schema/schema_query.c +++ b/source4/dsdb/schema/schema_query.c @@ -23,6 +23,7 @@ #include "includes.h" #include "dsdb/samdb/samdb.h" #include "lib/util/binsearch.h" +#include "lib/util/tsort.h" static const char **dsdb_full_attribute_list_internal(TALLOC_CTX *mem_ctx, const struct dsdb_schema *schema, @@ -379,11 +380,8 @@ static const char **dsdb_full_attribute_list_internal_el(TALLOC_CTX *mem_ctx, return attr_list; } -static int qsort_string(const void *v1, - const void *v2) +static int qsort_string(const char **s1, const char **s2) { - char * const *s1 = v1; - char * const *s2 = v2; return strcasecmp(*s1, *s2); } @@ -394,9 +392,7 @@ static const char **dedup_attr_list(const char **attr_list) /* Remove duplicates */ if (new_len > 1) { int i; - qsort(attr_list, new_len, - sizeof(*attr_list), - (comparison_fn_t)qsort_string); + TYPESAFE_QSORT(attr_list, new_len, qsort_string); for (i=1 ; i < new_len; i++) { const char **val1 = &attr_list[i-1]; diff --git a/source4/dsdb/schema/schema_set.c b/source4/dsdb/schema/schema_set.c index f59fc32696..99b26f6b9d 100644 --- a/source4/dsdb/schema/schema_set.c +++ b/source4/dsdb/schema/schema_set.c @@ -27,6 +27,7 @@ #include "param/param.h" #include "librpc/ndr/libndr.h" #include "librpc/gen_ndr/ndr_misc.h" +#include "lib/util/tsort.h" /* override the name to attribute handler function @@ -259,14 +260,10 @@ static int dsdb_setup_sorted_accessors(struct ldb_context *ldb, } /* sort the arrays */ - qsort(schema->classes_by_lDAPDisplayName, schema->num_classes, - sizeof(struct dsdb_class *), QSORT_CAST dsdb_compare_class_by_lDAPDisplayName); - qsort(schema->classes_by_governsID_id, schema->num_classes, - sizeof(struct dsdb_class *), QSORT_CAST dsdb_compare_class_by_governsID_id); - qsort(schema->classes_by_governsID_oid, schema->num_classes, - sizeof(struct dsdb_class *), QSORT_CAST dsdb_compare_class_by_governsID_oid); - qsort(schema->classes_by_cn, schema->num_classes, - sizeof(struct dsdb_class *), QSORT_CAST dsdb_compare_class_by_cn); + TYPESAFE_QSORT(schema->classes_by_lDAPDisplayName, schema->num_classes, dsdb_compare_class_by_lDAPDisplayName); + TYPESAFE_QSORT(schema->classes_by_governsID_id, schema->num_classes, dsdb_compare_class_by_governsID_id); + TYPESAFE_QSORT(schema->classes_by_governsID_oid, schema->num_classes, dsdb_compare_class_by_governsID_oid); + TYPESAFE_QSORT(schema->classes_by_cn, schema->num_classes, dsdb_compare_class_by_cn); /* now build the attribute accessor arrays */ talloc_free(schema->attributes_by_lDAPDisplayName); @@ -298,14 +295,10 @@ static int dsdb_setup_sorted_accessors(struct ldb_context *ldb, } /* sort the arrays */ - qsort(schema->attributes_by_lDAPDisplayName, schema->num_attributes, - sizeof(struct dsdb_attribute *), QSORT_CAST dsdb_compare_attribute_by_lDAPDisplayName); - qsort(schema->attributes_by_attributeID_id, schema->num_attributes, - sizeof(struct dsdb_attribute *), QSORT_CAST dsdb_compare_attribute_by_attributeID_id); - qsort(schema->attributes_by_attributeID_oid, schema->num_attributes, - sizeof(struct dsdb_attribute *), QSORT_CAST dsdb_compare_attribute_by_attributeID_oid); - qsort(schema->attributes_by_linkID, schema->num_attributes, - sizeof(struct dsdb_attribute *), QSORT_CAST dsdb_compare_attribute_by_linkID); + TYPESAFE_QSORT(schema->attributes_by_lDAPDisplayName, schema->num_attributes, dsdb_compare_attribute_by_lDAPDisplayName); + TYPESAFE_QSORT(schema->attributes_by_attributeID_id, schema->num_attributes, dsdb_compare_attribute_by_attributeID_id); + 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); return LDB_SUCCESS; -- cgit