You have to nest univ.Sequence
in univ.SequenceOf
and implement encodeControlValue
that returns the BER encoded control the server expect.
class SSSRequest(univ.SequenceOf):
componentType = univ.Sequence()
class SSSRequestSequence(univ.Sequence):
componentType = namedtype.NamedTypes(
namedtype.NamedType('attributeType', univ.OctetString()),
)
class SSS_CONTROL_REQUEST(LDAPControl):
def __init__(self,controlType,criticality,controlValue=None,encodedControlValue=None):
LDAPControl.__init__(self,controlType,criticality,controlValue,encodedControlValue)
def encodeControlValue(self):
sss = SSSRequest()
for k in self.controlValue:
Skey = SSSRequestSequence()
Skey.setComponentByName('attributeType', k)
sss.setComponentByPosition(0, Skey)
return encoder.encode(sss)
def decodeControlValue(self,encodedValue):
sssr = decoder.decode(encodedValue)[0]
rsp = SSSResponse()
for n, v in enumerate(sssr):
try:
rsp.setComponentByPosition(n, int(v))
except Exception, e:
print str(e)
if rsp.success:
return True
return rsp.error
if __name__ == '__main__':
SSSREQUEST_OID = '1.2.840.113556.1.4.473'
sss = SSS_CONTROL_REQUEST(SSSREQUEST_OID, False, ['cn'])
srv = ldap.open('localhost')
srv.simple_bind_s()
id = srv.search_ext('ou=people,dc=example,dc=com', ldap.SCOPE_SUBTREE, filterstr='(objectClass=user)', serverctrls=[sss])
print srv.result3(id)
Implementing reverse order sort is left as an exercice ;)
The code was tested successfully with a AD-LDS instance running on Windows Server 2008 R2, 64 bits (but you have to make the bind non-anonymous).