--- /usr/ports/www/horde/work/horde-3.0.4/lib/Horde/Prefs/ldap.php      Tue Mar 29 06:00:00 2005
+++ ldap.php    Fri Apr 15 14:38:36 2005
@@ -178,37 +178,41 @@
             return false;
         }
 
-        /* Define the DN of the current user */
-        $this->_dn = sprintf('%s=%s,%s', $this->_params['uid'][0],
-                            $this->_user,
-                            $this->_params['basedn']);
-
-        /* And the DN of the authenticating user (may be the same as above) */
-        if (!empty($this->_params['rootdn'])) {
-            $bind_dn = $this->_params['rootdn'];
-        } else {
-            $bind_dn = sprintf('%s=%s,%s', $this->_params['uid'][0],
-                               $this->_params['username'],
-                               $this->_params['basedn']);
-        }
-
         /* Store the connection handle at the instance level. */
         $this->_connection = $conn;
         $this->_connected = true;
 
-        /* Bind to the LDAP server as the authenticating user. */
-        $bind = @ldap_bind($this->_connection, $bind_dn,
-                           $this->_params['password']);
-        if (!$bind) {
-            Horde::logMessage(
-                sprintf('Bind to server %s:%d with DN %s failed: [%d] %s',
-                        $this->_params['hostspec'],
-                        $this->_params['port'],
-                        $bind_dn,
-                        ldap_errno($this->_connection),
-                        ldap_error($this->_connection)),
-                __FILE__, __LINE__);
-            return false;
+
+        if (! $this->_params['fetchdn']) {
+
+            /* Define the DN of the current user */
+            $this->_dn = sprintf('%s=%s,%s', $this->_params['uid'][0],
+                                $this->_user,
+                                $this->_params['basedn']);
+
+            /* And the DN of the authenticating user (may be the same as above
) */
+            if (!empty($this->_params['rootdn'])) {
+                $bind_dn = $this->_params['rootdn'];
+            } else {
+                $bind_dn = sprintf('%s=%s,%s', $this->_params['uid'][0],
+                                   $this->_params['username'],
+                                   $this->_params['basedn']);
+            }
+
+            /* Bind to the LDAP server as the authenticating user. */
+            $bind = @ldap_bind($this->_connection, $bind_dn,
+                               $this->_params['password']);
+            if (!$bind) {
+                Horde::logMessage(
+                    sprintf('Bind to server %s:%d with DN %s failed: [%d] %s',
+                            $this->_params['hostspec'],
+                            $this->_params['port'],
+                            $bind_dn,
+                            ldap_errno($this->_connection),
+                            ldap_error($this->_connection)),
+                    __FILE__, __LINE__);
+                return false;
+            }
         }
 
         /* Search for the user's full DN. */
@@ -217,8 +221,13 @@
                                   $uid_field . '=' . $this->_user, array('dn')
);
             if ($search) {
                 $result = ldap_get_entries($this->_connection, $search);
-                if ($result && !empty($result[0]['dn'])) {
+                if ($result) {
                     $this->_dn = $result[0]['dn'];
+                   if ($this->_params['fetchdn']) {
+                        // Re-bind as the user
+                        $bind = @ldap_bind($this->_connection, $this->_dn,
+                        $this->_params['password']);
+                   }
                     return true;
                 }
             }
