This repository has been archived by the owner on Nov 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 289
access.ftp fails to check if files are writable #634
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -214,16 +214,36 @@ public function uploadActions($action, $httpVars, $filesVars) | |
|
||
} | ||
|
||
// Checks if a file belongs to currently logged in FTP user | ||
private function isFileOwner($path) | ||
{ | ||
$ftp = new ftpAccessWrapper(); | ||
$stat = $ftp->url_stat($path, 2); | ||
$urlParts = AJXP_Utils::safeParseUrl($path); | ||
$repository = ConfService::getRepositoryById($urlParts["host"]); | ||
$credentials = AJXP_Safe::tryLoadingCredentialsFromSources($urlParts, $repository); | ||
if (empty($credentials["user"])) | ||
return is_writable($path); | ||
if ((string)$stat["uid"] == $credentials["user"]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Regarding your comments, this $stat["uid"] is in fact returning a numerical value or here it's can really be the user name? |
||
return true; | ||
} | ||
|
||
public function isWriteable($path, $type="dir") | ||
{ | ||
$parts = parse_url($path); | ||
$dir = $parts["path"]; | ||
if ($type == "dir" && ($dir == "" || $dir == "/" || $dir == "\\")) { // ROOT, WE ARE NOT SURE TO BE ABLE TO READ THE PARENT | ||
return true; | ||
} else { | ||
return is_writable($path); | ||
$perms = substr(decoct(fileperms($path)), -3); | ||
// World writable files | ||
if (preg_match("/..[2367]$/", $perms)) | ||
return true; | ||
// Files belonging to currently logged in FTP user that are writable by owner | ||
if ((preg_match("/^[2367]/", $perms)) && ($this->isFileOwner($path))) | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public function deldir($location) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we don't use the $stat value, so we should make sure to have this case return earlier in the function (before making an unecessary call to url_stat).