dsdb group audit: align dn_compare with memcmp
authorGary Lockyer <gary@catalyst.net.nz>
Wed, 24 Oct 2018 21:52:27 +0000 (10:52 +1300)
committerStefan Metzmacher <metze@samba.org>
Tue, 30 Oct 2018 15:40:13 +0000 (16:40 +0100)
Rename the parameter names and adjust the  return codes from dn_compare
so that:
dn_compare(a, b) =>

LESS_THAN means a is less than b.
GREATER_THAN means a is greater than b.

Thanks to metze for suggesting the correct semantics for dn_compare

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13664

Signed-off-by: Gary Lockyer <gary@catalyst.net.nz>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
selftest/knownfail.d/bug13664 [deleted file]
source4/dsdb/samdb/ldb_modules/group_audit.c
source4/dsdb/samdb/ldb_modules/tests/test_group_audit.c

diff --git a/selftest/knownfail.d/bug13664 b/selftest/knownfail.d/bug13664
deleted file mode 100644 (file)
index 6ffbf12..0000000
+++ /dev/null
@@ -1 +0,0 @@
-^samba4.dsdb.samdb.ldb_modules.group_audit.test_log_membership_changes_removed
index 1c74805eed0e22816487d4562de1c7d8eac5388f..47b69435195ecf8c151e84839b2a90a166736eb6 100644 (file)
@@ -311,35 +311,36 @@ enum dn_compare_result {
        GREATER_THAN
 };
 /*
- * @brief compare parsed_dns
+ * @brief compare parsed_dn, using GUID ordering
  *
- * Compare two parsed_dn structures, parsing the entries if necessary.
+ * Compare two parsed_dn structures, using GUID ordering.
  * To avoid the overhead of parsing the DN's this function does a binary
- * compare first. Only parsing the DN's they are not equal at a binary level.
+ * compare first. The DN's tre only parsed if they are not equal at a binary
+ * level.
  *
  * @param ctx talloc context that will own the parsed dsdb_dn
  * @param ldb ldb_context
- * @param old_val The old value
- * @param new_val The old value
+ * @param dn1 The first dn
+ * @param dn2 The second dn
  *
  * @return BINARY_EQUAL values are equal at a binary level
  *         EQUAL        DN's are equal but the meta data is different
- *         LESS_THAN    old value < new value
- *         GREATER_THAN old value > new value
+ *         LESS_THAN    dn1's GUID is less than dn2's GUID
+ *         GREATER_THAN dn1's GUID is greater than  dn2's GUID
  *
  */
 static enum dn_compare_result dn_compare(
        TALLOC_CTX *mem_ctx,
        struct ldb_context *ldb,
-       struct parsed_dn *old_val,
-       struct parsed_dn *new_val) {
+       struct parsed_dn *dn1,
+       struct parsed_dn *dn2) {
 
        int res = 0;
 
        /*
         * Do a binary compare first to avoid unnecessary parsing
         */
-       if (data_blob_cmp(new_val->v, old_val->v) == 0) {
+       if (data_blob_cmp(dn1->v, dn2->v) == 0) {
                /*
                 * Values are equal at a binary level so no need
                 * for further processing
@@ -351,22 +352,22 @@ static enum dn_compare_result dn_compare(
         * do a GUID ordering compare. To do this we will need to ensure
         * that the dn's have been parsed.
         */
-       if (old_val->dsdb_dn == NULL) {
+       if (dn1->dsdb_dn == NULL) {
                really_parse_trusted_dn(
                        mem_ctx,
                        ldb,
-                       old_val,
+                       dn1,
                        LDB_SYNTAX_DN);
        }
-       if (new_val->dsdb_dn == NULL) {
+       if (dn2->dsdb_dn == NULL) {
                really_parse_trusted_dn(
                        mem_ctx,
                        ldb,
-                       new_val,
+                       dn2,
                        LDB_SYNTAX_DN);
        }
 
-       res = ndr_guid_compare(&new_val->guid, &old_val->guid);
+       res = ndr_guid_compare(&dn1->guid, &dn2->guid);
        if (res < 0) {
                return LESS_THAN;
        } else if (res == 0) {
index 1f4cf3ea5b3d1ca7918e5b680ee9c537a095bfac..743ce206bc0e5e5db73428ae85820ff3c01602ef 100644 (file)
@@ -562,7 +562,7 @@ static void test_dn_compare(void **state)
        b->v = &bb;
 
        res = dn_compare(ctx, ldb, a, b);
-       assert_int_equal(GREATER_THAN, res);
+       assert_int_equal(LESS_THAN, res);
        /*
         * DN's should have been parsed
         */
@@ -590,7 +590,7 @@ static void test_dn_compare(void **state)
        b->v = &bb;
 
        res = dn_compare(ctx, ldb, a, b);
-       assert_int_equal(LESS_THAN, res);
+       assert_int_equal(GREATER_THAN, res);
        /*
         * DN's should have been parsed
         */