[4455] in Athena Bugs

home help back first fref pref prev next nref lref last post

cp -p preserves setuid bits

daemon@ATHENA.MIT.EDU (John Carr)
Thu Mar 8 01:52:56 1990

To: bugs@ATHENA.MIT.EDU
Date: Thu, 08 Mar 90 01:52:41 EST
From: John Carr <jfc@ATHENA.MIT.EDU>

This patch makes cp -p strip off the setuid bit from a file when the
copier is not the original owner.

[Reference: changes.70 #172]

*** /source/bsd-4.3/common/bin/cp.c	Mon May  9 12:49:21 1988
--- cp.c	Thu Mar  8 01:49:55 1990
***************
*** 26,31 ****
--- 26,32 ----
  int	iflag;
  int	rflag;
  int	pflag;
+ int	myuid;
  char	*rindex();
  
  main(argc, argv)
***************
*** 49,54 ****
--- 50,56 ----
  
  		case 'p':	/* preserve mtimes, atimes, and modes */
  			pflag++;
+ 			myuid = getuid();
  			(void) umask(0);
  			break;
  
***************
*** 153,165 ****
  			}
  		}
  	}
! 	fnew = creat(to, stfrom.st_mode & 07777);
  	if (fnew < 0) {
  		Perror(to);
  		(void) Close(fold); return(1);
  	}
  	if (exists && pflag)
! 		(void) fchmod(fnew, stfrom.st_mode & 07777);
  			
  	for (;;) {
  		n = read(fold, buf, sizeof buf);
--- 155,169 ----
  			}
  		}
  	}
! 	fnew = creat(to, stfrom.st_mode &
! 		     (myuid == stfrom.st_uid ? 07777 : 01777));
  	if (fnew < 0) {
  		Perror(to);
  		(void) Close(fold); return(1);
  	}
  	if (exists && pflag)
! 		(void) fchmod(fnew, stfrom.st_mode &
! 			      (myuid == stfrom.st_uid ? 07777 : 01777));
  			
  	for (;;) {
  		n = read(fold, buf, sizeof buf);

home help back first fref pref prev next nref lref last post