Here is a code example as requested.
The print statements in LDAPerror work fine. They display information in my web browser. I don't know why this works since I'm not printing the header anywhere. If I put a print statement in the main body of my code, I get an internal server error (as I should).
Thanks,
Shiva
#!/usr/bin/perl
use CGI;
use Net::LDAP;
use Net::LDAP::Entry;
use Net::LDAP::Util qw( ldap_error_name
ldap_error_text);
#prepare entry
$entry = Net::LDAP::Entry->new();
$addinfo = CGI->new();
my $index = 5000;
my($sec, $min, $hour, $day, $mon, $year, $wday, %yday, $isdst) = local
+time;
$mon += 1;
$year += 1900;
$dn = "index=" . $index . ", o=cert";
$entry->dn($dn);
$entry->add('objectclass' => 'certentry',
'index' => $index,
'openedOn' => $year . $mon . $day . '000000',
);
#bind to server
$ldap = Net::LDAP->new("shiva.mydomain.com",
port => 389) ||
die("Failed to connect to LDAP host.\n");
$mesg = $ldap->bind("cn=root",
password => "root",
version => 3);
LDAPerror("Bind", $mesg);
#add entry to server
$mesg = $ldap->add($entry);
LDAPerror("Adding", $mesg);
#unbind
$ldap->unbind;
sub LDAPerror
{
my ($from,$mesg) = @_;
print "\n$from\nReturn code: ",$mesg->code ;
print "\tMessage: ", ldap_error_name($mesg->code);
print " :", ldap_error_text($mesg->code);
print "MessageID: ",$mesg->mesg_id;
print "\tDN: ",$mesg->dn;
print "\n";
#---
# Programmer note:
#
# "$mesg->error" DOESN'T work!!!
#
#print "\tMessage: ", $mesg->error;
#-----
}
|