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