Ejemplo n.º 1
0
    def __internal_cmp__(self, other, verbose=False):
        """See CompareLinks() in MS-DRSR section 4.1.10.5.17"""
        if not isinstance(other, AbstractLink):
            if verbose:
                print("AbstractLink.__internal_cmp__(%r, %r) => wrong type" %
                      (self, other))
            return NotImplemented

        c = cmp(self.selfGUID_blob, other.selfGUID_blob)
        if c != 0:
            if verbose:
                print(
                    "AbstractLink.__internal_cmp__(%r, %r) => %d different identifier"
                    % (self, other, c))
            return c

        c = other.attid - self.attid
        if c != 0:
            if verbose:
                print(
                    "AbstractLink.__internal_cmp__(%r, %r) => %d different attid"
                    % (self, other, c))
            return c

        self_active = self.flags & drsuapi.DRSUAPI_DS_LINKED_ATTRIBUTE_FLAG_ACTIVE
        other_active = other.flags & drsuapi.DRSUAPI_DS_LINKED_ATTRIBUTE_FLAG_ACTIVE

        c = self_active - other_active
        if c != 0:
            if verbose:
                print(
                    "AbstractLink.__internal_cmp__(%r, %r) => %d different FLAG_ACTIVE"
                    % (self, other, c))
            return c

        c = cmp(self.targetGUID_blob, other.targetGUID_blob)
        if c != 0:
            if verbose:
                print(
                    "AbstractLink.__internal_cmp__(%r, %r) => %d different target"
                    % (self, other, c))
            return c

        c = self.flags - other.flags
        if c != 0:
            if verbose:
                print(
                    "AbstractLink.__internal_cmp__(%r, %r) => %d different flags"
                    % (self, other, c))
            return c

        return 0
Ejemplo n.º 2
0
def dn_sort(x, y):
    """Sorts two DNs in the lexicographical order it and put higher level DN
    before.

    So given the dns cn=bar,cn=foo and cn=foo the later will be return as
    smaller

    :param x: First object to compare
    :param y: Second object to compare
    """
    p = re.compile(r'(?<!\\), ?')
    tab1 = p.split(str(x))
    tab2 = p.split(str(y))
    minimum = min(len(tab1), len(tab2))
    len1 = len(tab1) - 1
    len2 = len(tab2) - 1
    # Note: python range go up to upper limit but do not include it
    for i in range(0, minimum):
        ret = cmp(tab1[len1 - i], tab2[len2 - i])
        if ret != 0:
            return ret
        else:
            if i == minimum - 1:
                assert len1 != len2, "PB PB PB" + " ".join(
                    tab1) + " / " + " ".join(tab2)
                if len1 > len2:
                    return 1
                else:
                    return -1
    return ret
Ejemplo n.º 3
0
def _linked_attribute_compare(la1, la2):
    """See CompareLinks() in MS-DRSR section 4.1.10.5.17"""
    la1, la1_target = la1
    la2, la2_target = la2

    # Ascending host object GUID
    c = cmp(ndr_pack(la1.identifier.guid), ndr_pack(la2.identifier.guid))
    if c != 0:
        return c

    # Ascending attribute ID
    if la1.attid != la2.attid:
        return -1 if la1.attid < la2.attid else 1

    la1_active = la1.flags & drsuapi.DRSUAPI_DS_LINKED_ATTRIBUTE_FLAG_ACTIVE
    la2_active = la2.flags & drsuapi.DRSUAPI_DS_LINKED_ATTRIBUTE_FLAG_ACTIVE

    # Ascending 'is present'
    if la1_active != la2_active:
        return 1 if la1_active else -1

    # Ascending target object GUID
    return cmp(ndr_pack(la1_target), ndr_pack(la2_target))
Ejemplo n.º 4
0
 def cmp_numeric(a, b):
     return cmp(int(a[0]), int(b[0]))
Ejemplo n.º 5
0
 def cmp_binary(a, b):
     return cmp(a[0], b[0])
Ejemplo n.º 6
0
 def test_compare_same(self):
     guid1 = misc.GUID(text1)
     guid2 = misc.GUID(text1)
     self.assertTrue(guid1 == guid2)
     self.assertEqual(guid1, guid2)
     self.assertEqual(0, cmp(guid1, guid2))
Ejemplo n.º 7
0
 def test_compare_different(self):
     guid1 = misc.GUID(text1)
     guid2 = misc.GUID(text2)
     self.assertFalse(guid1 == guid2)
     self.assertGreater(guid1, guid2)
     self.assertTrue(cmp(guid1, guid2) > 0)