Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 18 Jan 1997 11:52:19 +0500 (ESK)
From:      "Serge A. Babkin" <babkin@hq.icb.chel.su>
To:        jkh@time.cdrom.com
Cc:        hackers@freebsd.org
Subject:   Patch for cp
Message-ID:  <199701180652.LAA09943@hq.icb.chel.su>

next in thread | raw e-mail | index | archive | help
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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199701180652.LAA09943>