master pipe variables

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

master pipe variables

Steven King-6
I have a script I am using to pipe mail to SpamAssassin.

This is what I have in my master.cf

spamassassin    unix    -       n       n       -       -       pipe
        flags=Rhq user=spamfilter argv=/etc/postfix/sa-filter ${domain}
${sender} ${recipient}

At the end this script pipes the results back into postfix with the
sendmail command as follows

| /usr/sbin/sendmail -oi -f $sender -- $recip

The issue is when I check the results of domain, sender and recipient...
the sender and recipient end up being the same address.

I have narrowed this down to being either a script problem or a Postfix
problem. I am leaning towards postfix because the bash parameter
variables also hold the same information.

Does anyone have any ideas what could be the cause of this?

Thanks,

Steve King
Reply | Threaded
Open this post in threaded view
|

Re: master pipe variables

Victor Duchovni
On Fri, May 23, 2008 at 02:06:44AM -0400, Steven King wrote:

> I have a script I am using to pipe mail to SpamAssassin.
>
> This is what I have in my master.cf
>
> spamassassin    unix    -       n       n       -       -       pipe
>         flags=Rhq user=spamfilter argv=/etc/postfix/sa-filter ${domain}
> ${sender} ${recipient}

Make sure this transport has a recipient limit of 1!

    main.cf:
        spamassassin_destination_recipient_limit = 1

> At the end this script pipes the results back into postfix with the
> sendmail command as follows
>
> | /usr/sbin/sendmail -oi -f $sender -- $recip

It is a very bad idea to not quote these variables. White-space in the
sender or recipient address will cause serious grief and possible
security issues. Let pipe(8) pass the entire argument list for sendmail
and use:

        domain=$1; shift
        ...
        sendmail -oi "$@"

>         flags=Rhq user=spamfilter argv=/etc/postfix/sa-filter ${domain}
> -f ${sender} -- ${recipient}

> The issue is when I check the results of domain, sender and recipient...
> the sender and recipient end up being the same address.
>
> I have narrowed this down to being either a script problem or a Postfix
> problem. I am leaning towards postfix because the bash parameter
> variables also hold the same information.
>
> Does anyone have any ideas what could be the cause of this?

You have provided no factual evidence, just anecdotal evidence. The
problem is with your script and perhaps issues with multi-recipient
semantics of ${domain} and ${recipient}.

Given the serious correctness (and perhaps security) issue with the
only line of the script you post, expectations for the rest of it are
sadly low...

--
        Viktor.

Disclaimer: off-list followups get on-list replies or get ignored.
Please do not ignore the "Reply-To" header.

To unsubscribe from the postfix-users list, visit
http://www.postfix.org/lists.html or click the link below:
<mailto:[hidden email]?body=unsubscribe%20postfix-users>

If my response solves your problem, the best way to thank me is to not
send an "it worked, thanks" follow-up. If you must respond, please put
"It worked, thanks" in the "Subject" so I can delete these quickly.
Reply | Threaded
Open this post in threaded view
|

Re: master pipe variables

Steven King-6
Thanks for the advice Victor,

I have made the changes to the script as you requested. I already had
postfix setup to deliver only 1 recipient to the SpamAssassin Script.

Here is my script in whole as it stands now.

#!/bin/bash
#
# sa-filter: SpamAssassin Filtering System
#
#

user="spamfilter"
domain="$1"; shift
sender="$2"; shift
recip="$@"

user=`grep "^$domain" /etc/postfix/userdomains | cut -d ":" -f 2-`

if [[ "x$user" == "x" ]]; then
        user="spamfilter"
fi

# Used for value testing
echo "domain $domain sender $sender receipients $recip user $user" >>
/etc/postfix/sa-filter.log

if [ "$#" -eq 1 ]; then
        /usr/bin/spamc -u $user
else
        /usr/bin/spamc
fi | /usr/sbin/sendmail -oi -f "$sender" -- "$recip"
exit $?

Before the email gets processed by SpamAssassin the to and from in the
postfix log are correct. Immediately after the mail is passed back to
postfix the logs reflect the changes the same as the variables being
passed to the script do. ClamAV processes the mail before SpamAssassin
but even after ClamAV passes the mail back to postfix the to and from in
the logs are correct until after its passed back from SpamAssassin, then
the to and from addresses are the same.

Is there anything else that would help us track down the cause of this?

Victor Duchovni wrote:

> On Fri, May 23, 2008 at 02:06:44AM -0400, Steven King wrote:
>
>  
>> I have a script I am using to pipe mail to SpamAssassin.
>>
>> This is what I have in my master.cf
>>
>> spamassassin    unix    -       n       n       -       -       pipe
>>         flags=Rhq user=spamfilter argv=/etc/postfix/sa-filter ${domain}
>> ${sender} ${recipient}
>>    
>
> Make sure this transport has a recipient limit of 1!
>
>     main.cf:
> spamassassin_destination_recipient_limit = 1
>
>  
>> At the end this script pipes the results back into postfix with the
>> sendmail command as follows
>>
>> | /usr/sbin/sendmail -oi -f $sender -- $recip
>>    
>
> It is a very bad idea to not quote these variables. White-space in the
> sender or recipient address will cause serious grief and possible
> security issues. Let pipe(8) pass the entire argument list for sendmail
> and use:
>
> domain=$1; shift
> ...
> sendmail -oi "$@"
>
>  
>>         flags=Rhq user=spamfilter argv=/etc/postfix/sa-filter ${domain}
>> -f ${sender} -- ${recipient}
>>    
>
>  
>> The issue is when I check the results of domain, sender and recipient...
>> the sender and recipient end up being the same address.
>>
>> I have narrowed this down to being either a script problem or a Postfix
>> problem. I am leaning towards postfix because the bash parameter
>> variables also hold the same information.
>>
>> Does anyone have any ideas what could be the cause of this?
>>    
>
> You have provided no factual evidence, just anecdotal evidence. The
> problem is with your script and perhaps issues with multi-recipient
> semantics of ${domain} and ${recipient}.
>
> Given the serious correctness (and perhaps security) issue with the
> only line of the script you post, expectations for the rest of it are
> sadly low...
>
>  
Reply | Threaded
Open this post in threaded view
|

Re: master pipe variables

Victor Duchovni
On Fri, May 23, 2008 at 04:10:02AM -0400, Steven King wrote:

>
> user="spamfilter"
> domain="$1"; shift
> sender="$2"; shift

There's the bug. The old "$2" is now "$1".

> recip="$@"

This does not work. The "$@" form is the shell's built-in "argv" ARRAY.
The "recip" variable holds a single string, and cannot accurately hold
an array.

> if [ "$#" -eq 1 ]; then
>         /usr/bin/spamc -u $user
> else
>         /usr/bin/spamc
> fi | /usr/sbin/sendmail -oi -f "$sender" -- "$recip"

You should use "$@" here, not "$recip". Of course you expect just a single
recipient, (otherwise "$domain" is also multi-valued, and the script is
wrong!). If the script is to be robust with multiple users, it needs to
be prepared to process ($#-1)/2 domains and ($#-1)/2 recipients. Using
a shell implementation (ksh, bash, ...) that supports array variables
may be necessary for this.

--
        Viktor.

Disclaimer: off-list followups get on-list replies or get ignored.
Please do not ignore the "Reply-To" header.

To unsubscribe from the postfix-users list, visit
http://www.postfix.org/lists.html or click the link below:
<mailto:[hidden email]?body=unsubscribe%20postfix-users>

If my response solves your problem, the best way to thank me is to not
send an "it worked, thanks" follow-up. If you must respond, please put
"It worked, thanks" in the "Subject" so I can delete these quickly.
Reply | Threaded
Open this post in threaded view
|

Re: master pipe variables

Steven King-6
Thank you very much Victor for pointing out my flaw. I have corrected my
script and it works perfectly. I can't believe that I make a mistake
like that and didn't catch it.

Thanks again!

Victor Duchovni wrote:

> On Fri, May 23, 2008 at 04:10:02AM -0400, Steven King wrote:
>
>  
>> user="spamfilter"
>> domain="$1"; shift
>> sender="$2"; shift
>>    
>
> There's the bug. The old "$2" is now "$1".
>
>  
>> recip="$@"
>>    
>
> This does not work. The "$@" form is the shell's built-in "argv" ARRAY.
> The "recip" variable holds a single string, and cannot accurately hold
> an array.
>
>  
>> if [ "$#" -eq 1 ]; then
>>         /usr/bin/spamc -u $user
>> else
>>         /usr/bin/spamc
>> fi | /usr/sbin/sendmail -oi -f "$sender" -- "$recip"
>>    
>
> You should use "$@" here, not "$recip". Of course you expect just a single
> recipient, (otherwise "$domain" is also multi-valued, and the script is
> wrong!). If the script is to be robust with multiple users, it needs to
> be prepared to process ($#-1)/2 domains and ($#-1)/2 recipients. Using
> a shell implementation (ksh, bash, ...) that supports array variables
> may be necessary for this.
>
>