3

我正在尝试使用 ruby​​ 的 net-ldap 库查询 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

我获得了有关该组的详细信息,但没有获得该组的所有者。

知道什么是错的吗?以及如何做

4

1 回答 1

10

找到了访问 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

谢谢

于 2012-07-18T12:18:11.280 回答