From nobody@FreeBSD.org  Mon Feb 23 07:25:27 2009
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id DC9931065678
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 23 Feb 2009 07:25:27 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 9465A8FC16
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 23 Feb 2009 07:25:27 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id n1N7PQUB023380
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 23 Feb 2009 07:25:26 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id n1N7PQN7023379;
	Mon, 23 Feb 2009 07:25:26 GMT
	(envelope-from nobody)
Message-Id: <200902230725.n1N7PQN7023379@www.freebsd.org>
Date: Mon, 23 Feb 2009 07:25:26 GMT
From: Deomid Ryabkov <myself@rojer.pp.ru>
To: freebsd-gnats-submit@FreeBSD.org
Subject: chflags: unable to unset flags on symlinks when link target exists
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         131999
>Category:       bin
>Synopsis:       chflags(1): unable to unset flags on symlinks when link target exists
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Feb 23 07:30:03 UTC 2009
>Closed-Date:    Mon Mar 07 16:25:57 UTC 2011
>Last-Modified:  Mon Mar 07 16:25:57 UTC 2011
>Originator:     Deomid Ryabkov
>Release:        7.1-PRERELEASE #0: Mon Sep  8 14:15:33 MSD 2008
>Organization:
>Environment:
FreeBSD xxx 7.1-PRERELEASE FreeBSD 7.1-PRERELEASE #0: Mon Sep  8 14:15:33 MSD 2008     rojer@xxx:/usr/obj/usr/src/sys/GENERIC  amd64

>Description:
# ls -lo logs
lrwxr-xr-x   1 root   www-rojer  schg   17 Sep 16  2006 logs -> /logs/rojer
# ls -ldo /logs/rojer
drwxr-x---  2 root  www-rojer  - 512 Feb 23 09:59 /logs/rojer
# chflags -h noschg logs
# ls -lo logs
lrwxr-xr-x  1 root  www-rojer  schg 17 Sep 16  2006 logs -> /logs/rojer.pp.ru

i. e. nothing happened

truss of chflags reveals the problem: usage of stat() where lstat() should have been used.

# truss chflags -h noschg logs
[...]
stat("logs",{ mode=drwxr-x--- ,inode=22303757,size=512,blksize=4096 }) = 0 (0x0)
process exit, rval = 0

this way, lchflags(2) is never actually called because chflags(3) doesn't think it is necessary.
>How-To-Repeat:
create a symlink pointing to an existing flagless entry (this is important),
use chfalgs -h to set flags on the symlink - this one succeeds.
then try chflags -h to remove the flag you just set - this one fails, because stat(2) returns information on the entry symlink points at that does not have the flag.
>Fix:
i had a glance at bin/chflags/chflags.c and it seems to be using fts_* functions to traverse the tree. somehow those need to be told to use lstat to return information, when appropriate.

>Release-Note:
>Audit-Trail:

From: Bruce Evans <brde@optusnet.com.au>
To: Deomid Ryabkov <myself@rojer.pp.ru>
Cc: freebsd-gnats-submit@freebsd.org, freebsd-bugs@freebsd.org
Subject: Re: misc/131999: chflags: unable to unset flags on symlinks when
 link target exists
Date: Tue, 24 Feb 2009 17:19:17 +1100 (EST)

 On Mon, 23 Feb 2009, Deomid Ryabkov wrote:
 
 >> Synopsis:       chflags: unable to unset flags on symlinks when link target exists
 
 Also, setting only works accidentally in some cases.
 
 > truss of chflags reveals the problem: usage of stat() where lstat() should have been used.
 >
 > # truss chflags -h noschg logs
 > [...]
 > stat("logs",{ mode=drwxr-x--- ,inode=22303757,size=512,blksize=4096 }) = 0 (0x0)
 > process exit, rval = 0
 >
 > this way, lchflags(2) is never actually called because chflags(3) doesn't think it is necessary.
 
 And for chflags -h schg logs, lchflags() is only called because the wrong
 flags returned by stat() happen to have their schg bit clear.  If the
 schg bit were set in the symlink target, then this chflags would do nothing
 too.
 
 >> Fix:
 > i had a glance at bin/chflags/chflags.c and it seems to be using fts_* functions to traverse the tree. somehow those need to be told to use lstat to return information, when appropriate.
 
 Setting FTS_PHYSICAL seems to fix it:
 
 % Index: chflags.c
 % ===================================================================
 % RCS file: /home/ncvs/src/bin/chflags/chflags.c,v
 % retrieving revision 1.24
 % diff -u -2 -r1.24 chflags.c
 % --- chflags.c	9 Mar 2008 12:10:24 -0000	1.24
 % +++ chflags.c	24 Feb 2009 06:13:00 -0000
 % @@ -115,5 +115,7 @@
 %  			fts_options |= FTS_LOGICAL;
 %  		}
 % -	} else
 % +	} else if (hflag)
 % +		fts_options = FTS_PHYSICAL;
 % +	else
 %  		fts_options = FTS_LOGICAL;
 %
 
 Bruce

From: Jilles Tjoelker <jilles@stack.nl>
To: bug-followup@FreeBSD.org, myself@rojer.pp.ru, dd@freebsd.org
Cc:  
Subject: Re: bin/131999: chflags(1): unable to unset flags on symlinks when
	link target exists
Date: Sat, 4 Apr 2009 19:08:03 +0200

 bde's patch (use FTS_PHYSICAL instead of FTS_LOGICAL if -h is in effect)
 fixes chflags -h for me, and also agrees with what chmod does. So I
 think this can be committed.
 
 -- 
 Jilles Tjoelker

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/131999: commit references a PR
Date: Sun, 24 May 2009 15:27:40 +0000 (UTC)

 Author: jilles
 Date: Sun May 24 15:27:25 2009
 New Revision: 192687
 URL: http://svn.freebsd.org/changeset/base/192687
 
 Log:
   Fix chflags -h in various cases: do not use link target's flags as original.
   
   Patch slightly changed to align more with chmod.c.
   
   PR:		bin/131999
   Submitted by:	bde
   Approved by:	ed (mentor)
   MFC after:	3 weeks
 
 Modified:
   head/bin/chflags/chflags.c
 
 Modified: head/bin/chflags/chflags.c
 ==============================================================================
 --- head/bin/chflags/chflags.c	Sun May 24 13:22:00 2009	(r192686)
 +++ head/bin/chflags/chflags.c	Sun May 24 15:27:25 2009	(r192687)
 @@ -115,7 +115,7 @@ main(int argc, char *argv[])
  			fts_options |= FTS_LOGICAL;
  		}
  	} else
 -		fts_options = FTS_LOGICAL;
 +		fts_options = hflag ? FTS_PHYSICAL : FTS_LOGICAL;
  
  	/* XXX: Why don't chflags and lchflags have compatible prototypes? */
  	if (hflag)
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->patched 
State-Changed-By: jilles 
State-Changed-When: Sun May 24 15:43:23 UTC 2009 
State-Changed-Why:  
Mark patched pending MFC. 


Responsible-Changed-From-To: freebsd-bugs->jilles 
Responsible-Changed-By: jilles 
Responsible-Changed-When: Sun May 24 15:43:23 UTC 2009 
Responsible-Changed-Why:  
Mark patched pending MFC. 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/131999: commit references a PR
Date: Sun, 14 Jun 2009 17:04:18 +0000 (UTC)

 Author: jilles
 Date: Sun Jun 14 17:03:59 2009
 New Revision: 194199
 URL: http://svn.freebsd.org/changeset/base/194199
 
 Log:
   MFC r192687: fix chflags -h
   
   PR:		bin/131999
   Submitted by:	bde
   Approved by:	ed (mentor)
 
 Modified:
   stable/7/bin/chflags/   (props changed)
   stable/7/bin/chflags/chflags.c
 
 Modified: stable/7/bin/chflags/chflags.c
 ==============================================================================
 --- stable/7/bin/chflags/chflags.c	Sun Jun 14 17:00:35 2009	(r194198)
 +++ stable/7/bin/chflags/chflags.c	Sun Jun 14 17:03:59 2009	(r194199)
 @@ -115,7 +115,7 @@ main(int argc, char *argv[])
  			fts_options |= FTS_LOGICAL;
  		}
  	} else
 -		fts_options = FTS_LOGICAL;
 +		fts_options = hflag ? FTS_PHYSICAL : FTS_LOGICAL;
  
  	/* XXX: Why don't chflags and lchflags have compatible prototypes? */
  	if (hflag)
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
Responsible-Changed-From-To: jilles->freebsd-bugs 
Responsible-Changed-By: jilles 
Responsible-Changed-When: Sat Jun 20 13:18:50 UTC 2009 
Responsible-Changed-Why:  
I'm not interested in 6.x. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=131999 
State-Changed-From-To: patched->closed 
State-Changed-By: jh 
State-Changed-When: Mon Mar 7 16:25:56 UTC 2011 
State-Changed-Why:  
Fixed in supported branches. 

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