mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-02 08:42:48 +00:00
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
This commit is contained in:
parent
449eb73569
commit
e1d071dbfd
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=78070
@ -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))
|
||||
|
@ -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>
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user