PHP 进程无法删除“/var/run/”中的文件

发布于 2024-10-16 04:37:03 字数 478 浏览 12 评论 0原文

我有一个 PHP 进程:

  • 以 root
  • 写入启动,然后关闭 /var/run/ 中的 pid 文件
  • chown() 将另一个用户的 pid 文件
  • 更改为该用户通过 posix_setuid()
  • 尝试在进程结束时删除 pid 文件

现在,即使我将 pid 文件 chown() 给当前用户,它也无法删除在 unlink() 调用中声称“权限被拒绝”的文件。这意味着即使有效用户拥有该文件,并且该文件未在当前(或任何)进程中打开,仍然没有足够的权限。

凭直觉,我尝试将 pid 文件位置移动到我的主目录,这没有问题。请注意,该进程的用户不是“我的个人用户”,因此有效用户对我的主目录没有写权限,只有一个特定文件。

那么,为什么我无法删除 /var/run/ 中的 pid 文件呢?

I have a PHP process that:

  • starts as root
  • writes to and then closes a pid file in /var/run/
  • chown()s said pid file to another user
  • changes to that user via posix_setuid()
  • tries to delete pid file at end of process

Now, even though I am chown()ing the pid file to the current user, it is unable to delete the file claiming "Permission denied" on the unlink() call. That means that even though the effective user owns the file, and the file is NOT open in the current (or any) process, there is still insufficient permission.

On a hunch, I tried moving the pid file location to my home directory, and this works without a problem. Note that the user of the process is not MY personal user, so the effective user has no write permissions on my home directory, just the one specific file.

So, why can't I delete the pid file when it's in /var/run/?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

枯叶蝶 2024-10-23 04:37:03

问题是用户需要对目录具有写权限才能删除文件。对文件本身的写权限不允许他们删除该文件。这就是为什么当您将文件移动到他们的主目录时它会起作用,他们有写入权限:)。也许在通过 posix_setuid() 更改用户之前将文件移动到他们的家是一个可能的解决方案?

有关 Linux 权限的更多信息,请参阅本文

编辑:我刚刚重新阅读了您的帖子,并意识到您表示您没有将文件移动到用户的实际家中。但是,您移动文件的 /home/ 目录必须向用户授予写入权限,以便他们删除该文件。我的预感是,您将文件移动到的目录已向用户所属的组所有者授予写入权限,或者已向每个人授予写入权限。 “ls -l”应该向您显示此信息。

Issue is that the user needs write permissions on the directory in order to delete the file. Write permissions on the file itself does not enable them to delete the file. This is why it works when you move the file to their home directory, which they have write perms for :). Maybe moving the file to their home prior to changing users via posix_setuid() is a possible solution?

See this article for more information on Linux permissions.

Edit: I just re-read your post and realized that you stated you did not move the file to the user's actual home. However, the /home/ dir that your moving the file, must grant write permissions to the user for them to delete the file. My hunch is that the directory your moving the file to either has write granted to a group owner which the user is a member of or has write granted for everyone. "ls -l" should show you this information.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文