aboutsummaryrefslogtreecommitdiff
path: root/bin/rm
diff options
context:
space:
mode:
authorDoug Barton <dougb@FreeBSD.org>2005-09-29 20:40:29 +0000
committerDoug Barton <dougb@FreeBSD.org>2005-09-29 20:40:29 +0000
commita5f6295013e219bb639d738060b732c942314c06 (patch)
treeef816280e2930f226c08becb28e7b60dd57ecc36 /bin/rm
parent870d00144f5f9216c42a3517cb7d8721787a7275 (diff)
downloadsrc-a5f6295013e219bb639d738060b732c942314c06.tar.gz
src-a5f6295013e219bb639d738060b732c942314c06.zip
Handle the case where the -P flag is specified for a read-only file
earlier, and more gracefully. Previously, this combination would be ignored early in the code where permissions are tested and fail later with a very unhelpful "permission denied" error. Instead, test for this flag in the same block that generates the "override?" messages for read-only files, but instead of trying to guess what the user has in mind, generate an error and exit. Update the man page to reflect this new behavior. Not objected to by: freebsd-hackers@
Notes
Notes: svn path=/head/; revision=150729
Diffstat (limited to 'bin/rm')
-rw-r--r--bin/rm/rm.14
-rw-r--r--bin/rm/rm.c9
2 files changed, 9 insertions, 4 deletions
diff --git a/bin/rm/rm.1 b/bin/rm/rm.1
index c2d2d1b24026..07364fc6de59 100644
--- a/bin/rm/rm.1
+++ b/bin/rm/rm.1
@@ -88,6 +88,10 @@ yet provides almost the same level of protection against mistakes.
Overwrite regular files before deleting them.
Files are overwritten three times, first with the byte pattern 0xff,
then 0x00, and then 0xff again, before they are deleted.
+Specifying this flag for a read only file will cause
+.Nm
+to generate an error message and exit.
+The file wil not be removed or overwritten.
.It Fl R
Attempt to remove the file hierarchy rooted in each file argument.
The
diff --git a/bin/rm/rm.c b/bin/rm/rm.c
index aefa8c66a2bd..b838fef22ef5 100644
--- a/bin/rm/rm.c
+++ b/bin/rm/rm.c
@@ -452,11 +452,8 @@ check(char *path, char *name, struct stat *sp)
* talking to a terminal, ask. Symbolic links are excluded
* because their permissions are meaningless. Check stdin_ok
* first because we may not have stat'ed the file.
- * Also skip this check if the -P option was specified because
- * we will not be able to overwrite file contents and will
- * barf later.
*/
- if (!stdin_ok || S_ISLNK(sp->st_mode) || Pflag ||
+ if (!stdin_ok || S_ISLNK(sp->st_mode) ||
(!access(name, W_OK) &&
!(sp->st_flags & (SF_APPEND|SF_IMMUTABLE)) &&
(!(sp->st_flags & (UF_APPEND|UF_IMMUTABLE)) || !uid)))
@@ -464,6 +461,10 @@ check(char *path, char *name, struct stat *sp)
strmode(sp->st_mode, modep);
if ((flagsp = fflagstostr(sp->st_flags)) == NULL)
err(1, "fflagstostr");
+ if (Pflag)
+ errx(1,
+ "%s: -P was specified, but file is not writable",
+ path);
(void)fprintf(stderr, "override %s%s%s/%s %s%sfor %s? ",
modep + 1, modep[9] == ' ' ? "" : " ",
user_from_uid(sp->st_uid, 0),