Re: MDA exited prematurely when using custom script

2024-03-09 Thread Simon Hoffmann
Philipp wrote:

> [2024-03-05 17:07] Simon Hoffmann 
> > hmm... Based on Philipps idea I have modified my script as follows:
> >
> >
> >
> > #!/bin/bash
> >
> > cat - > /tmp/notfallemail
> 
> Have you notice that this is racy? A better (not elegant solution) is
> something like:
> 
> mail=`cat`

Yeah, in the final version I will do this differently. Writing stdin to a file 
gave
me the opportunity to inspect the file.


> 
> > from=`cat /tmp/notfallemail | head -n 50 | grep -i ^From`
> > from=${from// /+}
> >
> > subject=`cat /tmp/notfallemail | head -n 50 | grep -i ^Subject`
> > subject=${subject// /+}
> >
> >
> > out=`curl -g 
> > "https://smsgw01/cgi-bin/sms_send?text=Neue+Notfall+Email+von+$from+mit+Betreff+$subject"`
> >
> > exit 0
> >
> >
> > Stdin works. The SMS message now contains the From and the Subject header. 
> > However, OpenSMTPd still complains with "mda exited prematurely".
> 
> This sounds strange, are you sure that this error is produced while
> using this exact version of the script?

Yes, I have double checked that. 

> 
> >
> > If I however change the script to the following, while the message OpenSMTPd
> > complains about is still in the queue and pending
> >
> > #!/bin/bash
> >
> > cat - > /dev/null
> >
> > out=`curl -g "https://smsgw01/cgi-bin/sms_send?text=Neue+Notfall+Email"`
> >
> > exit 0
> >
> >
> > and then issue smtpctl schedule all, then OpenSMTPd reports a successful 
> > delivery and removes the mail from the queue.
> >
> >
> > Any ideas?
> 
> A wild guess is that your fs under '/tmp' is to small and cat gets a pipe
> error. Specialy when you have multible instances of your script running
> this is quite hard to detect.

There is ~150GB of free space on disk and /tmp is just a folder on /, no 
separate
filesystem. 




Simon



signature.asc
Description: PGP signature


Re: MDA exited prematurely when using custom script

2024-03-07 Thread Philipp
[2024-03-05 17:07] Simon Hoffmann 
> hmm... Based on Philipps idea I have modified my script as follows:
>
>
>
> #!/bin/bash
>
> cat - > /tmp/notfallemail

Have you notice that this is racy? A better (not elegant solution) is
something like:

mail=`cat`

> from=`cat /tmp/notfallemail | head -n 50 | grep -i ^From`
> from=${from// /+}
>
> subject=`cat /tmp/notfallemail | head -n 50 | grep -i ^Subject`
> subject=${subject// /+}
>
>
> out=`curl -g 
> "https://smsgw01/cgi-bin/sms_send?text=Neue+Notfall+Email+von+$from+mit+Betreff+$subject"`
>
> exit 0
>
>
> Stdin works. The SMS message now contains the From and the Subject header. 
> However, OpenSMTPd still complains with "mda exited prematurely".

This sounds strange, are you sure that this error is produced while
using this exact version of the script?

>
> If I however change the script to the following, while the message OpenSMTPd
> complains about is still in the queue and pending
>
> #!/bin/bash
>
> cat - > /dev/null
>
> out=`curl -g "https://smsgw01/cgi-bin/sms_send?text=Neue+Notfall+Email"`
>
> exit 0
>
>
> and then issue smtpctl schedule all, then OpenSMTPd reports a successful 
> delivery and removes the mail from the queue.
>
>
> Any ideas?

A wild guess is that your fs under '/tmp' is to small and cat gets a pipe
error. Specialy when you have multible instances of your script running
this is quite hard to detect.

Philipp



Re: MDA exited prematurely when using custom script

2024-03-05 Thread Simon Hoffmann


hmm... Based on Philipps idea I have modified my script as follows:



#!/bin/bash

cat - > /tmp/notfallemail
from=`cat /tmp/notfallemail | head -n 50 | grep -i ^From`
from=${from// /+}

subject=`cat /tmp/notfallemail | head -n 50 | grep -i ^Subject`
subject=${subject// /+}


out=`curl -g 
"https://smsgw01/cgi-bin/sms_send?text=Neue+Notfall+Email+von+$from+mit+Betreff+$subject"`

exit 0


Stdin works. The SMS message now contains the From and the Subject header. 
However, OpenSMTPd still complains with "mda exited prematurely".


If I however change the script to the following, while the message OpenSMTPd
complains about is still in the queue and pending

#!/bin/bash

cat - > /dev/null

out=`curl -g "https://smsgw01/cgi-bin/sms_send?text=Neue+Notfall+Email"`

exit 0


and then issue smtpctl schedule all, then OpenSMTPd reports a successful 
delivery and removes the mail from the queue.


Any ideas?

Thanks!

Cheers, 

Simon







Philipp wrote:

> Hi Simon
> 
> [2024-03-05 10:49] Simon Hoffmann 
> > in my virtual users file, I have specified an external script additionally 
> > to
> > delivery to mailboxes. 
> >
> >
> > emerge...@domain.tlduser1,user2,|/etc/smtpd/send_sms.sh
> >
> > Local delivery to the mailboxes works fine. 
> > The script itself is called as well as I do receive the SMS message.
> >
> > However, OpenSMTPd says "MDA exited prematurely" after calling the script, 
> > thus
> > leading to a TEMPFAIL and OpenSMTPd trying again periodically. 
> 
> This means your script exited while OpenSMTPd still has (parts of) the
> mail in the output buffer.
> 
> > [...]
> >
> > The send_sms.sh script consists of a static curl call at the moment, that 
> > performs a
> > HTTP Get call to the SMS Gateway with the static text "new emergency mail 
> > received".
> > I am not yet parsing sender/subject etc.
> 
> I would guess that you don't read stdin at all.
> 
> > Sadly, I could find nothing on the man pages as to which exit codes 
> > OpenSMTPd expects
> > from an mda script. Additionally, based on the documentation available, I 
> > am not sure
> > if OpenSMTPd just pipes the whole message into stdin or if OpenSMTPd 
> > expects some
> > form of "smtp communication" (MAIL FROM + response, RCPT TO + response, 
> > ) and
> > thus comlains that my script exits prematurely because I have not 
> > implemented
> > that.
> 
> smtpd pipes the mail to stdin and expect your script to read it.
> 
> > So, long story short: how shall I modify my script so that OpenSMTPd 
> > recognises that
> > the SMS Gateway received the call and has queued the SMS?
> 
> A simple line "cat - > /dev/null" should fix it.
> 
> Philipp
> 

-- 


--


signature.asc
Description: PGP signature


Re: MDA exited prematurely when using custom script

2024-03-05 Thread gilles
March 5, 2024 4:19 PM, "Simon Hoffmann"  wrote:

> gil...@poolp.org wrote:
> 
>> Does your script exit with 0 ?
> 
> If the curl output is "OK", then I exit with "exit 0". I have even removed 
> the "if"
> and have just set a static "exit 0" at the end no matter if the curl before 
> was
> successful or not. This did not work as well.
> 
> However, Philipp might be on to something. I will respond to his mail 
> separately.
> 

Indeed, his hypothesis is very likely to be correct



Re: MDA exited prematurely when using custom script

2024-03-05 Thread Simon Hoffmann
Philipp wrote:

> Hi Simon
> 
> [2024-03-05 10:49] Simon Hoffmann 
> > in my virtual users file, I have specified an external script additionally 
> > to
> > delivery to mailboxes. 
> >
> >
> > emerge...@domain.tlduser1,user2,|/etc/smtpd/send_sms.sh
> >
> > Local delivery to the mailboxes works fine. 
> > The script itself is called as well as I do receive the SMS message.
> >
> > However, OpenSMTPd says "MDA exited prematurely" after calling the script, 
> > thus
> > leading to a TEMPFAIL and OpenSMTPd trying again periodically. 
> 
> This means your script exited while OpenSMTPd still has (parts of) the
> mail in the output buffer.


aha! I thought so as well, but I had a brainfart and set "sleep 10" at the 
beginning
of the script, which still (obviously) does not solve the issue. 


> 
> > [...]
> >
> > The send_sms.sh script consists of a static curl call at the moment, that 
> > performs a
> > HTTP Get call to the SMS Gateway with the static text "new emergency mail 
> > received".
> > I am not yet parsing sender/subject etc.
> 
> I would guess that you don't read stdin at all.


No, I do not. The script is literally

#!/bin/bash

out=`curl https:/...`

if [ $out = "OK" ]
then
exit 0
else 
exit 1
fi





> 
> > Sadly, I could find nothing on the man pages as to which exit codes 
> > OpenSMTPd expects
> > from an mda script. Additionally, based on the documentation available, I 
> > am not sure
> > if OpenSMTPd just pipes the whole message into stdin or if OpenSMTPd 
> > expects some
> > form of "smtp communication" (MAIL FROM + response, RCPT TO + response, 
> > ) and
> > thus comlains that my script exits prematurely because I have not 
> > implemented
> > that.
> 
> smtpd pipes the mail to stdin and expect your script to read it.


makes sense when you think about it :)


> 
> > So, long story short: how shall I modify my script so that OpenSMTPd 
> > recognises that
> > the SMS Gateway received the call and has queued the SMS?
> 
> A simple line "cat - > /dev/null" should fix it.

*insert lightbulb here* :)

All my Testmails have worked before (probably because they were just a few 
lines of
text). I can later try to find the emergency Mail from
earlier today and insert it into the queue again. Otherwise I'll just wait for 
the
next monitoring alert :)


Thanks!

Cheers, 

Simon



> 
> Philipp
> 

-- 


--


signature.asc
Description: PGP signature


Re: MDA exited prematurely when using custom script

2024-03-05 Thread Simon Hoffmann
gil...@poolp.org wrote:

> Does your script exit with 0 ?

If the curl output is "OK", then I exit with "exit 0". I have even removed the 
"if"
and have just set a static "exit 0" at the end no matter if the curl before was
successful or not. This did not work as well. 


However, Philipp might be on to something. I will respond to his mail 
separately. 

Thanks!

Cheers, 

Simon



> 
> 
> March 5, 2024 10:49 AM, "Simon Hoffmann"  
> wrote:
> 
> > Hey list, 
> > 
> > in my virtual users file, I have specified an external script additionally 
> > to
> > delivery to mailboxes. 
> > 
> > emerge...@domain.tld user1,user2,|/etc/smtpd/send_sms.sh
> > 
> > Local delivery to the mailboxes works fine. 
> > The script itself is called as well as I do receive the SMS message.
> > 
> > However, OpenSMTPd says "MDA exited prematurely" after calling the script, 
> > thus
> > leading to a TEMPFAIL and OpenSMTPd trying again periodically. 
> > 
> > The only thing I could find was the following message:
> > 
> > https://www.mail-archive.com/misc@openbsd.org/msg165772.html
> > 
> > qoute:
> > mda is basically a program that reads input from stdin and exits with the
> > proper status to report to the mta that delivery was successful, whatever
> > happens in between is up to you.
> > 
> > The send_sms.sh script consists of a static curl call at the moment, that 
> > performs a
> > HTTP Get call to the SMS Gateway with the static text "new emergency mail 
> > received".
> > I am not yet parsing sender/subject etc.
> > 
> > The curl call / the SMS gateway responds with "OK" if the SMS was queued 
> > correctly on
> > the SMS gateway. At first I thought that this "OK" back to stdout would 
> > confuse
> > OpenSMTPd, so I catch the stdout of the curl call to a variable and just 
> > "exit 0" if
> > the content of the variable is "OK". 
> > 
> > However, this is still not working, OpenSMTPd still complains "MDA exited
> > prematurely"
> > 
> > Then I tried an "echo 250 OK". Still not working. 
> > Then 250 2.6.0 Message accepted, still not working. 
> > 
> > Sadly, I could find nothing on the man pages as to which exit codes 
> > OpenSMTPd expects
> > from an mda script. Additionally, based on the documentation available, I 
> > am not sure
> > if OpenSMTPd just pipes the whole message into stdin or if OpenSMTPd 
> > expects some
> > form of "smtp communication" (MAIL FROM + response, RCPT TO + response, 
> > ) and
> > thus comlains that my script exits prematurely because I have not 
> > implemented
> > that. 
> > 
> > So, long story short: how shall I modify my script so that OpenSMTPd 
> > recognises that
> > the SMS Gateway received the call and has queued the SMS?
> > 
> > Thanks!
> > 
> > Cheers, 
> > 
> > Simon

-- 


--


signature.asc
Description: PGP signature


Re: MDA exited prematurely when using custom script

2024-03-05 Thread Philipp
Hi Simon

[2024-03-05 10:49] Simon Hoffmann 
> in my virtual users file, I have specified an external script additionally to
> delivery to mailboxes. 
>
>
> emerge...@domain.tlduser1,user2,|/etc/smtpd/send_sms.sh
>
> Local delivery to the mailboxes works fine. 
> The script itself is called as well as I do receive the SMS message.
>
> However, OpenSMTPd says "MDA exited prematurely" after calling the script, 
> thus
> leading to a TEMPFAIL and OpenSMTPd trying again periodically. 

This means your script exited while OpenSMTPd still has (parts of) the
mail in the output buffer.

> [...]
>
> The send_sms.sh script consists of a static curl call at the moment, that 
> performs a
> HTTP Get call to the SMS Gateway with the static text "new emergency mail 
> received".
> I am not yet parsing sender/subject etc.

I would guess that you don't read stdin at all.

> Sadly, I could find nothing on the man pages as to which exit codes OpenSMTPd 
> expects
> from an mda script. Additionally, based on the documentation available, I am 
> not sure
> if OpenSMTPd just pipes the whole message into stdin or if OpenSMTPd expects 
> some
> form of "smtp communication" (MAIL FROM + response, RCPT TO + response, ) 
> and
> thus comlains that my script exits prematurely because I have not implemented
> that.

smtpd pipes the mail to stdin and expect your script to read it.

> So, long story short: how shall I modify my script so that OpenSMTPd 
> recognises that
> the SMS Gateway received the call and has queued the SMS?

A simple line "cat - > /dev/null" should fix it.

Philipp



Re: MDA exited prematurely when using custom script

2024-03-05 Thread gilles
Does your script exit with 0 ?


March 5, 2024 10:49 AM, "Simon Hoffmann"  wrote:

> Hey list, 
> 
> in my virtual users file, I have specified an external script additionally to
> delivery to mailboxes. 
> 
> emerge...@domain.tld user1,user2,|/etc/smtpd/send_sms.sh
> 
> Local delivery to the mailboxes works fine. 
> The script itself is called as well as I do receive the SMS message.
> 
> However, OpenSMTPd says "MDA exited prematurely" after calling the script, 
> thus
> leading to a TEMPFAIL and OpenSMTPd trying again periodically. 
> 
> The only thing I could find was the following message:
> 
> https://www.mail-archive.com/misc@openbsd.org/msg165772.html
> 
> qoute:
> mda is basically a program that reads input from stdin and exits with the
> proper status to report to the mta that delivery was successful, whatever
> happens in between is up to you.
> 
> The send_sms.sh script consists of a static curl call at the moment, that 
> performs a
> HTTP Get call to the SMS Gateway with the static text "new emergency mail 
> received".
> I am not yet parsing sender/subject etc.
> 
> The curl call / the SMS gateway responds with "OK" if the SMS was queued 
> correctly on
> the SMS gateway. At first I thought that this "OK" back to stdout would 
> confuse
> OpenSMTPd, so I catch the stdout of the curl call to a variable and just 
> "exit 0" if
> the content of the variable is "OK". 
> 
> However, this is still not working, OpenSMTPd still complains "MDA exited
> prematurely"
> 
> Then I tried an "echo 250 OK". Still not working. 
> Then 250 2.6.0 Message accepted, still not working. 
> 
> Sadly, I could find nothing on the man pages as to which exit codes OpenSMTPd 
> expects
> from an mda script. Additionally, based on the documentation available, I am 
> not sure
> if OpenSMTPd just pipes the whole message into stdin or if OpenSMTPd expects 
> some
> form of "smtp communication" (MAIL FROM + response, RCPT TO + response, ) 
> and
> thus comlains that my script exits prematurely because I have not implemented
> that. 
> 
> So, long story short: how shall I modify my script so that OpenSMTPd 
> recognises that
> the SMS Gateway received the call and has queued the SMS?
> 
> Thanks!
> 
> Cheers, 
> 
> Simon