From owner-freebsd-hackers Fri Jan 17 22:52:14 1997 Return-Path: Received: (from root@localhost) by freefall.freebsd.org (8.8.4/8.8.4) id WAA28394 for hackers-outgoing; Fri, 17 Jan 1997 22:52:14 -0800 (PST) Received: from hq.icb.chel.su (hq.icb.chel.su [193.125.10.33]) by freefall.freebsd.org (8.8.4/8.8.4) with ESMTP id WAA28359 for ; Fri, 17 Jan 1997 22:51:57 -0800 (PST) Received: (babkin@localhost) by hq.icb.chel.su (8.8.3/8.6.5) id LAA09943; Sat, 18 Jan 1997 11:52:20 +0500 (ESK) From: "Serge A. Babkin" Message-Id: <199701180652.LAA09943@hq.icb.chel.su> Subject: Patch for cp To: jkh@time.cdrom.com Date: Sat, 18 Jan 1997 11:52:19 +0500 (ESK) Cc: hackers@freebsd.org X-Mailer: ELM [version 2.4 PL23] Content-Type: text Sender: owner-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk Hi! This patch fixes bug in /bin/cp that made it returning error "Operation not permitted" when copying files with schg flags with -p key like: cp -p /usr/bin/passwd /tmp/x Commit it please. -SB *** utils.c 1997/01/18 06:36:56 1.1 --- utils.c 1997/01/18 06:46:47 *************** *** 159,181 **** * to remove it if we created it and its length is 0. */ ! 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); --- 159,184 ---- * to remove it if we created it and its length is 0. */ ! if (pflag) { ! if (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);