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@
This commit is contained in:
parent
9dde40faaa
commit
a6ef64df7a
@ -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
|
||||
|
@ -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),
|
||||
|
Loading…
Reference in New Issue
Block a user