Re: Problems with special characters in passwords or filenames
Stephan Lauffer <[email protected]> Wed, 12 Jun 2013 14:32:41 +0200
| Newsgroups | gmane.comp.horde.gollem |
|---|---|
| Message-ID | <20130612143241.Horde.JIA67FvE_duUXgioSYvHjQ1@mymail.ph-freiburg.de> |
Hi! Sorry for the very long delay... :( Zitat von Jan Schneider <[email protected]>: > Zitat von Stephan Lauffer <[email protected]>: [...] >> (Jan:) Are you interested in a patch for the DFS and Domain problems? > > Yes, and additions to the existing Horde_Vfs unit tests too, so that > we can reproduce the problem. The 1st part of the patch may not be interesting for you. It is just adding some features (see the comment there). To fix our password problems I just modify the password with escapeshellcmd(). To figure out what went wrong with the smb stuff here I rewrote some lines of putting together the smbclient command (see $fullcmd). If I remember right it just was importat to not pass some quotation marks around some of the smbclient options (not in any case). Btw: It is important for us to add the domain option there. Poorly right now I do not have the time to go on with adding some parts to your Horde_Vfs unit tests. -- Liebe Gruesse, with best regards Stephan Lauffer [ Pedagogical University Freiburg - Germany ] [ http://www.ph-freiburg.de/zik/ ] [ Fon/ Fax: +49 761 682 -459/ -486 ] -- gollem mailing list Frequently Asked Questions: http://wiki.horde.org/FAQ To unsubscribe, mail: [email protected]
Smb.php.Gollem-3.0.0.patch
(text/x-lisp, 3.3 KB)
--- Smb.php.Gollem-3.0.0 2013-05-08 11:16:51.000000000 +0200
+++ Smb.php 2013-05-08 11:40:20.000000000 +0200
@@ -612,12 +612,88 @@
{
+ ## 2013-03-19 by lauffer <[email protected]>
+ #
+ # Read smb homeshare from AD/OpenLDAP (if configured...)
+ # See also: http://lists.horde.org/archives/gollem/Week-of-Mon-20120220/001713.html
+
+ $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]);
+ ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
+ 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;
+ }
+ } else {
+ list($share) = $this->_escapeShellCommand($this->_params['share']);
+ }
+
+ if (!isset($share)) {
list($share) = $this->_escapeShellCommand($this->_params['share']);
- putenv('PASSWD=' . $this->_params['password']);
- $ipoption = (isset($this->_params['ipaddress'])) ? (' -I ' . $this->_params['ipaddress']) : null;
- $fullcmd = $this->_params['smbclient'] .
- ' "//' . $this->_params['hostspec'] . '/' . $share . '"' .
- ' "-p' . $this->_params['port'] . '"' .
- ' "-U' . $this->_params['username'] . '"' .
- ' -D "' . $path . '" ' .
- $ipoption .
- ' -c "';
+ $netshare = '//' . $this->_params['hostspec'] . '/' . $share;
+ }
+
+ ## 2013 by lauffer <[email protected]>
+ # $this->_params['password'] may contain special characters which needs
+ # to be escaped
+ $smb_pw = escapeshellcmd($this->_params['password']);
+
+ putenv('PASSWD=' . $smb_pw);
+
+ ## 2013 by lauffer <[email protected]>
+ # - Remove double quotation from share URI to prevent problems accessing DFS shares
+ # - Add optional smbclient option '-W' for the domain/workgroup
+ $fullcmd = $this->_params['smbclient'] . ' "' . $netshare . '" ';
+
+ if ($this->_params['port']) {
+ $fullcmd .= ' -p ' . $this->_params['port'];
+ }
+ if ($this->_params['domain']) {
+ $fullcmd .= ' -W ' . $this->_params['domain'];
+ }
+ if ($this->_params['username']) {
+ $fullcmd .= ' -U ' . $this->_params['username'] . '%' . $smb_pw . ' ';
+ }
+ if ($path) {
+ $fullcmd .= ' -D "' . $path . '"';
+ }
+ if ($this->_params['ipaddress']) {
+ $fullcmd .= ' -I ' . $this->_params['ipaddress'] ;
+ }
+
+ $fullcmd .= ' -c "';
+
foreach ($cmd as $c) {
smime.p7s
(application/pkcs7-signature, 5.3 KB) - not displayed