Skip to content

Commit 4963df7

Browse files
committed
Backport fix for upstream issue pydio#634.
1 parent 2b6e1b5 commit 4963df7

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

core/src/plugins/access.ftp/class.ftpAccessDriver.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,16 +214,36 @@ public function uploadActions($action, $httpVars, $filesVars)
214214

215215
}
216216

217+
// Checks if a file belongs to currently logged in FTP user
218+
private function isFileOwner($path)
219+
{
220+
$ftp = new ftpAccessWrapper();
221+
$stat = $ftp->url_stat($path, 2);
222+
$urlParts = AJXP_Utils::safeParseUrl($path);
223+
$repository = ConfService::getRepositoryById($urlParts["host"]);
224+
$credentials = AJXP_Safe::tryLoadingCredentialsFromSources($urlParts, $repository);
225+
if (empty($credentials["user"]))
226+
return is_writable($path);
227+
if ((string)$stat["uid"] == $credentials["user"])
228+
return true;
229+
}
230+
217231
public function isWriteable($path, $type="dir")
218232
{
219233
$parts = parse_url($path);
220234
$dir = $parts["path"];
221235
if ($type == "dir" && ($dir == "" || $dir == "/" || $dir == "\\")) { // ROOT, WE ARE NOT SURE TO BE ABLE TO READ THE PARENT
222236
return true;
223237
} else {
224-
return is_writable($path);
238+
$perms = substr(decoct(fileperms($path)), -3);
239+
// World writable files
240+
if (preg_match("/..[2367]$/", $perms))
241+
return true;
242+
// Files belonging to currently logged in FTP user that are writable by owner
243+
if ((preg_match("/^[2367]/", $perms)) && ($this->isFileOwner($path)))
244+
return true;
225245
}
226-
246+
return false;
227247
}
228248

229249
public function deldir($location)

0 commit comments

Comments
 (0)