From owner-freebsd-bugs Tue Jun 11 11:15:56 1996 Return-Path: owner-bugs Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id LAA16752 for bugs-outgoing; Tue, 11 Jun 1996 11:15:56 -0700 (PDT) Received: from crh.cl.msu.edu (crh.cl.msu.edu [35.8.1.24]) by freefall.freebsd.org (8.7.5/8.7.3) with SMTP id LAA16744 for ; Tue, 11 Jun 1996 11:15:46 -0700 (PDT) Received: (from henrich@localhost) by crh.cl.msu.edu (8.6.12/8.6.12) id OAA04730 for freebsd-bugs@freebsd.org; Tue, 11 Jun 1996 14:15:42 -0400 From: Charles Henrich Message-Id: <199606111815.OAA04730@crh.cl.msu.edu> Subject: mail.local quota fix To: freebsd-bugs@freebsd.org Date: Tue, 11 Jun 1996 14:15:41 -0400 (EDT) X-Mailer: ELM [version 2.4 PL24 ME8a] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-bugs@freebsd.org X-Loop: FreeBSD.org Precedence: bulk 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);