implement readonly mounts and use that for sharing

This commit is contained in:
Ralf Becker 2014-11-14 08:50:05 +00:00
parent 16c27de80a
commit 1affa826b1
3 changed files with 40 additions and 0 deletions

View File

@ -73,6 +73,11 @@ class egw_sharing
common::egw_exit();
}
$share['resolve_url'] = egw_vfs::resolve_url($share['share_path']);
// if share not writable append ro=1 to mount url to make it readonly
if (!$this->db->from_bool($share['share_writable']))
{
$share['resolve_url'] .= (strpos($share['resolve_url'], '?') ? '&' : '?').'ro=1';
}
//_debug_array($share);
// arrange vfs to only contain shared url

View File

@ -717,6 +717,7 @@ class egw_vfs extends vfs_stream_wrapper
*
* @param string|array $urls url or array of url's
* @param boolean $allow_urls=false allow to use url's, default no only pathes (to stay within the vfs)
* @throws egw_exception_assertion_failed when trainig to remove /, /apps or /home
* @return array
*/
static function remove($urls,$allow_urls=false)

View File

@ -293,6 +293,10 @@ class vfs_stream_wrapper implements iface_stream_wrapper
{
return false;
}
if ($mode != 'r' && self::url_is_readonly($url))
{
return false;
}
if (!($this->opened_stream = fopen($url,$mode,$options)))
{
return false;
@ -463,6 +467,10 @@ class vfs_stream_wrapper implements iface_stream_wrapper
{
return false;
}
if (self::url_is_readonly($url))
{
return false;
}
$stat = self::url_stat($path, STREAM_URL_STAT_LINK);
self::symlinkCache_remove($path);
@ -583,6 +591,10 @@ class vfs_stream_wrapper implements iface_stream_wrapper
{
return false;
}
if (self::url_is_readonly($url))
{
return false;
}
$stat = self::url_stat($path, STREAM_URL_STAT_LINK);
self::symlinkCache_remove($path);
@ -957,6 +969,10 @@ class vfs_stream_wrapper implements iface_stream_wrapper
{
$stat['url'] = $url;
}
if (($stat['mode'] & 0222) && self::url_is_readonly($stat['url']))
{
$stat['mode'] &= ~0222;
}
if (self::LOG_LEVEL > 1) error_log(__METHOD__."('$path',$flags,try_create_home=$try_create_home,check_symlink_components=$check_symlink_components) returning ".array2string($stat));
return $stat;
@ -1311,6 +1327,24 @@ class vfs_stream_wrapper implements iface_stream_wrapper
return $path;
}
/**
* Check if url contains ro=1 parameter to mark mount readonly
*
* @param string $url
* @return boolean
*/
static function url_is_readonly($url)
{
static $cache = array();
$ret =& $cache[$url];
if (!isset($ret))
{
$matches = null;
$ret = preg_match('/?(.*&)?ro=([^&]+)/', $url, $matches) && $matches[1];
}
return $ret;
}
/**
* Init our static properties and register this wrapper
*