1

I have managed to extract all attachments from emails being delivered to a certain email to a public folder on my linux server (using postfix->procmail->uudeview). Unfortunately the files themselves are saved with the permissions restricted to the system user that the files were sent to (called 'scans').

How can I build a "chmod 777 /path/to/folder/*.pdf" into my setup so that the files (which are coming from my scanner) are available to anyone?

Is there a better way to do this?

Regards Frank

Toffix
  • 51
  • 3

1 Answers1

2

Whatever it is that you are doing, chmod 777 is so misdirected as to lose your computer driver's license. It is a serious security problem to make files world-writable and executable.

You are probably looking for Procmail's UMASK variable. If permissions are too tight, set a more relaxed UMASK before delivering. Example:

:0
* some conditions
{
    UMASK=003
    :0
    | uudeview --whatever
}

The umask system call can only strip permissions, not add them. Typically, a C program tries to create a data file using mode 0666 and then the umask is applied, often yielding something like 0644 (meaning the effective umask was something like 0022 or 0033). On Linux, the directory's permissions also somewhat influence the permissions of newly created files. But we are venturing outside of Procmail here. Perhaps you can achieve the end result you require by combining the UMASK facility of Procmail with directory permissions.

If the "attachments" you are extracting are not MIME attachments but actual uuencode, note also that the encoding specifies permissions for every encoded file. If the begin line says 644 then you might have to change that. Procmail to the rescue again!

:0
* some conditions
{
    UMASK=003
    | sed 's/^begin [0-7][0-7][0-7][0-7]* /begin 664 /' | uudeview --whatever
}

In the end, if even this doesn't help, it may come down to modifying uudeview, perhaps by tweaking its source, or by creating a wrapper which fixes up permissions after writing.

tripleee
  • 175,061
  • 34
  • 275
  • 318
  • I suspected that the 777 wouldn't go down well ;) – Toffix Mar 13 '14 at 08:24
  • The UMASK does what I am after but only "half way". I have tried UMASK=001, UMASK=003, UMASK=010 and UMASK=100, but all just provide rw-r--r-- access to the files. My .procmailrc is: :0 *^content-Type: { UMASK=001 :0fw | uudeview -p /home/storage/scans - } – Toffix Mar 13 '14 at 08:35
  • Updated somewhat. Incidentally, your condition on the presence of the `Content-Type:` header is kind of weird. If it works for you, good; but basically all MIME messages have that. – tripleee Mar 13 '14 at 09:46