diff options
author | dougb <dougb@FreeBSD.org> | 2005-09-29 20:40:29 +0000 |
---|---|---|
committer | dougb <dougb@FreeBSD.org> | 2005-09-29 20:40:29 +0000 |
commit | a6ef64df7a0ff6faf8780a1ed6169806a007aa9a (patch) | |
tree | ef816280e2930f226c08becb28e7b60dd57ecc36 /bin | |
parent | 9dde40faaa1ff846fdae765c134893d92136b6fc (diff) | |
download | FreeBSD-src-a6ef64df7a0ff6faf8780a1ed6169806a007aa9a.zip FreeBSD-src-a6ef64df7a0ff6faf8780a1ed6169806a007aa9a.tar.gz |
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@
Diffstat (limited to 'bin')
-rw-r--r-- | bin/rm/rm.1 | 4 | ||||
-rw-r--r-- | bin/rm/rm.c | 9 |
2 files changed, 9 insertions, 4 deletions
diff --git a/bin/rm/rm.1 b/bin/rm/rm.1 index c2d2d1b..07364fc 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 aefa8c6..b838fef 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), |