From nobody  Tue Apr 29 16:42:57 1997
Received: (from nobody@localhost)
          by hub.freebsd.org (8.8.5/8.8.5) id QAA18096;
          Tue, 29 Apr 1997 16:42:57 -0700 (PDT)
Message-Id: <199704292342.QAA18096@hub.freebsd.org>
Date: Tue, 29 Apr 1997 16:42:57 -0700 (PDT)
From: pius@ienet.com
To: freebsd-gnats-submit@freebsd.org
Subject: chown/chgrp show wrong error message when superuser tries to change group of immutable file
X-Send-Pr-Version: www-1.0

>Number:         3421
>Category:       bin
>Synopsis:       chown/chgrp show wrong error message when superuser tries to change group of immutable file
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    steve
>State:          closed
>Quarter:
>Keywords:
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Apr 29 16:50:00 PDT 1997
>Closed-Date:    Sat Aug 23 09:26:28 PDT 1997
>Last-Modified:  Sat Aug 23 17:00:01 PDT 1997
>Originator:     Pius Fischer
>Release:        FreeBSD 3.0-current
>Organization:
>Environment:
FreeBSD iago.ienet.com 3.0-CURRENT FreeBSD 3.0-CURRENT #0: Wed Mar  5
19:20:16 PST 1997     pius@iago.ienet.com:/usr/src/sys/compile/IAGO  i386

>Description:
chown and chgrp emit the wrong error message when the superuser tries to
change the group of immutable files. It should say "Operation not permitted"
instead of "you are not a member of group <foo>". The superuser doesn't have
to be in group <foo> to change a file's group to <foo>.

While I was looking at chownerr() in chown.c, I also noticed that there is
no need to check fflag in chownerr() because the function is only called if
fflag is false. The diff below removes the fflag checks as well as fixing
the error message problem (which only involves adding the && euid == -1 &&
(euid = geteuid()) != 0 to the condition of the second if statement).

>How-To-Repeat:
as superuser:
# touch a
# chgrp wheel a
# chflags schg a
# chgrp bin a
chgrp: you are not a member of group bin
#
>Fix:
Here's a diff -u with respect to rev 1.6 of chown.c:

--- chown.c.1.6.orig	Tue Apr 29 16:02:42 1997
+++ chown.c.1.6	Tue Apr 29 16:05:57 1997
@@ -244,25 +244,19 @@
 
 	/* Check for chown without being root. */
 	if (errno != EPERM ||
-	    uid != -1 && euid == -1 && (euid = geteuid()) != 0) {
-		if (fflag)
-			exit(0);
+	    uid != -1 && euid == -1 && (euid = geteuid()) != 0)
 		err(1, "%s", file);
-	}
 
 	/* Check group membership; kernel just returns EPERM. */
-	if (gid != -1 && ngroups == -1) {
+	if (gid != -1 && ngroups == -1 &&
+	    euid == -1 && (euid = geteuid()) != 0) {
 		ngroups = getgroups(NGROUPS, groups);
 		while (--ngroups >= 0 && gid != groups[ngroups]);
-		if (ngroups < 0) {
-			if (fflag)
-				exit(0);
+		if (ngroups < 0)
 			errx(1, "you are not a member of group %s", gname);
-		}
 	}
 
-	if (!fflag)
-		warn("%s", file);
+	warn("%s", file);
 }
 
 void

>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: steve 
State-Changed-When: Sat Aug 23 09:26:28 PDT 1997 
State-Changed-Why:  
PR should be closed as noted in misc/4028. 

From: pius@ienet.com
To: Steve Price <steve@FreeBSD.ORG>, freebsd-gnats-submit@FreeBSD.ORG
Cc:  Subject: Re: bin/3421: chown/chgrp show wrong error message when superuser tries to change group of immutable file
Date: Sat, 23 Aug 1997 16:59:05 -0700

 On Sat, 23 Aug 1997, steve@FreeBSD.ORG wrote:
 > Synopsis: chown/chgrp show wrong error message when superuser tries to change
 > group of immutable file
 >
 > State-Changed-From-To: open->closed
 > State-Changed-By: steve
 > State-Changed-When: Sat Aug 23 09:26:28 PDT 1997
 > State-Changed-Why:
 > PR should be closed as noted in misc/4028.
 
 I just wanted to point out that this one (bin/3421)
 was a duplicate of bin/3445.
 
 The latter is still open and it still applies.
 
 Best regards,
 Pius
>Unformatted:
