Ejemplo n.º 1
0
    def handle_LDAPExtendedRequest(self, request, controls, reply):
        self.checkControls(controls)

        for handler in [getattr(self, attr)
                        for attr in dir(self)
                        if attr.startswith('extendedRequest_')]:
            if getattr(handler, 'oid', None) == request.requestName:
                berdecoder = getattr(handler, 'berdecoder', None)

                if berdecoder is None:
                    values = [request.requestValue]
                else:
                    values = pureber.berDecodeMultiple(
                        request.requestValue, berdecoder)

                d = defer.maybeDeferred(handler, *values, **{'reply': reply})

                def eb(fail, oid):
                    fail.trap(ldaperrors.LDAPException)
                    return pureldap.LDAPExtendedResponse(
                        resultCode=fail.value.resultCode,
                        errorMessage=fail.value.message,
                        responseName=oid,
                        )

                d.addErrback(eb, request.requestName)
                return d

        raise ldaperrors.LDAPProtocolError(
            'Unknown extended request: %s' % request.requestName)
Ejemplo n.º 2
0
    def fromBER(klass, tag, content, berdecoder=None):
        l = berDecodeMultiple(
            content,
            LDAPBERDecoderContext_LDAPExtendedResponse(fallback=berdecoder))

        assert 3 <= len(l) <= 6

        referral = None
        responseName = None
        response = None
        for obj in l[3:]:
            if isinstance(obj, LDAPResponseName):
                responseName = obj.value
            elif isinstance(obj, LDAPResponse):
                response = obj.value
            elif isinstance(obj, LDAPReferral):
                #TODO support referrals
                #self.referral=self.data[0]
                pass
            else:
                assert False

        r = klass(resultCode=l[0].value,
                  matchedDN=l[1].value,
                  errorMessage=l[2].value,
                  referral=referral,
                  responseName=responseName,
                  response=response,
                  tag=tag)
        return r
Ejemplo n.º 3
0
    def fromBER(klass, tag, content, berdecoder=None):
        l = berDecodeMultiple(
            content, LDAPBERDecoderContext_BindResponse(fallback=berdecoder))

        assert 3 <= len(l) <= 4

        try:
            if isinstance(l[3], LDAPBindResponse_serverSaslCreds):
                serverSaslCreds = l[3]
            else:
                serverSaslCreds = None
        except IndexError:
            serverSaslCreds = None

        referral = None
        #if (l[3:] and isinstance(l[3], LDAPReferral)):
        #TODO support referrals
        #self.referral=self.data[0]

        r = klass(resultCode=l[0].value,
                  matchedDN=l[1].value,
                  errorMessage=l[2].value,
                  referral=referral,
                  serverSaslCreds=serverSaslCreds,
                  tag=tag)
        return r
Ejemplo n.º 4
0
    def fromBER(klass, tag, content, berdecoder=None):
        matchingRule = None
        atype = None
        matchValue = None
        dnAttributes = None
        l = berDecodeMultiple(
            content,
            LDAPBERDecoderContext_MatchingRuleAssertion(fallback=berdecoder,
                                                        inherit=berdecoder))
        assert 1 <= len(l) <= 4
        if isinstance(l[0], LDAPMatchingRuleAssertion_matchingRule):
            matchingRule = l[0]
            del l[0]
        if len(l) >= 1 and isinstance(l[0], LDAPMatchingRuleAssertion_type):
            atype = l[0]
            del l[0]
        if len(l) >= 1 and isinstance(l[0],
                                      LDAPMatchingRuleAssertion_matchValue):
            matchValue = l[0]
            del l[0]
        if len(l) >= 1 and isinstance(l[0],
                                      LDAPMatchingRuleAssertion_dnAttributes):
            dnAttributes = l[0]
            del l[0]
        assert matchValue
        if not dnAttributes:
            dnAttributes = None
        r = klass(matchingRule=matchingRule,
                  type=atype,
                  matchValue=matchValue,
                  dnAttributes=dnAttributes,
                  tag=tag)

        return r
Ejemplo n.º 5
0
    def fromBER(klass, tag, content, berdecoder=None):
        l = berDecodeMultiple(content, berdecoder)

        assert len(l) == 2

        r = klass(object=l[0].value, modification=l[1].data, tag=tag)
        return r
Ejemplo n.º 6
0
    def fromBER(klass, tag, content, berdecoder=None):
        matchingRule = None
        atype = None
        matchValue = None
        dnAttributes = None
        l = berDecodeMultiple(content,
                              LDAPBERDecoderContext_MatchingRuleAssertion(fallback=berdecoder, inherit=berdecoder))
        assert 1 <= len(l) <= 4
        if isinstance(l[0], LDAPMatchingRuleAssertion_matchingRule):
            matchingRule = l[0]
            del l[0]
        if len(l) >= 1 and isinstance(l[0], LDAPMatchingRuleAssertion_type):
            atype = l[0]
            del l[0]
        if len(l) >= 1 and isinstance(l[0], LDAPMatchingRuleAssertion_matchValue):
            matchValue = l[0]
            del l[0]
        if len(l) >= 1 and isinstance(l[0], LDAPMatchingRuleAssertion_dnAttributes):
            dnAttributes = l[0]
            del l[0]
        assert matchValue
        if not dnAttributes:
            dnAttributes = None
        r = klass(
            matchingRule=matchingRule,
            type=atype,
            matchValue=matchValue,
            dnAttributes=dnAttributes,
            tag=tag)

        return r
Ejemplo n.º 7
0
    def fromBER(klass, tag, content, berdecoder=None):
        l = berDecodeMultiple(content, berdecoder)

        r = klass(entry=l[0].value,
                  attributes=l[1],
                  tag=tag)
        return r
Ejemplo n.º 8
0
    def fromBER(klass, tag, content, berdecoder=None):
        l = berDecodeMultiple(content, LDAPBERDecoderContext_BindResponse(
                fallback=berdecoder))

        assert 3 <= len(l) <= 4

        try:
            if isinstance(l[3], LDAPBindResponse_serverSaslCreds):
                serverSaslCreds = l[3]
            else:
                serverSaslCreds = None
        except IndexError:
            serverSaslCreds = None

        referral = None
        #if (l[3:] and isinstance(l[3], LDAPReferral)):
            #TODO support referrals
            #self.referral=self.data[0]

        r = klass(resultCode=l[0].value,
                  matchedDN=l[1].value,
                  errorMessage=l[2].value,
                  referral=referral,
                  serverSaslCreds=serverSaslCreds,
                  tag=tag)
        return r
Ejemplo n.º 9
0
    def fromBER(klass, tag, content, berdecoder=None):
        l = berDecodeMultiple(content, berdecoder)

        r = klass(entry=l[0].value,
                  attributes=l[1],
                  tag=tag)
        return r
Ejemplo n.º 10
0
    def fromBER(klass, tag, content, berdecoder=None):
        l = berDecodeMultiple(content, LDAPBERDecoderContext_LDAPExtendedResponse(
            fallback=berdecoder))

        assert 3 <= len(l) <= 6

        referral = None
        responseName = None
        response = None
        for obj in l[3:]:
            if isinstance(obj, LDAPResponseName):
                responseName = obj.value
            elif isinstance(obj, LDAPResponse):
                response = obj.value
            elif isinstance(obj, LDAPReferral):
                #TODO support referrals
                #self.referral=self.data[0]
                pass
            else:
                assert False

        r = klass(resultCode=l[0].value,
                  matchedDN=l[1].value,
                  errorMessage=l[2].value,
                  referral=referral,
                  responseName=responseName,
                  response=response,
                  tag=tag)
        return r
Ejemplo n.º 11
0
    def fromBER(klass, tag, content, berdecoder=None):
        l = berDecodeMultiple(content, berdecoder)
        assert len(l) == 2

        r = klass(attributeDesc=l[0],
                  assertionValue=l[1],
                  tag=tag)
        return r
Ejemplo n.º 12
0
    def fromBER(klass, tag, content, berdecoder=None):
        l = berDecodeMultiple(content, berdecoder)
        assert len(l) == 2

        r = klass(attributeDesc=l[0],
                  assertionValue=l[1],
                  tag=tag)
        return r
Ejemplo n.º 13
0
    def fromBER(klass, tag, content, berdecoder=None):
        l = berDecodeMultiple(content, berdecoder)

        assert len(l) == 2

        r = klass(object=l[0].value,
                  modification=l[1].data,
                  tag=tag)
        return r
Ejemplo n.º 14
0
    def fromBER(klass, tag, content, berdecoder=None):
        l = berDecodeMultiple(content, LDAPBERDecoderContext_Filter_substrings(fallback=berdecoder))
        assert len(l) == 2
        assert len(l[1]) >= 1

        r = klass(type=l[0].value,
                  substrings=list(l[1]),
                  tag=tag)
        return r
Ejemplo n.º 15
0
    def fromBER(klass, tag, content, berdecoder=None):
        l = berDecodeMultiple(
            content,
            LDAPBERDecoderContext_Filter_substrings(fallback=berdecoder))
        assert len(l) == 2
        assert len(l[1]) >= 1

        r = klass(type=l[0].value, substrings=list(l[1]), tag=tag)
        return r
Ejemplo n.º 16
0
    def fromBER(klass, tag, content, berdecoder=None):
        l = berDecodeMultiple(
            content,
            LDAPBERDecoderContext_Compare(fallback=berdecoder,
                                          inherit=berdecoder))

        r = klass(entry=l[0].value, ava=l[1], tag=tag)

        return r
Ejemplo n.º 17
0
    def fromBER(klass, tag, content, berdecoder=None):
        l = berDecodeMultiple(content, LDAPBERDecoderContext_Filter(fallback=berdecoder, inherit=berdecoder))

        objectName = l[0].value
        attributes = []
        for attr, li in l[1].data:
            attributes.append((attr.value, map(lambda x: x.value, li)))
        r = klass(objectName=objectName,
                  attributes=attributes,
                  tag=tag)
        return r
Ejemplo n.º 18
0
    def fromBER(klass, tag, content, berdecoder=None):
        l = berDecodeMultiple(content, LDAPBERDecoderContext_Filter(fallback=berdecoder, inherit=berdecoder))

        objectName = l[0].value
        attributes = []
        for attr, li in l[1].data:
            attributes.append((attr.value, map(lambda x: x.value, li)))
        r = klass(objectName=objectName,
                  attributes=attributes,
                  tag=tag)
        return r
Ejemplo n.º 19
0
    def fromBER(klass, tag, content, berdecoder=None):
        l = berDecodeMultiple(
            content,
            LDAPBERDecoderContext_LDAPExtendedRequest(fallback=berdecoder))

        kw = {}
        try:
            kw['requestValue'] = l[1].value
        except IndexError:
            pass

        r = klass(requestName=l[0].value, tag=tag, **kw)
        return r
Ejemplo n.º 20
0
    def fromBER(klass, tag, content, berdecoder=None):
        l = berDecodeMultiple(
                content,
                LDAPBERDecoderContext_Compare(
                    fallback=berdecoder,
                    inherit=berdecoder
                    )
                )

        r = klass(entry=l[0].value,
                  ava=l[1],
                  tag=tag)

        return r
Ejemplo n.º 21
0
    def fromBER(klass, tag, content, berdecoder=None):
        l = berDecodeMultiple(content, LDAPBERDecoderContext_Filter(fallback=berdecoder, inherit=berdecoder))

        assert 8 <= len(l) <= 8
        r = klass(baseObject=l[0].value,
                  scope=l[1].value,
                  derefAliases=l[2].value,
                  sizeLimit=l[3].value,
                  timeLimit=l[4].value,
                  typesOnly=l[5].value,
                  filter=l[6],
                  attributes=[x.value for x in l[7]],
                  tag=tag)
        return r
Ejemplo n.º 22
0
    def fromBER(klass, tag, content, berdecoder=None):
        l = berDecodeMultiple(content, LDAPBERDecoderContext_Filter(fallback=berdecoder, inherit=berdecoder))

        assert 8 <= len(l) <= 8
        r = klass(baseObject=l[0].value,
                  scope=l[1].value,
                  derefAliases=l[2].value,
                  sizeLimit=l[3].value,
                  timeLimit=l[4].value,
                  typesOnly=l[5].value,
                  filter=l[6],
                  attributes=[x.value for x in l[7]],
                  tag=tag)
        return r
Ejemplo n.º 23
0
    def fromBER(klass, tag, content, berdecoder=None):
        l = berDecodeMultiple(content, LDAPBERDecoderContext_ModifyDNRequest(fallback=berdecoder))

        kw = {}
        try:
            kw['newSuperior'] = str(l[3].value)
        except IndexError:
            pass

        r = klass(entry=str(l[0].value),
                  newrdn=str(l[1].value),
                  deleteoldrdn=l[2].value,
                  tag=tag,
                  **kw)
        return r
Ejemplo n.º 24
0
    def fromBER(klass, tag, content, berdecoder=None):
        l = berDecodeMultiple(content, LDAPBERDecoderContext_ModifyDNRequest(fallback=berdecoder))

        kw = {}
        try:
            kw['newSuperior'] = str(l[3].value)
        except IndexError:
            pass

        r = klass(entry=str(l[0].value),
                  newrdn=str(l[1].value),
                  deleteoldrdn=l[2].value,
                  tag=tag,
                  **kw)
        return r
Ejemplo n.º 25
0
    def fromBER(klass, tag, content, berdecoder=None):
        l = berDecodeMultiple(content,
                              LDAPBERDecoderContext_LDAPExtendedRequest(
                                  fallback=berdecoder))

        kw = {}
        try:
            kw['requestValue'] = l[1].value
        except IndexError:
            pass

        r = klass(requestName=l[0].value,
                  tag=tag,
                  **kw)
        return r
Ejemplo n.º 26
0
    def fromBER(klass, tag, content, berdecoder=None):
        l = berDecodeMultiple(content, LDAPBERDecoderContext_LDAPBindRequest(
            fallback=berdecoder))

        assert 3 <= len(l) <= 4

        referral = None
        # if (l[3:] and isinstance(l[3], LDAPReferral)):
            # TODO support referrals
            # self.referral=self.data[0]

        r = klass(resultCode=l[0].value,
                  matchedDN=l[1].value,
                  errorMessage=l[2].value,
                  referral=referral,
                  tag=tag)
        return r
Ejemplo n.º 27
0
    def fromBER(klass, tag, content, berdecoder=None):
        l = berDecodeMultiple(content, LDAPBERDecoderContext_LDAPBindRequest(
            fallback=berdecoder))

        assert 3 <= len(l) <= 4

        referral = None
        # if (l[3:] and isinstance(l[3], LDAPReferral)):
            # TODO support referrals
            # self.referral=self.data[0]

        r = klass(resultCode=l[0].value,
                  matchedDN=l[1].value,
                  errorMessage=l[2].value,
                  referral=referral,
                  tag=tag)
        return r
Ejemplo n.º 28
0
    def fromBER(klass, tag, content, berdecoder=None):
        l = berDecodeMultiple(content, berdecoder)

        assert 1 <= len(l) <= 3

        kw = {}
        if len(l) == 2:
            if isinstance(l[1], BERBoolean):
                kw['criticality'] = l[1].value
            elif isinstance(l[1], BEROctetString):
                kw['controlValue'] = l[1].value
        elif len(l) == 3:
            kw['criticality'] = l[1].value
            kw['controlValue'] = l[2].value

        r = klass(controlType=l[0].value, tag=tag, **kw)
        return r
Ejemplo n.º 29
0
    def fromBER(klass, tag, content, berdecoder=None):
        l = berDecodeMultiple(content, berdecoder)

        id_ = l[0].value
        value = l[1]
        if l[2:]:
            controls = []
            for c in l[2]:
                controls.append((
                    c.controlType,
                    c.criticality,
                    c.controlValue,
                ))
        else:
            controls = None
        assert not l[3:]

        r = klass(id=id_, value=value, controls=controls, tag=tag)
        return r
Ejemplo n.º 30
0
    def fromBER(klass, tag, content, berdecoder=None):
        l = berDecodeMultiple(
            content,
            LDAPBERDecoderContext_LDAPBindRequest(fallback=berdecoder))

        sasl = False
        auth = None
        if isinstance(l[2], BEROctetString):
            auth = l[2].value
        elif isinstance(l[2], BERSequence):
            auth = (l[2][0].value, l[2][1].value)
            sasl = True

        r = klass(version=l[0].value,
                  dn=l[1].value,
                  auth=auth,
                  tag=tag,
                  sasl=sasl)
        return r
Ejemplo n.º 31
0
    def fromBER(klass, tag, content, berdecoder=None):
        l = berDecodeMultiple(content,
                              LDAPBERDecoderContext_LDAPBindRequest(
                                  fallback=berdecoder))

        sasl = False
        auth = None
        if isinstance(l[2], BEROctetString):
            auth = l[2].value
        elif isinstance(l[2], BERSequence):
            auth = (l[2][0].value, l[2][1].value)
            sasl = True

        r = klass(version=l[0].value,
                  dn=l[1].value,
                  auth=auth,
                  tag=tag,
                  sasl=sasl)
        return r
Ejemplo n.º 32
0
    def fromBER(klass, tag, content, berdecoder=None):
        l = berDecodeMultiple(content, berdecoder)

        assert 1<=len(l)<= 3

        kw = {}
        if len(l) == 2:
            if isinstance(l[1], BERBoolean):
              kw['criticality'] = l[1].value
            elif isinstance(l[1], BEROctetString):
              kw['controlValue'] = l[1].value
        elif len(l) == 3:
            kw['criticality'] = l[1].value
            kw['controlValue'] = l[2].value

        r = klass(controlType=l[0].value,
                  tag=tag,
                  **kw)
        return r
Ejemplo n.º 33
0
    def fromBER(klass, tag, content, berdecoder=None):
        l = berDecodeMultiple(content, berdecoder)

        id_ = l[0].value
        value = l[1]
        if l[2:]:
            controls = []
            for c in l[2]:
                controls.append((
                    c.controlType,
                    c.criticality,
                    c.controlValue,
                    ))
        else:
            controls = None
        assert not l[3:]

        r = klass(id=id_,
                  value=value,
                  controls=controls,
                  tag=tag)
        return r
Ejemplo n.º 34
0
 def fromBER(cls, tag, content, berdecoder=None):
     l = berDecodeMultiple(content,
                           LDAPBERDecoderContext_LDAPSearchResultReference(
                               fallback=berdecoder))
     r = cls(uris=l)
     return r
Ejemplo n.º 35
0
    def fromBER(klass, tag, content, berdecoder=None):
        l = berDecodeMultiple(
            content, LDAPBERDecoderContext_LDAPControls(inherit=berdecoder))

        r = klass(l, tag=tag)
        return r
Ejemplo n.º 36
0
 def fromBER(klass, tag, content, berdecoder=None):
     l = berDecodeMultiple(content, LDAPBERDecoderContext_Filter(fallback=berdecoder))
     r = klass(l, tag=tag)
     return r
Ejemplo n.º 37
0
 def fromBER(klass, tag, content, berdecoder=None):
     l = berDecodeMultiple(
         content, LDAPBERDecoderContext_Filter(fallback=berdecoder))
     r = klass(l, tag=tag)
     return r
Ejemplo n.º 38
0
    def fromBER(klass, tag, content, berdecoder=None):
        l = berDecodeMultiple(content, LDAPBERDecoderContext_LDAPControls(
                inherit=berdecoder))

        r = klass(l, tag=tag)
        return r