Subject: Re: Pine lockfile

From: Stephen Casner <[email-masked]>
Date: Thu, 6 Mar 2003 11:08:03 -0800 (PST)

On Tue, 18 Feb 2003, Mats Dufberg wrote:

> On Feb 17, 2003, 18:18 (-0500) Mike A. Harris <[email-masked]> wrote:
>
> > >And you have verified that locking is working correctly with pine?
> >
> > Well, we've been shipping like this for years, and yes it does
> > work, although our pine is patched.  Open 2 pine sessions at once
> > and you're told the mailbox is in use by another pine session.
>
> Yes, that should be a sufficient test, and I knew that I came to the same
> conclusion but you reminded me how. The same thing is true on FreeBSD.

The question of setting the spool directory protection to 1777 is a
FAQ.  I've quoted below the info from the Pine Information Center.
It indicates that the locking mechanism under discussion here is for
locking between the mail delivery agent and the mail user agent, not
between two mail user agents.  So, is the test above really
sufficient?

                                                        -- Steve

http://www.washington.edu/pine/faq/sysadmins.html says:

11.5 Where does Pine create lockfiles, and what should that
directory's permissions be?

To protect against conflicts with mail delivery by sendmail, which
could cause INBOX corruption, Pine creates lockfiles in the directory
/var/spool/mail [1]. The permission setting for that directory should
be 1777 (world writable with the sticky bit set). The alternative
would be to make all mail programs setgid to some special group -- an
unacceptable security risk in the opinion of the Pine developers [2].

By contrast, lockfiles created in the /tmp directory serve
interlocking of different Pine sessions with each other, not of Pine
with the Mail Delivery Agent. Lockfiles in the /tmp directory are mode
666 because of the case of shared folders (e.g., tenex format) and
"kiss of death" functionality (UNIX mbox format and MMDF format). The
lock needs to be accessible by processes which may be logged in as
another user name; this is a tradeoff between security and
functionality.

[1] Versions of Pine prior to 3.92 did not warn users when locking in
/var/spool/mail failed.

[2] Some version of the Linux operating system are being distributed
with permissions that would require Pine to run setgid.

---

From: Mats Dufberg <[email-masked]>
Date: Thu, 6 Mar 2003 21:30:43 +0100 (CET)

> between two mail user agents.  So, is the test above really

Probably not.

I have, however, done some other tests that I start to remember now. I
created a small perl script that did lock a file in the same manner as the
MDA does with fcntl(2). When I lock the spool file with the script neither
the MDA nor pine will access the file.

The script is written for FreeBSD. The locks are OS dependent, as far as I
remember.

I locking works, it should not be possible to deliver to the spool file if
the spool file is locked by the script. And pine should not do any changes
or even read the spool file.

######################################################################

#!/usr/bin/perl

use Fcntl;

unless ($ARGV[1]) { warn "Usage: $0 -r|-w FILE\n"; exit 1;};

$writlck = pack "l4 i s2",0,0,0,0,0,&F_WRLCK,0;
$readlck = pack "l4 i s2",0,0,0,0,0,&F_RDLCK,0;
$unlck   = pack "l4 i s2",0,0,0,0,0,&F_UNLCK,0;

$file = $ARGV[1];

if ($ARGV[0] =~ /^-w/i) {
        open FIL, ">>$file" or die "$!";
        if (fcntl (FIL, &F_SETLK, $writlck)) {
            print "Write locked -- press <CR> to unlock.\n";
            $tmp=<STDIN>;
            if (fcntl (FIL, &F_SETLK, $unlck)) {
                print "Unlocked\n";
            } else {
                print "ERROR unlocking\n";
            };
        } else {
            print "Cannot write lock\n";
        };
} elsif ($ARGV[0] =~ /^-r/i) {
        open FIL, "$file" or die "$!";
        if (fcntl (FIL, &F_SETLK, $readlck)) {
            print "Read locked -- press <CR> to unlock.\n";
            $tmp=<STDIN>;
            if (fcntl (FIL, &F_SETLK, $unlck)) {
                print "Unlocked\n";
            } else {
                print "ERROR unlocking\n";
            };
        } else {
            print "Cannot read lock\n";
        };
} else {
        die "Illegal argument.\n";
};

######################################################################

Mats

-----------------------------------------------------------------
Mats Dufberg                                 [email-masked]
Blaoarvsgraend 42                                  +46-8-38 48 59
SE-162 45 Vaellingby, Sweden                      +46-70-258 2588