@@ -103,6 +103,20 @@ def handle_bind_request pdu
103103 end
104104 end
105105
106+
107+
108+ #--
109+ # Search Response ::=
110+ # CHOICE {
111+ # entry [APPLICATION 4] SEQUENCE {
112+ # objectName LDAPDN,
113+ # attributes SEQUENCE OF SEQUENCE {
114+ # AttributeType,
115+ # SET OF AttributeValue
116+ # }
117+ # },
118+ # resultCode [APPLICATION 5] LDAPResult
119+ # }
106120 def handle_search_request pdu
107121 unless @authenticated
108122 send_ldap_response 5 , pdu [ 0 ] . to_i , 50 , "" , "Who did you say you were?"
@@ -117,76 +131,36 @@ def handle_search_request pdu
117131
118132 msgid = pdu [ 0 ] . to_i . to_ber
119133
134+ # pdu[1][7] is the list of requested attributes.
135+ # If it's an empty array, that means that *all* attributes were requested.
136+ requested_attrs = if pdu [ 1 ] [ 7 ] . length > 0
137+ pdu [ 1 ] [ 7 ] . map { |a | a . downcase }
138+ else
139+ :all
140+ end
141+
142+
120143 $ldif. each { |dn , entry |
121144
122145 attrs = [ ]
123146 entry . each { |k , v |
124- attrvals = v . map { |v1 | v1 . to_ber } . to_ber_set
125- attrs << [ k . to_ber , attrvals ] . to_ber_sequence
147+ if requested_attrs == :all or requested_attrs . include? ( k . downcase )
148+ attrvals = v . map { |v1 | v1 . to_ber } . to_ber_set
149+ attrs << [ k . to_ber , attrvals ] . to_ber_sequence
150+ end
126151 }
127152
128153 appseq = [ dn . to_ber , attrs . to_ber_sequence ] . to_ber_appsequence ( 4 )
129154 pkt = [ msgid . to_ber , appseq ] . to_ber_sequence
130155 send_data pkt
131156 }
132157
133- # pdu[1][7] is the attributes. It's an empty array to signify ALL attributes.
134- puts "WARNING, not interpreting attributes specifier"
135- =begin
136- Search Response ::=
137- CHOICE {
138- entry [APPLICATION 4] SEQUENCE {
139- objectName LDAPDN,
140- attributes SEQUENCE OF SEQUENCE {
141- AttributeType,
142- SET OF AttributeValue
143- }
144- },
145- resultCode [APPLICATION 5] LDAPResult
146- }
147- =end
148-
149- =begin
150- send_data( [
151- pdu[0].to_i.to_ber, [
152- "abcdefghijklmnopqrstuvwxyz".to_ber, [
153-
154- [
155- "mail".to_ber, ["aaa".to_ber, "bbb".to_ber, "ccc".to_ber].to_ber_set
156- ].to_ber_sequence,
157- [
158- "objectclass".to_ber, ["111".to_ber, "222".to_ber, "333".to_ber].to_ber_set
159- ].to_ber_sequence,
160- [
161- "cn".to_ber, ["CNCNCNCN".to_ber].to_ber_set
162- ].to_ber_sequence,
163-
164- ].to_ber_sequence
165- ].to_ber_appsequence(4)
166- ].to_ber_sequence)
167-
168- send_data( [
169- pdu[0].to_i.to_ber, [
170- "ABCDEFGHIJKLMNOPQRSTUVWXYZ".to_ber, [
171-
172- [
173- "mail".to_ber, ["aaa".to_ber, "bbb".to_ber, "ccc".to_ber].to_ber_set
174- ].to_ber_sequence,
175- [
176- "objectclass".to_ber, ["111".to_ber, "222".to_ber, "333".to_ber].to_ber_set
177- ].to_ber_sequence,
178- [
179- "cn".to_ber, ["CNCNCNCN".to_ber].to_ber_set
180- ].to_ber_sequence,
181-
182- ].to_ber_sequence
183- ].to_ber_appsequence(4)
184- ].to_ber_sequence)
185- =end
186158
187159 send_ldap_response 5 , pdu [ 0 ] . to_i , 0 , "" , "Was that what you wanted?"
188160 end
189161
162+
163+
190164 def send_ldap_response pkt_tag , msgid , code , dn , text
191165 send_data ( [ msgid . to_ber , [ code . to_ber , dn . to_ber , text . to_ber ] . to_ber_appsequence ( pkt_tag ) ] . to_ber )
192166 end
0 commit comments