aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorBruce Evans <bde@FreeBSD.org>2001-06-11 13:57:54 +0000
committerBruce Evans <bde@FreeBSD.org>2001-06-11 13:57:54 +0000
commite1d071dbfd4dcb74b363b1240fc128096c90e0e0 (patch)
tree46f648b9bcd8b6bd904eb0058e3befa6575f8467 /bin
parent449eb73569141d67a7e2d3fa417551278bb29678 (diff)
downloadsrc-e1d071dbfd4dcb74b363b1240fc128096c90e0e0.tar.gz
src-e1d071dbfd4dcb74b363b1240fc128096c90e0e0.zip
Removed the broken code which claimed to lose the set[ug]id bits in
the !(pflag && setfile()) case for regular files unless the copy is owned by the same user and group. These bits have already been lost (or never gained) in the correct way. The code didn't actually lose the bits; it depended on them being lost already (apparently in all cases) and attempted to gain them as necessary, but it often gained them (and sometimes collateral bits) when wrong: - pflag && setfile() == 0 case (i.e., for a successful cp -p): setfile() copies all the attributes as correctly as possible (as specified by POSIX), and we sometimes messed up the up the mode by setting it again. Also, if the file is immutable, then setting the mode again gave spurious errors (PR 20646). - !pflag case. If the target is created, POSIX requires it to not have the set[ug]id bits, but we sometimes copied them from the source. If the target already exists, POSIX requires its mode to be unchanged, but we sometimes copied the whole mode from the source. PR: 20646 MFC after: 4 weeks
Notes
Notes: svn path=/head/; revision=78070
Diffstat (limited to 'bin')
-rw-r--r--bin/cp/cp.c8
-rw-r--r--bin/cp/extern.h3
-rw-r--r--bin/cp/utils.c20
3 files changed, 4 insertions, 27 deletions
diff --git a/bin/cp/cp.c b/bin/cp/cp.c
index 0592444d90f5..3478c735b88f 100644
--- a/bin/cp/cp.c
+++ b/bin/cp/cp.c
@@ -83,9 +83,7 @@ static const char rcsid[] =
PATH_T to = { to.p_path, "", "" };
-uid_t myuid;
int Rflag, iflag, pflag, rflag, fflag, vflag;
-int myumask;
enum op { FILE_TO_FILE, FILE_TO_DIR, DIR_TO_DNE };
@@ -170,12 +168,6 @@ main(argc, argv)
fts_options |= FTS_LOGICAL;
}
- myuid = getuid();
-
- /* Copy the umask for explicit mode setting. */
- myumask = umask(0);
- (void)umask(myumask);
-
/* Save the target base in "to". */
target = argv[--argc];
if (strlcpy(to.p_path, target, sizeof(to.p_path)) >= sizeof(to.p_path))
diff --git a/bin/cp/extern.h b/bin/cp/extern.h
index 3b0ecef59600..4e5f07c8644a 100644
--- a/bin/cp/extern.h
+++ b/bin/cp/extern.h
@@ -41,8 +41,7 @@ typedef struct {
} PATH_T;
extern PATH_T to;
-extern uid_t myuid;
-extern int iflag, pflag, fflag, vflag, myumask;
+extern int iflag, pflag, fflag, vflag;
#include <sys/cdefs.h>
diff --git a/bin/cp/utils.c b/bin/cp/utils.c
index 110cc791a776..479550e1ea06 100644
--- a/bin/cp/utils.c
+++ b/bin/cp/utils.c
@@ -63,7 +63,7 @@ copy_file(entp, dne)
int dne;
{
static char buf[MAXBSIZE];
- struct stat to_stat, *fs;
+ struct stat *fs;
int ch, checkch, from_fd, rcount, rval, to_fd, wcount, wresid;
char *bufp;
#ifdef VM_AND_BUFFER_CACHE_SYNCHRONIZED
@@ -180,22 +180,6 @@ copy_file(entp, dne)
if (pflag && setfile(fs, to_fd))
rval = 1;
- /*
- * If the source was setuid or setgid, lose the bits unless the
- * copy is owned by the same user and group.
- */
-#define RETAINBITS \
- (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO)
- else if (fs->st_mode & (S_ISUID | S_ISGID) && fs->st_uid == myuid) {
- if (fstat(to_fd, &to_stat)) {
- warn("%s", to.p_path);
- rval = 1;
- } else if (fs->st_gid == to_stat.st_gid &&
- fchmod(to_fd, fs->st_mode & RETAINBITS & ~myumask)) {
- warn("%s", to.p_path);
- rval = 1;
- }
- }
(void)close(from_fd);
if (close(to_fd)) {
warn("%s", to.p_path);
@@ -260,6 +244,8 @@ copy_special(from_stat, exists)
return (pflag ? setfile(from_stat, 0) : 0);
}
+#define RETAINBITS \
+ (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO)
int
setfile(fs, fd)