ruby-net-ldap
ruby-net-ldap copied to clipboard
Simple search going wrong (Base DN query)
me@host ~ # gem list | grep ldap
net-ldap (0.16.1)
ruby-ldap (0.9.19)
me@host ~ # ruby --version
ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-linux]
I try to execute:
ldapsearch -H ldap://host-0/ -x -s base -b "" -LLL "+"
with
require 'net-ldap'
Net::LDAP.open(:host => 'host-0', :port => 389) do |ldap|
ldap.search(:base => '', :attributes => 'namingContexts', :scope => Net::LDAP::SearchScope_BaseObject)
puts entry
puts "DN: #{entry.dn}"
entry.each do |attr, values|
puts ".......#{attr}:"
values.each do |value|
puts " #{value}"
end
end
end
end
With slapd outputs, respectively:
ldapsearch -x -l 5 -LLL -H ldap://host-0 -b '' -s base namingContexts
5bd1a2bc conn=1005 fd=16 ACCEPT from IP=192.168.206.171:33374 (IP=0.0.0.0:389)
5bd1a2bc conn=1005 op=0 BIND dn="" method=128
5bd1a2bc conn=1005 op=0 RESULT tag=97 err=0 text=
5bd1a2bc conn=1005 op=1 SRCH base="" scope=0 deref=0 filter="(objectClass=*)"
5bd1a2bc conn=1005 op=1 SRCH attr=namingContexts
5bd1a2bc conn=1005 op=1 SEARCH RESULT tag=101 err=0 nentries=1 text=
5bd1a2bc conn=1005 op=2 UNBIND
5bd1a2bc conn=1005 fd=16 closed
vs
Net::LDAP.open(:host => 'host-0', :port => 389) do |ldap|
ldap.search(:base => '', :attributes => 'namingContexts', :scope => Net::LDAP::SearchScope_BaseObject) do |entry|
puts entry
puts "DN: '#{entry.dn}'"
entry.each do |attr, values|
puts "# #{attr}:"
values.each do |value|
puts " #{value}"
end
end
end
end
5bd1a2c6 conn=1007 fd=16 ACCEPT from IP=192.168.206.171:33512 (IP=0.0.0.0:389)
5bd1a2c6 conn=1007 op=0 BIND dn="" method=128
5bd1a2c6 conn=1007 op=0 RESULT tag=97 err=0 text=
5bd1a2c6 conn=1007 op=1 SRCH base="" scope=0 deref=0 filter="(objectClass=*)"
5bd1a2c6 conn=1007 op=1 SRCH attr=altServer namingContexts supportedCapabilities supportedControl supportedExtension supportedFeatures supportedLdapVersion supportedSASLMechanisms
5bd1a2c6 conn=1007 op=1 SEARCH RESULT tag=101 err=0 nentries=1 text=
5bd1a2c6 conn=1007 op=2 SRCH base="" scope=0 deref=0 filter="(objectClass=*)"
5bd1a2c6 conn=1007 op=2 SRCH attr=namingContexts
5bd1a2c6 conn=1007 op=2 SEARCH RESULT tag=101 err=0 nentries=1 text=
5bd1a2c6 conn=1007 fd=16 closed (connection lost)
Why does Ruby give me extra
5bd1a2bf conn=1006 op=1 SRCH attr=altServer namingContexts supportedCapabilities supportedControl supportedExtension supportedFeatures supportedLdapVersion supportedSASLMechanisms
and
5bd1a2c6 conn=1007 op=2 SRCH base="" scope=0 deref=0 filter="(objectClass=*)"
5bd1a2c6 conn=1007 op=2 SRCH attr=namingContexts
5bd1a2c6 conn=1007 op=2 SEARCH RESULT tag=101 err=0 nentries=1 text=
5bd1a2c6 conn=1007 fd=16 closed (connection lost)
instead of
5abe4cf6 conn=1063 op=2 UNBIND
5abe4cf6 conn=1063 fd=17 closed
and, fails to unbind properly?
5bd1a2c6 conn=1007 fd=16 closed (connection lost)
?