]> git.mjollnir.org Git - moodle.git/commitdiff
Allow auth_ldap_connect() to take binddn ja bindpwd
authorpaca70 <paca70>
Mon, 18 Oct 2004 16:33:25 +0000 (16:33 +0000)
committerpaca70 <paca70>
Mon, 18 Oct 2004 16:33:25 +0000 (16:33 +0000)
 CVS: ----------------------------------------------------------------------

auth/ldap/lib.php

index 197b5bf6d646f3c1488e51c31edab0fe36b2ceba..e1dd0dcc15eb11c39cabf65fa77e11368b326603 100644 (file)
@@ -996,14 +996,26 @@ function auth_ldap_isgroupmember ($username='', $groupdns='') {
  *
  * @return connection result
  */
-function auth_ldap_connect(){
+function auth_ldap_connect($binddn='',$bindpwd=''){
 /// connects  and binds to ldap-server
 /// Returns connection result
 
     global $CFG;
     auth_ldap_init();
+    
+    //Select bind password, With empty values use
+    //ldap_bind_* variables or anonymous bind if ldap_bind_* are empty
+    if ($binddn == '' AND $bindpwd == '') {
+        if (!empty($CFG->ldap_bind_dn)){
+           $binddn = $CFG->ldap_bind_dn;
+        }
+        if (!empty($CFG->ldap_bind_pw)){
+           $bindpwd = $CFG->ldap_bind_pw;
+        }
+    }
+    
     $urls = explode(";",$CFG->ldap_host_url);
-
+        
     foreach ($urls as $server){
         $connresult = ldap_connect($server);
         //ldap_connect returns ALWAYS true
@@ -1012,9 +1024,9 @@ function auth_ldap_connect(){
             ldap_set_option($connresult, LDAP_OPT_PROTOCOL_VERSION, $CFG->ldap_version);
         }
 
-        if ($CFG->ldap_bind_dn){
+        if (!empty($binddn)){
             //bind with search-user
-            $bindresult=@ldap_bind($connresult, $CFG->ldap_bind_dn,$CFG->ldap_bind_pw);
+            $bindresult=@ldap_bind($connresult, $binddn,$bindpwd);
         } else {
             //bind anonymously
             $bindresult=@ldap_bind($connresult);