Changes to support accessing Samba shares with Collabora

This commit is contained in:
nathangray 2019-01-31 14:14:03 -07:00
parent 75b21741b9
commit 3dd671ad8d
3 changed files with 40 additions and 12 deletions

View File

@ -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()

View File

@ -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;
}
}

View File

@ -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)!