我正在尝试使用net-ldap库为ruby查询ldap服务器以获取任何组的详细信息
require 'rubygems'
require 'net/ldap'
username = "user1"
password = "pass1"
host = 'server.address'
ldap = Net::LDAP.new :host => host, :port => 389
ldap.auth username, password
filter = Net::LDAP::Filter.eq("cn", "*group*")
ldap.search(:base => treebase, :filter => filter, :return_result => true) do |entry|
puts "DN: #{entry.dn}"
entry.each do |attr, values|
puts ".......#{attr}:"
values.each do |value|
puts " #{value}"
end
end
end
我获得了有关该组的详细信息,但没有获得该组的所有者。
有什么问题吗?以及如何做到
答案 0 :(得分:7)
找到访问LDAP服务器提供的所有属性的正确方法
require 'rubygems'
require 'net/ldap'
ldap = Net::LDAP.new :host => 'server',
:port => 389,
:auth => {
:method => :simple,
:username => "user",
:password => "pass"
}
group_name_filter = Net::LDAP::Filter.eq( "cn", "la lakers" )
group_type_filter = Net::LDAP::Filter.eq( "objectclass", "basketball" )
filter = group_name_filter & group_type_filter
treebase = "dc=example,dc=com"
attrs = ["dn", "cn", "mail", "displayname", "listowner", "members"]
ldap.search( :base => treebase, :filter => filter, :attributes => attrs, :return_result => true ) do |entry|
puts "DN: #{entry.dn}"
entry.each do |attribute, values|
puts " #{attribute}:"
values.each do |value|
puts " --->#{value}"
end
end
end
p ldap.get_operation_result
<强>感谢强>