logo
Apache Lounge
Webmasters

 


About

Forum Index Downloads Search Register Log in  RSS Apache Lounge
 



Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Apache Lounge is not sponsored.

Your donations will help to keep this site alive and well, and continuing building binaries.



Perl script works outside of Apache

 
Post new topic   Reply to topic    Apache Forum Index -> Coding & Scripting Corner



View previous topic :: View next topic  
Author Message
robertc



Joined: 25 Jul 2012
Posts: 3
Location: USA, San Diego

PostPosted: Wed 25 Jul '12 19:50    Post subject: Perl script works outside of Apache Reply with quote

Hi,
I have an issue I would like some insights into. I am porting a standalone Perl script into a CGI. Part of what the script does is to open an LDAP connection to another server. This script works fine as a standalone script, but fails to connect when it is run as a CGI. I am running Apache 2.2.22. I am running on a Windows 7 machine to debug as localhost:7080. The final target will be a Linux platform running Apache (Lampps).
I am guessing it is a permissions issue but I read elsewhere that Apache ignores permissions on Windows platforms, so any help you can give me would be very appreciated.

The line that is failing is

my $ldap = Net::LDAP->new($host);
The $ldap scalar should be a LDAP object and comes back as an undef.

Thanks,
Bob
Back to top
robertc



Joined: 25 Jul 2012
Posts: 3
Location: USA, San Diego

PostPosted: Thu 26 Jul '12 4:00    Post subject: Reply with quote

Update:
I just tried an experiment; instead of trying to open the LDAP connection from the CGI script, I called another Perl script from my CGI (which only opens the connection) using system() call. This works.

So
my $ldap = Net::LDAP->new($keyhost)
fails,
but
my $r = system("perl ldaptest.pl $keyhost");
$r == 0 or die "Failed to connect";
works fine.

ldaptest.pl:

use Net::LDAP;

my $server = $ARGV[0];
my $ldap = Net::LDAP->new($server);
if(defined($ldap))
{
$ldap->disconnect();
exit(0);
}
else
{
exit(1);
}

Any ideas, anyone?

Bob
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 6255
Location: Germany, Next to Hamburg

PostPosted: Thu 26 Jul '12 11:32    Post subject: Reply with quote

I guess that the user apache runs with is not allowed to connect to the ldap network. Using the default system account, when running as service, apache can't connect to networkdrives and UNC paths.
You might check run apache as a different user.
Back to top
robertc



Joined: 25 Jul 2012
Posts: 3
Location: USA, San Diego

PostPosted: Thu 09 Aug '12 0:19    Post subject: Reply with quote

Hi James,
I took your advice and it appears to be working. Took me a little while to figure out how to set up a new user within our company's security structure, but everything looks good now. Thanks for the help.

Bob
Back to top


Post new topic   Reply to topic    Apache Forum Index -> Coding & Scripting Corner
Page 1 of 1