basic/rm-rf: allow a symlink to / to be removed

We open the target path with O_DIRECTORY|O_NOFOLLOW, and if that doesn't work,
we call unlink() on the path. In neither case we will follow the symlink, so
we can relax our check to also not follow symlinks.

Fixes #5864.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2017-06-17 12:41:08 -04:00
parent e3f791a2b3
commit 7cb53855dc

View File

@ -182,7 +182,7 @@ int rm_rf(const char *path, RemoveFlags flags) {
/* We refuse to clean the root file system with this
* call. This is extra paranoia to never cause a really
* seriously broken system. */
if (path_equal_or_files_same(path, "/", 0)) {
if (path_equal_or_files_same(path, "/", AT_SYMLINK_NOFOLLOW)) {
log_error("Attempted to remove entire root file system, and we can't allow that.");
return -EPERM;
}