Date: Sun, 11 Feb 2001 23:39:16 +0100 (CET) From: Martin Kammerhofer <mkamm@sbox.tu-graz.ac.at> To: FreeBSD-gnats-submit@freebsd.org Subject: bin/25012: tar(1) as root does not preserve ownership of symlinks Message-ID: <200102112239.f1BMdGh02533@homebox.kammerhofer.org>
next in thread | raw e-mail | index | archive | help
>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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200102112239.f1BMdGh02533>