--- pear/php/Horde/Vfs/Smb-orig.php	2012-02-24 14:03:17.000000000 +0100
+++ pear/php/Horde/Vfs/Smb.php	2012-02-24 14:52:50.000000000 +0100
@@ -626,3 +626,51 @@
     {
-        list($share) = $this->_escapeShellCommand($this->_params['share']);
+	$share = NULL;
+
+	if (isset($this->_params['shareLdapURI'])) {
+
+		# Test if param shareLdapURI is set.
+		# If true query LDAP server for the share to mount.
+		# If shareLdapURI is unset we will take the data from 'share'
+
+		$ldap_share_path = mb_split("\?", $this->_params['shareLdapURI']);
+
+		$ds = @ldap_connect($ldap_share_path[0]);
+		if (!$ds)  {
+			throw new Horde_Vfs_Exception("LDAP connection error");
+		}
+
+		if (isset($this->_params['shareLdapDN']) && isset($this->_params['shareLdapPW'])) {
+			$lb = @ldap_bind( 	$ds,	
+						$this->_params['shareLdapDN'],
+						$this->_params['shareLdapPW']);
+		} else {
+			$lb = @ldap_bind($ds);
+		}	
+
+		if (!$lb) {
+			throw new Horde_Vfs_Exception(ldap_error($ds));
+		}
+
+		$justthese = array($ldap_share_path[3]);
+		$sr = ldap_list(	$ds,
+					$ldap_share_path[1],
+					$ldap_share_path[2] . "=" . $this->_params['username'],
+					$justthese);
+		$result = ldap_get_entries($ds, $sr);
+	
+		if ($ds) @ldap_unbind($ds);
+
+		if ($result['count']==1) {
+			$share = $result[0][$ldap_share_path[3]][0];
+			$splitarr = preg_split('/\\\/',$share);
+
+			$netshare = '//'.implode('/',array_slice($splitarr,2,2));
+			$path = implode('/',array_slice($splitarr,4)) . '/' . $path;
+		}
+	}
+	if (!isset($share)) { 
+		list($share) = $this->_escapeShellCommand($this->_params['share']);
+		$netshare = '//' . $this->_params['hostspec'] . '/' . $share;
+	}
+	
         putenv('PASSWD=' . $this->_params['password']);
@@ -630,5 +678,6 @@
         $fullcmd = $this->_params['smbclient'] .
-            ' "//' . $this->_params['hostspec'] . '/' . $share . '"' .
+            ' "' . $netshare . '"' .
             ' "-p' . $this->_params['port'] . '"' .
             ' "-U' . $this->_params['username'] . '"' .
+            ' "-W' . $this->_params['domain'] . '"' .
             ' -D "' . $path . '" ' .
