rhirst has asked for the wisdom of the Perl Monks concerning the following question:
I have a script that I'm using on a Windows 2003 64-bit server, to do LDAP queries and updates. It runs fine from the command line but I need it to run as a CGI script.
When running in CGI, I get an error
IO::Socket::INET: Bad hostname '<hostname>'When I try putting in an IP address instead of a host name, I get:
IO::Socket::INET: Unknown errorDoes anyone know of a reason why IO::Socket would fail in this situation? Here is the code up to where the failure occurs
use strict; use Net::LDAP; # global variables # my $bind_dn = "uid=xxx,ou=Directory Administrators,dc=xxx,dc=com"; my $bind_pw = "secret"; my $host = "ldapd1.xxx.com"; my $port = 389; my $group = "Operator"; my $action = "add"; # Read in user name from Web Field my ($buffer, @pairs, %FORM); $ENV{'REQUEST_METHOD'} =~ tr/a-z/A-Z/; if ($ENV{'REQUEST_METHOD'} eq "POST") { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); } else { $buffer = $ENV{'QUERY_STRING'}; } @pairs = split(/&/, $buffer); foreach my $pair (@pairs) { my ($name, $fvalue) = split(/=/, $pair); $fvalue =~ tr/+/ /; $fvalue =~ s/%(..)/pack("C", hex($1))/eg; $FORM{$name} = $fvalue; } my $mail = $FORM{'j_username'}; # Print out header stuff print "Content-type: text/html\n\n"; print "<!DOCTYPE HTML PUBLIC \"-\/\/W3C\/\/DTD HTML 4.01\/\/EN\" \"htt +p:\/\/www.w3.org\/TR\/html4\/strict.dtd\">\n"; print "<html>\n"; print "<head>\n"; print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset= +UTF-8\">\n"; print "<link rel=stylesheet type=text/css href=\"/css/default.css\" /> +\n"; print "<title>Request Access</title>\n"; if ($mail eq "") { printError ("You must enter a user name"); } # configuration # my $usr_base_dn = "ou=people,ou=global,dc=xxx,dc=com"; my $grp_base_dn = "ou=xxx,ou=groups,ou=services,ou=global,dc=xxx,dc=co +m"; # open an LDAP connection my $ldap = new Net::LDAP($host, port => $port); if (!$ldap) { printError ("Cannot contact Directory Server: $@\n"); exit; }
Any help greatly appreciated!
Thanks!
Rich
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Net::LDAP in a CGI script
by jethro (Monsignor) on Jan 22, 2010 at 22:38 UTC | |
by rhirst (Initiate) on Jan 26, 2010 at 09:43 UTC | |
|
Re: Net::LDAP in a CGI script
by james2vegas (Chaplain) on Jan 24, 2010 at 09:27 UTC |