Date: Sun, 11 Feb 2001 02:06:28 +0100 (CET) From: mkamm@gmx.net To: FreeBSD-gnats-submit@freebsd.org Subject: bin/25017: cp -pRP does not preserve symlink ownership Message-ID: <200102110106.f1B16SU01894@homebox.kammerhofer.org>
next in thread | raw e-mail | index | archive | help
>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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200102110106.f1B16SU01894>
