rm -F
The build system at work occasionally generates entire directory trees full of files and directories with read-
rm -rf directoryrmgetsEPERMon every file in a read-only subdirectory - swear
chmod -r +w directorychmodtries to take the r permission away from the nonexistent file+w- swear
chmod -R +w directorychmodnow getsEPERM, because the previous invocation also successfully took the r permission away fromdirectory- swear
chmod -R +rw directoryrm -rf directory
… and since I mostly try to avoid generating these directories in the first place, this happens just infrequently enough that the next time I've forgotten all the pitfalls and do pretty much the same thing again.
What I want is for rm to support the -F option, which is like -f except that it also authorises rm to temporarily restore write permission (if permitted to) on any directory from which the lack of it is preventing it from deleting a file. Or possibly it should only be allowed to do that if the directory is one it's planning to delete completely later in the operation anyway; that might be safer. But either way, the point is, if the Unix permissions system makes it possible in principle to arrange for the directory not to be there any more, then I want to be able to get rm to just do so, by any means necessary short of requesting the root password, and not bother me with trivial details of how.
no subject
no subject
no subject
no subject
Meanwhile, thinking about it I also have a nasty feeling in my waters: is rm -r secure? Particularly, what if someone suddenly replaces a subdirectory with a symlink to another point in the filesystem?
Hohum…
no subject
no subject
- rm -r starts deleting stuff
- It determines that foo is a subdirectory
- A Bad Person quickly does mv foo old-foo; ln -s /home/victim foo
- rm -r descends into foo, which is now in reality the victim's home directory
- It recursively deletes everything it finds there.
I suspect the GNU version, at least, checks this hasn't happened. But I'm not sure, and I really ought to know.no subject
no subject
/* There is a race condition in that an attacker could replace the nonempty directory, DIR, with a symlink between the preceding call to rmdir (in our caller) and the chdir below. However, the following lstat, along with the `stat (".",...' and dev/ino comparison in AD_push ensure that we detect it and fail. */(coreutils-5.96/src/remove.c:remove_dir(); not quite current but I had it handy.)