Пример #1
0
 async def modify_params(self, dn, mod_list):
     req = rfc4511.ModifyRequest()
     req.setComponentByName('object', rfc4511.LDAPDN(dn))
     changes = rfc4511.Changes()
     for i, mod_op in enumerate(mod_list):
         op, attr_type, attr_vals = mod_op
         change = rfc4511.Change()
         change.setComponentByName('operation', op)
         mod = rfc4511.PartialAttribute()
         mod.setComponentByName('type', rfc4511.Type(attr_type))
         vals = rfc4511.Vals()
         for j, val in enumerate(attr_vals):
             vals.setComponentByPosition(j, val)
         mod.setComponentByName('vals', vals)
         change.setComponentByName('modification', mod)
         changes.setComponentByPosition(i, change)
     req.setComponentByName('changes', changes)
     return await self.modify(req)
Пример #2
0
 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
Пример #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
Пример #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)
Пример #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))