From ff87e3837143f9c11c515533a9e4eb2bd4281d12 Mon Sep 17 00:00:00 2001 From: millert Date: Tue, 25 Feb 1997 02:27:28 +0000 Subject: [PATCH] Better fix for -p and links. --- bin/cp/extern.h | 3 ++- bin/cp/utils.c | 33 +++++++++++++++++++-------------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/bin/cp/extern.h b/bin/cp/extern.h index 812c0bb50cd..6d20efd07b2 100644 --- a/bin/cp/extern.h +++ b/bin/cp/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.2 1996/06/23 14:19:10 deraadt Exp $ */ +/* $OpenBSD: extern.h,v 1.3 1997/02/25 02:27:28 millert Exp $ */ /* $NetBSD: extern.h,v 1.3 1995/03/21 09:02:16 cgd Exp $ */ /*- @@ -54,5 +54,6 @@ int copy_file __P((FTSENT *, int)); int copy_link __P((FTSENT *, int)); int copy_special __P((struct stat *, int)); int setfile __P((struct stat *, int)); +int setlink __P((struct stat *)); void usage __P((void)); __END_DECLS diff --git a/bin/cp/utils.c b/bin/cp/utils.c index 7e9d94aa5dd..af6e3c0fd07 100644 --- a/bin/cp/utils.c +++ b/bin/cp/utils.c @@ -1,4 +1,4 @@ -/* $OpenBSD: utils.c,v 1.4 1997/02/24 20:43:27 millert Exp $ */ +/* $OpenBSD: utils.c,v 1.5 1997/02/25 02:27:28 millert Exp $ */ /* $NetBSD: utils.c,v 1.4 1995/08/02 07:17:02 jtc Exp $ */ /*- @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)utils.c 8.3 (Berkeley) 4/1/94"; #else -static char rcsid[] = "$OpenBSD: utils.c,v 1.4 1997/02/24 20:43:27 millert Exp $"; +static char rcsid[] = "$OpenBSD: utils.c,v 1.5 1997/02/25 02:27:28 millert Exp $"; #endif #endif /* not lint */ @@ -200,7 +200,7 @@ copy_link(p, exists) warn("symlink: %s", link); return (1); } - return (pflag ? setfile(p->fts_statp, 0) : 0); + return (pflag ? setlink(p->fts_statp) : 0); } int @@ -244,17 +244,6 @@ setfile(fs, fd) static struct timeval tv[2]; int rval = 0; - /* Only change the owner for symbolic links. */ - if (S_ISLNK(fs->st_mode)) { - if (lchown(to.p_path, fs->st_uid, fs->st_gid)) { - if (errno != EPERM) { - warn("lchown: %s", to.p_path); - rval = 1; - } - } - return (rval); - } - fs->st_mode &= S_ISUID | S_ISGID | S_IRWXU | S_IRWXG | S_IRWXO; TIMESPEC_TO_TIMEVAL(&tv[0], &fs->st_atimespec); @@ -290,6 +279,22 @@ setfile(fs, fd) return (rval); } + +int +setlink(fs) + register struct stat *fs; +{ + + 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() { -- 2.20.1