Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 28 Feb 1997 18:31:27 -0500 (EST)
From:      Charles Henrich <henrich@crh.cl.msu.edu>
To:        mpp@freefall.freebsd.org (Mike Pritchard)
Cc:        freebsd-bugs@freebsd.org
Subject:   Re: mail.local modifications?
Message-ID:  <199702282331.SAA07013@crh.cl.msu.edu>
In-Reply-To: <199702280358.TAA11910@freefall.freebsd.org> from Mike Pritchard at "Feb 27, 97 07:58:14 pm"

next in thread | previous in thread | raw e-mail | index | archive | help
> The cvs log for mail.local is attached to this message.  It appears that 
> the patch you supplied was screwed up.  Looking at the PR, you
> didn't submit a proper context diff, and that caused it to not apply
> correctly.  Please submit a new diff so that someone can work
> with it.  

Okay here is the correct patch.  This is the same one I've been running for 
years, so unless I had a complete brain fart, it works wonderful.  Everyone
please review and commit asap, thanks!

One more thing, whomever added nobiff support intruduced a real nasty bug, 
in the case when the write to mailbox fails (for whatever reason) mail.local
truncates the box, unfortunatly if running in nobiff mode the offset is 
never initialized (doesnt anyone use -Wall?) and the mailbox would be truncated
at some random point.  This patch also fixes that problem.

Generated with:

    diff -c mail.local.c mail.local.c.new 

-Crh

*** mail.local.c	Sat Feb 22 23:49:15 1997
--- mail.local.c.new	Fri Feb 28 18:30:44 1997
***************
*** 203,208 ****
--- 203,209 ----
  	int mbfd, nr, nw, off;
  	char biffmsg[100], buf[8*1024], path[MAXPATHLEN];
  	off_t curoff;
+         uid_t saveeuid;
  
  	/*
  	 * Disallow delivery to unknown names -- special mailboxes can be
***************
*** 238,243 ****
--- 239,247 ----
  	 * XXX
  	 * open(2) should support flock'ing the file.
  	 */
+ 
+         saveeuid=geteuid();
+ 
  tryagain:
  	if (lstat(path, &sb)) {
  		mbfd = open(path,
***************
*** 250,260 ****
--- 254,282 ----
  			warn("chown %u.%u: %s", pw->pw_uid, pw->pw_gid, name);
  			return;
  		}
+ 
+                 /* Now that the box is created and permissions are correct, we
+                    close it and go back to the top so that we will come in
+                    and write as the user.  We dont seteuid() before the above
+                    open, because we have to be root/bin to write in var/mail 
+ 		   -Crh (henrich@msu.edu) */
+  
+                 close(mbfd);
+                 goto tryagain;
+ 
  	} else if (sb.st_nlink != 1 || S_ISLNK(sb.st_mode)) {
  		e_to_sys(errno);
  		warn("%s: linked file", path);
  		return;
  	} else {
+ 
+                 /* Become the user, so quota enforcement will occur */
+         
+                 if(seteuid(pw->pw_uid) != 0) {
+                         warn("Unable to seteuid()");
+                         return; 
+                 }
+ 
  		mbfd = open(path, O_APPEND|O_WRONLY, 0);
  		if (mbfd != -1 &&
  		    (fstat(mbfd, &fsb) || fsb.st_nlink != 1 ||
***************
*** 262,267 ****
--- 284,290 ----
  		    sb.st_ino != fsb.st_ino)) {
  			warn("%s: file changed after open", path);
  			(void)close(mbfd);
+                         seteuid(saveeuid); 
  			return;
  		}
  	}
***************
*** 269,274 ****
--- 292,299 ----
  	if (mbfd == -1) {
  		e_to_sys(errno);
  		warn("%s: %s", path, strerror(errno));
+                 seteuid(saveeuid);
+ 
  		return;
  	}
  
***************
*** 279,288 ****
  		goto err1;
  	}
  
! 	if (!nobiff) {
! 		/* Get the starting offset of the new message for biff. */
! 		curoff = lseek(mbfd, (off_t)0, SEEK_END);
! 		(void)snprintf(biffmsg, sizeof(biffmsg), "%s@%qd\n",
  			       name, curoff);
  	}
  
--- 304,313 ----
  		goto err1;
  	}
  
! 	curoff = lseek(mbfd, (off_t)0, SEEK_END);
! 
!         if (!nobiff) {
! 		(void)snprintf(biffmsg, sizeof(biffmsg), "%s@%qd\n", 
  			       name, curoff);
  	}
  
***************
*** 304,309 ****
--- 329,335 ----
  		warn("temporary file: %s", strerror(errno));
  err2:		(void)ftruncate(mbfd, curoff);
  err1:		(void)close(mbfd);
+                 seteuid(saveeuid);
  		return;
  	}
  
***************
*** 320,327 ****
--- 346,356 ----
  	if (close(mbfd)) {
  		e_to_sys(errno);
  		warn("%s: %s", path, strerror(errno));
+                 seteuid(saveeuid);
  		return;
  	}
+ 
+         seteuid(saveeuid);
  
  	if (!nobiff)
  		notifybiff(biffmsg);



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