lib/net/ldap.rb in net-ldap-0.2.2 vs lib/net/ldap.rb in net-ldap-0.3.0
- old
+ new
@@ -239,11 +239,11 @@
# operation (typically binding first) and then disconnect from the server.
# The exception is Net::LDAP#open, which makes a connection to the server
# and then keeps it open while it executes a user-supplied block.
# Net::LDAP#open closes the connection on completion of the block.
class Net::LDAP
- VERSION = "0.2.2"
+ VERSION = "0.3.0"
class LdapError < StandardError; end
SearchScope_BaseObject = 0
SearchScope_SingleLevel = 1
@@ -315,10 +315,11 @@
0 => "Success",
1 => "Operations Error",
2 => "Protocol Error",
3 => "Time Limit Exceeded",
4 => "Size Limit Exceeded",
+ 10 => "Referral",
12 => "Unavailable crtical extension",
14 => "saslBindInProgress",
16 => "No Such Attribute",
17 => "Undefined Attribute Type",
20 => "Attribute or Value Exists",
@@ -617,11 +618,12 @@
unless args[:ignore_server_caps]
args[:paged_searches_supported] = paged_searches_supported?
end
args[:base] ||= @base
- result_set = (args and args[:return_result] == false) ? nil : []
+ return_result_set = args[:return_result] != false
+ result_set = return_result_set ? [] : nil
if @open_connection
@result = @open_connection.search(args) { |entry|
result_set << entry if result_set
yield entry if block_given?
@@ -640,11 +642,15 @@
ensure
conn.close if conn
end
end
- @result == 0 and result_set
+ if return_result_set
+ @result == 0 ? result_set : nil
+ else
+ @result == 0
+ end
end
# #bind connects to an LDAP server and requests authentication based on
# the <tt>:auth</tt> parameter passed to #open or #new. It takes no
# parameters.
@@ -1318,11 +1324,11 @@
# can block forever. That's because we keep reading results until we get a
# type-5 packet, which might never come. We need to support the time-limit
# in the protocol.
#++
def search(args = {})
- search_filter = (args && args[:filter]) ||
+ search_filter = (args && args[:filter]) ||
Net::LDAP::Filter.eq("objectclass", "*")
search_filter = Net::LDAP::Filter.construct(search_filter) if search_filter.is_a?(String)
search_base = (args && args[:base]) || "dc=example, dc=com"
search_attributes = ((args && args[:attributes]) || []).map { |attr| attr.to_s.to_ber}
return_referrals = args && args[:return_referrals] == true
@@ -1387,13 +1393,13 @@
Net::LDAP::LdapControls::PagedResults.to_ber,
# Criticality MUST be false to interoperate with normal LDAPs.
false.to_ber,
rfc2696_cookie.map{ |v| v.to_ber}.to_ber_sequence.to_s.to_ber
].to_ber_sequence if paged_searches_supported
- controls = controls.to_ber_contextspecific(0)
+ controls = controls.empty? ? nil : controls.to_ber_contextspecific(0)
- pkt = [next_msgid.to_ber, request, controls].to_ber_sequence
+ pkt = [next_msgid.to_ber, request, controls].compact.to_ber_sequence
@conn.write pkt
result_code = 0
controls = []
@@ -1411,10 +1417,17 @@
end
end
when 5 # search-result
result_code = pdu.result_code
controls = pdu.result_controls
+ if return_referrals && result_code == 10
+ if block_given?
+ se = Net::LDAP::Entry.new
+ se[:search_referrals] = (pdu.search_referrals || [])
+ yield se
+ end
+ end
break
else
raise Net::LDAP::LdapError, "invalid response-type in search: #{pdu.app_tag}"
end
end
@@ -1519,18 +1532,20 @@
#++
def rename args
old_dn = args[:olddn] or raise "Unable to rename empty DN"
new_rdn = args[:newrdn] or raise "Unable to rename to empty RDN"
delete_attrs = args[:delete_attributes] ? true : false
- new_superior = args[:new_superior]
+ new_superior = args[:new_superior]
- request = [old_dn.to_ber, new_rdn.to_ber, delete_attrs.to_ber]
- request << new_superior.to_ber unless new_superior == nil
-
+ request = [old_dn.to_ber, new_rdn.to_ber, delete_attrs.to_ber]
+ request << new_superior.to_ber unless new_superior == nil
+
pkt = [next_msgid.to_ber, request.to_ber_appsequence(12)].to_ber_sequence
@conn.write pkt
- (be = @conn.read_ber(AsnSyntax)) && (pdu = LdapPdu.new( be )) && (pdu.app_tag == 13) or raise LdapError.new( "response missing or invalid" )
+ (be = @conn.read_ber(Net::LDAP::AsnSyntax)) &&
+ (pdu = Net::LDAP::PDU.new( be )) && (pdu.app_tag == 13) or
+ raise Net::LDAP::LdapError.new( "response missing or invalid" )
pdu.result_code
end
#--
# TODO, need to support a time limit, in case the server fails to respond.