#!/usr/bin/ruby -w
require 'ldap'
$HOST = '192.168.18.65'
$PORT = LDAP::LDAP_PORT
base = 'ou=users,dc=case,dc=org'
scope = LDAP::LDAP_SCOPE_SUBTREE
filter = '(&(objectClass=caseAccount)([email protected]))'
attrs = ['cn']
conn = LDAP::Conn.new($HOST, $PORT)
conn.bind('cn=Manager,dc=case,dc=org','case',LDAP::LDAP_AUTH_SIMPLE)
conn.perror("bind")
begin
conn.search(base, scope, filter ,attrs) { |entry|
# print distinguished name
p entry.dn
# print all attribute names
p entry.attrs
# print values of attribute 'sn'
p entry.vals('cn')
# print entry as Hash
p entry.to_hash
}
rescue LDAP::ResultError
conn.perror("search")
exit
end
conn.perror("search")
conn.unbind
报了如下错误就是bind方法那行。
deal_ldap.rb:14:in `bind': Protocol error (LDAP::ResultError)
from deal_ldap.rb:14:in `<main>'
报错了,不知道为啥。找不到原因,bind方法应该就是这样的吧??或者有好的方法吗??先谢谢啦。