LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-09-2004, 05:05 PM   #1
J_Szucs
Senior Member
 
Registered: Nov 2001
Location: Budapest, Hungary
Distribution: SuSE 6.4-11.3, Dsl linux, FreeBSD 4.3-6.2, Mandrake 8.2, Redhat, UHU, Debian Etch
Posts: 1,126

Rep: Reputation: 58
Perl guru needed


I am totally noob to perl, and I want to write an efficient redirector script for squid in perl. The script downloads the target of each url, checks the downloaded file and rewrites the url if the file contains a virus. (there are two proxies in series, so delays by duplicate download are avoided).
My script is ready and works well, however it is not very efficient in its present form, as it calls an external bash script on each file for jpeg sanity checking.

I want to do this in perl, too, e.g. as a function of my redirector script.

I found this somewhere; and I think I could use it as a start:
@stat = stat($file);
$size = $stat[7];
open HANDLE, $file;
sysread(HANDLE, $input, $size);
close HANDLE;
if ($input =~ /\xff\xfe\x00[\x00\x01]/s) {
@debug = `djpeg -debug $file 2>&1 > /dev/null`;
if (grep (/Corrupt JPEG data/i, @debug)) {
print "jpeg has trojan\n";
} else {
print "no trojan found\n";
}
}

My questions are:
1.) So far as I can judge, the above script reads a whole file into variable $file. I suppose this is not very efficient as it may require a lot of memory. Could it be modified so that it treats (checks) the file as a stream? How?
2.) Could the @debug variable be avoided, and the grep performed on the output stream of djpeg directly? How?
3.) How to modify the script so that it accepts its input from a pipe rather than processing a file? (This would be extremely advantageous in the case of jpegs in a zip archive: then I could pipe unzip's standard output to the input of the jpeg checker function.)

Squid starts several instances of the redirector perl script. Each redirector process should have read/write access to a common url blacklist/whitelist, in order to speed up things by avoiding the re-checking of urls that have already been checked. Besides, the url blacklist/whitelist should be kept in memory, as it is faster.
My question is:
4) What is the best way to share this whitelist/blacklist between several instances of the same perl script?
5) Can the lists be kept in memory efficiently?

Thanks in advance for your hints.

Last edited by J_Szucs; 10-09-2004 at 08:21 PM.
 
Old 10-11-2004, 03:05 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.x
Posts: 18,441

Rep: Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791
1.) Actually, it's reading $file into var $input......

1., 3.) See this link: http://iis1.cps.unizar.es/Oreilly/pe...ok/ch16_05.htm
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
KDE Guru needed AxXium Slackware 15 06-03-2005 07:04 PM
hotplug,errors and x..guru needed wrat Linux - Newbie 2 01-09-2005 08:37 AM
Slackware Guru Advice Needed g452 Slackware 20 04-07-2004 12:32 PM
Linux Guru Needed !!! Tuzinor Linux - General 6 11-17-2002 05:40 PM
guru help needed. dk Linux - Newbie 2 04-26-2001 12:03 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:00 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration