Hi,
In relation to ticket 47757, I have started work on a deref control for Noriko.
The idea is to get it working in lib389, then get it upstreamed into pyldap.
At this point it's all done, except that the actual request control doesn't
appear to work. Could one of the lib389 / ldap python experts cast their eye
over this and let me know where I've gone wrong?
For one, I don't think that the DerferenceControl decodeControlValue function is
ever called, as I'm never seeing the encodedControlValue printed in my logs.
Second, the results I get from result3 are:
[('cn=testgroup,dc=example,dc=com', {'objectClass': ['top', 'extensibleobject'],
'uniqueMember': ['uid=test,dc=example,dc=com'], 'cn': ['testgroup']})]
[]
Which again, doesn't seem correct, as there should be a result from the control.
Additionally, any tips on how to make the code nicer would be appreciated.
I've attached the complete patch, with a unit test to trigger the search, but
the request control looks like:
controlValue ::= SEQUENCE OF derefSpec DerefSpec
DerefSpec ::= SEQUENCE {
derefAttr attributeDescription,; with DN syntax
attributes AttributeList }
AttributeList ::= SEQUENCE OF attr AttributeDescription
class AttributeList(univ.SequenceOf):
componentType = AttributeDescription()
class DerefSpec(univ.Sequence):
componentType = namedtype.NamedTypes(
namedtype.NamedType('derefAttr', AttributeDescription()),
namedtype.NamedType('attributes', AttributeList()),
)
class ControlValue(univ.SequenceOf):
componentType = DerefSpec()
class DereferenceControl(LDAPControl):
Dereference Control
def __init__(self, criticality, deref):
LDAPControl.__init__(self, CONTROL_DEREF, criticality)
self.deref = deref
def encodeControlValue(self):
# How does -E ask for many values?
derefAttr, attributes = self.deref.split(':')
attributes = attributes.split(',')
al = AttributeList()
i = 0
while len(attributes) 0:
al.setComponentByPosition(i, attributes.pop())
i += 1
ds = DerefSpec()
ds.setComponentByName('derefAttr', derefAttr)
ds.setComponentByName('attributes', al)
cv = ControlValue()
cv.setComponentByPosition(0, ds)
print(cv.prettyPrint())
return encoder.encode(cv)
def decodeControlValue(self,encodedControlValue):
print(encodedControlValue)
From eb3dede21afcfb930d9c45ee0d83d309683f02ce Mon Sep 17 00:00:00 2001
From: William Brown will...@blackhats.net.au
Date: Tue, 25 Aug 2015 15:38:11 +0930
Subject: [PATCH] Add dereference request control to lib389 for testing.
---
lib389/__init__.py| 99 +++
lib389/_constants.py | 6 +++
tests/dereference_test.py | 75 +++
3 files changed, 180 insertions(+)
create mode 100644 tests/dereference_test.py
diff --git a/lib389/__init__.py b/lib389/__init__.py
index 8dfe28f..1f3e6a4 100644
--- a/lib389/__init__.py
+++ b/lib389/__init__.py
@@ -73,6 +73,65 @@ MAJOR, MINOR, _, _, _ = sys.version_info
if MAJOR = 3 or (MAJOR == 2 and MINOR = 7):
from ldap.controls.simple import GetEffectiveRightsControl
+from ldap.controls import LDAPControl
+
+from pyasn1.type import namedtype,univ
+from pyasn1.codec.ber import encoder,decoder
+from pyasn1_modules.rfc2251 import AttributeDescription
+
+# Could use AttributeDescriptionList
+
+
+ controlValue ::= SEQUENCE OF derefSpec DerefSpec
+
+ DerefSpec ::= SEQUENCE {
+ derefAttr attributeDescription,; with DN syntax
+ attributes AttributeList }
+
+ AttributeList ::= SEQUENCE OF attr AttributeDescription
+
+class AttributeList(univ.SequenceOf):
+componentType = AttributeDescription()
+
+class DerefSpec(univ.Sequence):
+componentType = namedtype.NamedTypes(
+namedtype.NamedType('derefAttr', AttributeDescription()),
+namedtype.NamedType('attributes', AttributeList()),
+)
+
+class ControlValue(univ.SequenceOf):
+componentType = DerefSpec()
+
+class DereferenceControl(LDAPControl):
+
+Dereference Control
+
+
+def __init__(self, criticality, deref):
+LDAPControl.__init__(self, CONTROL_DEREF, criticality)
+self.deref = deref
+
+def encodeControlValue(self):
+# How does -E ask for many values?
+derefAttr, attributes = self.deref.split(':')
+attributes = attributes.split(',')
+al = AttributeList()
+i = 0
+while len(attributes) 0:
+al.setComponentByPosition(i, attributes.pop())
+i += 1
+