scott@dtscp1.UUCP (Scott Barman) (03/21/89)
I know this has been discussed before, so please respond by email. I am trying to write some software for mail that will interact with our internal network and must co-exist with the mailers on our bsd-based systems (actually, SunOS 3.5 and SunOS 4.0) and with a System V Release 3.2 system. I need to know how these systems lock the mail file. Does /usr/.../*.lock work on both of these? I know that our v7-like system uses the execute bit, but I do not have the sources to the other systems. Any help is appreciated. -- scott barman {gatech, emory}!dtscp1!scott
jonathan@cs.keele.ac.uk (Jonathan Knight) (03/22/89)
From article <588@dtscp1.UUCP>, by scott@dtscp1.UUCP (Scott Barman): > I am trying to write some software for mail that will interact with our > internal network and must co-exist with the mailers on our bsd-based > systems (actually, SunOS 3.5 and SunOS 4.0) and with a System V Release > 3.2 system. I need to know how these systems lock the mail file. > Does /usr/.../*.lock work on both of these? I know that our v7-like > system uses the execute bit, but I do not have the sources to the other > systems. I would like to see this posted as its a problem I just bumped into. I was installing 'mush' which has just appeared in comp.sources.unix and I noted that it would lock the mail files by using the *.lock method and by using flock(). I wanted it to work the same way the BSD 'mail' worked so I read up on the manual pages. The manual for /bin/mail said it used the *.lock method but the manual for '/usr/ucb/mail' didn't mention any method of mailbox locking. Seeing as /usr/ucb/mail isn't a setuid program I assume that it doesn't perform the same locking as /bin/mail as users don't have write access to /usr/spool/mail. If this is the case how does /usr/ucb/mail and /bin/mail avoid writing to the users mailbox at the same time? This is an Ultrix 1.2 machine. (BSD 4.2 ish) -- ______ JANET :jonathan@uk.ac.keele.cs Jonathan Knight, / BITNET:jonathan%cs.kl.ac.uk@ukacrl Department of Computer Science / _ __ other :jonathan@cs.keele.ac.uk University of Keele, Keele, (_/ (_) / / UUCP :...!ukc!kl-cs!jonathan Staffordshire. ST5 5BG. U.K.
syd@dsinc.UUCP (Syd Weinstein) (03/23/89)
In article <548@kl-cs.UUCP> jonathan@cs.keele.ac.uk (Jonathan Knight) writes: >From article <588@dtscp1.UUCP>, by scott@dtscp1.UUCP (Scott Barman): >> I am trying to write some software for mail that will interact with our >> internal network and must co-exist with the mailers on our bsd-based >> systems (actually, SunOS 3.5 and SunOS 4.0) and with a System V Release >> 3.2 system. I need to know how these systems lock the mail file. >> Does /usr/.../*.lock work on both of these? I know that our v7-like >> system uses the execute bit, but I do not have the sources to the other >> systems. Ok, here's a quick overview of locking for mail systems: Systems that don't use flock() on the spool file itself, use a .lock file. Where that file resides depends on the system. It's difficult to tell which systems use flock and which use .lock if the system has the flock system call, so most mail user agents use both to be sure. You never know when someone puts an older style user agent on an flock machine, so it doesn't hurt to do both. BSD and Sys V.2 put the lock file in the mail directory. Xenix puts it in /tmp and Sys V.3 puts it in the locks directory. Elm uses both flock and .lock files whenever possible, and .lock files if flock is not available. -- ===================================================================== Sydney S. Weinstein, CDP, CCP Elm Coordinator Datacomp Systems, Inc. Voice: (215) 947-9900 {allegra,bpa,vu-vlsi}!dsinc!syd FAX: (215) 938-0235
erik@mpx2.UUCP (Erik Murrey) (03/24/89)
In article <98@dsinc.UUCP> syd@dsinc.UUCP (Syd Weinstein) writes: >In article <548@kl-cs.UUCP> jonathan@cs.keele.ac.uk (Jonathan Knight) writes: >>From article <588@dtscp1.UUCP>, by scott@dtscp1.UUCP (Scott Barman): >>> 3.2 system. I need to know how these systems lock the mail file. >>> Does /usr/.../*.lock work on both of these? I know that our v7-like > >Ok, here's a quick overview of locking for mail systems: >Systems that don't use flock() on the spool file itself, use a .lock >file. Where that file resides depends on the system. Actually, the easiest way to tell what kind of locking is used is to to an "od" or "hd" of the spool directory. Look for deleted files that end in .lock or .lck. Also look at /tmp. If you don't see any, then I'll bet they use lockf (SYSV) or flock (BSD). ... Erik -- Erik Murrey /| // /~~~~/ | / MPX Data Systems, Inc. / | / / /____/ |/ erik@mpx2.UUCP / / / / /| Data Systems, Inc. {spl1,vu-vlsi,bpa}!mpx1!erik / / / / |====================
jeff@tc.fluke.COM (Jeff Stearns) (04/01/89)
In article <588@dtscp1.UUCP> scott@dtscp1.UUCP (Scott Barman) writes: > I am trying to write some software for mail that will interact with our > internal network and must co-exist with the mailers on our bsd-based > systems (actually, SunOS 3.5 and SunOS 4.0) and with a System V Release > 3.2 system. I need to know how these systems lock the mail file. > Does /usr/.../*.lock work on both of these? I know that our v7-like > system uses the execute bit, but I do not have the sources to the other > systems. > > scott barman {gatech, emory}!dtscp1!scott Scott, I had the unfortunate occasion to study mailbox locking under SunOS 4.0; my findings might be of interest to you and others on the net. This was originally submitted to Sun as a bug report. They didn't follow up on it, so I can't say whether things are likely to change in the future. Jeff Stearns jeff@tc.fluke.COM John Fluke Mfg. Co, Inc. (206) 356-5064 ------------------------------------------------------------------------ Date: Thu, 25 Aug 88 16:42:44 PDT From: jeff (Jeff Stearns) To: rdk@sun.com Subject: /usr/ucb/mail doesn't follow /bin/mail lock protocol Cc: jhc@sun.com Status: R Name: Jeff Stearns Phone Number: 206/356-5064 Site: John Fluke Mfg. Co., Inc. PAL #: FLUKE-MF01 Subject: /usr/ucb/mail doesn't follow /bin/mail lock protocol Index: usr.ucb/mail SunOS 4.0 Description: - /bin/mail locks a user's mailbox with flock("/var/spool/mail/user") before delivery. This is good. - /usr/ucb/mail follows a different strategy which is guaranteed to fail: creat("/var/spool/mail/user.lock"); This can never succeed because the permissions of /var/spool/mail forbid file creation. (This is for security reasons.) - Thus /usr/ucb/mail manipulates mailboxes without the benefit of any locking. This leads to garbled messages and mangled mailboxes if /bin/mail delivers a message at the same time that /usr/ucb/mail is manipulating the mailbox. /bin/mail delivers a message at the same time that /usr/ucb/mail is manipulating the mailbox. Repeat-By: Nondeterminism forbids an exact recipe. Receive a lot of mail while you are running /usr/ucb/mail. Better yet, run trace(1) or inspect the code. Related-bug: - You may note that /bin/mail actually tries to follow two schemes for locking a mailbox. It repeatedly tries the creat("/var/spool/mail/user.lock"); of /usr/ucb/mail, but this fails (/bin/mail runs as the target uid at the instant of delivery). After this fails seven times, it gives up and simply flocks the mailbox file. /bin/mail's repeated fiddling with /var/spool/mail/user.lock is probably also a bug. -- Jeff Stearns John Fluke Mfg. Co, Inc. (206) 356-5064 jeff@tc.fluke.COM {uw-beaver,microsoft,sun}!fluke!jeff PS - Calling all users of the Vitalink TransLAN IV Ethernet bridge! Please drop me a line.
dheller@cory.Berkeley.EDU (Dan Heller) (04/02/89)
In article <7521@fluke.COM> jeff@tc.fluke.COM (Jeff Stearns) writes: > In article <588@dtscp1.UUCP> scott@dtscp1.UUCP (Scott Barman) writes: > > Does /usr/.../*.lock work on both of these? I know that our v7-like > > system uses the execute bit, but I do not have the sources to the other > > systems. > I had the unfortunate occasion to study mailbox locking under SunOS 4.0; my > findings might be of interest to you and others on the net. The use of .../mail/*.lock is not uncommon -- Mail should also use flock, but if it doesn't, then it's another unfortunate problem with Mail. The best thing to do is use both mechanisms if you're not sure or intending to port your beast to other unix systems. If you use the .lock mechanism (I term it "dot-locking" in mush), then the binary has to be setgid to the group of whatever owns /usr/spool/mail (or whatever the directory is for your system). I presume that Sun's Mail is indeed setgid, but if it isn't and it is trying to create the .lock file, it should be setgid. If it is setgid, I'm sure that they have taken the obvious precausion to unset the group id mode when not attempting to create this file. [soap-box] If you are concerned that Mail is going to lose mail or corrupt your folders, then don't use it. There are plenty of as-good-or-better alternatives than Mail that are available to you for free. [end of soap-box] Dan Heller <island!argv@sun.com>