Custom Function for Virus Scanners Variable {Scanned by HJMS}

Kyle Harris lists at TRCINTL.COM
Tue Oct 21 18:13:55 IST 2003


On Tue, 21 Oct 2003 16:43:26 +0100, Kyle Harris <lists at TRCINTL.COM> wrote:

One other piece I can add that might help.  If I use the following code
snippet:

sub InitVirusScanners {
 MailScanner::Log::InfoLog("Starting VirusScanners");
}
EndVirusScanners {
  MailScanner::Log::InfoLog("Stopping VirusScanners");
}
sub VirusScanners {
 MailScanner::Log::InfoLog("Doing VirusScanners");
 my ($message) = @_;
 #my @todomain = @{$message->{todomain}};
 open(FILE,">>/home/out.txt");
 print FILE "$message\n";
 close (FILE);
 return "clamav";
}

It never prints the contents of $message, leading me to believe it never
receives the message.



>On Tue, 21 Oct 2003 16:29:49 +0100, Kyle Harris <lists at TRCINTL.COM> wrote:
>
>>On Tue, 21 Oct 2003 16:20:07 +0100, Steve Freegard
>><steve.freegard at LBSLTD.CO.UK> wrote:
>>
>>>Kyle,
>>>
>>>How about:
>>>
>>>sub VirusScanners {
>>>   MailScanner::Log::InfoLog("Doing VirusScanners");
>>>   my($message) = @_;
>>>+  my(@todomain);
>>>+  @todomain = @{$message->{todomain}};
>>>   open(FILE,">>/home/out.txt");
>>>   print FILE "some junk here\n";
>>>   close (FILE);
>>>   return "clamav";
>>>
>>>Does that work??
>
>Oops! I misread your post when I first answered. To answer your question
>correctly, No, making the changes on the 2 lines above does not work.  It
>still hangs.
>
>Sorry, and thanks again for the assistance!
>
>>
>>Yep, but it sill runs both the Init code and the function code itself
>>during startup (again, unique to this variable).
>>
>>This code originally started out having a MySql connection so that I could
>>use a virus scanner for some domains and not others based upon the domain
>>it was going to and the results of an SQL query.  If I can't get the
domain
>>information, than that is not a possibility.  I just worked it down to the
>>test code above to try and figure out what the problem is and to eliminate
>>the MySql connection.
>>
>>As long as the line "@todomain = @{$message->{todomain}};" isn't present,
>>it works . . . although I still don't think it should run the function
code
>>during startup.
>>
>>
>>
>>>
>>>Regards,
>>>Steve.
>>>
>>>-----Original Message-----
>>>From: Kyle Harris [mailto:lists at TRCINTL.COM]
>>>Sent: 21 October 2003 14:59
>>>To: MAILSCANNER at JISCMAIL.AC.UK
>>>Subject: Re: Custom Function for Virus Scanners Variable {Scanned by
HJMS}
>>>
>>>On Tue, 21 Oct 2003 09:08:43 -0500, Furnish, Trever G <TGFurnish at HERFF-
>>>JONES.COM> wrote:
>>>
>>>>> When I save this and reboot, I receive the "Starting VirusScanners"
>>>>
>>>>"reboot"?!  Why would you reboot?  Hopefully you just mean "restart
>>>>MailScanner"...
>>>
>>>I said "reboot" as this is a test system and I just wanted to make sure I
>>>restarted everything before I posted.  Just a safeguard.
>>>>
>>>>> and "Doing VirusScanners" log entries twice
>>>>
>>>>I think you ought to see it once per MS child, since each one is going
to
>>>>run these functions.
>>>This is not the case for other functions I have written.  Normally the
>Init
>>>function is ran once during startup and the function itself is ran once
>for
>>>each message (not at startup).
>>>
>>>>
>>>>> (I don't when
>>>>> using this method
>>>>> with other custom functions).
>>>>
>>>>That surprises me.
>>>>
>>>When I use this same exact function for another variable in the config
>file
>>>(I'll use Virus Scanning for this example and just change the return
value
>>>of "clamav" to 1) the code does not run at all when MailScanner starts.
>>>Only the Init code runs.  This is what I have seen with the other
>functions
>>>I have written.  However, any function used for Virus Scanners runs when
>>>MailScanner first starts (the init code runs and the function itself
>runs).
>>>
>>>>> It never writes the out.txt
>>>>> file ...
>>>>
>>>>Suggest changing your file opening code from:
>>>>>   open(FILE,">>/home/out.txt");
>>>>>   print FILE "some junk here\n";
>>>>>   close (FILE);
>>>>
>>>>...to:
>>>>if (open(FILE, ">>/home/out.txt")) {
>>>>   print FILE, "some junk here\n";
>>>>   close FILE;
>>>>} else {
>>>>   MailScanner::Log::InfoLog("Open failed: $!");
>>>>}
>>>>
>>>This makes no difference as it stops processing code at the following
>line:
>>>my @todomain = >> @{$message->todomain}};
>>>It makes no difference what comes after it, unless I remove this line.
>>>Again, when this code is used to replace other variables (also changing
>the
>>>return value of "clamav" to a correct value) the code works fine.  For
>some
>>>reason, the variable Virus Scanners doesn't like this line of code.
>>>
>>>
>>>>But keep in mind that your approach isn't multi-process safe - that is,
>>you
>>>>will have multiple processes writing to the same file at the same time,
>so
>>>>don't be surprised to find corruption in that file, especially as email
>>>>traffic increases.
>>>>
>>>>> nor does it
>>>>> pick up mail from the mailqueie.in?  MailScanner starts without any
>>>>> errors.  If I take out the line "my @todomain =
>>>>> @{$message->todomain}};" it
>>>>> seems to run, but It still runs the code twice at startup.
>>>>
>>>>When you enabled debugging of mailscanner, did you run it from the init
>>>>script or directly from a command line?  Sometimes you'll see more when
>>>>running it via the command-line, though I'm not quite sure why.
>>>I ran it from the init script.
>>>
>>>>
>>>>You say it "runs the code twice at startup" -- how many mailscanner
child
>>>>processes are you starting?
>>>
>>>Again, I don't think the child processes make a difference in how many
>>>times the Init process or the function itself runs.  They haven't for my
>>>other functions.  Anyway, to answer your question, I have 5 child
>>processes.
>>>
>>>Thanks for any help.
>>>
>>>>
>>>>--
>>>>Trever
>>>>
>>>>> -----Original Message-----
>>>>> From: Kyle Harris [mailto:lists at TRCINTL.COM]
>>>>> Sent: Monday, October 20, 2003 6:26 PM
>>>>> To: MAILSCANNER at JISCMAIL.AC.UK
>>>>> Subject: Re: Custom Function for Virus Scanners Variable {Scanned by
>>>>> HJMS}
>>>>>
>>>>>
>>>>> Here is some more info regarding my own previous post.
>>>>> Hopefully someone
>>>>> will be able to help out.  Anyway, if I set Virus Scanners =
>>>>> &VirusScanners
>>>>> in the config file and then define the following custom
>>>>> function in the
>>>>> CustomConfig.pm file (this is my entire file for
>>>>> troubleshooting purposes
>>>>> only):
>>>>>
>>>>> package MailScanner::CustomConfig;
>>>>> use strict 'vars';
>>>>> use strict 'refs';
>>>>> no  strict 'subs'; # Allow bare words for parameter %'s
>>>>> use vars qw($VERSION);
>>>>>
>>>>> sub InitVirusScanners {
>>>>>   MailScanner::Log::InfoLog("Starting VirusScanners");
>>>>> }
>>>>> sub EndVirusScanners {
>>>>>   MailScanner::Log::InfoLog("Stopping VirusScanners");
>>>>> }
>>>>> sub VirusScanners {
>>>>>   MailScanner::Log::InfoLog("Doing VirusScanners");
>>>>>   my ($message) = @_;
>>>>>   my @todomain = @{$message->{todomain}};
>>>>>   open(FILE,">>/home/out.txt");
>>>>>   print FILE "some junk here\n";
>>>>>   close (FILE);
>>>>>   return "clamav";
>>>>> }
>>>>> 1;
>>>>>
>>>>> When I save this and reboot, I receive the "Starting VirusScanners"
>>>>> and "Doing VirusScanners" log entries twice (I don't when
>>>>> using this method
>>>>> with other custom functions).  It never writes the out.txt
>>>>> file nor does it
>>>>> pick up mail from the mailqueie.in?  MailScanner starts without any
>>>>> errors.  If I take out the line "my @todomain =
>>>>> @{$message->todomain}};" it
>>>>> seems to run, but It still runs the code twice at startup.
>>>>>
>>>>> Julian, any ideas?
>>>>>
>>>
>>>--
>>>This email and any files transmitted with it are confidential and
>>>intended solely for the use of the individual or entity to whom they
>>>are addressed. If you have received this email in error please notify
>>>the sender and delete the message from your mailbox.
>>>
>>>This footnote also confirms that this email message has been swept by
>>>MailScanner (www.mailscanner.info) for the presence of computer viruses.



More information about the MailScanner mailing list