From owner-freebsd-bugs Sun Feb 11 14:50:34 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 D933337B401 for ; Sun, 11 Feb 2001 14:50:02 -0800 (PST) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.1/8.11.1) id f1BMo2v56768; Sun, 11 Feb 2001 14:50:02 -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 9000E37B4EC for ; Sun, 11 Feb 2001 14:43:49 -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 XAA07821 for ; Sun, 11 Feb 2001 23:43:44 +0100 (MET) Received: (from mkamm@localhost) by homebox.kammerhofer.org (8.11.2/8.11.2) id f1B16SU01894; Sun, 11 Feb 2001 02:06:28 +0100 (CET) (envelope-from mkamm) Message-Id: <200102110106.f1B16SU01894@homebox.kammerhofer.org> Date: Sun, 11 Feb 2001 02:06:28 +0100 (CET) From: mkamm@gmx.net Reply-To: mkamm@gmx.net To: FreeBSD-gnats-submit@freebsd.org X-Send-Pr-Version: 3.2 Subject: bin/25017: cp -pRP does not preserve symlink ownership Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org >Number: 25017 >Category: bin >Synopsis: cp -pRP does not preserve symlink ownership >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:02 PST 2001 >Closed-Date: >Last-Modified: >Originator: Martin Kammerhofer >Release: FreeBSD 4.2-STABLE i386 >Organization: Universität Graz >Environment: >Description: I quote "man cp": -p Cause cp to preserve in the copy as many of the modification time, access time, file flags, file mode, user ID, and group ID as al- lowed by permissions. However no attempt is made by cp(1) to preserve ownership of copied symlinks. >How-To-Repeat: as root try: # ln -s /COPYRIGHT copyright # chown -h uucp:bin copyright # ls -l copyright lrwxr-xr-x 1 uucp bin 10 11 Feb 01:57 copyright -> /COPYRIGHT # cp -pR copyright copyright2 # ls -l copyright2 lrwxr-xr-x 1 root mkamm 10 11 Feb 01:57 copyright2 -> /COPYRIGHT >Fix: Index: utils.c =================================================================== RCS file: /home/ncvs/src/bin/cp/utils.c,v retrieving revision 1.28 diff -u -r1.28 utils.c --- utils.c 2000/10/10 01:48:18 1.28 +++ utils.c 2001/02/11 00:52:13 @@ -224,7 +224,7 @@ warn("symlink: %s", link); return (1); } - return (0); + return (pflag ? setlink(p->fts_statp) : 0); } int @@ -305,7 +305,7 @@ if (!gotstat || fs->st_mode != ts.st_mode) if (fd ? fchmod(fd, fs->st_mode) : chmod(to.p_path, fs->st_mode)) { - warn("chown: %s", to.p_path); + warn("chmod: %s", to.p_path); rval = 1; } @@ -318,6 +318,31 @@ return (rval); } + + +int +setlink(fs) + struct stat *fs; +{ + struct stat ts; + + if (lstat(to.p_path, &ts)) { + warn("symlink %s disappeared", to.p_path); + return (1); + } + /* + * Changing the ownership probably won't succeed, unless we are root. + */ + if (fs->st_uid != ts.st_uid || fs->st_gid != ts.st_gid) + if (lchown(to.p_path, fs->st_uid, fs->st_gid)) { + if (errno != EPERM) { + warn("lchown: %s", to.p_path); + return (1); + } + } + return (0); +} + void usage() >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message