Title: Multiple Base DNs
Last modified: August 22, 2016

---

# Multiple Base DNs

 *  [Dr. Ivo Bleylevens](https://wordpress.org/support/users/ibleylevens/)
 * (@ibleylevens)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/multiple-base-dns-2/)
 * **Dear developers,
 * Are you planning to support multiple Base DNs in a later version of this plugin?
   
   It will be pretty easy to support this feature because the ldap_search(…) function
   accepts arrays of connections and baseDNs as first two arguments. It requires
   only one more for-each-loop to loop through the resulting connections for the
   functions ldap_first_entry(…) and ldap_get_dn(…).
 * Im looking forward to your reply.
 * Kind regards,
    Ivo Maastricht University
 * [https://wordpress.org/plugins/wpdirauth/](https://wordpress.org/plugins/wpdirauth/)

Viewing 7 replies - 1 through 7 (of 7 total)

 *  [haoundz](https://wordpress.org/support/users/haoundz/)
 * (@haoundz)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/multiple-base-dns-2/#post-5558163)
 * Hi
    I tried something and it’s seems the multiples base dns work to me can you
   check on it
 * [https://github.com/haoundz/wpDirAuth](https://github.com/haoundz/wpDirAuth)
 * Kind regards
 * Henda Aoun
    junior programmer Montreal
 *  Thread Starter [Dr. Ivo Bleylevens](https://wordpress.org/support/users/ibleylevens/)
 * (@ibleylevens)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/multiple-base-dns-2/#post-5558164)
 * **Dear Handa,**
 * I had a quick look at your code and I do think there is one part missing.
 * You are now passing an array of baseDNs to ldap_search().
    The result of this
   is also an array of connectionIDs. Next you have to check in an extra loop with
   ldap_count_entries() which of these connections is the right one to take into
   the next step: ldap_first_entry().
 * At least that is how I implemented it. And it works. See:
 *     ```
       if ($preBindUser && $preBindPassword) {
       /**
        * Use case 1: Servers requiring pre-binding with admin defined
        * credentials to search for the user's full DN before attempting
        * to login.
        * @see http://dev.wp-plugins.org/ticket/681
        */
       if ( $isPreBound = wpDirAuth_bindTest($connection, $preBindUser, $preBindPassword,$baseDn) === true )
       {   $connections[]=$connection;
           $connections[]=$connection;
           $baseDns[]=$baseDn;			//DN1
           $baseDns[]="EXTRA DN INFO";		//DN2
           if ( ($results = @ldap_search($connections, $baseDns, $filterQuery, $returnKeys)) !== false )
           {   foreach ($results as $conn)
               {   if(ldap_count_entries($connection, $conn)>0)
                   {   $results = $conn;
                       break;
                   }
               };
               if ( ($userDn = @ldap_get_dn($connection, ldap_first_entry($connection, $results))) !== false )
               {   if ( ($isBound = wpDirAuth_bindTest($connection, $userDn, $password,$baseDn)) === true )
                   {  $isLoggedIn = true; // valid server, valid login, move on
                      break; // valid server, valid login, move on
                   }
               }
           }
       }
       }
       ```
   
 * Kind regards,
    Ivo
 *  [haoundz](https://wordpress.org/support/users/haoundz/)
 * (@haoundz)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/multiple-base-dns-2/#post-5558165)
 * Thank you for your answer
    I know but i tested the code and it’s worked perfectly
   that’s weird but true ,you can test it and tell me the result . Kind regards
 *  [haoundz](https://wordpress.org/support/users/haoundz/)
 * (@haoundz)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/multiple-base-dns-2/#post-5558186)
 * I figured out why it’s work without adding a loop , because of the function
    
   ldap_search support using an array of base DNs you can read more about it on 
   [http://php.net/manual/en/function.ldap-search.php](http://php.net/manual/en/function.ldap-search.php)
 *  Thread Starter [Dr. Ivo Bleylevens](https://wordpress.org/support/users/ibleylevens/)
 * (@ibleylevens)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/multiple-base-dns-2/#post-5558189)
 * All cool but sorry doesn’t work on my side.!
 * The function ldap_search indeed accepts an array of baseDNs as 2nd argument but
   then it also needs an array of connections as first argument. Without such an
   array as first argument it doesn’t work at all.
 * Secondly, ldap_search returns an array of connections (Resource IDs #xxx) and
   you need to pass only ONE of them into the ldap_first_entry method. Otherwise
   it won’t work either, which means you need a while loop to investigate which 
   connection contains usefull information. Moreover, ldap_first_entry only accepts
   non-array arguments.
 * So I can only get your code working by passing the following into ldap_search:
   
   $connections[]=$connection; $connections[]=$connection; ldap_search($connections,
   $baseDn, …);//2 array arguments; same size.
 * And then before executing ‘ldap_first_entry($connection, $results)’ do this:
   
   $results=$results[0] or $results=$results[1] or…(this is where you need the for
   loop to search for useful information, e.g., with ldap_count_entries).
 * Exactly this is also described on the link you showed in the previous post; see
   section ‘Example of parallel search’.
 * Kind regards,
    Ivo
 *  Plugin Author [Paul Gilzow](https://wordpress.org/support/users/gilzow/)
 * (@gilzow)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/multiple-base-dns-2/#post-5558190)
 * > Are you planning to support multiple Base DNs in a later version of this plugin?
 * As of right now, no. Can you give me some more background on your specific situation
   and what you are needing to accomplish?
 *  Thread Starter [Dr. Ivo Bleylevens](https://wordpress.org/support/users/ibleylevens/)
 * (@ibleylevens)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/multiple-base-dns-2/#post-5558191)
 * I needed a authentication method with non-anonymous pre-binding prior to LDAP
   login using multiple baseDNs. I have my code working now for my own purposes (
   see my full code above).
 * Kind regards,
    Ivo

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Multiple Base DNs’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/wpdirauth.svg)
 * [wpDirAuth](https://wordpress.org/plugins/wpdirauth/)
 * [Support Threads](https://wordpress.org/support/plugin/wpdirauth/)
 * [Active Topics](https://wordpress.org/support/plugin/wpdirauth/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wpdirauth/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wpdirauth/reviews/)

## Tags

 * [multiple](https://wordpress.org/support/topic-tag/multiple/)

 * 7 replies
 * 3 participants
 * Last reply from: [Dr. Ivo Bleylevens](https://wordpress.org/support/users/ibleylevens/)
 * Last activity: [11 years, 6 months ago](https://wordpress.org/support/topic/multiple-base-dns-2/#post-5558191)
 * Status: not resolved