From nobody@FreeBSD.org  Fri Mar 29 01:25:28 2002
Return-Path: <nobody@FreeBSD.org>
Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21])
	by hub.freebsd.org (Postfix) with ESMTP id 6D82437B41B
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 29 Mar 2002 01:25:28 -0800 (PST)
Received: (from nobody@localhost)
	by freefall.freebsd.org (8.11.6/8.11.6) id g2T9PSu60783;
	Fri, 29 Mar 2002 01:25:28 -0800 (PST)
	(envelope-from nobody)
Message-Id: <200203290925.g2T9PSu60783@freefall.freebsd.org>
Date: Fri, 29 Mar 2002 01:25:28 -0800 (PST)
From: Joshua Goodall <joshua@roughtrade.net>
To: freebsd-gnats-submit@FreeBSD.org
Subject: Overdue MFC's in chmod/chown/chflags
X-Send-Pr-Version: www-1.0

>Number:         36473
>Category:       bin
>Synopsis:       Overdue MFC's in chmod/chown/chflags
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    ru
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Fri Mar 29 01:30:03 PST 2002
>Closed-Date:    Fri Nov 08 14:22:00 PST 2002
>Last-Modified:  Fri Nov 08 14:22:00 PST 2002
>Originator:     Joshua Goodall
>Release:        4-stable
>Organization:
>Environment:
FreeBSD green.shallow.net 4.5-STABLE FreeBSD 4.5-STABLE #0: Fri Feb  1 00:19:52 EST 2002 joshua@green.shallow.net:/usr/obj/usr/src/sys/GREEN  i386

>Description:
The following are now very overdue MFC's:

r1.17 and r1.18 of src/usr.sbin/chown/chown.c
- Follow symbolic links named as command line arguments without -R.
- chown -h owner symlink did not set the symlink's owner
  if the file the symlink points to already had that owner

r1.20 r1.21 and r1.22 of src/bin/chmod/chmod.c
- Follow symbolic links named as command line arguments without -R
- Change noop option -h to do the real work.
- chmod -h mode symlink did not set the symlink's mode
  if the file the symlink points to already had that mode

r1.11 of src/usr.bin/chflags/chflags.c
- Follow symbolic links named as command line arguments without -R


>How-To-Repeat:
      
>Fix:
Attention to these permission-related details would be appreciated!
Please arrange MFC.

Note that there is no lchflags syscall, so changing symlink
flags is not an issue (subject of an existing open PR).

Joshua

>Release-Note:
>Audit-Trail:

From: Joshua Goodall <joshua@roughtrade.net>
To: freebsd-gnats-submit@FreeBSD.org
Cc:  
Subject: Re: bin/36473: Overdue MFC's in chmod/chown/chflags
Date: Tue, 16 Apr 2002 13:15:35 +1000

 On Fri, Mar 29, 2002 at 01:25:28AM -0800, Joshua Goodall wrote:
 > The following are now very overdue MFC's:
 [snip]
 
 This is a (tested) diff against -stable:
 
 
 Index: src/bin/chmod/chmod.c
 ===================================================================
 RCS file: /cvs/src/bin/chmod/chmod.c,v
 retrieving revision 1.16.2.3
 diff -u -r1.16.2.3 chmod.c
 --- src/bin/chmod/chmod.c	1 Aug 2001 01:21:09 -0000	1.16.2.3
 +++ src/bin/chmod/chmod.c	15 Apr 2002 15:13:10 -0000
 @@ -74,11 +74,12 @@
  	int vflag;
  	char *ep, *mode;
  	int newmode;
 +	int (*change_mode) __P((const char *, mode_t));
  
  	set = NULL;
  	omode = 0;
  	Hflag = Lflag = Pflag = Rflag = fflag = hflag = vflag = 0;
 -	while ((ch = getopt(argc, argv, "HLPRXfgorstuvwx")) != -1)
 +	while ((ch = getopt(argc, argv, "HLPRXfghorstuvwx")) != -1)
  		switch (ch) {
  		case 'H':
  			Hflag = 1;
 @@ -102,9 +103,10 @@
  			/*
  			 * In System V (and probably POSIX.2) the -h option
  			 * causes chmod to change the mode of the symbolic
 -			 * link.  4.4BSD's symbolic links don't have modes,
 -			 * so it's an undocumented noop.  Do syntax checking,
 -			 * though.
 +			 * link.  4.4BSD's symbolic links didn't have modes,
 +			 * so it was an undocumented noop.  In FreeBSD 3.0,
 +			 * lchmod(2) is introduced and this option does real
 +			 * work.
  			 */
  			hflag = 1;
  			break;
 @@ -134,8 +136,8 @@
  	if (argc < 2)
  		usage();
  
 -	fts_options = FTS_PHYSICAL;
  	if (Rflag) {
 +		fts_options = FTS_PHYSICAL;
  		if (hflag)
  			errx(1,
  		"the -R and -h options may not be specified together.");
 @@ -145,7 +147,13 @@
  			fts_options &= ~FTS_PHYSICAL;
  			fts_options |= FTS_LOGICAL;
  		}
 -	}
 +	} else
 +		fts_options = hflag ? FTS_PHYSICAL : FTS_LOGICAL;
 +
 +	if (hflag)
 +		change_mode = lchmod;
 +	else
 +		change_mode = chmod;
  
  	mode = *argv;
  	if (*mode >= '0' && *mode <= '7') {
 @@ -189,14 +197,17 @@
  			 * don't point to anything and ones that we found
  			 * doing a physical walk.
  			 */
 -			continue;
 +			if (!hflag)
 +				continue;
 +			/* else */
 +			/* FALLTHROUGH */
  		default:
  			break;
  		}
  		newmode = oct ? omode : getmode(set, p->fts_statp->st_mode);
  		if ((newmode & ALLPERMS) == (p->fts_statp->st_mode & ALLPERMS))
  			continue;
 -		if (chmod(p->fts_accpath, newmode) && !fflag) {
 +		if ((*change_mode)(p->fts_accpath, newmode) && !fflag) {
  			warn("%s", p->fts_path);
  			rval = 1;
  		} else {
 @@ -214,6 +225,6 @@
  usage()
  {
  	(void)fprintf(stderr,
 -	    "usage: chmod [-fv] [-R [-H | -L | -P]] mode file ...\n");
 +	    "usage: chmod [-fhv] [-R [-H | -L | -P]] mode file ...\n");
  	exit(1);
  }
 Index: src/usr.bin/chflags/chflags.c
 ===================================================================
 RCS file: /cvs/src/usr.bin/chflags/chflags.c,v
 retrieving revision 1.7.2.3
 diff -u -r1.7.2.3 chflags.c
 --- src/usr.bin/chflags/chflags.c	1 Aug 2001 23:09:18 -0000	1.7.2.3
 +++ src/usr.bin/chflags/chflags.c	15 Apr 2002 15:03:40 -0000
 @@ -99,15 +99,16 @@
  	if (argc < 2)
  		usage();
  
 -	fts_options = FTS_PHYSICAL;
  	if (Rflag) {
 +		fts_options = FTS_PHYSICAL;
  		if (Hflag)
  			fts_options |= FTS_COMFOLLOW;
  		if (Lflag) {
  			fts_options &= ~FTS_PHYSICAL;
  			fts_options |= FTS_LOGICAL;
  		}
 -	}
 +	} else
 +		fts_options = FTS_LOGICAL;
  
  	flags = *argv;
  	if (*flags >= '0' && *flags <= '7') {
 Index: src/usr.sbin/chown/chown.c
 ===================================================================
 RCS file: /cvs/src/usr.sbin/chown/chown.c,v
 retrieving revision 1.15.2.1
 diff -u -r1.15.2.1 chown.c
 --- src/usr.sbin/chown/chown.c	7 Aug 2000 02:03:09 -0000	1.15.2.1
 +++ src/usr.sbin/chown/chown.c	15 Apr 2002 15:07:45 -0000
 @@ -122,8 +122,8 @@
  	if (argc < 2)
  		usage();
  
 -	fts_options = FTS_PHYSICAL;
  	if (Rflag) {
 +		fts_options = FTS_PHYSICAL;
  		if (hflag && (Lflag || Hflag))
  			errx(1, "the -R and -h options may not be specified together");
  		if (Hflag)
 @@ -132,7 +132,8 @@
  			fts_options &= ~FTS_PHYSICAL;
  			fts_options |= FTS_LOGICAL;
  		}
 -	}
 +	} else
 +		fts_options = hflag ? FTS_PHYSICAL : FTS_LOGICAL;
  
  	uid = gid = -1;
  	if (ischown) {
Responsible-Changed-From-To: freebsd-bugs->ru 
Responsible-Changed-By: johan 
Responsible-Changed-When: Tue Apr 23 17:27:56 PDT 2002 
Responsible-Changed-Why:  
Over to Ruslan, who made the original commit. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=36473 
State-Changed-From-To: open->suspended 
State-Changed-By: ru 
State-Changed-When: Tue May 7 01:20:55 PDT 2002 
State-Changed-Why:  
These are not yet ready for MFC. 

I have more changes to these utilities (not yet committed) planned 
that I will come up with soon on -standards. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=36473 
State-Changed-From-To: suspended->closed 
State-Changed-By: trhodes 
State-Changed-When: Fri Nov 8 14:21:12 PST 2002 
State-Changed-Why:  
I've already MFC'ed these changes per email with bde, jhb, ru, and johan. 

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