Skip site navigation (1)Skip section navigation (2)
Date:      23 Oct 1996 07:08:15 -0500
From:      Zach Heilig <zach@blizzard.gaffaneys.com>
To:        freebsd-bugs@freefall.freebsd.org
Subject:   Re: bin/1377
Message-ID:  <87684151e8.fsf@bedrock.gaffaneys.com>
In-Reply-To: "Marc G. Fournier"'s message of Tue, 22 Oct 1996 21:32:58 -0700 (PDT)

next in thread | raw e-mail | index | archive | help

> Synopsis: mv(1) retains the setuid bit when it is unable to preserve the uid.

Here is a patch that updates the fastcopy() routine in mv(1) to
conform to the method cp(1) uses for handling setuid/setgid bits when
the uid and gid cannot be preserved.  Note that the actual behavior of
cp -p does NOT match the man page (more on this later).

*** mv.c.orig	Wed Oct 23 05:42:32 1996
--- mv.c	Wed Oct 23 06:56:45 1996
***************
*** 207,219 ****
  	static u_int blen;
  	static char *bp;
  	register int nread, from_fd, to_fd;
  
  	if ((from_fd = open(from, O_RDONLY, 0)) < 0) {
  		warn("%s", from);
  		return (1);
  	}
! 	if ((to_fd =
! 	    open(to, O_CREAT | O_TRUNC | O_WRONLY, sbp->st_mode)) < 0) {
  		warn("%s", to);
  		(void)close(from_fd);
  		return (1);
--- 207,219 ----
  	static u_int blen;
  	static char *bp;
  	register int nread, from_fd, to_fd;
+ 	mode_t new_mode;
  
  	if ((from_fd = open(from, O_RDONLY, 0)) < 0) {
  		warn("%s", from);
  		return (1);
  	}
! 	if ((to_fd = open(to, O_CREAT | O_TRUNC | O_WRONLY, 0600)) < 0) {
  		warn("%s", to);
  		(void)close(from_fd);
  		return (1);
***************
*** 237,245 ****
  	}
  	(void)close(from_fd);
  
! 	if (fchown(to_fd, sbp->st_uid, sbp->st_gid))
  		warn("%s: set owner/group", to);
! 	if (fchmod(to_fd, sbp->st_mode))
  		warn("%s: set mode", to);
  
  	tval[0].tv_sec = sbp->st_atime;
--- 237,249 ----
  	}
  	(void)close(from_fd);
  
! 	if (fchown(to_fd, sbp->st_uid, sbp->st_gid)) {
  		warn("%s: set owner/group", to);
! 		new_mode = sbp->st_mode & 01777;
! 	} else
! 		new_mode = sbp->st_mode;
! 	
! 	if (fchmod(to_fd, new_mode))
  		warn("%s: set mode", to);
  
  	tval[0].tv_sec = sbp->st_atime;


-- 
Zach Heilig (zach@blizzard.gaffaneys.com) | ALL unsolicited commercial email
Support bacteria -- it's the              | is unwelcome.  I avoid dealing
only culture some people have!            | with companies that email ads.



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