@@ -110,11 +110,26 @@ def handle_search_request pdu
110110 end
111111
112112 treebase = pdu [ 1 ] [ 0 ]
113- if treebase != "dc=bigdomain ,dc=com"
113+ if treebase != "dc=bayshorenetworks ,dc=com"
114114 send_ldap_response 5 , pdu [ 0 ] . to_i , 32 , "" , "unknown treebase"
115115 return
116116 end
117117
118+ msgid = pdu [ 0 ] . to_i . to_ber
119+
120+ $ldif. each { |dn , entry |
121+
122+ attrs = [ ]
123+ entry . each { |k , v |
124+ attrvals = v . map { |v1 | v1 . to_ber } . to_ber_set
125+ attrs << [ k . to_ber , attrvals ] . to_ber_sequence
126+ }
127+
128+ appseq = [ dn . to_ber , attrs . to_ber_sequence ] . to_ber_appsequence ( 4 )
129+ pkt = [ msgid . to_ber , appseq ] . to_ber_sequence
130+ send_data pkt
131+ }
132+
118133 # pdu[1][7] is the attributes. It's an empty array to signify ALL attributes.
119134 puts "WARNING, not interpreting attributes specifier"
120135=begin
@@ -131,6 +146,7 @@ def handle_search_request pdu
131146 }
132147=end
133148
149+ =begin
134150 send_data( [
135151 pdu[0].to_i.to_ber, [
136152 "abcdefghijklmnopqrstuvwxyz".to_ber, [
@@ -166,6 +182,7 @@ def handle_search_request pdu
166182 ].to_ber_sequence
167183 ].to_ber_appsequence(4)
168184 ].to_ber_sequence)
185+ =end
169186
170187 send_ldap_response 5 , pdu [ 0 ] . to_i , 0 , "" , "Was that what you wanted?"
171188 end
@@ -177,6 +194,28 @@ def send_ldap_response pkt_tag, msgid, code, dn, text
177194end
178195
179196
197+ #------------------------------------------------
198+
199+ # Rather bogus, a global method, which reads a HARDCODED filename
200+ # parses out LDIF data. It will be used to serve LDAP queries out of this server.
201+ #
202+ def load_test_data
203+ ary = File . readlines ( "./testdata.ldif" )
204+ hash = { }
205+ while line = ary . shift and line . chomp!
206+ if line =~ /^dn:[\s ]*/i
207+ dn = $'
208+ hash [ dn ] = { }
209+ while attr = ary . shift and attr . chomp! and attr =~ /^([\w ]+)[\s ]*:[\s ]*/
210+ hash [ dn ] [ $1. downcase ] ||= [ ]
211+ hash [ dn ] [ $1. downcase ] << $'
212+ end
213+ end
214+ end
215+ hash
216+ end
217+
218+
180219#------------------------------------------------
181220
182221if __FILE__ == $0
@@ -190,6 +229,8 @@ def send_ldap_response pkt_tag, msgid, code, dn, text
190229 $logger. info "adding ../lib to loadpath, to pick up dev version of Net::LDAP."
191230 $:. unshift "../lib"
192231
232+ $ldif = load_test_data
233+
193234 require 'net/ldap'
194235
195236 EventMachine . run {
0 commit comments