The junk below is what I ended up having to do to stuff a jpg into
Windows 2003 Active Directory...and then to read it out. Maybe it will
give you some hints.
 


Code to read image data from Active Directory

use Net::LDAP;
$ldapnode="192.168.2.10";
$ldap = new Net::LDAP("$ldapnode",port => 389,debug =>3, version => 3)
or
        die "Failed on new\n";
$result=$ldap->ldapbind() || die "Bind Failed:$@"; 
@attr=("thumbnailPhoto"); 
$filter="([EMAIL PROTECTED])";
$mesg = $ldap->search(filter => $filter,attrs => [EMAIL PROTECTED], base =>
"CN=Users,DC=home,DC=yyy,DC=zzz,DC=xxx"
    ) or die "Search Failed using FILTER: $filter$@";
 
foreach $entry ($mesg->all_entries) {
 $t=$entry->get("thumbnailPhoto");
 
} 

open(OUT,">test.jpg");
binmode(OUT);
foreach(@$t){
        print OUT "$_";
}
close(OUT);
$ldap->unbind;



Code to put a photo in Active Directory

#get the name of the jpeg file
($in)[EMAIL PROTECTED];
open(IN,"$in");
binmode(IN);
$c=0;
while(<IN>){
        $c++;
        $photo=$photo.$_;
        print "NEXT: $c\n";
}
close(IN);
use Net::LDAP;
$ldapnode="192.168.2.10";

$ldap = new Net::LDAP("$ldapnode",port => 389,debug => 0) or
        die "Failed on new\n";

$pass="notmypassword";
$dn="[EMAIL PROTECTED]";

$dnu="CN=bozo,CN=Users,DC=home,DC=yyy,DC=zzz,dc=xxx";

$ldap->ldapbind(dn => "$dn", password => "$pass") || die "Bind
Failed:$@";



if (!$photo){
        print "DELETE\n";
        $result=$ldap->modify( $dnu, delete => { thumbnailPhoto => [] }
);
        $err=$result->code;
}
else
{
        print "REPLACE\n";
        $result=$ldap->modify( $dnu, replace => { thumbnailPhoto =>
"$photo" } );
        $err=$result->code;
}

print "ERR: $err\n";
 

-----Original Message-----
From: Chris Ridd [mailto:[EMAIL PROTECTED] 
Sent: Monday, March 29, 2004 10:04 PM
To: jehan.procaccia; [EMAIL PROTECTED]
Subject: Re: retrieve jpegPhoto

On 29/3/04 1:09 pm, jehan.procaccia <[EMAIL PROTECTED]> wrote:

> Hello,
> I am trying to retrieve jpegPhotos from my openldap directory with 
> Net::Ldap, however I keep getting files containing only "data" and not

> a jpeg files.
> I took inspiration from:
> http://search.cpan.org/src/GBARR/perl-ldap-0.31/contrib/jpegDisplay.pl
> here's the section of code I took:
> 
>   $photo=$entry->get_attribute( 'jpegPhoto' );

That really ought to be:

     $photo=$entry->get_value( 'jpegPhoto' );

If you run the script with 'use warn;' you will see why.

>   if(ref($photo))
>     {$picture = @$photo[0];}
>   else
>    {print "\n";
>     print "No jpegPhoto attribute for DN: $dn\n";} open (TMP, 
> ">./photos/$mail"); $| = 1; print TMP $picture; close(TMP);
> 
> $ file photos/[EMAIL PROTECTED]
> photos/[EMAIL PROTECTED]: data which cannot be viewed as a 
> jpeg photo :-(
> 
> What I am doing wrong ?

Is there a difference between the value you retrieved and the value in
the file (ie is writing to the file going wrong)?

Are the JPEGs being *added* correctly to the server? Are any other
clients able to read the JPEGs?

Cheers,

Chris

Cheers,

Chris



Reply via email to