server sort

Michael Ströder michael at stroeder.com
Mon Jul 6 15:14:13 CEST 2009


Anil wrote:
> I am having a bit of a problem trying to setup the controlValue in 
> LDAPControl for doing server sorting. My LDAP server supports this 
> control, but I keep getting back Not supported error. Clearly this is a 
> problem on my end with how I am passing in controlValue.
> 
> I am not that familiar with BER encoding.
> 
> So, from what I've found, I tried doing something like this:
> 
> from pyasn1.type import univ, namedtype
> from pyasn1.codec.ber import encoder
> 
> seq = univ.Sequence(
> componentType=namedtype.NamedTypes(namedtype.NamedType('attributeType', 
> univ.OctetString("uid")))
> )
> 
> control = [ldap.controls.LDAPControl('1.2.840.113556.1.4.473',True,seq)]
> 
> 
> I then pass control to LDAPObject.search_ext().
> 
> That doesn't work, and I am sure I massacred my intepretation of using 
> the pyasn1 module. Unfortunately, the documentation for it is not clear 
> to me.

Never did this myself but here are some hints:

1. You have to actually encode the ASN.1 data structure represented in
pyasn1 as BER. So you would have to call pyasn1.codec.ber.encoder(seq)
somewhere.

2. You should more carefully read RFC 2891: SortKeyList is SEQUENCE OF
SEQUENCE { .. }. I don't see the nested SEQUENCE in your code snipped above.

3. The python-ldap way of implementing a LDAP control would be deriving
a new class for this control and implement the methods
encodeControlValue() and decodeControlValue() as needed.

Ciao, Michael.



More information about the python-ldap mailing list