procmail returning with exit code 0 even if it can't read its config file: How to prevent?
1
vote
2
answers
255
views
I am dealing with
procmail
the first time, so I apologize if the following question is stupid. Before I put procmail
in production, I am doing a few basic tests. One of them yielded a totally unexpected result which makes it nearly worthless in my scenario:
When procmail
cannot read its configuration file, it nevertheless sets its exit code to 0
(true) when it finishes. This is catastrophic, because in my scenario, I am using procmail
as an MDA which is executed from within fetchmail
. If procmail
can't read its configuration file, it can't process (deliver) messages as needed, but sets exit code 0
when it finishes; fetchmail
interprets this as successful delivery and deletes the respective messages upstream. In summary, this leads to those messages being lost.
The permissions in this scenario are quite complex (fetchmail
+ procmail
+ cyrdeliver
over lmtp
, fetchmail
running under its own user account, procmail
being suid
and setgid
, and so on), so it could very well happen that somebody makes a mistake with the permissions when something needs to be changed. Due to the problem described above, such mistakes likely lead to loss of messages.
Therefore, I'd like to know how to make procmail
to exit with failure (exit code other than 0
) if it can't read its configuration file.
To give an idea what this is about, please consider the following terminal session (irrelevant lines removed). Please note that the ownership / permissions in the config directory are wrong by intention, because this is my test case.
root@morn /etc/fetchmail # whoami
root
root@morn /etc/fetchmail # dir
total 52K
drwx------ 2 fetchmail root 4.0K 2022-01-23 10:09 .
drwxr-xr-x 123 root root 12K 2022-01-22 17:17 ..
-rw------- 1 fetchmail root 2.4K 2022-01-23 10:09 fetchmailrc
-rw------- 1 root mail 282 2022-01-23 02:49 procmailrc
-rw-r--r-- 1 root root 110 2022-01-23 00:36 testmessage
root@morn /etc/fetchmail # dir which procmail
-rwsr-sr-x 1 root mail 92K 2017-11-16 23:42 /usr/bin/procmail
root@morn /etc/fetchmail # cat /etc/systemd/system/pp-fetchmail.service
User=fetchmail
Group=mail
ExecStart=/usr/bin/fetchmail -f /etc/fetchmail/fetchmailrc --pidfile /run/fetchmail/fetchmail.pid --syslog
root@morn /etc/fetchmail # cat fetchmailrc
poll
pop3.example.com
proto pop3
bad-header accept
user "user1@example.com"
ssl
pass "supersecret"
is "user1" here
no rewrite
mda "/usr/bin/procmail TARGET=user1 /etc/fetchmail/procmailrc"
root@morn /etc/fetchmail # cat testmessage
From: nobody@nowhere.com
To: somebody@somewhere.com
Subject: Test message
This is a test message.
root@morn /etc/fetchmail # sudo -u fetchmail -g mail /usr/bin/procmail /etc/fetchmail/procmailrc < testmessage && echo "procmail exited 0"
procmail: Couldn't read "/etc/fetchmail/procmailrc"
procmail exited 0
Of course, the last two lines are the problem. Does anybody know how to circumvent it? Of course, fixing the permissions would make it work correctly, but that is what I'm explicitly not asking for. I'd like to have a solution which is more robust in case of mistakes (mine or others').
Asked by Binarus
(3891 rep)
Jan 23, 2022, 10:11 AM
Last activity: Jan 24, 2022, 07:18 AM
Last activity: Jan 24, 2022, 07:18 AM