rmdir()具有特定文件名的bug?没有权限 [英] rmdir() bug with particular filename? Permission denied
问题描述
首先,让我们得到这些:
- 目录上没有打开的句柄。
- 目录中没有文件。
-
chmod
将权限设置为0777不会阻止错误。 / li>
- 目录名称正确。
现在这是我的问题。尝试删除目录时, rmdir()
正在抛出此错误:
rmdir (098f6bcd4621d373cade4e832627b4f6)[function.rmdir]:第124行路径中的path\to\administrate.php中的权限被拒绝
098f6bcd4621d373cade4e832627b4f6 是目录的名称。
这是脚本的相关部分。
if(is_dir($ userhash)):
foreach(new DirectoryIterator($ userhash)as $ fileInfo){
$ fileName = $ fileInfo-> getFilename();
if($ fileInfo-> isDot())继续;
if(!rename($ userhash。'/'。$ fileName,'trashcan /'.$ username。'/'。$ fileName)){
echo'< p class =error>无法移动'$ fileName。'< / p>';
$ err = 1;
}
}
else:
echo'< p class =error>无法删除文件!错误:67< / p>';
$ err = 1;
endif;
//只能确定
chmod('./',0777);
chmod($ userhash,0777);
// RMDIR ONCE DIR是空的。
if(rmdir($ userhash))
echo'< p class =success>删除用户目录。文件位于垃圾箱中。< / p>';
else {
echo'< p class =error>无法删除用户目录。错误:656< / p>';
$ err = 1;
}
更新
我在同一目录中手动创建了目录'jake'
。我做了 rmdir('jake');
,它的效果很好。现在,我在同一目录中手动创建了一个目录'098f6bcd4621d373cade4e832627b4f6'
。我做了 rmdir('098f6bcd4621d373cade4e832627b4f6');
并且它错误!
更新2
这似乎开始看起来像一些奇怪的 rmdir()
错误。以下是我创建的目录名称,然后尝试使用 rmdir
删除
098f6bcd4621d373cade4e832627b4f6 |没有工作(五元组检查)
098f6bcd4621d373cade4e832627b4f7 |工作
098f6bcd4621d373cade4e832627b4f |工作
098f6bcd4621d373cade4e832627b4f66 |工作
为了能够删除文件: p>
- 用户应该具有PARENT目录的写入权限
- 不应为PARENT目录设置限制删除标志
更新:
关于限制删除标志 - 从 man chmod
:
限制删除标记或STICKY位
限制删除标记或粘性
位是一个位,其
解释取决于文件
类型。对于目录,它可以防止
未经许可的用户删除
或重命名目录
中的文件,除非他们拥有该文件或
目录;这被称为
限制删除标记为
目录,通常在
世界可写目录(如/ tmp)中找到。
对于一些较旧的
系统上的常规文件,该位在交换设备上保存程序的
文本图像,以便
在运行时加载更快;这个
被称为粘性位。
您可以通过在模式中将1加到第一个八进制数来进行设置,例如:
chmod 1xxx dirname
更新2:
执行哪个php的用户是否具有chmod父目录的权限? / p>
换句话说,你确定第一个chmod调用返回true吗?
CHMOD( './',0777);
First, let's get these out of the way:
- There are no open handles on the directory.
- There are no files in the directory.
chmod
ing the permissions to 0777 does not prevent the error.- the directory name is correct.
Now then, here's my problem. rmdir()
is throwing this error when trying to delete the directory:
rmdir(098f6bcd4621d373cade4e832627b4f6) [function.rmdir]: Permission denied in path\to\administrate.php on line 124
098f6bcd4621d373cade4e832627b4f6 is the name of the directory.
Here is the relevant portion of the script.
if(is_dir($userhash)) :
foreach (new DirectoryIterator($userhash) as $fileInfo) {
$fileName = $fileInfo->getFilename();
if($fileInfo->isDot()) continue;
if(!rename($userhash.'/'.$fileName , 'trashcan/'.$username.'/'.$fileName)) {
echo '<p class="error">Could not move '.$fileName.'</p>';
$err = 1;
}
}
else :
echo '<p class="error">Unable to delete files! error: 67</p>';
$err = 1;
endif;
//JUST TO BE SURE
chmod('./',0777);
chmod($userhash,0777);
// RMDIR ONCE THE DIR IS EMPTY.
if(rmdir($userhash))
echo '<p class="success">Deleted the user directory. The files are in the trash.</p>';
else {
echo '<p class="error">Could not remove the user directory. Error: 656</p>';
$err = 1;
}
Update
I manually created the dir 'jake'
in the same directory. I did rmdir('jake');
and it worked great. Now, I manually created a dir '098f6bcd4621d373cade4e832627b4f6'
in the same directory. I did rmdir('098f6bcd4621d373cade4e832627b4f6');
and it errored!
Update 2
This is beginning to look like some weird rmdir()
bug, as unlikely as that seems. Here are directory names I've created and then tried to remove with rmdir
;
098f6bcd4621d373cade4e832627b4f6 | didn't work (quintuple checked)
098f6bcd4621d373cade4e832627b4f7 | worked
098f6bcd4621d373cade4e832627b4f | worked
098f6bcd4621d373cade4e832627b4f66 | worked
In order to be able remove file:
- user should have write permissions to PARENT directory
- restricted deletion flag should NOT be set for PARENT directory
UPDATE:
About restricted deletion flag - from man chmod
:
RESTRICTED DELETION FLAG OR STICKY BIT
The restricted deletion flag or sticky bit is a single bit, whose interpretation depends on the file type. For directories, it prevents unprivi‐leged users from removing or renaming a file in the directory unless they own the file or the directory; this is called the restricted deletion flag for the directory, and is commonly found on world-writable directories like /tmp. For regular files on some older systems, the bit saves the program's text image on the swap device so it will load more quickly when run; this is called the sticky bit.
You may SET it by adding 1 to the first octal digit in mode, for example:
chmod 1xxx dirname
UPDATE 2:
Does user, under which php is executed, has permissions to chmod parent directory?
In other words, are you sure that first chmod call returns true?
chmod('./',0777);
这篇关于rmdir()具有特定文件名的bug?没有权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!