From bugghy@phenix.rootshell.be  Mon Sep 27 07:12:05 2004
Return-Path: <bugghy@phenix.rootshell.be>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id D39D716A4CE
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 27 Sep 2004 07:12:05 +0000 (GMT)
Received: from phenix.rootshell.be (phenix.rootshell.be [217.22.55.50])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 4D0AA43D39
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 27 Sep 2004 07:12:05 +0000 (GMT)
	(envelope-from bugghy@phenix.rootshell.be)
Received: from phenix.rootshell.be (phenix [127.0.0.1])
	by phenix.rootshell.be (8.12.8/8.12.8) with ESMTP id i8R7C1xL009301;
	Mon, 27 Sep 2004 09:12:01 +0200
Received: from localhost (bugghy@localhost)
	by phenix.rootshell.be (8.12.8/8.12.8/Submit) with ESMTP id i8R7Bw5Q025830;
	Mon, 27 Sep 2004 09:11:58 +0200
Message-Id: <Pine.LNX.4.61.0409270910210.2686@phenix.rootshell.be>
Date: Mon, 27 Sep 2004 09:11:58 +0200 (CEST)
From: bugghy <bugghy@phenix.rootshell.be>
To: FreeBSD-gnats-submit@freebsd.org
Cc: bugghy@safe-mail.net
Subject: rm -P can't unlink u-w files

>Number:         72124
>Category:       bin
>Synopsis:       [patch] rm -P can't unlink u-w files
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Mon Sep 27 07:20:22 GMT 2004
>Closed-Date:    Fri Mar 30 16:46:44 GMT 2007
>Last-Modified:  Fri Mar 30 16:46:44 GMT 2007
>Originator:     bugghy
>Release:        FreeBSD 6.0-CURRENT i386
>Organization:
>Environment:

 System: FreeBSD illusion.com 6.0-CURRENT FreeBSD 6.0-CURRENT #13: Thu Sep 9 
 14:58:31 UTC 2004 root@illusion.com:/usr/obj/usr/src/sys/BUGNERIC i386

> Description:
 
          "/bin/rm -P" cannot remove files not writeable by user while "/bin/rm" can
 
          The patch will chmod the file "u+w" and then remove it.

> How-To-Repeat:
          $ touch 1; chmod 0 1; ls -l 1
          ----------  1 bugghy  bugghy  0 Sep 26 22:59 1
          $ /bin/rm -P 1
          rm: 1: Permission denied
          $ /bin/rm 1
          override r--r--r--  bugghy/bugghy for 1? y
          $ ls -l 1
          $ ls: 1: No such file or directory

> Fix:
 --- /usr/src/bin/rm/rm.c.orig   Sun Sep 26 22:23:02 2004
 +++ /usr/src/bin/rm/rm.c        Mon Sep 27 10:00:50 2004
 @@ -384,6 +384,8 @@
          }
          if (!S_ISREG(sbp->st_mode))
                  return (1);
 +       if (lchmod(file, S_IWUSR) == -1)
 +               goto err;
          if ((fd = open(file, O_WRONLY, 0)) == -1)
                  goto err;
          if (fstatfs(fd, &fsb) == -1)
 @@ -441,7 +443,7 @@
                   * 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)))
 
>Description:
>How-To-Repeat:
>Fix:
>Release-Note:
>Audit-Trail:
Class-Changed-From-To: sw-bug->change-request 
Class-Changed-By: ceri 
Class-Changed-When: Mon Sep 27 11:04:22 GMT 2004 
Class-Changed-Why:  
This is a request for a change of semantics. 


Responsible-Changed-From-To: gnats-admin->freebsd-bugs 
Responsible-Changed-By: ceri 
Responsible-Changed-When: Mon Sep 27 11:04:22 GMT 2004 
Responsible-Changed-Why:  
Reassign misfiled PR. 

For what it's worth, I believe that the current behaviour is correct. 
Perhaps rm -Pf should do what the submitter is asking for. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=72124 

From: Bugghy <bugghy@rootshell.be>
To: freebsd-gnats-submit@FreeBSD.org, bugghy@phenix.rootshell.be
Cc:  
Subject: Re: bin/72124: [patch] rm -P can't unlink u-w files
Date: Sun, 05 Dec 2004 18:17:50 +0200

 $ touch 1;chmod 0 1;ls -l 1
 ----------  1 bugghy  bugghy  0 Dec  5 18:14 1
 $ /bin/rm -Pf 1
 rm: 1: Permission denied
 
  So, I still consider this a bug.
 -- 
 Bugghy <bugghy@rootshell.be>
 

From: Ceri Davies <ceri@submonkey.net>
To: FreeBSD Gnats Submit <freebsd-gnats-submit@FreeBSD.org>
Cc:  
Subject: Re: bin/72124: [patch] rm -P can't unlink u-w files
Date: Mon, 6 Dec 2004 12:21:57 +0000

 On Sun, Dec 05, 2004 at 04:20:26PM +0000, Bugghy wrote:
 
 >  $ touch 1;chmod 0 1;ls -l 1
 >  ----------  1 bugghy  bugghy  0 Dec  5 18:14 1
 >  $ /bin/rm -Pf 1
 >  rm: 1: Permission denied
 >  
 >   So, I still consider this a bug.
 
 I didn't say that it *would* do what you wanted - only that "perhaps
 it should".  In hindsight I don't believe that anymore.
 There is nothing in the manual that suggests that this will work, and
 therefore I don't think that this is a bug.  The PR is still open for a
 second opinion.
 
 Ceri
State-Changed-From-To: open->closed 
State-Changed-By: le 
State-Changed-When: Fri Mar 30 16:45:11 UTC 2007 
State-Changed-Why:  
I support Ceri's opinion on this matter.  The manual page 
rm(1) clearly describes this behaviour, so I won't consider 
this a bug.  

http://www.freebsd.org/cgi/query-pr.cgi?pr=72124 
>Unformatted:
