@@ -214,16 +214,36 @@ public function uploadActions($action, $httpVars, $filesVars)
214
214
215
215
}
216
216
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
+
217
231
public function isWriteable ($ path , $ type ="dir " )
218
232
{
219
233
$ parts = parse_url ($ path );
220
234
$ dir = $ parts ["path " ];
221
235
if ($ type == "dir " && ($ dir == "" || $ dir == "/ " || $ dir == "\\" )) { // ROOT, WE ARE NOT SURE TO BE ABLE TO READ THE PARENT
222
236
return true ;
223
237
} 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 ;
225
245
}
226
-
246
+ return false ;
227
247
}
228
248
229
249
public function deldir ($ location )
0 commit comments