Hello,
I have a simple perl script that connects to an LDAP server, searches for a user ID, then extracts the photo of that user and prints it to a file. The only problem, is that the printed file is not recognized as a photo. I believe that the file is stored in LDAP in either JPG format or HEX format. Either way, I need to print the file as a JPG. Any suggestions?
Here is the code:
#open a connection to LDAP
my $ldap = Net::LDAP->new ( "$idvServer" ) or die "$@";
my $result = $ldap->bind ( "$idvAdmin", password => "$idvPW", version
+=> 3 ) or die($result->error());
# open the input file
open WFIDS, "<$inputFile" or die("Could not open input file.");
open LOGFILE, ">>$logFile" or die("Could not open log file.");
foreach $empID (<WFIDS>) {
chomp($empID); # remove the newline from $line.
my $filter = "(workforceID=$empID)";
$mesg = $ldap->search (base => $userBase, filter => "$filter", sco
+pe => "$scope", attrs => $userAttributes) ;
$totalFound=$mesg->count; # determine the number of entries found,
+ should only be one
my @entries = $mesg->entries;
if ($totalFound eq 1)
{
my $photo = $entries[0]->get_value('photo');
open OUTFILE, ">${outputFile}${empID}.jpg" or die("Could not c
+reate the empID file.");
print OUTFILE "$photo";
close OUTFILE;
print LOGFILE "Found 1 ID for $empID\n";
}
else
{
print LOGFILE "Found more than 1 ID or found 0 IDs for $empID\
+n";
}
}
close(WFIDS);
close LOGFILE;
$ldap->unbind;