diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 1997-02-24 20:43:28 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 1997-02-24 20:43:28 +0000 |
commit | 957b3fcc106174a8919537602a81fac949433b38 (patch) | |
tree | 25ee9119bfc1f2c17ce3d5e2b9efae93bb69f60a /bin/cp/utils.c | |
parent | ae006aa53bb996527615f4cad1af7048d3167edf (diff) |
Only update owner (via lchown) when dealing with symbolic links.
Fixes core dump problem with ``-p'' and symbolic links. Noted by
Carsten Hammer <chammer@post.uni-bielefeld.de>.
Diffstat (limited to 'bin/cp/utils.c')
-rw-r--r-- | bin/cp/utils.c | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/bin/cp/utils.c b/bin/cp/utils.c index c54b07e7f81..7e9d94aa5dd 100644 --- a/bin/cp/utils.c +++ b/bin/cp/utils.c @@ -1,4 +1,4 @@ -/* $OpenBSD: utils.c,v 1.3 1997/01/26 22:04:45 kstailey Exp $ */ +/* $OpenBSD: utils.c,v 1.4 1997/02/24 20:43:27 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.3 1997/01/26 22:04:45 kstailey Exp $"; +static char rcsid[] = "$OpenBSD: utils.c,v 1.4 1997/02/24 20:43:27 millert Exp $"; #endif #endif /* not lint */ @@ -200,7 +200,7 @@ copy_link(p, exists) warn("symlink: %s", link); return (1); } - return (pflag ? setfile(NULL, 0) : 0); + return (pflag ? setfile(p->fts_statp, 0) : 0); } int @@ -242,18 +242,26 @@ setfile(fs, fd) int fd; { static struct timeval tv[2]; - int rval; + int rval = 0; - rval = 0; - if (fs != NULL) { - fs->st_mode &= S_ISUID | S_ISGID | S_IRWXU | S_IRWXG | S_IRWXO; - - TIMESPEC_TO_TIMEVAL(&tv[0], &fs->st_atimespec); - TIMESPEC_TO_TIMEVAL(&tv[1], &fs->st_mtimespec); - if (utimes(to.p_path, tv)) { - warn("utimes: %s", to.p_path); - rval = 1; + /* 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); + TIMESPEC_TO_TIMEVAL(&tv[1], &fs->st_mtimespec); + if (utimes(to.p_path, tv)) { + warn("utimes: %s", to.p_path); + rval = 1; } /* * Changing the ownership probably won't succeed, unless we're root @@ -262,17 +270,15 @@ setfile(fs, fd) * chown. If chown fails, lose setuid/setgid bits. */ if (fd ? fchown(fd, fs->st_uid, fs->st_gid) : - lchown(to.p_path, fs->st_uid, fs->st_gid)) { + chown(to.p_path, fs->st_uid, fs->st_gid)) { if (errno != EPERM) { - warn("lchown: %s", to.p_path); + warn("chown: %s", to.p_path); rval = 1; } - if (fs == NULL) - return (rval); fs->st_mode &= ~(S_ISUID | S_ISGID); } 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; } |