@@ -50,8 +50,11 @@ class LdapPdu
50
50
#
51
51
# initialize
52
52
# An LDAP PDU always looks like a BerSequence with
53
- # two elements: an integer (message-id number), and
53
+ # at least two elements: an integer (message-id number), and
54
54
# an application-specific sequence.
55
+ # Some LDAPv3 packets also include an optional
56
+ # third element, which is a sequence of "controls"
57
+ # (See RFC 2251, section 4.1.12).
55
58
# The application-specific tag in the sequence tells
56
59
# us what kind of packet it is, and each kind has its
57
60
# own format, defined in RFC-1777.
@@ -62,6 +65,10 @@ class LdapPdu
62
65
# it remains to be seen whether there are servers out
63
66
# there that will not work well with our approach.
64
67
#
68
+ # Added a controls-processor to SearchResult.
69
+ # Didn't add it everywhere because it just _feels_
70
+ # like it will need to be refactored.
71
+ #
65
72
def initialize ber_object
66
73
begin
67
74
@msg_id = ber_object [ 0 ] . to_i
@@ -78,6 +85,7 @@ def initialize ber_object
78
85
parse_search_return ber_object [ 1 ]
79
86
when SearchResult
80
87
parse_ldap_result ber_object [ 1 ]
88
+ parse_controls ( ber_object [ 2 ] ) if ber_object [ 2 ]
81
89
when ModifyResponse
82
90
parse_ldap_result ber_object [ 1 ]
83
91
when AddResponse
@@ -102,7 +110,6 @@ def result_code code = :resultCode
102
110
end
103
111
104
112
105
- private
106
113
107
114
#
108
115
# parse_ldap_result
@@ -146,6 +153,28 @@ def parse_search_return sequence
146
153
@search_attributes [ seq [ 0 ] . downcase . intern ] = seq [ 1 ]
147
154
}
148
155
end
156
+ private :parse_ldap_result
157
+
158
+
159
+ # Per RFC 2251, an LDAP "control" is a sequence of tuples, each consisting
160
+ # of an OID, a boolean criticality flag defaulting FALSE, and an OPTIONAL
161
+ # Octet String. If only two fields are given, the second one may be
162
+ # either criticality or data, since criticality has a default value.
163
+ # Someday we may want to come back here and add support for some of
164
+ # more-widely used controls. RFC-2696 is a good example.
165
+ #
166
+ def parse_controls sequence
167
+ @ldap_controls = sequence . map do |control |
168
+ o = OpenStruct . new
169
+ o . oid , o . criticality , o . value = control [ 0 ] , control [ 1 ] , control [ 2 ]
170
+ if o . criticality and o . criticality . is_a? ( String )
171
+ o . value = o . criticality
172
+ o . criticality = false
173
+ end
174
+ o
175
+ end
176
+ end
177
+ private :parse_controls
149
178
150
179
151
180
end
0 commit comments