You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@spamassassin.apache.org by Cory Hawkless <co...@hawkless.id.au> on 2009/12/21 12:24:21 UTC

Perl SA util: setuid: oops: fileno(STDIN) [6]

Hi All,

 

I am writing an app in perl that gets mail passed from Postfix then runs the
mail through SA and will run various actions based on the score(Very much
like Amavisd-new)

I'm struggling a bit my SpamAssassin code though and was wondering if anyone
here could help. I'm getting the following error when using my
SpamAssassinCheck subroutine

 

util: setuid: oops: fileno(STDIN) [6] != 0 at
/usr/lib/perl5/vendor_perl/5.10.0/Mail/SpamAssassin/Util.pm line 1375.

Message:MonDec212147542009-1037461244 SPAM Results - Score 2.729 Tests -
AWL=-2.064,EMPTY_MESSAGE=0.607,HTML_MESSAGE=0.001,MIME_HTML_MOSTLY=0.001,MIS
SING_SUBJECT=1.285,TVD_SPACE_RATIO=2.899

 

As you can see i'm still getting a result, if I let me app continue to
process a few more emails I eventually get a "Alarm Clock" error and perl
bombs out.

 

Here is my SpamAssassinCheck code(I also don't think i'm using the eval
correctly)

 

P.S Let me know if this is not the appropriate place to be posting this
message, but I couldn't think of a better group of people to help solve my
problem.

 

Regards,

Cory

 

sub SpamAssassinScan {

eval {

        #Record the time when this program was started

        #my $starttime = [gettimeofday];

 

        #User to run SPAM Assasin as

        my $SAUser;

        $SAUser=$_[0];

 

        #Subroutine expects the second paramater to be the content of the
email to be scanned

        my $rawemail;

        $rawemail=$_[1];

 

        my $messageID = $_[2];

 

        my $ThisThreadSA=$MainSA;

 

        ##print "Beginning test\n"

 

        if ($SAUser eq "") { $SAUser="root" }

        logit("info", "Message:$messageID Running SA test as: $SAUser");

 

        $ThisThreadSA->{username}=$SAUser;

 

        my $mail = $ThisThreadSA->parse($rawemail);

        my $status = $ThisThreadSA->check($mail);

 

        ##print "SA scanning done\n";

 

        logit("info","Message:$messageID SPAM Results - Score
".$status->get_score()." Tests - ".$status->get_tag('TESTSSCORES',','));

};

if ($@){

        ### Catch block

        logit("info", "Failed SA Scan");;

};

 

}

 


Re: Perl SA util: setuid: oops: fileno(STDIN) [6]

Posted by Mark Martinec <Ma...@ijs.si>.
On Tuesday December 22 2009 10:52:47 Cory Hawkless wrote:

> I am writing an app in perl that gets mail passed from Postfix then runs
> the mail through SA and will run various actions based on the score(Very
> much like Amavisd-new)

Why not just add a custom hook to the amavisd config file? It has
access to all the information about a message, and can influence further
course of action. All the dirty details have already been dealt with.

> Has anyone had any experience with this? There seems to be very little
> documentation on any of the Perl - SpamAssassin interfaces, other than the
> CPAN site I havent been able to find anything at all, does anybody have any
> pointers?

$ man Mail::SpamAssassin
# man Mail::SpamAssassin::PerMsgStatus
and browsing through spamd (or amavisd) is about pretty much it.

> I'm struggling a bit my SpamAssassin code though and was wondering if
> anyone here could help. I'm getting the following error when using my
> SpamAssassinCheck subroutine

> util: setuid: oops: fileno(STDIN) [6] != 0 at
> /usr/lib/perl5/vendor_perl/5.10.0/Mail/SpamAssassin/Util.pm line 1375.

Which operating system? Which version of SpamAssassin?

I know I had difficulties with NetBSD, which did not always choose
the lowest free file descriptor when opening a new file, so I had to
resort to POSIX::dup2() to solve it (amavisd, sub open_on_specific_fd).

> As you can see i'm still getting a result, if I let me app continue to
> process a few more emails I eventually get a "Alarm Clock" error and perl
> bombs out.

Yes, SpamAssassin sometimes 'forgets' to clear alarm after it finishes
its job (depending on its version). Just call alarm(0) after each call
to SpamAssassin.

> use Mail::SpamAssassin;
> my $MainSA = new Mail::SpamAssassin;
> $MainSA->compile_now();
>
> sub SpamAssassinScan {
> eval {
>         my $SAUser;
>         $SAUser=$_[0];
>         my $rawemail;
>         $rawemail=$_[1];
>         my $messageID = $_[2];
>         my $ThisThreadSA=$MainSA;
>         if ($SAUser eq "") { $SAUser="root" }
>         $ThisThreadSA->{username}=$SAUser;
>         my $mail = $ThisThreadSA->parse($rawemail);
>         my $status = $ThisThreadSA->check($mail);
> };
> [...]

Are you trying to call SpamAssasin from a multithreaded Perl?
I don't think this has even been tried and tested, it is quite likely
things would not work as they should.

  Mark

RE: Perl SA util: setuid: oops: fileno(STDIN) [6]

Posted by Cory Hawkless <co...@hawkless.id.au>.
More research on this problem, the error only appears when I run this line
of code

 

my $status = $ThisThreadSA->check($mail);

 

Has anyone had any experience with this? There seems to be very little
documentation on any of the Perl - SpamAssassin interfaces, other than the
CPAN site I havent been able to find anything at all, does anybody have any
pointers?

 

 

From: Cory Hawkless [mailto:cory@hawkless.id.au] 
Sent: Monday, 21 December 2009 10:29 PM
To: dev@spamassassin.apache.org
Subject: RE: Perl SA util: setuid: oops: fileno(STDIN) [6]

 

In addition to this, the line "Message:MonDec212147542009-1037461244 SPAM
Results - Score 2.729 Tests -
AWL=-2.064,EMPTY_MESSAGE=0.607,HTML_MESSAGE=0.001,MIME_HTML_MOSTLY=0.001,MIS
SING_SUBJECT=1.285,TVD_SPACE_RATIO=2.899" Is the result from my application 

 

And at the top of my application I have

 

use Mail::SpamAssassin;

 

#Create and compile a SpamAssassin object to be used by all threads

my $MainSA = new Mail::SpamAssassin;

$MainSA->compile_now();

 

 

From: Cory Hawkless [mailto:cory@hawkless.id.au] 
Sent: Monday, 21 December 2009 9:54 PM
To: dev@spamassassin.apache.org
Subject: Perl SA util: setuid: oops: fileno(STDIN) [6]

 

Hi All,

 

I am writing an app in perl that gets mail passed from Postfix then runs the
mail through SA and will run various actions based on the score(Very much
like Amavisd-new)

I'm struggling a bit my SpamAssassin code though and was wondering if anyone
here could help. I'm getting the following error when using my
SpamAssassinCheck subroutine

 

util: setuid: oops: fileno(STDIN) [6] != 0 at
/usr/lib/perl5/vendor_perl/5.10.0/Mail/SpamAssassin/Util.pm line 1375.

Message:MonDec212147542009-1037461244 SPAM Results - Score 2.729 Tests -
AWL=-2.064,EMPTY_MESSAGE=0.607,HTML_MESSAGE=0.001,MIME_HTML_MOSTLY=0.001,MIS
SING_SUBJECT=1.285,TVD_SPACE_RATIO=2.899

 

As you can see i'm still getting a result, if I let me app continue to
process a few more emails I eventually get a "Alarm Clock" error and perl
bombs out.

 

Here is my SpamAssassinCheck code(I also don't think i'm using the eval
correctly)

 

P.S Let me know if this is not the appropriate place to be posting this
message, but I couldn't think of a better group of people to help solve my
problem.

 

Regards,

Cory

 

sub SpamAssassinScan {

eval {

        #Record the time when this program was started

        #my $starttime = [gettimeofday];

 

        #User to run SPAM Assasin as

        my $SAUser;

        $SAUser=$_[0];

 

        #Subroutine expects the second paramater to be the content of the
email to be scanned

        my $rawemail;

        $rawemail=$_[1];

 

        my $messageID = $_[2];

 

        my $ThisThreadSA=$MainSA;

 

        ##print "Beginning test\n"

 

        if ($SAUser eq "") { $SAUser="root" }

        logit("info", "Message:$messageID Running SA test as: $SAUser");

 

        $ThisThreadSA->{username}=$SAUser;

 

        my $mail = $ThisThreadSA->parse($rawemail);

        my $status = $ThisThreadSA->check($mail);

 

        ##print "SA scanning done\n";

 

        logit("info","Message:$messageID SPAM Results - Score
".$status->get_score()." Tests - ".$status->get_tag('TESTSSCORES',','));

};

if ($@){

        ### Catch block

        logit("info", "Failed SA Scan");;

};

 

}

 


RE: Perl SA util: setuid: oops: fileno(STDIN) [6]

Posted by Cory Hawkless <co...@hawkless.id.au>.
In addition to this, the line "Message:MonDec212147542009-1037461244 SPAM
Results - Score 2.729 Tests -
AWL=-2.064,EMPTY_MESSAGE=0.607,HTML_MESSAGE=0.001,MIME_HTML_MOSTLY=0.001,MIS
SING_SUBJECT=1.285,TVD_SPACE_RATIO=2.899" Is the result from my application 

 

And at the top of my application I have

 

use Mail::SpamAssassin;

 

#Create and compile a SpamAssassin object to be used by all threads

my $MainSA = new Mail::SpamAssassin;

$MainSA->compile_now();

 

 

From: Cory Hawkless [mailto:cory@hawkless.id.au] 
Sent: Monday, 21 December 2009 9:54 PM
To: dev@spamassassin.apache.org
Subject: Perl SA util: setuid: oops: fileno(STDIN) [6]

 

Hi All,

 

I am writing an app in perl that gets mail passed from Postfix then runs the
mail through SA and will run various actions based on the score(Very much
like Amavisd-new)

I'm struggling a bit my SpamAssassin code though and was wondering if anyone
here could help. I'm getting the following error when using my
SpamAssassinCheck subroutine

 

util: setuid: oops: fileno(STDIN) [6] != 0 at
/usr/lib/perl5/vendor_perl/5.10.0/Mail/SpamAssassin/Util.pm line 1375.

Message:MonDec212147542009-1037461244 SPAM Results - Score 2.729 Tests -
AWL=-2.064,EMPTY_MESSAGE=0.607,HTML_MESSAGE=0.001,MIME_HTML_MOSTLY=0.001,MIS
SING_SUBJECT=1.285,TVD_SPACE_RATIO=2.899

 

As you can see i'm still getting a result, if I let me app continue to
process a few more emails I eventually get a "Alarm Clock" error and perl
bombs out.

 

Here is my SpamAssassinCheck code(I also don't think i'm using the eval
correctly)

 

P.S Let me know if this is not the appropriate place to be posting this
message, but I couldn't think of a better group of people to help solve my
problem.

 

Regards,

Cory

 

sub SpamAssassinScan {

eval {

        #Record the time when this program was started

        #my $starttime = [gettimeofday];

 

        #User to run SPAM Assasin as

        my $SAUser;

        $SAUser=$_[0];

 

        #Subroutine expects the second paramater to be the content of the
email to be scanned

        my $rawemail;

        $rawemail=$_[1];

 

        my $messageID = $_[2];

 

        my $ThisThreadSA=$MainSA;

 

        ##print "Beginning test\n"

 

        if ($SAUser eq "") { $SAUser="root" }

        logit("info", "Message:$messageID Running SA test as: $SAUser");

 

        $ThisThreadSA->{username}=$SAUser;

 

        my $mail = $ThisThreadSA->parse($rawemail);

        my $status = $ThisThreadSA->check($mail);

 

        ##print "SA scanning done\n";

 

        logit("info","Message:$messageID SPAM Results - Score
".$status->get_score()." Tests - ".$status->get_tag('TESTSSCORES',','));

};

if ($@){

        ### Catch block

        logit("info", "Failed SA Scan");;

};

 

}