From nobody@FreeBSD.org  Wed Jan  4 20:30:31 2006
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id C973F16A41F
	for <freebsd-gnats-submit@FreeBSD.org>; Wed,  4 Jan 2006 20:30:31 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 8A43343D45
	for <freebsd-gnats-submit@FreeBSD.org>; Wed,  4 Jan 2006 20:30:31 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.13.1/8.13.1) with ESMTP id k04KUV2G061541
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 4 Jan 2006 20:30:31 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id k04KUVrh061540;
	Wed, 4 Jan 2006 20:30:31 GMT
	(envelope-from nobody)
Message-Id: <200601042030.k04KUVrh061540@www.freebsd.org>
Date: Wed, 4 Jan 2006 20:30:31 GMT
From: "J.R. Oldroyd" <fbsd@opal.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: pax -pe does not preserve times on symlinks
X-Send-Pr-Version: www-2.3

>Number:         91316
>Category:       bin
>Synopsis:       [patch] pax(1): pax -pe does not preserve times on symlinks
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    kientzle
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Jan 04 20:40:04 GMT 2006
>Closed-Date:    Sun Mar 29 01:02:23 UTC 2009
>Last-Modified:  Sun Mar 29 01:10:01 UTC 2009
>Originator:     J.R. Oldroyd
>Release:        6.0 and 7.0
>Organization:
>Environment:
FreeBSD linwhf.opal.com 6.0-STABLE FreeBSD 6.0-STABLE #0: Wed Nov  9 11:17:26 EST 2005 xx@linwhf.opal.com:/usr/obj/usr/src-current/sys/LINWHF  i386
       
>Description:
Use of the pax -pe option is supposed to "`Preserve everything', the user
ID, group ID, file mode bits, file access time, and file modification time."
However, this is not honored for symlinks that are copied.

>How-To-Repeat:
mkdir /tmp/x
pax -rw -pe /path/to/a/symlink /tmp/x
ls -l /path/to/a/symlink /tmp/x/path/to/a/symlink


>Fix:
I suspect that when a symlink is copied, pax needs to check for this and
use lutimes() instead of utimes() to preserve the original times.  Don't
have a patch, though.
>Release-Note:
>Audit-Trail:

From: Jaakko Heinonen <jh@saunalahti.fi>
To: bug-followup@FreeBSD.org, fbsd@opal.com
Cc:  
Subject: Re: bin/91316: pax(1): pax -pe does not preserve times on symlinks
Date: Wed, 5 Mar 2008 13:12:13 +0200

 --5vNYLRcllDrimb99
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 
 
 Hi,
 
 Here's a patch for the problem. pax(1) doesn't restore symbolic link modes
 either. The patch fixes that too. NetBSD has similar fixes.
 
 -- 
 Jaakko
 
 --5vNYLRcllDrimb99
 Content-Type: text/x-diff; charset=us-ascii
 Content-Disposition: attachment; filename="pax-symlink-times-mode.diff"
 
 Index: file_subs.c
 ===================================================================
 RCS file: /home/ncvs/src/bin/pax/file_subs.c,v
 retrieving revision 1.22
 diff -p -u -r1.22 file_subs.c
 --- file_subs.c	24 May 2007 06:44:37 -0000	1.22
 +++ file_subs.c	5 Mar 2008 09:31:41 -0000
 @@ -432,12 +432,6 @@ node_creat(ARCHD *arcn)
  		res = 0;
  
  	/*
 -	 * symlinks are done now.
 -	 */
 -	if (arcn->type == PAX_SLK)
 -		return(0);
 -
 -	/*
  	 * IMPORTANT SECURITY NOTE:
  	 * if not preserving mode or we cannot set uid/gid, then PROHIBIT any
  	 * set uid/gid bits
 @@ -632,7 +626,7 @@ chk_path( char *name, uid_t st_uid, gid_
   *	used by -t to reset access times).
   *	When ign is zero, only those times the user has asked for are set, the
   *	other ones are left alone. We do not assume the un-documented feature
 - *	of many utimes() implementations that consider a 0 time value as a do
 + *	of many lutimes() implementations that consider a 0 time value as a do
   *	not set request.
   */
  
 @@ -661,7 +655,7 @@ set_ftime(char *fnm, time_t mtime, time_
  	/*
  	 * set the times
  	 */
 -	if (utimes(fnm, tv) < 0)
 +	if (lutimes(fnm, tv) < 0)
  		syswarn(1, errno, "Access/modification time set failed on: %s",
  		    fnm);
  	return;
 @@ -724,7 +718,7 @@ void
  set_pmode(char *fnm, mode_t mode)
  {
  	mode &= ABITS;
 -	if (chmod(fnm, mode) < 0)
 +	if (lchmod(fnm, mode) < 0)
  		syswarn(1, errno, "Could not set permissions on %s", fnm);
  	return;
  }
 
 --5vNYLRcllDrimb99--

From: "J.R. Oldroyd" <fbsd@opal.com>
To: Jaakko Heinonen <jh@saunalahti.fi>
Cc: bug-followup@FreeBSD.org
Subject: Re: bin/91316: pax(1): pax -pe does not preserve times on symlinks
Date: Tue, 1 Apr 2008 14:42:57 -0400

 --Sig_/l32ofrsiGBzgEBNRsr0vSVZ
 Content-Type: text/plain; charset=US-ASCII
 Content-Transfer-Encoding: quoted-printable
 
 I'd completely forgotten about this PR, so thanks Jaakko.
 
 I an confirm this patch does fix the problem.  Please can someone
 commit and MFC.
 
 	-jr
 
 --Sig_/l32ofrsiGBzgEBNRsr0vSVZ
 Content-Type: application/pgp-signature; name=signature.asc
 Content-Disposition: attachment; filename=signature.asc
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.7 (FreeBSD)
 
 iD8DBQFH8oIyls33urr0k4kRAljjAJ0drwCsavDbDRUL0f+yI6pgS9z8bQCglNsN
 VcsPdlO+VhjTJ7RJbZKSTnA=
 =OLhZ
 -----END PGP SIGNATURE-----
 
 --Sig_/l32ofrsiGBzgEBNRsr0vSVZ--
State-Changed-From-To: open->analyzed 
State-Changed-By: linimon 
State-Changed-When: Wed Apr 2 00:06:44 UTC 2008 
State-Changed-Why:  
Submitter confirms that the patch fixes the problem. 

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

From: "J.R. Oldroyd" <fbsd@opal.com>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/91316: [patch] pax(1): pax -pe does not preserve times on
 symlinks
Date: Mon, 11 Aug 2008 18:22:58 -0400

 Any chance this patch can be committed and MFC'd soon, please?
 
 	-jr

From: Joerg Sonnenberger <joerg@britannica.bec.de>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/91316: pax(1): pax -pe does not preserve times on symlinks
Date: Fri, 17 Oct 2008 15:55:46 +0200

 --G4iJoqBmSsgzjUCe
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 
 Attached is a reviewed patch that also cleans up set_lids. lchown should
 be used all the time for security reasons.
 
 Joerg
 
 --G4iJoqBmSsgzjUCe
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: attachment; filename="file_subs.c.diff"
 
 Index: file_subs.c
 ===================================================================
 RCS file: /home/joerg/repo/freebsd/src/bin/pax/file_subs.c,v
 retrieving revision 1.22
 diff -u -p -r1.22 file_subs.c
 --- file_subs.c	24 May 2007 06:44:37 -0000	1.22
 +++ file_subs.c	17 Oct 2008 13:49:49 -0000
 @@ -425,19 +425,11 @@ node_creat(ARCHD *arcn)
  	 * we were able to create the node. set uid/gid, modes and times
  	 */
  	if (pids)
 -		res = ((arcn->type == PAX_SLK) ?
 -		    set_lids(arcn->name, arcn->sb.st_uid, arcn->sb.st_gid) :
 -		    set_ids(arcn->name, arcn->sb.st_uid, arcn->sb.st_gid));
 +		res = set_ids(arcn->name, arcn->sb.st_uid, arcn->sb.st_gid);
  	else
  		res = 0;
  
  	/*
 -	 * symlinks are done now.
 -	 */
 -	if (arcn->type == PAX_SLK)
 -		return(0);
 -
 -	/*
  	 * IMPORTANT SECURITY NOTE:
  	 * if not preserving mode or we cannot set uid/gid, then PROHIBIT any
  	 * set uid/gid bits
 @@ -632,7 +624,7 @@ chk_path( char *name, uid_t st_uid, gid_
   *	used by -t to reset access times).
   *	When ign is zero, only those times the user has asked for are set, the
   *	other ones are left alone. We do not assume the un-documented feature
 - *	of many utimes() implementations that consider a 0 time value as a do
 + *	of many lutimes() implementations that consider a 0 time value as a do
   *	not set request.
   */
  
 @@ -661,7 +653,7 @@ set_ftime(char *fnm, time_t mtime, time_
  	/*
  	 * set the times
  	 */
 -	if (utimes(fnm, tv) < 0)
 +	if (lutimes(fnm, tv) < 0)
  		syswarn(1, errno, "Access/modification time set failed on: %s",
  		    fnm);
  	return;
 @@ -677,30 +669,6 @@ set_ftime(char *fnm, time_t mtime, time_
  int
  set_ids(char *fnm, uid_t uid, gid_t gid)
  {
 -	if (chown(fnm, uid, gid) < 0) {
 -		/*
 -		 * ignore EPERM unless in verbose mode or being run by root.
 -		 * if running as pax, POSIX requires a warning.
 -		 */
 -		if (strcmp(NM_PAX, argv0) == 0 || errno != EPERM || vflag ||
 -		    geteuid() == 0)
 -			syswarn(1, errno, "Unable to set file uid/gid of %s",
 -			    fnm);
 -		return(-1);
 -	}
 -	return(0);
 -}
 -
 -/*
 - * set_lids()
 - *	set the uid and gid of a file system node
 - * Return:
 - *	0 when set, -1 on failure
 - */
 -
 -int
 -set_lids(char *fnm, uid_t uid, gid_t gid)
 -{
  	if (lchown(fnm, uid, gid) < 0) {
  		/*
  		 * ignore EPERM unless in verbose mode or being run by root.
 @@ -724,7 +692,7 @@ void
  set_pmode(char *fnm, mode_t mode)
  {
  	mode &= ABITS;
 -	if (chmod(fnm, mode) < 0)
 +	if (lchmod(fnm, mode) < 0)
  		syswarn(1, errno, "Could not set permissions on %s", fnm);
  	return;
  }
 
 --G4iJoqBmSsgzjUCe--
Responsible-Changed-From-To: freebsd-bugs->kientzle 
Responsible-Changed-By: kientzle 
Responsible-Changed-When: Sun Feb 1 06:17:34 UTC 2009 
Responsible-Changed-Why:  
The patch looks good; I've already committed it. 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/91316: commit references a PR
Date: Sun,  1 Feb 2009 06:16:00 +0000 (UTC)

 Author: kientzle
 Date: Sun Feb  1 06:15:46 2009
 New Revision: 187976
 URL: http://svn.freebsd.org/changeset/base/187976
 
 Log:
   Before this fix, pax would stop the restore sequence for
   symlinks after setting the owner.  As a result, mode
   and timestamp were not restored.  This patch corrects the
   problem by simply removing the short-circuit for symlinks
   and using lchown()/lchmod()/lutimes() always for restoring
   metadata.
   
   PR:		bin/91316
   Submitted by:	Jaakko Heinonen
   Reviewed by:	Joerg Sonnenberger
   MFC after:	14 days
 
 Modified:
   head/bin/pax/file_subs.c
 
 Modified: head/bin/pax/file_subs.c
 ==============================================================================
 --- head/bin/pax/file_subs.c	Sun Feb  1 02:33:02 2009	(r187975)
 +++ head/bin/pax/file_subs.c	Sun Feb  1 06:15:46 2009	(r187976)
 @@ -425,19 +425,11 @@ node_creat(ARCHD *arcn)
  	 * we were able to create the node. set uid/gid, modes and times
  	 */
  	if (pids)
 -		res = ((arcn->type == PAX_SLK) ?
 -		    set_lids(arcn->name, arcn->sb.st_uid, arcn->sb.st_gid) :
 -		    set_ids(arcn->name, arcn->sb.st_uid, arcn->sb.st_gid));
 +		res = set_ids(arcn->name, arcn->sb.st_uid, arcn->sb.st_gid);
  	else
  		res = 0;
  
  	/*
 -	 * symlinks are done now.
 -	 */
 -	if (arcn->type == PAX_SLK)
 -		return(0);
 -
 -	/*
  	 * IMPORTANT SECURITY NOTE:
  	 * if not preserving mode or we cannot set uid/gid, then PROHIBIT any
  	 * set uid/gid bits
 @@ -632,7 +624,7 @@ chk_path( char *name, uid_t st_uid, gid_
   *	used by -t to reset access times).
   *	When ign is zero, only those times the user has asked for are set, the
   *	other ones are left alone. We do not assume the un-documented feature
 - *	of many utimes() implementations that consider a 0 time value as a do
 + *	of many lutimes() implementations that consider a 0 time value as a do
   *	not set request.
   */
  
 @@ -661,7 +653,7 @@ set_ftime(char *fnm, time_t mtime, time_
  	/*
  	 * set the times
  	 */
 -	if (utimes(fnm, tv) < 0)
 +	if (lutimes(fnm, tv) < 0)
  		syswarn(1, errno, "Access/modification time set failed on: %s",
  		    fnm);
  	return;
 @@ -677,30 +669,6 @@ set_ftime(char *fnm, time_t mtime, time_
  int
  set_ids(char *fnm, uid_t uid, gid_t gid)
  {
 -	if (chown(fnm, uid, gid) < 0) {
 -		/*
 -		 * ignore EPERM unless in verbose mode or being run by root.
 -		 * if running as pax, POSIX requires a warning.
 -		 */
 -		if (strcmp(NM_PAX, argv0) == 0 || errno != EPERM || vflag ||
 -		    geteuid() == 0)
 -			syswarn(1, errno, "Unable to set file uid/gid of %s",
 -			    fnm);
 -		return(-1);
 -	}
 -	return(0);
 -}
 -
 -/*
 - * set_lids()
 - *	set the uid and gid of a file system node
 - * Return:
 - *	0 when set, -1 on failure
 - */
 -
 -int
 -set_lids(char *fnm, uid_t uid, gid_t gid)
 -{
  	if (lchown(fnm, uid, gid) < 0) {
  		/*
  		 * ignore EPERM unless in verbose mode or being run by root.
 @@ -724,7 +692,7 @@ void
  set_pmode(char *fnm, mode_t mode)
  {
  	mode &= ABITS;
 -	if (chmod(fnm, mode) < 0)
 +	if (lchmod(fnm, mode) < 0)
  		syswarn(1, errno, "Could not set permissions on %s", fnm);
  	return;
  }
 _______________________________________________
 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"
 

From: Tim Kientzle <kientzle@freebsd.org>
To: bug-followup@freebsd.org, fbsd@opal.com
Cc:  
Subject: Re: bin/91316: [patch] pax(1): pax -pe does not preserve times on
 symlinks
Date: Sat, 31 Jan 2009 22:16:49 -0800

 I just committed Joerg's refinement of Jaakko's
 patch to FreeBSD-CURRENT.
 
 Please let me know if you see any problems with this.
 I'll MFC it in a couple of weeks.
 
 Tim
State-Changed-From-To: analyzed->patched 
State-Changed-By: emaste 
State-Changed-When: Thu Mar 19 19:48:39 UTC 2009 
State-Changed-Why:  
Patch has been applied. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=91316 
State-Changed-From-To: patched->closed 
State-Changed-By: kientzle 
State-Changed-When: Sun Mar 29 01:01:30 UTC 2009 
State-Changed-Why:  
Merged to 7-STABLE in r190516. 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/91316: commit references a PR
Date: Sun, 29 Mar 2009 01:01:04 +0000 (UTC)

 Author: kientzle
 Date: Sun Mar 29 01:00:48 2009
 New Revision: 190516
 URL: http://svn.freebsd.org/changeset/base/190516
 
 Log:
   MFC r187976:  Restore timestamps on symlinks
      Before this fix, pax would stop the restore sequence for
      symlinks after setting the owner.  As a result, mode
      and timestamp were not restored.  This patch corrects the
      problem by simply removing the short-circuit for symlinks
      and using lchown()/lchmod()/lutimes() always for restoring
      metadata.
   
   PR:		bin/91316
   Submitted by:	Jaakko Heinonen
   Reviewed by:	Joerg Sonnenberger
   Approved by:    re (Ken Smith)
 
 Modified:
   stable/7/bin/pax/   (props changed)
   stable/7/bin/pax/file_subs.c
 
 Modified: stable/7/bin/pax/file_subs.c
 ==============================================================================
 --- stable/7/bin/pax/file_subs.c	Sat Mar 28 23:24:34 2009	(r190515)
 +++ stable/7/bin/pax/file_subs.c	Sun Mar 29 01:00:48 2009	(r190516)
 @@ -425,19 +425,11 @@ node_creat(ARCHD *arcn)
  	 * we were able to create the node. set uid/gid, modes and times
  	 */
  	if (pids)
 -		res = ((arcn->type == PAX_SLK) ?
 -		    set_lids(arcn->name, arcn->sb.st_uid, arcn->sb.st_gid) :
 -		    set_ids(arcn->name, arcn->sb.st_uid, arcn->sb.st_gid));
 +		res = set_ids(arcn->name, arcn->sb.st_uid, arcn->sb.st_gid);
  	else
  		res = 0;
  
  	/*
 -	 * symlinks are done now.
 -	 */
 -	if (arcn->type == PAX_SLK)
 -		return(0);
 -
 -	/*
  	 * IMPORTANT SECURITY NOTE:
  	 * if not preserving mode or we cannot set uid/gid, then PROHIBIT any
  	 * set uid/gid bits
 @@ -632,7 +624,7 @@ chk_path( char *name, uid_t st_uid, gid_
   *	used by -t to reset access times).
   *	When ign is zero, only those times the user has asked for are set, the
   *	other ones are left alone. We do not assume the un-documented feature
 - *	of many utimes() implementations that consider a 0 time value as a do
 + *	of many lutimes() implementations that consider a 0 time value as a do
   *	not set request.
   */
  
 @@ -661,7 +653,7 @@ set_ftime(char *fnm, time_t mtime, time_
  	/*
  	 * set the times
  	 */
 -	if (utimes(fnm, tv) < 0)
 +	if (lutimes(fnm, tv) < 0)
  		syswarn(1, errno, "Access/modification time set failed on: %s",
  		    fnm);
  	return;
 @@ -677,30 +669,6 @@ set_ftime(char *fnm, time_t mtime, time_
  int
  set_ids(char *fnm, uid_t uid, gid_t gid)
  {
 -	if (chown(fnm, uid, gid) < 0) {
 -		/*
 -		 * ignore EPERM unless in verbose mode or being run by root.
 -		 * if running as pax, POSIX requires a warning.
 -		 */
 -		if (strcmp(NM_PAX, argv0) == 0 || errno != EPERM || vflag ||
 -		    geteuid() == 0)
 -			syswarn(1, errno, "Unable to set file uid/gid of %s",
 -			    fnm);
 -		return(-1);
 -	}
 -	return(0);
 -}
 -
 -/*
 - * set_lids()
 - *	set the uid and gid of a file system node
 - * Return:
 - *	0 when set, -1 on failure
 - */
 -
 -int
 -set_lids(char *fnm, uid_t uid, gid_t gid)
 -{
  	if (lchown(fnm, uid, gid) < 0) {
  		/*
  		 * ignore EPERM unless in verbose mode or being run by root.
 @@ -724,7 +692,7 @@ void
  set_pmode(char *fnm, mode_t mode)
  {
  	mode &= ABITS;
 -	if (chmod(fnm, mode) < 0)
 +	if (lchmod(fnm, mode) < 0)
  		syswarn(1, errno, "Could not set permissions on %s", fnm);
  	return;
  }
 _______________________________________________
 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"
 
>Unformatted:
