From 3dd671ad8d006d07d3c21aa0df917c02051c2032 Mon Sep 17 00:00:00 2001 From: nathangray Date: Thu, 31 Jan 2019 14:14:03 -0700 Subject: [PATCH] Changes to support accessing Samba shares with Collabora --- api/src/Mail/Credentials.php | 4 ++-- api/src/Sharing.php | 32 ++++++++++++++++++++++++++++++++ api/src/Vfs/StreamWrapper.php | 16 ++++++---------- 3 files changed, 40 insertions(+), 12 deletions(-) diff --git a/api/src/Mail/Credentials.php b/api/src/Mail/Credentials.php index f8aeb28777..3ead67a225 100644 --- a/api/src/Mail/Credentials.php +++ b/api/src/Mail/Credentials.php @@ -196,7 +196,7 @@ class Credentials // Remove special x char added to the end for \0 trimming escape. if ($type == self::SMIME && substr($password, -1) === 'x') $password = substr($password, 0, -1); - foreach(self::$type2prefix as $pattern => $prefix) + foreach(static::$type2prefix as $pattern => $prefix) { if ($row['cred_type'] & $pattern) { @@ -807,7 +807,7 @@ class Credentials /** * Get the current Db object, from either setup or egw - * + * * @return Db */ static public function get_db() diff --git a/api/src/Sharing.php b/api/src/Sharing.php index 4de8785aad..0b7bbd7a77 100644 --- a/api/src/Sharing.php +++ b/api/src/Sharing.php @@ -105,6 +105,7 @@ class Sharing $path_info = substr($path_info, strlen($_SERVER['SCRIPT_NAME'])); list(, $token/*, $path*/) = preg_split('|[/?]|', $path_info, 3); + list($token, $pw_session) = explode(':', $token); return $token; } @@ -523,6 +524,9 @@ class Sharing $table_def = static::$db->get_table_definitions(false,static::TABLE); $extra = array_intersect_key($extra, $table_def['fd']); + // Check if path is mounted somewhere that needs a password + static::path_needs_password($path); + // check if file has been shared before, with identical attributes if (($share = static::$db->select(static::TABLE, '*', $extra+array( 'share_path' => $path, @@ -776,4 +780,32 @@ class Sharing return Framework::getUrl(Framework::link('/share.php')).'/'.$share; } + + /** + * Check to see if the path has a password required for it's mounting (eg: Samba) + * we need to deal with it specially. In general, we just throw an exception + * if the mount has $pass in it. + * + * @param string $path + * + * @throws WrongParameter if you try to share a path that needs a password + */ + public static function path_needs_password($path) + { + $mounts = array_reverse(Vfs::mount()); + $parts = Vfs::parse_url($path); + + foreach($mounts as $mounted => $url) + { + if(($mounted == $parts['path'] || $mounted.'/' == substr($parts['path'],0,strlen($mounted)+1)) && strpos($url, '$pass') !== FALSE) + { + throw new Exception\WrongParameter( + 'Cannot share a file that needs a password. (' . + $path . ' mounted from '. $url . ')' + ); + } + } + + return false; + } } \ No newline at end of file diff --git a/api/src/Vfs/StreamWrapper.php b/api/src/Vfs/StreamWrapper.php index e20cd9ec67..67ce97bdfe 100644 --- a/api/src/Vfs/StreamWrapper.php +++ b/api/src/Vfs/StreamWrapper.php @@ -213,16 +213,12 @@ class StreamWrapper implements StreamWrapperIface $path = self::symlinkCache_resolve($path,$do_symlink); } // setting default user, passwd and domain, if it's not contained int the url - static $defaults=null; - if (is_null($defaults)) - { - $defaults = array( - 'user' => $GLOBALS['egw_info']['user']['account_lid'], - 'pass' => urlencode($GLOBALS['egw_info']['user']['passwd']), - 'host' => $GLOBALS['egw_info']['user']['domain'], - 'home' => str_replace(array('\\\\','\\'),array('','/'),$GLOBALS['egw_info']['user']['homedirectory']), - ); - } + $defaults = array( + 'user' => $GLOBALS['egw_info']['user']['account_lid'], + 'pass' => urlencode($GLOBALS['egw_info']['user']['passwd']), + 'host' => $GLOBALS['egw_info']['user']['domain'], + 'home' => str_replace(array('\\\\','\\'),array('','/'),$GLOBALS['egw_info']['user']['homedirectory']), + ); $parts = array_merge(Vfs::parse_url($path),$defaults); if (!$parts['host']) $parts['host'] = 'default'; // otherwise we get an invalid url (scheme:///path/to/something)!