procmail
[Top] [All Lists]

Re: Fw: help changinf owner of file crated by /etc/procmailrc

2005-04-11 10:57:51
On Mon, Apr 11, 2005 at 10:27:51AM -0700, Bart Schaefer wrote:

On Apr 11, 2005 9:45 AM, Dallman Ross <dman(_at_)nomotek(_dot_)com> wrote:

It sounds like you want chown.  You would have to do it in
/etc/procmailrc as the elevated user.


I'd approach this roughly as follows:

# Use a "c"lone (copy) delivery here so delivery doesn't terminate processing
:0 c:
* conditions matching spammy messages
/path/to/webmail/spammymessagefile

# Now check if we performed a delivery, and if so do a chown and exit
:0
* LASTFOLDER ?? .
* ? chown  apache $LASTFOLDER
{ HOST }

# Here do error handling if chown failed
:0 E
{
 # Whatever ....
}

Not bad.  Better  not to bother with touch and chown every time,
as mine would.  However, yours has a slight problem, I believe:
what if a user tries to access the file in a race condition with
your chown, but after delivery from the previous
recipe?

Perhaps we need a global lockfile here around the recipe set.

But we could slightly alter the approach and avoid that, I think.
As long as there is a file already, we'd have chowned it previously
and it would have the correct attributes.  Only if the file has
been deleted and is being created newly is there a problem with
ownership.  So how about:


   :0
   * ? test -o apache $FILE
   $FILE

   :0 E
   * ? chown apache $FILE
   $FILE

   :0 E
   /path/to/failed/chowns

We still need a "test" call for every message -- would be best if
the shell has been set to /bin/sh to keep a small footprint --


  SHELL = /bin/sh

early on in the /etc/procmailrc --

and we're only running chown now if the test failed.  I don't know that
it makes all that much difference from my earlier suggestion of touch
and chown each time, though, because both will be in the memory cache
and will be quick.  But anyway . . .

Dallman

____________________________________________________________
procmail mailing list   Procmail homepage: http://www.procmail.org/
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail