]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s4:dsdb:mod: repl_md: make message_sort transitive
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Fri, 12 Apr 2024 06:11:47 +0000 (18:11 +1200)
committerJule Anger <janger@samba.org>
Mon, 10 Jun 2024 13:25:17 +0000 (13:25 +0000)
Before we had (with a TODO of regret):

       if (!a1 || !a2) {
               return strcasecmp(e1->name, e2->name);
       }

so, given {name:"A", id 2}, {name:"B", NO id}, {name:"C", id 1},

 A < B by name
 B < C by name
 A > C by id

Now the sort order is always A > C > B.

This sort could have caused mysterious crashes in repl_meta_data if
the schema is out of sync.

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

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
(cherry picked from commit 5335f122fb551231a02a58f88f6a0aa23b5e02cb)

source4/dsdb/samdb/ldb_modules/repl_meta_data.c

index 1975c01b91d02e11dfa353e6853f015b514d9abd..762fe69f6c559794d113f4d5b5f59115d4571cc2 100644 (file)
@@ -1063,12 +1063,20 @@ static int replmd_ldb_message_element_attid_sort(const struct ldb_message_elemen
        a2 = dsdb_attribute_by_lDAPDisplayName(schema, e2->name);
 
        /*
-        * TODO: remove this check, we should rely on e1 and e2 having valid attribute names
-        *       in the schema
+        * If the elements do not have valid attribute names in the schema
+        * (which we would prefer to think can't happen), we need to sort them
+        * somehow. The current strategy is to put them at the end, sorted by
+        * attribute name.
         */
-       if (!a1 || !a2) {
+       if (a1 == NULL && a2 == NULL) {
                return strcasecmp(e1->name, e2->name);
        }
+       if (a1 == NULL) {
+               return 1;
+       }
+       if (a2 == NULL) {
+               return -1;
+       }
        if (a1->attributeID_id == a2->attributeID_id) {
                return 0;
        }