mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-06 09:17:25 +00:00
Don't attempt to change owner/mode/flags that don't need to changed.
This should calm down attempts to `cp -p' to a nfs mount or some other filesystem that doesn't accept flags or all combinations of flags. It will warn if it fails to change flags though.
This commit is contained in:
parent
d2b4b1fa20
commit
4faaa03777
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=36838
@ -36,7 +36,7 @@
|
|||||||
static char sccsid[] = "@(#)utils.c 8.3 (Berkeley) 4/1/94";
|
static char sccsid[] = "@(#)utils.c 8.3 (Berkeley) 4/1/94";
|
||||||
#endif
|
#endif
|
||||||
static const char rcsid[] =
|
static const char rcsid[] =
|
||||||
"$Id: utils.c,v 1.18 1998/05/13 07:25:17 charnier Exp $";
|
"$Id: utils.c,v 1.19 1998/06/09 03:38:26 imp Exp $";
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
@ -263,7 +263,9 @@ setfile(fs, fd)
|
|||||||
int fd;
|
int fd;
|
||||||
{
|
{
|
||||||
static struct timeval tv[2];
|
static struct timeval tv[2];
|
||||||
|
struct stat ts;
|
||||||
int rval;
|
int rval;
|
||||||
|
int gotstat;
|
||||||
|
|
||||||
rval = 0;
|
rval = 0;
|
||||||
fs->st_mode &= S_ISUID | S_ISGID | S_ISVTX |
|
fs->st_mode &= S_ISUID | S_ISGID | S_ISVTX |
|
||||||
@ -275,30 +277,42 @@ setfile(fs, fd)
|
|||||||
warn("utimes: %s", to.p_path);
|
warn("utimes: %s", to.p_path);
|
||||||
rval = 1;
|
rval = 1;
|
||||||
}
|
}
|
||||||
|
if (fd ? fstat(fd, &ts) : stat(to.p_path, &ts))
|
||||||
|
gotstat = 0;
|
||||||
|
else {
|
||||||
|
gotstat = 1;
|
||||||
|
ts.st_mode &= S_ISUID | S_ISGID | S_ISVTX |
|
||||||
|
S_IRWXU | S_IRWXG | S_IRWXO;
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
* Changing the ownership probably won't succeed, unless we're root
|
* Changing the ownership probably won't succeed, unless we're root
|
||||||
* or POSIX_CHOWN_RESTRICTED is not set. Set uid/gid before setting
|
* or POSIX_CHOWN_RESTRICTED is not set. Set uid/gid before setting
|
||||||
* the mode; current BSD behavior is to remove all setuid bits on
|
* the mode; current BSD behavior is to remove all setuid bits on
|
||||||
* chown. If chown fails, lose setuid/setgid bits.
|
* chown. If chown fails, lose setuid/setgid bits.
|
||||||
*/
|
*/
|
||||||
if (fd ? fchown(fd, fs->st_uid, fs->st_gid) :
|
if (!gotstat || fs->st_uid != ts.st_uid || fs->st_gid != ts.st_gid)
|
||||||
chown(to.p_path, fs->st_uid, fs->st_gid)) {
|
if (fd ? fchown(fd, fs->st_uid, fs->st_gid) :
|
||||||
if (errno != EPERM) {
|
chown(to.p_path, fs->st_uid, fs->st_gid)) {
|
||||||
|
if (errno != EPERM) {
|
||||||
|
warn("chown: %s", to.p_path);
|
||||||
|
rval = 1;
|
||||||
|
}
|
||||||
|
fs->st_mode &= ~(S_ISUID | S_ISGID);
|
||||||
|
}
|
||||||
|
|
||||||
|
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("chown: %s", to.p_path);
|
||||||
rval = 1;
|
rval = 1;
|
||||||
}
|
}
|
||||||
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);
|
|
||||||
rval = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fd ?
|
if (!gotstat || fs->st_flags != ts.st_flags)
|
||||||
fchflags(fd, fs->st_flags) : chflags(to.p_path, fs->st_flags)) {
|
if (fd ?
|
||||||
warn("chflags: %s", to.p_path);
|
fchflags(fd, fs->st_flags) : chflags(to.p_path, fs->st_flags)) {
|
||||||
rval = 1;
|
warn("chflags: %s", to.p_path);
|
||||||
}
|
rval = 1;
|
||||||
|
}
|
||||||
|
|
||||||
return (rval);
|
return (rval);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user