Beispiel #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_fn(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_fn(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
Beispiel #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_fn(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
Beispiel #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_fn(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_fn(ndr_pack(la1_target), ndr_pack(la2_target))
Beispiel #4
0
 def cmp_numeric(a, b):
     return cmp_fn(int(a[0]), int(b[0]))
Beispiel #5
0
 def cmp_binary(a, b):
     return cmp_fn(a[0], b[0])