]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ldb:dn_compare: be a bit more transitive
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Thu, 22 Aug 2024 22:17:17 +0000 (10:17 +1200)
committerDouglas Bagnall <dbagnall@samba.org>
Thu, 19 Dec 2024 23:00:32 +0000 (23:00 +0000)
If neither dn can casefold, they should be considered equal. Otherwise
cmp(dn1, dn2) will be inconsistent with cmp(dn2, dn1).

These will still sort to the end of the list, relative to any valid
DNs.

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@samba.org>
lib/ldb/common/ldb_dn.c

index 8e89571229fc8400d77a61fde4361181c7b331a0..16de79db5523ad178fd3067fa812de2e15dcd425 100644 (file)
@@ -1171,6 +1171,7 @@ int ldb_dn_compare(struct ldb_dn *dn0, struct ldb_dn *dn1)
        }
 
        if (( ! dn0->valid_case) || ( ! dn1->valid_case)) {
+               bool ok0, ok1;
                if (dn0->linearized && dn1->linearized) {
                        /* try with a normal compare first, if we are lucky
                         * we will avoid exploding and casefolding */
@@ -1178,15 +1179,20 @@ int ldb_dn_compare(struct ldb_dn *dn0, struct ldb_dn *dn1)
                                return 0;
                        }
                }
-
-               if ( ! ldb_dn_casefold_internal(dn0)) {
+               /*
+                * If a DN can't casefold, it goes to the end.
+                */
+               ok0 = ldb_dn_casefold_internal(dn0);
+               ok1 = ldb_dn_casefold_internal(dn1);
+               if (! ok0) {
+                       if (! ok1) {
+                               return 0;
+                       }
                        return 1;
                }
-
-               if ( ! ldb_dn_casefold_internal(dn1)) {
+               if (! ok1) {
                        return -1;
                }
-
        }
 
        /*