diff options
author | Doug Barton <dougb@FreeBSD.org> | 2005-09-29 20:40:29 +0000 |
---|---|---|
committer | Doug Barton <dougb@FreeBSD.org> | 2005-09-29 20:40:29 +0000 |
commit | a5f6295013e219bb639d738060b732c942314c06 (patch) | |
tree | ef816280e2930f226c08becb28e7b60dd57ecc36 /bin | |
parent | 870d00144f5f9216c42a3517cb7d8721787a7275 (diff) | |
download | src-test2-a5f6295013e219bb639d738060b732c942314c06.tar.gz src-test2-a5f6295013e219bb639d738060b732c942314c06.zip |
Notes
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 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), |