On Thursday, March 31, 2016 5:11 PM, Wietse Venema <wie...@porcupine.org> wrote:

> Have to tried to run it by hand as user
> VMAIL, just like you configured in master.cf?
>
>    Wietse


Yes, in fact, I have run it in 4 different ways. When I run maildropwrapper 
from the command line mail is delivered to the right Maildir, both as root and 
as vmail. When maildropwrapper is called by postfix it doesn't deliver mail to 
the right Maildir. 

1. calling maildirwrapper from the command line, as root

cat /var/vmail/maildropwrapper

#!/bin/bash
echo $(date) > /tmp/maildrop
echo running maildrop as "$(whoami)" with arguments "$@"  >> /tmp/maildrop 2>&1
args="$@"
echo "je suis toujours là" >> /tmp/maildrop
maildrop $args >> /tmp/maildrop 2>&1
echo " suis-je toujours là ?" >> /tmp/maildrop

root@messagerie[10.10.10.20] /var/vmail/algerian-radio.dz/a.chaouche/new # 
/var/vmail/maildropwrapper -V 9 -d a.chaou...@algerian-radio.dz -w 80 
test mail
root@messagerie[10.10.10.20] /var/vmail/algerian-radio.dz/a.chaouche/new #

maildrop trace

root@messagerie[10.10.10.20] /var/vmail/algerian-radio.dz/a.chaouche/new # cat 
/tmp/maildrop 
Wed Apr 6 14:15:20 CET 2016
running maildrop as root with arguments -V 9 -d a.chaou...@algerian-radio.dz -w 
80
je suis toujours là
maildrop: authlib: groupid=1002
maildrop: authlib: userid=113
maildrop: authlib: logname=a.chaou...@algerian-radio.dz, home=/var/vmail/, 
mail=algerian-radio.dz/a.chaouche/
maildrop: Changing to /var/vmail/
Message envelope sender=MAILER-DAEMON
Tokenized ;
Tokenized ;
Tokenized ;
Tokenized ;
Tokenized ;
Tokenized eof
maildrop: Attempting .mailfilter
maildrop: Delivery complete.
suis-je toujours là ?
root@messagerie[10.10.10.20] /var/vmail/algerian-radio.dz/a.chaouche/new # 

Mail delivered (file was created at 14:18)

root@messagerie[10.10.10.20] /var/vmail/algerian-radio.dz/a.chaouche/new # ls 
-rt | head -n 2
total 104K
-rw------- 1 vmail vmail  1 Mar 31 14:18 
1459430303.M654267P3399V0000000000000811I00000000004402EC_0.messagerie,S=1
root@messagerie[10.10.10.20] /var/vmail/algerian-radio.dz/a.chaouche/new # 



2. calling maildirwrapper from the command line, as root, but changing to vmail 
inside the script (su)

cat /var/vmail/maildropwrapper

#!/bin/bash
echo $(date) > /tmp/maildrop
echo running maildrop as "$(whoami)" with arguments "$@"  >> /tmp/maildrop 2>&1
args="$@"
echo "je suis toujours là" >> /tmp/maildrop
su vmail -c "maildrop $args >> /tmp/maildrop 2>&1"
echo " suis-je toujours là ?" >> /tmp/maildrop

root@messagerie[10.10.10.20] /var/vmail/algerian-radio.dz/a.chaouche/new # 
/var/vmail/maildropwrapper -V 9 -d a.chaou...@algerian-radio.dz -w 80
test mail
root@messagerie[10.10.10.20] /var/vmail/algerian-radio.dz/a.chaouche/new # 

Mail was delivered :


root@messagerie[10.10.10.20] /var/vmail/algerian-radio.dz/a.chaouche/new # ls 
-t | head -2
total 108K
-rw------- 1 vmail vmail 10 Apr  6 14:19 
1459948794.M288704P8101V0000000000000811I0000000000441E4D_0.messagerie,S=10
root@messagerie[10.10.10.20] /var/vmail/algerian-radio.dz/a.chaouche/new # 

maildrop trace file :

vmail@messagerie:/root$ cat /tmp/maildrop
Wed Apr 6 14:19:49 CET 2016
running maildrop as root with arguments -V 9 -d a.chaou...@algerian-radio.dz -w 
80
je suis toujours là
maildrop: authlib: groupid=1002
maildrop: authlib: userid=113
maildrop: authlib: logname=a.chaou...@algerian-radio.dz, home=/var/vmail/, 
mail=algerian-radio.dz/a.chaouche/
maildrop: Changing to /var/vmail/
Message envelope sender=MAILER-DAEMON
Tokenized ;
Tokenized ;
Tokenized ;
Tokenized ;
Tokenized ;
Tokenized eof
maildrop: Attempting .mailfilter
maildrop: Delivery complete.
suis-je toujours là ?
vmail@messagerie:/root$ 


3. calling maildropwrapper from the command line as user vmail 

vmail@messagerie:/var/vmail$ /var/vmail/maildropwrapper -V 9 -d 
a.chaou...@algerian-radio.dz 
test 
vmail@messagerie:/var/vmail$ 

Mail was delivered : 

root@messagerie[10.10.10.20] /var/vmail/algerian-radio.dz/a.chaouche/new # ls 
-t | head -2
total 112K
-rw------- 1 vmail vmail  6 Apr  6 14:22 
1459948965.M511937P8110V0000000000000811I0000000000441E4E_0.messagerie,S=6
root@messagerie[10.10.10.20] /var/vmail/algerian-radio.dz/a.chaouche/new # 

maildrop trace 

vmail@messagerie:/var/vmail$ cat /tmp/maildrop 
Wed Apr 6 14:22:42 CET 2016
running maildrop as vmail with arguments -V 9 -d a.chaou...@algerian-radio.dz
je suis toujours là
maildrop: authlib: groupid=1002
maildrop: authlib: userid=113
maildrop: authlib: logname=a.chaou...@algerian-radio.dz, home=/var/vmail/, 
mail=algerian-radio.dz/a.chaouche/
maildrop: Changing to /var/vmail/
Message envelope sender=MAILER-DAEMON
Tokenized ;
Tokenized ;
Tokenized ;
Tokenized ;
Tokenized ;
Tokenized eof
maildrop: Attempting .mailfilter
maildrop: Delivery complete.
suis-je toujours là ?
vmail@messagerie:/var/vmail$ 


4. calling maildropwrapper through postfix

Here's master.cf : 

maildrop  unix  -       n       n       -       -       pipe
flags=DRhu user=vmail argv=/var/vmail/maildropwrapper -V9 -d ${recipient}


It's run as user vmail, we'll also see this in the trace file of maildropwrapper

Sending the mail : 

root@messagerie[10.10.10.20] /var/vmail/algerian-radio.dz/a.chaouche/new # mail 
a.chaou...@algerian-radio.dz
Subject: this will go through postfix
test
.
Cc: 
root@messagerie[10.10.10.20] /var/vmail/algerian-radio.dz/a.chaouche/new # 


postfix logs : 

Apr  6 14:26:44 messagerie postfix/pickup[7867]: CCEDF1620079: uid=0 from=<root>
Apr  6 14:26:44 messagerie postfix/cleanup[8122]: CCEDF1620079: 
message-id=<20160406132644.ccedf1620...@messagerie.algerian-radio.dz>
Apr  6 14:26:44 messagerie postfix/smtpd[8127]: connect from 
localhost[127.0.0.1]
Apr  6 14:26:44 messagerie postfix/smtpd[8127]: EAFBB1620077: 
client=localhost[127.0.0.1]
Apr  6 14:26:44 messagerie postfix/cleanup[8122]: EAFBB1620077: 
message-id=<20160406132644.ccedf1620...@messagerie.algerian-radio.dz>
Apr  6 14:26:44 messagerie postfix/smtpd[8127]: disconnect from 
localhost[127.0.0.1]
Apr  6 14:26:45 messagerie postfix/smtp[8125]: CCEDF1620079: 
to=<a.chaou...@algerian-radio.dz>, relay=127.0.0.1[127.0.0.1]:10024, 
delay=0.21, delays=0.08/0.01/0/0.12, dsn=2.0.0, status=sent (250 2.0.0 from 
MTA(smtp:[127.0.0.1]:10025): 250 2.0.0 Ok: queued as EAFBB1620077)


maildropwrapper trace : 

vmail@messagerie:/var/vmail$ cat /tmp/maildrop 
Wed Apr 6 14:26:45 CET 2016
running maildrop as vmail with arguments -V9 -d a.chaou...@algerian-radio.dz
je suis toujours là
ERR: authdaemon: s_connect() failed: Permission denied
Invalid user specified.
suis-je toujours là ?
vmail@messagerie:/var/vmail$ 


The error message is a bit unclear, but it seems something is not being able to 
connect to authdaemon. I edited the maildropwrapper script to show an strace of 
what maildrop is trying to do and got more details on the error : 

maildropwrapper straced version : 


#!/bin/bash
echo $(date) > /tmp/maildrop
echo running maildrop as "$(whoami)" with arguments "$@"  >> /tmp/maildrop 2>&1
args="$@"
echo "je suis toujours là" >> /tmp/maildrop
strace maildrop $args >> /tmp/maildrop 2>&1
echo " suis-je toujours là ?" >> /tmp/maildrop

Now the trace file of maildropwrapper (/tmp/maildrop) shows where's the error 
coming from : 

connect(3, {sa_family=AF_LOCAL, sun_path="/var/run/courier/authdaemon/socket"}, 
110) = -1 EACCES (Permission denied)

I checked the permissions of that file, here they are : 

root@messagerie[10.10.10.20] /var/vmail/algerian-radio.dz/a.chaouche/new # 
namei -l /var/run/courier/authdaemon/socket 
f: /var/run/courier/authdaemon/socket
drwxr-xr-x root   root   /
drwxr-xr-x root   root   var
lrwxrwxrwx root   root   run -> /run
drwxr-xr-x root   root     /
drwxr-xr-x root   root     run
drwxrwxr-x daemon daemon courier
drwxr-x--- daemon daemon authdaemon
srwxrwxrwx root   root   socket
root@messagerie[10.10.10.20] /var/vmail/algerian-radio.dz/a.chaouche/new # 

I made sure vmail could read it as user vmail : 

root@messagerie[10.10.10.20] ~ # su vmail
vmail@messagerie:/root$ ls /var/run/courier/authdaemon/
pid       pid.lock  socket 
vmail@messagerie:/root$ ls /var/run/courier/authdaemon/socket 
/var/run/courier/authdaemon/socket
vmail@messagerie:/root$ ls -lh /var/run/courier/authdaemon/socket 
srwxrwxrwx 1 root root 0 Apr  5 14:22 /var/run/courier/authdaemon/socket
vmail@messagerie:/root$ 


I also made sure that the authentication service is running (I'm using Cyrus)
root@messagerie[10.10.10.20] /var/vmail/algerian-radio.dz/a.chaouche/new # 
/etc/init.d/courier-authdaemon status
● courier-authdaemon.service - (null)
Loaded: loaded (/etc/init.d/courier-authdaemon)
Active: active (running) since Tue 2016-04-05 14:22:30 CET; 24h ago
Process: 7201 ExecStop=/etc/init.d/courier-authdaemon stop (code=exited, 
status=0/SUCCESS)
Process: 2257 ExecStart=/etc/init.d/courier-authdaemon start (code=exited, 
status=0/SUCCESS)
CGroup: /system.slice/courier-authdaemon.service
├─2261 /usr/sbin/courierlogger -pid=/var/run/courier/authdaemon/pid -sta...
├─2262 /usr/lib/courier/courier-authlib/authdaemond
├─2266 /usr/lib/courier/courier-authlib/authdaemond
├─2267 /usr/lib/courier/courier-authlib/authdaemond
├─2269 /usr/lib/courier/courier-authlib/authdaemond
├─2270 /usr/lib/courier/courier-authlib/authdaemond
└─2273 /usr/lib/courier/courier-authlib/authdaemond

Apr 05 14:22:30 messagerie courier-authdaemon[2257]: Starting Courier 
authenticati....
Hint: Some lines were ellipsized, use -l to show in full.
root@messagerie[10.10.10.20] /var/vmail/algerian-radio.dz/a.chaouche/new # 



I have no idea why is delivey working just fine EXCEPT when run from postfix ?


root@messagerie[10.10.10.20] /var/vmail/algerian-radio.dz/a.chaouche/new # 
postfix check
root@messagerie[10.10.10.20] /var/vmail/algerian-radio.dz/a.chaouche/new # 

Reply via email to