Beispiel #1
0
    async def compare_params(self, dn, attr_type, attr_value):
        req = rfc4511.CompareRequest()
        req.setComponentByName('entry', rfc4511.LDAPDN(dn))
        ava = rfc4511.AttributeValueAssertion()
        ava.setComponentByName('attributeDesc',
                               rfc4511.AttributeDescription(attr_type))
        ava.setComponentByName('assertionValue',
                               rfc4511.AssertionValue(attr_value))
        req.setComponentByName('ava', ava)

        return await self.compare(req)
 def to_proto(self):
     op = rfc4511.ProtocolOp()
     res = rfc4511.SearchResultEntry()
     res.setComponentByName('objectName', rfc4511.LDAPDN(self.dn))
     attrs = rfc4511.PartialAttributeList()
     j = 0
     for attr, vals in self.attrs.items():
         if not vals:
             continue
         _attr = rfc4511.PartialAttribute()
         _attr.setComponentByName('type', rfc4511.AttributeDescription(attr))
         _vals = rfc4511.Vals()
         for i, val in enumerate(vals):
             _vals.setComponentByPosition(i, rfc4511.AttributeValue(val))
         _attr.setComponentByName('vals', _vals)
         attrs.setComponentByPosition(j, _attr)
         j += 1
     res.setComponentByName('attributes', attrs)
     op.setComponentByName('searchResEntry', res)
     return op
Beispiel #3
0
def make_add_request(dn, attrs=None):
    req = rfc4511.AddRequest()
    req.setComponentByName('entry', rfc4511.LDAPDN(dn))
    al = rfc4511.AttributeList()
    if attrs:
        i = 0
        for attr_type, attr_vals in attrs.items():
            attr = rfc4511.Attribute()
            attr.setComponentByName('type',
                                    rfc4511.AttributeDescription(attr_type))
            vals = rfc4511.Vals()
            j = 0
            for val in attr_vals:
                vals.setComponentByPosition(j, rfc4511.AttributeValue(val))
                j += 1
            attr.setComponentByName('vals', vals)
            al.setComponentByPosition(i, attr)
            i += 1
    req.setComponentByName('attributes', al)
    return req
Beispiel #4
0
    async def add_params(self, dn: str, attrs: dict):
        req = rfc4511.AddRequest()
        req.setComponentByName('entry', rfc4511.LDAPDN(dn))
        al = rfc4511.AttributeList()
        if attrs:
            i = 0
            for attr_type, attr_vals in attrs.items():
                attr = rfc4511.Attribute()
                attr.setComponentByName(
                    'type', rfc4511.AttributeDescription(attr_type))
                vals = rfc4511.Vals()
                j = 0
                for val in attr_vals:
                    vals.setComponentByPosition(j, rfc4511.AttributeValue(val))
                    j += 1
                attr.setComponentByName('vals', vals)
                al.setComponentByPosition(i, attr)
                i += 1
        req.setComponentByName('attributes', al)

        return await self.add(req)
Beispiel #5
0
    def add_search_res_entry(self, dn, attrs_dict, controls=None):
        """Create a searchResEntry LDAPMessage"""
        sre = rfc4511.SearchResultEntry()
        sre.setComponentByName('objectName', rfc4511.LDAPDN(dn))

        attrs = rfc4511.PartialAttributeList()
        i = 0
        for attr, values in attrs_dict.items():
            _attr = rfc4511.PartialAttribute()
            _attr.setComponentByName('type',
                                     rfc4511.AttributeDescription(attr))
            _vals = rfc4511.Vals()
            for j, val in enumerate(values):
                _vals.setComponentByPosition(j, rfc4511.AttributeValue(val))
            _attr.setComponentByName('vals', _vals)
            attrs.setComponentByPosition(i, _attr)
            i += 1

        sre.setComponentByName('attributes', attrs, controls)

        self.add_message(
            protoutils.pack(self._next_add_message_id, 'searchResEntry', sre))