Koozali.org: home of the SME Server

cgi strangeness from ibay

alt-testing

cgi strangeness from ibay
« on: January 29, 2007, 12:56:39 PM »
Hi all,
I am having problems getting a perl script to run from the primary (or any other) ibay. I have included the whole program below. For now; the program is a perl script to automatically compress images an create a gallery. (uses Image Magick & nagg)

The problem is this: The program works when run from the command line -perfectly.

When run from the cgi-bin of an ibay, I get this error in the logs:
[Mon Jan 29 22:40:48 2007] [error] [client 192.168.1.194] /usr/bin/convert: error while loading shared libraries: libdpstk.so.1: cannot open shared object file: No such file or directory

OK, so it's just an ENV thing like the PATH, or something similar right?

Also, when I use a suid "C wrapper" that I wrote around it:
like this: "c-wrapper?make_gallery_and_compress.pl", I get this:
[Mon Jan 29 22:42:00 2007] [error] [client 192.168.1.194] make_gallery_and_compress.pl: line 3: use: command not found

There are a few lines for this error in the logs, but it exactly like the error you get when the "path to perl" at the top is wrong, the line quoted that generates the error is "use strict;" - bummer.

So, I should mention that running similar perl scripts, and also using the "C wrapper" in this way, works perfectly on many other Straight CentOS 4.3 boxes that I have installed. So proof of concept there.

What the hell is going wrong here, it almost seems as though the script gets put in a chrooted jail, without the corresponding libs...

Anyway, any help is greatly appreciated. TIA



Code: [Select]

#!/usr/bin/perl

use strict;
use warnings;
use File::Find;

my @gallery_base_dir = ( "/home/e-smith/files/ibays/web/files/dev/GALLERY_MAKER" );
my @gallery_dir_list = @gallery_base_dir;

header();

print "\nSearching directories and compressing images:\n\n";

find ( \&wanted,  @gallery_base_dir );

my $nagg_result;
my $base_gallery_dir = pop @gallery_dir_list;

print "\nNow creating Galleries\n";
print "Base gallery directory is: $base_gallery_dir\n\n";

foreach my $dir ( @gallery_dir_list ) {

 if ( defined($dir) && $dir ne $gallery_base_dir[0] ) {

  print "Working on: $dir";
  $nagg_result = qx#nagg -d "$dir"#;

   if ( $? == 0 ) {
    print " -> gallery complete\n"
   }
   else {
    print "$nagg_result\n";
    footer_and_exit(172)
   }
 }
}

print "\nAll processes complete!\n\n";

footer_and_exit();

#=========================================================================================#

sub wanted {
my $convert_result;
my $current_dir      =  $File::Find::dir;
my $current_file     =  $_;
my $path_to_file     =  $current_dir . "/" . $current_file;
my $path_to_new_file =  $path_to_file;

unshift @gallery_dir_list, $current_dir unless ( $current_dir eq $gallery_dir_list[0] );  
 

 if ( /jp.?g/i ) {
 
  $path_to_new_file =~ s/$/.mod/;

  $convert_result = qx#/usr/bin/convert -compress JPEG -quality 30 $path_to_file $path_to_new_file#;

   if ( $? != 0 ) {
    print "$convert_result\n\n";
    footer_and_exit(172)
   }
   else {
    unlink $path_to_file or die "Couldn't delete $path_to_file: $!\n";
    rename $path_to_new_file, $path_to_file or die "Couldn't rename $path_to_new_file: $!\n";
    print "$path_to_file  -> compressed\n";
   }
 }
}



sub header {
print <<'END_HTML';
Content-Type: text/html

<html>
<body>
<blockquote>
END_HTML

}


sub footer_and_exit {
my $exit_code = shift;
   $exit_code = 0 unless defined($exit_code);

print <<'END_HTML';
</blockquote>
</pre> </em>
</body> </HTML>
END_HTML

exit $exit_code;
}

Offline cactus

  • *
  • 4,880
  • +3/-0
    • http://www.snetram.nl
cgi strangeness from ibay
« Reply #1 on: January 29, 2007, 04:38:25 PM »
The difference is that SME Server is based on CentOS and is much stricter than CentOS, to improve security and stability of your server. The chrooted jail you mention might be very well pinpointed.

What user are you using to run the script on the command line? I think the problem might be in permissions compared to your test user and the user under which the apache process runs (www).

It also seems that your c-wrapper is stumbling on the use keyword in your perl file. Do you have apache configured to recognize your script as perl script?
Be careful whose advice you buy, but be patient with those who supply it. Advice is a form of nostalgia, dispensing it is a way of fishing the past from the disposal, wiping it off, painting over the ugly parts and recycling it for more than its worth ~ Baz Luhrmann - Everybody's Free (To Wear Sunscreen)