Skip to content

Commit a54f213

Browse files
committed
Backport fix for upstream issue pydio#634.
1 parent 862e68d commit a54f213

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
@@ -213,16 +213,36 @@ public function uploadActions($action, $httpVars, $filesVars)
213213

214214
}
215215

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

228248
public function deldir($location)

0 commit comments

Comments
 (0)