SCCS-vsn: bin/cp/cp.c 5.18
#endif /* not lint */
#ifndef lint
#endif /* not lint */
#ifndef lint
-static char sccsid[] = "@(#)cp.c 5.17 (Berkeley) %G%";
+static char sccsid[] = "@(#)cp.c 5.18 (Berkeley) %G%";
{
static struct timeval tv[2];
{
static struct timeval tv[2];
+ fs->st_mode &= S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO;
+
tv[0].tv_sec = fs->st_atime;
tv[1].tv_sec = fs->st_mtime;
if (utimes(to.p_path, tv))
error(to.p_path);
/*
* Changing the ownership probably won't succeed, unless we're root
tv[0].tv_sec = fs->st_atime;
tv[1].tv_sec = fs->st_mtime;
if (utimes(to.p_path, tv))
error(to.p_path);
/*
* Changing the ownership probably won't succeed, unless we're root
- * or POSIX_CHOWN_RESTRICTED is not set. Set uid before setting the
- * mode; current BSD behavior is to remove all setuid bits on chown.
- * If setuid, lose the bits if chown fails.
- * If setgid, lose the bits if chgrp fails.
- * If both, lose the bits if either fails.
+ * or POSIX_CHOWN_RESTRICTED is not set. Set uid/gid before setting
+ * the mode; current BSD behavior is to remove all setuid bits on
+ * chown. If chown fails, lose setuid/setgid bits.
- if ((fd ?
- fchown(fd, fs->st_uid, -1) : chown(to.p_path, fs->st_uid, -1))) {
- if (errno != EPERM)
- error(to.p_path);
- if (fs->st_mode & S_ISUID)
- fs->st_mode &= ~(S_ISUID|S_ISGID);
- }
- if ((fd ?
- fchown(fd, -1, fs->st_gid) : chown(to.p_path, -1, fs->st_gid))) {
+ if (fd ? fchown(fd, fs->st_uid, fs->st_gid) :
+ chown(to.p_path, fs->st_uid, fs->st_gid)) {
if (errno != EPERM)
error(to.p_path);
if (errno != EPERM)
error(to.p_path);
- if (fs->st_mode & S_ISGID)
- fs->st_mode &= ~(S_ISUID|S_ISGID);
+ fs->st_mode &= ~(S_ISUID|S_ISGID);
- fs->st_mode &= S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO;
if (fd ? fchmod(fd, fs->st_mode) : chmod(to.p_path, fs->st_mode))
error(to.p_path);
}
if (fd ? fchmod(fd, fs->st_mode) : chmod(to.p_path, fs->st_mode))
error(to.p_path);
}