Skip to content

Commit 8323341

Browse files
author
blackhedd
committed
Supported BindRequest, SearchRequest, and UnbindRequest
1 parent fad144b commit 8323341

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

lib/net/ldap/pdu.rb

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ class LdapPduError < Exception; end
3636

3737
class LdapPdu
3838

39+
BindRequest = 0
3940
BindResult = 1
41+
UnbindRequest = 2
42+
SearchRequest = 3
4043
SearchReturnedData = 4
4144
SearchResult = 5
4245
ModifyResponse = 7
@@ -48,6 +51,7 @@ class LdapPdu
4851
attr_reader :msg_id, :app_tag
4952
attr_reader :search_dn, :search_attributes, :search_entry
5053
attr_reader :search_referrals
54+
attr_reader :search_parameters, :bind_parameters
5155

5256
#
5357
# initialize
@@ -74,7 +78,13 @@ class LdapPdu
7478
def initialize ber_object
7579
begin
7680
@msg_id = ber_object[0].to_i
77-
@app_tag = ber_object[1].ber_identifier - 0x60
81+
# Modified 25Nov06. We want to "un-decorate" the ber-identifier
82+
# of the incoming packet. Originally we did this by subtracting 0x60,
83+
# which ASSUMES the identifier is a constructed app-specific value.
84+
# But at least one value (UnbindRequest) is app-specific primitive.
85+
# So it makes more sense just to grab the bottom five bits.
86+
#@app_tag = ber_object[1].ber_identifier - 0x60
87+
@app_tag = ber_object[1].ber_identifier & 31
7888
rescue
7989
# any error becomes a data-format error
8090
raise LdapPduError.new( "ldap-pdu format error" )
@@ -98,6 +108,12 @@ def initialize ber_object
98108
parse_ldap_result ber_object[1]
99109
when ModifyRDNResponse
100110
parse_ldap_result ber_object[1]
111+
when SearchRequest
112+
parse_ldap_search_request ber_object[1]
113+
when BindRequest
114+
parse_bind_request ber_object[1]
115+
when UnbindRequest
116+
parse_unbind_request ber_object[1]
101117
else
102118
raise LdapPduError.new( "unknown pdu-type: #{@app_tag}" )
103119
end
@@ -213,6 +229,35 @@ def parse_controls sequence
213229
private :parse_controls
214230

215231

232+
# (provisional, must document)
233+
def parse_ldap_search_request sequence
234+
s = OpenStruct.new
235+
s.base_object,
236+
s.scope,
237+
s.deref_aliases,
238+
s.size_limit,
239+
s.time_limit,
240+
s.types_only,
241+
s.filter,
242+
s.attributes = sequence
243+
@search_parameters = s
244+
end
245+
246+
# (provisional, must document)
247+
def parse_bind_request sequence
248+
s = OpenStruct.new
249+
s.version,
250+
s.name,
251+
s.authentication = sequence
252+
@bind_parameters = s
253+
end
254+
255+
256+
# (provisional, must document)
257+
# UnbindRequest has no content so this is a no-op.
258+
def parse_unbind_request sequence
259+
end
260+
216261
end
217262

218263

0 commit comments

Comments
 (0)