From madler@tapil.com  Thu May  2 06:56:19 2002
Return-Path: <madler@tapil.com>
Received: from tapil.com (dsl092-068-186.bos1.dsl.speakeasy.net [66.92.68.186])
	by hub.freebsd.org (Postfix) with ESMTP id BE72637B419
	for <FreeBSD-gnats-submit@freebsd.org>; Thu,  2 May 2002 06:56:18 -0700 (PDT)
Received: (from madler@localhost)
	by tapil.com (8.11.6/8.11.6) id g42DuH215977;
	Thu, 2 May 2002 09:56:17 -0400 (EDT)
	(envelope-from madler)
Message-Id: <200205021356.g42DuH215977@tapil.com>
Date: Thu, 2 May 2002 09:56:17 -0400 (EDT)
From: "Michael C. Adler" <mad1@tapil.com>
Reply-To: "Michael C. Adler" <mad1@tapil.com>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: restore does not recover uid, gid, etc. of symbolic link
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         37665
>Category:       bin
>Synopsis:       restore does not recover uid, gid, etc. of symbolic link
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    iedowse
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu May 02 07:00:03 PDT 2002
>Closed-Date:    Sun Jun 30 15:58:49 PDT 2002
>Last-Modified:  Sun Jun 30 15:58:49 PDT 2002
>Originator:     Michael C. Adler
>Release:        FreeBSD 4.5-RELEASE-p3 i386
>Organization:
>Environment:
System: FreeBSD grumpy.tapil.com 4.5-RELEASE-p3 FreeBSD 4.5-RELEASE-p3 #3: Sat Apr 27 16:08:30 EDT 2002 madler@grumpy.tapil.com:/usr/obj/usr/src/sys/GRUMPY i386


	
>Description:
	/sbin/restore does not restore the uid, gid, mode or times
	associated with symbolic links.

	A nearly correct fix has been floating around on Usenet for
	about a year, first by Yoshihiko Sarumaru and modified by
	Matthew Jacob, though neither was quite correct. 
>How-To-Repeat:
	dump a file system with a symbolic link.  restore the link
	with restore running as someone other than the owner/group
	of the original link.  Note that the restored link is owned
	by the owner of the restore process.
>Fix:
	Patch /usr/src/sbin/restore/tape.c:

--- tape.c.~1~	Wed Aug  1 05:00:28 2001
+++ tape.c	Thu May  2 09:28:19 2002
@@ -559,6 +559,14 @@
 		return (genliteraldir(name, curfile.ino));
 
 	case IFLNK:
+	  {
+		uid_t uid;
+		gid_t gid;
+		int ret;
+
+		uid = curfile.dip->di_uid;
+		gid = curfile.dip->di_gid;
+
 		lnkbuf[0] = '\0';
 		pathlen = 0;
 		getfile(xtrlnkfile, xtrlnkskip);
@@ -567,7 +575,17 @@
 			    "%s: zero length symbolic link (ignored)\n", name);
 			return (GOOD);
 		}
-		return (linkit(lnkbuf, name, SYMLINK));
+		ret = linkit(lnkbuf, name, SYMLINK);
+		if (ret == GOOD) {
+			if (lchown(name, uid, gid))
+				perror(name);
+			if (lchmod(name, mode))
+				perror(name);
+			lutimes(name, timep);
+		}
+		/* symbolic link doesn't have any flags */
+		return (ret);
+	  }
 
 	case IFIFO:
 		vprintf(stdout, "extract fifo %s\n", name);
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->patched 
State-Changed-By: iedowse 
State-Changed-When: Thu May 2 10:39:28 PDT 2002 
State-Changed-Why:  
Committed, thanks! I will merge it into stable after 4.6 (unfortunately 
you just missed the start of the code freeze). 


Responsible-Changed-From-To: freebsd-bugs->iedowse 
Responsible-Changed-By: iedowse 
Responsible-Changed-When: Thu May 2 10:39:28 PDT 2002 
Responsible-Changed-Why:  
MFC reminder. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=37665 
State-Changed-From-To: patched->closed 
State-Changed-By: iedowse 
State-Changed-When: Sun Jun 30 15:58:17 PDT 2002 
State-Changed-Why:  

The change has been merged into -stable now. 

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