--- LDAP_orig.php	2005-10-09 18:34:41.000000000 +0200
+++ LDAP.php	2005-10-09 19:21:37.000000000 +0200
@@ -54,8 +54,10 @@
  * userdn:      gets prepended to basedn when searching for user
  * userattr:    the user attribute to search for (default: uid)
  * useroc:      objectclass of user (for the search filter)
  *              (default: posixAccount)
+ * bindattr:    the user attribute to bind on in the authentication
+ *              fase (default: dn)
  * groupdn:     gets prepended to basedn when searching for group
  * groupattr  : the group attribute to search for (default: cn)
  * groupoc    : objectclass of group (for the search filter)
  *              (default: groupOfUniqueNames)
@@ -296,8 +298,9 @@
         $this->options['basedn']      = '';
         $this->options['userdn']      = '';
         $this->options['userattr']    = "uid";
         $this->options['useroc']      = 'posixAccount';
+        $this->options['bindattr']    = 'dn';
         $this->options['groupdn']     = '';
         $this->options['groupattr']   = 'cn';
         $this->options['groupoc']     = 'groupOfUniqueNames';
         $this->options['memberattr']  = 'uniqueMember';
@@ -358,9 +361,9 @@
         }
         $search_basedn .= $this->options['basedn'];
         
         // make functions params array
-        $func_params = array($this->conn_id, $search_basedn, $filter, array($this->options['userattr']));
+        $func_params = array($this->conn_id, $search_basedn, $filter, array($this->options['userattr'], $this->options['bindattr']));
 
         $this->_debug("Searching with $filter in $search_basedn", __LINE__);
 
         // search
@@ -371,9 +374,12 @@
             $this->_debug('User was found', __LINE__);
             
             // then get the user dn
             $entry_id = ldap_first_entry($this->conn_id, $result_id);
-            $user_dn  = ldap_get_dn($this->conn_id, $entry_id);
+            $this->_debug('Using attribute to bind to: '.$this->options['bindattr'], __LINE__);
+            $user_dns = ldap_get_values($this->conn_id, $entry_id, $this->options['bindattr']);
+            $user_dn = $user_dns[0];
+
 
             ldap_free_result($result_id);
 
             // need to catch an empty password as openldap seems to return TRUE
