From owner-freebsd-bugs Sun Feb 11 14:50:15 2001 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id AE57E37B491 for ; Sun, 11 Feb 2001 14:50:01 -0800 (PST) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.1/8.11.1) id f1BMo1h56723; Sun, 11 Feb 2001 14:50:01 -0800 (PST) (envelope-from gnats) Received: from ns1.tu-graz.ac.at (ns1.tu-graz.ac.at [129.27.2.3]) by hub.freebsd.org (Postfix) with ESMTP id A2C3937B491 for ; Sun, 11 Feb 2001 14:43:40 -0800 (PST) Received: from homebox.kammerhofer.org (isdn091.tu-graz.ac.at [129.27.240.91]) by ns1.tu-graz.ac.at (8.9.3/8.9.3) with ESMTP id XAA07800 for ; Sun, 11 Feb 2001 23:43:33 +0100 (MET) Received: (from mkamm@localhost) by homebox.kammerhofer.org (8.11.2/8.11.2) id f1BMdGh02533; Sun, 11 Feb 2001 23:39:16 +0100 (CET) (envelope-from mkamm) Message-Id: <200102112239.f1BMdGh02533@homebox.kammerhofer.org> Date: Sun, 11 Feb 2001 23:39:16 +0100 (CET) From: Martin Kammerhofer Reply-To: mkamm@sbox.tu-graz.ac.at To: FreeBSD-gnats-submit@freebsd.org X-Send-Pr-Version: 3.2 Subject: bin/25012: tar(1) as root does not preserve ownership of symlinks Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org >Number: 25012 >Category: bin >Synopsis: tar(1) as root does not preserve ownership of symlinks >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Sun Feb 11 14:50:01 PST 2001 >Closed-Date: >Last-Modified: >Originator: Martin Kammerhofer >Release: FreeBSD 4.2-STABLE i386 >Organization: Universität Graz >Environment: >Description: Tar is supposed to preserve owner/group when invoked as root. This does not work for extracted symlinks. Note: FreeBSD's cpio(1) from the base system and gtar from the ports collection can do that. >How-To-Repeat: As root do: # ln -sf /1/2/3 slink # chown -h nobody:nogroup slink # ls -l slink lrwxr-xr-x 1 nobody nogroup - 6 11 Feb 23:35 slink@ -> /1/2/3 # tar cf slink.tar slink # rm -f slink # tar xf slink.tar # ls -l slink lrwxr-xr-x 1 root wheel - 6 11 Feb 23:35 slink@ -> /1/2/3 >Fix: Index: extract.c =================================================================== RCS file: /home/ncvs/src/gnu/usr.bin/tar/extract.c,v retrieving revision 1.5 diff -u -r1.5 extract.c --- extract.c 1997/04/13 08:39:38 1.5 +++ extract.c 2001/02/10 15:36:35 @@ -605,9 +605,19 @@ check = symlink (current_link_name, skipcrud + current_file_name); - /* FIXME, don't worry uid, gid, etc... */ - if (check == 0) - break; + if (check == 0) { + if (we_are_root || f_do_chown) + { + if (lchown (skipcrud + current_file_name, + hstat.st_uid, hstat.st_gid) < 0) + { + msg_perror ("cannot chown slink %s to uid %d gid %d", + skipcrud + current_file_name, + hstat.st_uid, hstat.st_gid); + } + } + break; + } if (make_dirs (current_file_name + skipcrud)) goto again_symlink; msg_perror ("Could not create symlink to %s", >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message