Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 11 Jun 1996 14:15:41 -0400 (EDT)
From:      Charles Henrich <henrich@crh.cl.msu.edu>
To:        freebsd-bugs@freebsd.org
Subject:   mail.local quota fix
Message-ID:  <199606111815.OAA04730@crh.cl.msu.edu>

next in thread | raw e-mail | index | archive | help
Hey Folks, this patch fixed mail.local.c in -current so that it will understand how 
to deal with mailboxes that go over quota (in this case it queues the mail for 
redelivery, allowing the user a few days to make room..)  This has been tested
extensivly with the same patches applied to the mail.local in 2.1R, and works
beautifully.

Please commit this !

-Crh

diff -cr orig-current/mail.local.c mod-current/mail.local.c
*** orig-current/mail.local.c	Sat Apr 13 15:42:57 1996
--- mod-current/mail.local.c	Tue Jun 11 14:10:37 1996
***************
*** 198,203 ****
--- 198,204 ----
  {
  	struct stat fsb, sb;
  	struct passwd *pw;
+         uid_t saveeuid;
  	int mbfd, nr, nw, off;
  	char biffmsg[100], buf[8*1024], path[MAXPATHLEN];
  	off_t curoff;
***************
*** 236,241 ****
--- 237,244 ----
  	 * XXX
  	 * open(2) should support flock'ing the file.
  	 */
+ 
+         saveeuid=geteuid();
  tryagain:
  	if (lstat(path, &sb)) {
  		mbfd = open(path,
***************
*** 248,258 ****
--- 251,278 ----
  			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 */
+ 
+                 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 setuid()");
+                         return;
+                 }
+ 
  		mbfd = open(path, O_APPEND|O_WRONLY, 0);
  		if (mbfd != -1 &&
  		    (fstat(mbfd, &fsb) || fsb.st_nlink != 1 ||
***************
*** 260,265 ****
--- 280,286 ----
  		    sb.st_ino != fsb.st_ino)) {
  			warn("%s: file changed after open", path);
  			(void)close(mbfd);
+                         seteuid(saveeuid);
  			return;
  		}
  	}
***************
*** 267,272 ****
--- 288,294 ----
  	if (mbfd == -1) {
  		e_to_sys(errno);
  		warn("%s: %s", path, strerror(errno));
+                 seteuid(saveeuid);
  		return;
  	}
  
***************
*** 302,307 ****
--- 324,330 ----
  		warn("temporary file: %s", strerror(errno));
  err2:		(void)ftruncate(mbfd, curoff);
  err1:		(void)close(mbfd);
+                 seteuid(saveeuid);
  		return;
  	}
  
***************
*** 318,325 ****
--- 341,351 ----
  	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?199606111815.OAA04730>