whimsical-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sam Ruby <ru...@apache.org>
Subject [whimsy.git] [1/1] Commit b384c88: force reset when binding with a password
Date Mon, 15 Feb 2016 15:54:25 GMT
Commit b384c880c2ffe59cbfdec12e65a45ee6e6119592:
    force reset when binding with a password


Branch: refs/heads/master
Author: Sam Ruby <rubys@intertwingly.net>
Committer: Sam Ruby <rubys@intertwingly.net>
Pusher: rubys <rubys@apache.org>

------------------------------------------------------------
lib/whimsy/asf/ldap.rb                                       | +++++++++ -----
------------------------------------------------------------
26 changes: 17 additions, 9 deletions.
------------------------------------------------------------


diff --git a/lib/whimsy/asf/ldap.rb b/lib/whimsy/asf/ldap.rb
index 5f3aa61..b5243c3 100644
--- a/lib/whimsy/asf/ldap.rb
+++ b/lib/whimsy/asf/ldap.rb
@@ -71,7 +71,7 @@ def self.puppet_ldapservers
     end
 
     # connect to LDAP
-    def self.connect
+    def self.connect(test = true)
       # Try each host at most once
       hosts.length.times do
         host = next_host
@@ -87,7 +87,7 @@ def self.connect
           end
 
           # test the connection
-          ldap.bind
+          ldap.bind if test
 
           # save the host
           @host = host
@@ -106,8 +106,9 @@ def self.connect
   end
 
   # backwards compatibility for tools that called this interface
-  def self.init_ldap
-    @ldap ||= ASF::LDAP.connect
+  def self.init_ldap(reset = false)
+    @ldap = nil if reset
+    @ldap ||= ASF::LDAP.connect(!reset)
   end
 
   # determine where ldap.conf resides
@@ -144,7 +145,7 @@ def self.search_one(base, filter, attrs=nil)
         raise
       else
         Wunderbar.warn "[#{target}] => #{re.inspect} for #{cmd}, retrying ..."
-        @ldap.unbind rescue nil
+        @ldap.unbind if @ldap.bound? rescue nil
         @ldap = nil # force new connection
         sleep 1
         retry
@@ -435,12 +436,14 @@ def remove(people)
       people = Array(people).map(&:id)
       mod = ::LDAP::Mod.new(::LDAP::LDAP_MOD_DELETE, 'memberUid', people)
       ASF.ldap.modify(self.dn, [mod])
+      @members = nil
     end
 
     def add(people)
       people = Array(people).map(&:dn)
       mod = ::LDAP::Mod.new(::LDAP::LDAP_MOD_ADD, 'memberUid', people)
       ASF.ldap.modify(self.dn, [mod])
+      @members = nil
     end
   end
 
@@ -485,12 +488,14 @@ def remove(people)
       people = Array(people).map(&:dn)
       mod = ::LDAP::Mod.new(::LDAP::LDAP_MOD_DELETE, 'member', people)
       ASF.ldap.modify(self.dn, [mod])
+      @members = nil
     end
 
     def add(people)
       people = Array(people).map(&:dn)
       mod = ::LDAP::Mod.new(::LDAP::LDAP_MOD_ADD, 'member', people)
       ASF.ldap.modify(self.dn, [mod])
+      @members = nil
     end
   end
 
@@ -535,12 +540,14 @@ def remove(people)
       people = Array(people).map(&:dn)
       mod = ::LDAP::Mod.new(::LDAP::LDAP_MOD_DELETE, 'member', people)
       ASF.ldap.modify(self.dn, [mod])
+      @members = nil
     end
 
     def add(people)
       people = Array(people).map(&:dn)
       mod = ::LDAP::Mod.new(::LDAP::LDAP_MOD_ADD, 'member', people)
       ASF.ldap.modify(self.dn, [mod])
+      @members = nil
     end
   end
 
@@ -549,12 +556,13 @@ def self.bind(user, password, &block)
       dn = ASF::Person.new(user).dn
       raise ::LDAP::ResultError.new('Unknown user') unless dn
 
-      ASF.ldap.unbind rescue nil
+      ASF.ldap.unbind if ASF.ldap.bound? rescue nil
+      ldap = ASF.init_ldap(true)
       if block
-        ASF.ldap.bind(dn, password, &block)
-        ASF.init_ldap
+        ldap.bind(dn, password, &block)
+        ASF.init_ldap(true)
       else
-        ASF.ldap.bind(dn, password)
+        ldap.bind(dn, password)
       end
     end
 

Mime
View raw message