lib/active_ldap/adapter/base.rb in activeldap-1.2.2 vs lib/active_ldap/adapter/base.rb in activeldap-1.2.3

- old
+ new

@@ -129,15 +129,19 @@ 'ldapSyntaxes', #'extendedAttributeInfo', # if we need RANGE-LOWER/UPPER. ] base ||= root_dse_values('subschemaSubentry', options)[0] base ||= 'cn=schema' - dn, attributes = search(:base => base, - :scope => :base, - :filter => '(objectClass=subschema)', - :attributes => attrs).first - Schema.new(attributes) + schema = nil + search(:base => base, + :scope => :base, + :filter => '(objectClass=subschema)', + :attributes => attrs, + :limit => 1) do |dn, attributes| + schema = Schema.new(attributes) + end + schema || Schema.new([]) end end def naming_contexts root_dse_values('namingContexts') @@ -155,31 +159,22 @@ base = options[:base] limit = options[:limit] || 0 limit = nil if limit <= 0 attrs = attrs.to_a # just in case - - values = [] - callback = Proc.new do |value, block| - value = block.call(value) if block - values << value - end - base = ensure_dn_string(base) begin operation(options) do - yield(base, scope, filter, attrs, limit, callback) + yield(base, scope, filter, attrs, limit) end rescue LdapError::NoSuchObject, LdapError::InvalidDnSyntax # Do nothing on failure @logger.info do args = [$!.class, $!.message, filter, attrs.inspect] _("Ignore error %s(%s): filter %s: attributes: %s") % args end end - - values end def delete(targets, options={}) targets = [targets] unless targets.is_a?(Array) return if targets.empty? @@ -316,11 +311,11 @@ def with_timeout(try_reconnect=true, options={}, &block) n_retries = 0 retry_limit = options[:retry_limit] || @retry_limit begin - Timeout.alarm(@timeout, &block) + do_in_timeout(@timeout, &block) rescue Timeout::Error => e @logger.error {_('Requested action timed out.')} if @retry_on_timeout and retry_limit < 0 and n_retries <= retry_limit if connecting? retry @@ -331,10 +326,14 @@ @logger.error {e.message} raise TimeoutError, e.message end end + def do_in_timeout(timeout, &block) + Timeout.alarm(timeout, &block) + end + def sasl_bind(bind_dn, options={}) # Get all SASL mechanisms mechanisms = operation(options) do root_dse_values("supportedSASLMechanisms") end @@ -501,11 +500,11 @@ when Numeric, DN value = value.to_s when Time value = Schema::GeneralizedTime.new.normalize_value(value) end - value.gsub(/(?:[()\\\0]|\*\*?)/) do |s| + value.gsub(/(?:[:()\\\0]|\*\*?)/) do |s| if s == "*" s else s = "*" if s == "**" if s.respond_to?(:getbyte) @@ -620,24 +619,27 @@ retry_limit < 0 or reconnect_attempts <= retry_limit end def root_dse_values(key, options={}) - dse = root_dse([key], options)[0] + dse = root_dse([key], options) return [] if dse.nil? normalized_key = key.downcase dse.each do |_key, _value| return _value if _key.downcase == normalized_key end [] end def root_dse(attrs, options={}) + found_attributes = nil search(:base => "", :scope => :base, - :attributes => attrs).collect do |dn, attributes| - attributes + :attributes => attrs, + :limit => 1) do |dn, attributes| + found_attributes = attributes end + found_attributes end def construct_uri(host, port, ssl) protocol = ssl ? "ldaps" : "ldap" URI.parse("#{protocol}://#{host}:#{port}").to_s