summaryrefslogtreecommitdiff
path: root/src/shared/rm-rf.c
Commit message (Collapse)AuthorAgeFilesLines
* rm-rf: also chmod() directory if it cannot be openedYu Watanabe2023-03-311-21/+135
| | | | | | | | Otherwise, directory with zero access mode cannot be removed. This is a revised version of 808c8b25eece33c503430151641f5f77676af38c, - dropped O_NOFOLLOW from fd_reopen() - fixed error handling on opening path in rm_rf().
* Revert "rm-rf: also chmod() directory if it cannot be opened"Luca Boccassi2023-03-301-131/+18
| | | | This reverts commit 808c8b25eece33c503430151641f5f77676af38c.
* rm-rf: also chmod() directory if it cannot be openedYu Watanabe2023-03-251-18/+131
| | | | Otherwise, directory with zero access mode cannot be removed.
* rm-rf: mask file mode with 07777 when passed to chmod()Yu Watanabe2023-03-251-4/+4
| | | | No functional change hopefully, just for safety.
* rm-rf: fix errno handlingYu Watanabe2023-03-251-4/+4
|
* shared/rm-rf: loop over nested directories instead of instead of recursingZbigniew Jędrzejewski-Szmek2021-12-211-47/+112
| | | | | | | | | | | | | | | | | | | | To remove directory structures, we need to remove the innermost items first, and then recursively remove higher-level directories. We would recursively descend into directories and invoke rm_rf_children and rm_rm_children_inner. This is problematic when too many directories are nested. Instead, let's create a "TODO" queue. In the the queue, for each level we hold the DIR* object we were working on, and the name of the directory. This allows us to leave a partially-processed directory, and restart the removal loop one level down. When done with the inner directory, we use the name to unlinkat() it from the parent, and proceed with the removal of other items. Because the nesting is increased by one level, it is best to view this patch with -b/--ignore-space-change. This fixes CVE-2021-3997, https://bugzilla.redhat.com/show_bug.cgi?id=2024639. The issue was reported and patches reviewed by Qualys Team. Mauro Matteo Cascella and Riccardo Schirone from Red Hat handled the disclosure.
* shared/rm_rf: refactor rm_rf() to shorten code a bitZbigniew Jędrzejewski-Szmek2021-12-211-30/+23
|
* shared/rm_rf: refactor rm_rf_children_inner() to shorten code a bitZbigniew Jędrzejewski-Szmek2021-12-211-18/+9
|
* tree-wide: make FOREACH_DIRENT_ALL define the iterator variableZbigniew Jędrzejewski-Szmek2021-12-151-1/+0
| | | | | | | | | The variable is not useful outside of the loop (it'll always be null after the loop is finished), so we can declare it inline in the loop. This saves one variable declaration and reduces the chances that somebody tries to use the variable outside of the loop. For consistency, 'de' is used everywhere for the var name.
* tmpfiles: 'st' may have been used uninitializedZbigniew Jędrzejewski-Szmek2021-11-301-1/+3
|
* rm-rf: optionally fsync() after removing directory treeLennart Poettering2021-10-111-0/+3
|
* tree-wide: fix typoYu Watanabe2021-08-181-3/+3
|
* rm-rf: refactor rm_rf_children(), split out body of directory iteration loopLennart Poettering2021-07-301-94/+129
| | | | | | This splits out rm_rf_children_inner() as body of the loop. We can use that to implement rm_rf_child() for deleting one specific entry in a directory.
* basic,shared: move a bunch of files to src/shared/Zbigniew Jędrzejewski-Szmek2021-06-241-0/+316
| | | | | | | | | | | | The goal is to move everything that requires selinux or smack away from src/basic/. This means that src/basic/label.[ch] must move, which implies btrfs-util.[ch], copy.[ch], and a bunch of other files which form a cluster of internal use. This is just moving text around, so there should be no functional difference. test-blockdev-util is new, because path_is_encrypted() is moved to blockdev-util.c, and so far we didn't have any tests for code there.
* build-sys: split internal basic/ library from shared/Kay Sievers2015-06-111-224/+0
| | | | | | | | | | basic/ can be used by everything cannot use anything outside of basic/ libsystemd/ can use basic/ cannot use shared/ shared/ can use libsystemd/
* path-util: Fix path_is_mount_point for filesMartin Pitt2015-05-291-1/+1
| | | | | | | | | | | | | | | | | | | | Commits 27cc6f166 and f25afeb broke path_is_mount_point() for files (such as /etc/machine-id → /run/machine-id bind mounts) as with the factorization of fd_is_mount_point() we lost the parent directory. We cannot determine that from an fd only as openat(fd, "..") only works for directory fds. Change fd_is_mount_point() to behave like openat(): It now takes a file descriptor of the containing directory, a file name in it, and flags (which can be 0 or AT_SYMLINK_FOLLOW). Unlike name_to_handle_at() or openat(), fstatat() only accepts the inverse flag AT_SYMLINK_NOFOLLOW and complains with EINVAL about AT_SYMLINK_FOLLOW; so we need to transform the flags for that fallback. Adjust rm_rf_children() accordingly (only other caller of fd_is_mount_point() aside from path_is_mount_point()). Add test cases for files, links, and file bind mounts (the latter will only work when running as root). Split out a new test_path_is_mount_point() test case function as it got significantly larger now.
* btrfs: support recursively removing btrfs snapshotsLennart Poettering2015-04-061-9/+22
|
* rm-rf: add support for recursively removing btrfs subvolumesLennart Poettering2015-04-061-1/+26
|
* rm-rf: never cross mount pointsLennart Poettering2015-04-061-2/+15
|
* util: rework rm_rf() logicLennart Poettering2015-04-061-0/+173
- Move to its own file rm-rf.c - Change parameters into a single flags parameter - Remove "honour sticky" logic, it's unused these days