From: Stefan Metzmacher Date: Tue, 30 Jan 2018 08:51:20 +0000 (+0100) Subject: python/common: add __cmp__ function to dsdb_Dn similar to parsed_dn_compare() X-Git-Tag: tevent-0.9.36~244 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=55d466549a3113f7625acdd6eb42f71cf63719b5;p=thirdparty%2Fsamba.git python/common: add __cmp__ function to dsdb_Dn similar to parsed_dn_compare() Linked attribute values are sorted by objectGUID of the link target. For C code we have parsed_dn_compare() to implement the logic, the same is now available on python dsdb_Dn objects. BUG: https://bugzilla.samba.org/show_bug.cgi?id=13228 Signed-off-by: Stefan Metzmacher Reviewed-by: Ralph Boehme --- diff --git a/python/samba/common.py b/python/samba/common.py index 20f170cf36e..a915934f184 100644 --- a/python/samba/common.py +++ b/python/samba/common.py @@ -19,6 +19,8 @@ import ldb import dsdb +from samba.ndr import ndr_pack +from samba.dcerpc import misc import binascii @@ -93,6 +95,21 @@ class dsdb_Dn(object): def __str__(self): return self.prefix + str(self.dn.extended_str(mode=1)) + def __cmp__(self, other): + ''' compare dsdb_Dn values similar to parsed_dn_compare()''' + dn1 = self + dn2 = other + guid1 = dn1.dn.get_extended_component("GUID") + guid1b = ndr_pack(misc.GUID(guid1)) + guid2 = dn2.dn.get_extended_component("GUID") + guid2b = ndr_pack(misc.GUID(guid2)) + + v = cmp(guid1, guid2) + if v != 0: + return v + v = cmp(dn1.binary, dn2.binary) + return v + def get_binary_integer(self): '''return binary part of a dsdb_Dn as an integer, or None''' if self.prefix == '': diff --git a/selftest/knownfail.d/test_dsdb_Dn_sorted b/selftest/knownfail.d/test_dsdb_Dn_sorted deleted file mode 100644 index 2377dccc355..00000000000 --- a/selftest/knownfail.d/test_dsdb_Dn_sorted +++ /dev/null @@ -1 +0,0 @@ -^samba.tests.common.samba.tests.common.CommonTests.test_dsdb_Dn_sorted