Net::LDAP and Net:LDAP::LDIF read & add problems

I'm trying to read in a simple LDIF file to add an entry to my LDAP
server.  Here is the basic routine (extraneous details omitted for
brevity and security):

$ldif = Net::LDAP::LDIF->new($tmp,"r",onerror => 'warn');
$entry = $ldif->ready_entry();
$ldap = Net::LDAP->new($LDAPSERVER);
$result=$ldap->bind("$binddn",password=>"$bindpass",version=>"3");
$result=$ldap->add($entry);

Now, everything seems to work until I get to the $ldap->add method.
 From that I get various versions of the following:

objectclass: value #0 invalid per syntax at ldap.cgi

I can get that error message to change to different attributes, but
basically keeps saying the same thing.  I've tried adding the following
just before the $ldap->add but it didn't help:
$entry->add('changetype'=>'add');

I've even gone through a routine to save off the value of each
attribute, do a $entry->delete on the attribute, and then a $entry->add
to re-add the attribute, to no avail.

I've done extensive searching on the web and nothing I've found has
helped, so I'm really hoping someone here can aid me ASAP, for I have to
get this done in the next day or two.

Thanks,
Rick



______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________
0
rickg
8/19/2005 7:57:37 PM
perl.ldap 1268 articles. 0 followers. Follow

8 Replies
1529 Views

Similar Articles

[PageSpeed] 47
Get it on Google Play
Get it on Apple App Store

Further update:

I have tried to just manually create a new entry within the PERL script 
itself, and it fails on different message:

add error: addRequest.addRequest.objectName is undefined at 
/usr/lib/perl5/site_perl/5.8.6/Net/LDAP/Message.pm line 178

Here is the code that leads up to the above message (the bind is done a 
few lines before, authenticated and it does succeed):

   $entry=Net::LDAP::Entry->new();
   $entry->add( 
'dn'=>'cn=kingr,o=PennLibraryStaff,dc=library,dc=upenn,dc=edu');
   $entry->add( 'objectclass'=> 
["person","organizationalPerson","inetOrgPerson","posixAccount","upennEduPerson" 
]);
   $entry->add( 'cn' => "kingr");
   $entry->add( 'sn' => "kingr");
   $entry->add( 'userid' => "kingr");
   $entry->add( 'uidNumber' => "3019");
   $entry->add( 'gidNumber' => "100");
   $entry->add( 'homeDirectory' => "/home/kingr");
   $entry->add( 'userPassword' => "{SHA}6wEWbSyjuY4/gp469HkIAxqj3vs=");
   $entry->add( 'loginShell' => "/bin/bash");
   $entry->add( 'gecos' => "Richard P. King");
   $result=$ldap->add( $entry ) ;
   $result->code && die "add error: ", $result->error;

I feel like I'm missing a key detail here.  Can anyone see what it is?

Thanks in advance,
Rick

Rick Greene wrote:
> I'm trying to read in a simple LDIF file to add an entry to my LDAP
> server.  Here is the basic routine (extraneous details omitted for
> brevity and security):
> 
> $ldif = Net::LDAP::LDIF->new($tmp,"r",onerror => 'warn');
> $entry = $ldif->ready_entry();
> $ldap = Net::LDAP->new($LDAPSERVER);
> $result=$ldap->bind("$binddn",password=>"$bindpass",version=>"3");
> $result=$ldap->add($entry);
> 
> Now, everything seems to work until I get to the $ldap->add method.
>  From that I get various versions of the following:
> 
> objectclass: value #0 invalid per syntax at ldap.cgi
> 
> I can get that error message to change to different attributes, but
> basically keeps saying the same thing.  I've tried adding the following
> just before the $ldap->add but it didn't help:
> $entry->add('changetype'=>'add');
> 
> I've even gone through a routine to save off the value of each
> attribute, do a $entry->delete on the attribute, and then a $entry->add
> to re-add the attribute, to no avail.
> 
> I've done extensive searching on the web and nothing I've found has
> helped, so I'm really hoping someone here can aid me ASAP, for I have to
> get this done in the next day or two.
> 
> Thanks,
> Rick
> 
> 
> 
> ______________________________________________________________________
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit http://www.messagelabs.com/email 
> ______________________________________________________________________
> 


______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________
0
rickg
8/22/2005 7:10:38 PM
On Mon, August 22, 2005 2:10 pm, Rick Greene said:
> Further update:
>
> I have tried to just manually create a new entry within the PERL script
> itself, and it fails on different message:
>
> add error: addRequest.addRequest.objectName is undefined at
> /usr/lib/perl5/site_perl/5.8.6/Net/LDAP/Message.pm line 178
>
> Here is the code that leads up to the above message (the bind is done a
> few lines before, authenticated and it does succeed):
>
>    $entry=Net::LDAP::Entry->new();

You need to set the DN with

  $entry->dn($dn);

Graham.

>    $entry->add(
> 'dn'=>'cn=kingr,o=PennLibraryStaff,dc=library,dc=upenn,dc=edu');
>    $entry->add( 'objectclass'=>
> ["person","organizationalPerson","inetOrgPerson","posixAccount","upennEduPerson"
> ]);
>    $entry->add( 'cn' => "kingr");
>    $entry->add( 'sn' => "kingr");
>    $entry->add( 'userid' => "kingr");
>    $entry->add( 'uidNumber' => "3019");
>    $entry->add( 'gidNumber' => "100");
>    $entry->add( 'homeDirectory' => "/home/kingr");
>    $entry->add( 'userPassword' => "{SHA}6wEWbSyjuY4/gp469HkIAxqj3vs=");
>    $entry->add( 'loginShell' => "/bin/bash");
>    $entry->add( 'gecos' => "Richard P. King");
>    $result=$ldap->add( $entry ) ;
>    $result->code && die "add error: ", $result->error;
>
> I feel like I'm missing a key detail here.  Can anyone see what it is?
>
> Thanks in advance,
> Rick
>
> Rick Greene wrote:
>> I'm trying to read in a simple LDIF file to add an entry to my LDAP
>> server.  Here is the basic routine (extraneous details omitted for
>> brevity and security):
>>
>> $ldif = Net::LDAP::LDIF->new($tmp,"r",onerror => 'warn');
>> $entry = $ldif->ready_entry();
>> $ldap = Net::LDAP->new($LDAPSERVER);
>> $result=$ldap->bind("$binddn",password=>"$bindpass",version=>"3");
>> $result=$ldap->add($entry);
>>
>> Now, everything seems to work until I get to the $ldap->add method.
>>  From that I get various versions of the following:
>>
>> objectclass: value #0 invalid per syntax at ldap.cgi
>>
>> I can get that error message to change to different attributes, but
>> basically keeps saying the same thing.  I've tried adding the following
>> just before the $ldap->add but it didn't help:
>> $entry->add('changetype'=>'add');
>>
>> I've even gone through a routine to save off the value of each
>> attribute, do a $entry->delete on the attribute, and then a $entry->add
>> to re-add the attribute, to no avail.
>>
>> I've done extensive searching on the web and nothing I've found has
>> helped, so I'm really hoping someone here can aid me ASAP, for I have to
>> get this done in the next day or two.
>>
>> Thanks,
>> Rick
>>
>>
>>
>> ______________________________________________________________________
>> This email has been scanned by the MessageLabs Email Security System.
>> For more information please visit http://www.messagelabs.com/email
>> ______________________________________________________________________
>>
>
>
> ______________________________________________________________________
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit http://www.messagelabs.com/email
> ______________________________________________________________________
>
>


0
gbarr
8/22/2005 7:25:11 PM
Ok, Graham supplied the missing bit, so now I know at least the basics 
are working.

Now the question remains, what is wrong with the original thing I was 
trying, using the Net::LDAP::LDIF functionality?  Here's the code (part 
of a script fed from a web form, cut out extraneous details):

#Version to do it through LDIF read
use Net::LDAP::LDIF ;
local $tmp="/tmp/$$.ldif" ;
open OUTFILE,"> $tmp"; print OUTFILE $w->param('ldif') ; close OUTFILE ;
$ldif = Net::LDAP::LDIF->new($tmp,"r",onerror => 'warn');
$entry = $ldif->read_entry();
if ($debug) {
   print "${redon}ldif loaded with dn=",$entry->dn(),"${redoff}$br";
   @attributes=$entry->attributes;
   print "${redon}read entry:<BR>"; foreach $key (sort @attributes) { 
print "$key=" ; print $entry->get_value($key); print "${br}"; } print 
"${redoff}${br}";
}
$ldap = Net::LDAP->new($LDAPSERVER);
$result=$ldap->bind("$binddn",password=>"$bindpass",version=>"3");
$result=$ldap->add($entry);
$result->code && die "add error: ", $result->error;

And here is the LDIF that is pasted into the form (a textarea field):

dn: cn=kingr,o=PennLibraryStaff,dc=library,dc=upenn,dc=edu
objectclass: person
objectclass: organizationalPerson
objectclass: inetOrgPerson
objectclass: posixAccount
objectclass: upennEduPerson
cn: kingr
gn: Richard
sn: King
userid: kingr
uidNumber: 3019
gidNumber: 100
homeDirectory: /home/kingr
loginShell: /bin/bash
gecos: Richard P. King
ou: Reference
title: Systems Tech II

And here's the results (some debug statements were omitted from the code 
above, but the output is below):
In sub process_ldif
creating /tmp/19277.ldif
/tmp/19277.ldif contains

dn: cn=kingr,o=PennLibraryStaff,dc=library,dc=upenn,dc=edu
objectclass: person
objectclass: organizationalPerson
objectclass: inetOrgPerson
objectclass: posixAccount
objectclass: upennEduPerson
cn: kingr
gn: Richard
sn: King
userid: kingr
uidNumber: 3019
gidNumber: 100
homeDirectory: /home/kingr
userPassword: {SHA}6wEWbSyjuY4/gp469HkIAxqj3vs=
loginShell: /bin/bash
gecos: Richard P. King
ou: Reference
mail: kingr@wharton.upenn.edu
telephonenumber: 215-898-5928
title: Systems Tech II

ldif loaded with dn=cn=kingr,o=PennLibraryStaff,dc=library,dc=upenn,dc=edu
read entry:
cn=kingr
gecos=Richard P. King
gidnumber=100
gn=Richard
homedirectory=/home/kingr
loginshell=/bin/bash
mail=kingr@wharton.upenn.edu
objectclass=person organizationalPerson inetOrgPerson posixAccount 
upennEduPerson
ou=Reference
sn=King
telephonenumber=215-898-5928
title=Systems Tech II
uidnumber=3019
userid=kingr
userpassword={SHA}6wEWbSyjuY4/gp469HkIAxqj3vs=

add error: objectclass: value #0 invalid per syntax at 
/var/www/html/bin/ldappasswd.cgi line 117, line 1.

So, as far as I can tell the $entry reference has everything in it, and 
I know the object classes in the LDIF are good, for they are the same as 
every other entry in this particular LDAP instance.  In fact, if I use 
this LDIF file from the command line with an ldapadd statement, it works 
fine.  So again, I am missing something but can't tell what.  It's not 
the bit I was missing doing it manually that Graham pointed out, for you 
can see the debug code is correctly outputting $entry->dn() and showing 
the value is set.

Thanks again in advance,
Rick



______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________
0
rickg
8/22/2005 7:46:32 PM
Ok, I found the problem.  Somehow (probably a default action that I 
didn't know about), when taking in the LDIF formatted text from the 
textarea field of the web form, dumping to a local temporary text file, 
and then using Net::LDAP::LDIF's $ldif->read_entry(), ALL the attributes 
were ending up with a CR (ascii 13) character at the end, and the PERL 
chomp function wasn't removing it.  I got more brute-force-ish about it 
and it all works now.

I did two things...after writing the $w->param('ldif') out to a file, I 
then did:

system ("/usr/bin/dos2unix $tmp")

Which probably took care of everything, but I also put in the following 
line in a couple of key places to be sure:

if ( ord(substr($line,-1)) <= 32 ) { chop($line) ; }

Sorry to have taken up everyone's time with this, thanks to Graham for 
the one hint, hopefully this thread will help someone else along the line.

Rick

Rick Greene wrote:
> Ok, Graham supplied the missing bit, so now I know at least the basics 
> are working.
> 
> Now the question remains, what is wrong with the original thing I was 
> trying, using the Net::LDAP::LDIF functionality?  Here's the code (part 
> of a script fed from a web form, cut out extraneous details):
> 
> #Version to do it through LDIF read
> use Net::LDAP::LDIF ;
> local $tmp="/tmp/$$.ldif" ;
> open OUTFILE,"> $tmp"; print OUTFILE $w->param('ldif') ; close OUTFILE ;
> $ldif = Net::LDAP::LDIF->new($tmp,"r",onerror => 'warn');
> $entry = $ldif->read_entry();
> if ($debug) {
>   print "${redon}ldif loaded with dn=",$entry->dn(),"${redoff}$br";
>   @attributes=$entry->attributes;
>   print "${redon}read entry:<BR>"; foreach $key (sort @attributes) { 
> print "$key=" ; print $entry->get_value($key); print "${br}"; } print 
> "${redoff}${br}";
> }
> $ldap = Net::LDAP->new($LDAPSERVER);
> $result=$ldap->bind("$binddn",password=>"$bindpass",version=>"3");
> $result=$ldap->add($entry);
> $result->code && die "add error: ", $result->error;
> 
> And here is the LDIF that is pasted into the form (a textarea field):
> 
> dn: cn=kingr,o=PennLibraryStaff,dc=library,dc=upenn,dc=edu
> objectclass: person
> objectclass: organizationalPerson
> objectclass: inetOrgPerson
> objectclass: posixAccount
> objectclass: upennEduPerson
> cn: kingr
> gn: Richard
> sn: King
> userid: kingr
> uidNumber: 3019
> gidNumber: 100
> homeDirectory: /home/kingr
> loginShell: /bin/bash
> gecos: Richard P. King
> ou: Reference
> title: Systems Tech II
> 
> And here's the results (some debug statements were omitted from the code 
> above, but the output is below):
> In sub process_ldif
> creating /tmp/19277.ldif
> /tmp/19277.ldif contains
> 
> dn: cn=kingr,o=PennLibraryStaff,dc=library,dc=upenn,dc=edu
> objectclass: person
> objectclass: organizationalPerson
> objectclass: inetOrgPerson
> objectclass: posixAccount
> objectclass: upennEduPerson
> cn: kingr
> gn: Richard
> sn: King
> userid: kingr
> uidNumber: 3019
> gidNumber: 100
> homeDirectory: /home/kingr
> userPassword: {SHA}6wEWbSyjuY4/gp469HkIAxqj3vs=
> loginShell: /bin/bash
> gecos: Richard P. King
> ou: Reference
> mail: kingr@wharton.upenn.edu
> telephonenumber: 215-898-5928
> title: Systems Tech II
> 
> ldif loaded with dn=cn=kingr,o=PennLibraryStaff,dc=library,dc=upenn,dc=edu
> read entry:
> cn=kingr
> gecos=Richard P. King
> gidnumber=100
> gn=Richard
> homedirectory=/home/kingr
> loginshell=/bin/bash
> mail=kingr@wharton.upenn.edu
> objectclass=person organizationalPerson inetOrgPerson posixAccount 
> upennEduPerson
> ou=Reference
> sn=King
> telephonenumber=215-898-5928
> title=Systems Tech II
> uidnumber=3019
> userid=kingr
> userpassword={SHA}6wEWbSyjuY4/gp469HkIAxqj3vs=
> 
> add error: objectclass: value #0 invalid per syntax at 
> /var/www/html/bin/ldappasswd.cgi line 117, line 1.
> 
> So, as far as I can tell the $entry reference has everything in it, and 
> I know the object classes in the LDIF are good, for they are the same as 
> every other entry in this particular LDAP instance.  In fact, if I use 
> this LDIF file from the command line with an ldapadd statement, it works 
> fine.  So again, I am missing something but can't tell what.  It's not 
> the bit I was missing doing it manually that Graham pointed out, for you 
> can see the debug code is correctly outputting $entry->dn() and showing 
> the value is set.
> 
> Thanks again in advance,
> Rick
> 
> 
> 
> ______________________________________________________________________
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit http://www.messagelabs.com/email 
> ______________________________________________________________________
> 


______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________
0
rickg
8/23/2005 4:46:24 PM

--On Tuesday, August 23, 2005 12:46 PM -0400 Rick Greene <rickg@serve.com> 
wrote:

> Ok, I found the problem.  Somehow (probably a default action that I
> didn't know about), when taking in the LDIF formatted text from the
> textarea field of the web form, dumping to a local temporary text file,
> and then using Net::LDAP::LDIF's $ldif->read_entry(), ALL the attributes
> were ending up with a CR (ascii 13) character at the end, and the PERL
> chomp function wasn't removing it.  I got more brute-force-ish about it
> and it all works now.
>
> I did two things...after writing the $w->param('ldif') out to a file, I
> then did:
>
> system ("/usr/bin/dos2unix $tmp")
>
> Which probably took care of everything, but I also put in the following
> line in a couple of key places to be sure:
>
> if ( ord(substr($line,-1)) <= 32 ) { chop($line) ; }
>
> Sorry to have taken up everyone's time with this, thanks to Graham for
> the one hint, hopefully this thread will help someone else along the line.

This was actually just recently discussed.

You could, I would think, use perl itself to clean up the \r\n fairly 
easily. ;)

$line =~ s/\r\n//;

for example, rather than chomp.

--Quanah

--
Quanah Gibson-Mount
Principal Software Developer
ITSS/Shared Services
Stanford University
GnuPG Public Key: http://www.stanford.edu/~quanah/pgp.html

"These censorship operations against schools and libraries are stronger
than ever in the present religio-political climate. They often focus on
fantasy and sf books, which foster that deadly enemy to bigotry and blind
faith, the imagination." -- Ursula K. Le Guin

0
quanah
8/23/2005 4:51:14 PM
On 23/8/05 5:51, Quanah Gibson-Mount <quanah@stanford.edu> wrote:

> This was actually just recently discussed.
> 
> You could, I would think, use perl itself to clean up the \r\n fairly
> easily. ;)
> 
> $line =~ s/\r\n//;
> 
> for example, rather than chomp.

Or if you wanted to cope with other mutant kinds of line ends:

    $line =~ s/[\r\n]+$//;

(Dunno if that's more efficient that /\r?\n?$/ but they'd both catch
old-style Mac linebreaks.)

Cheers,

Chris


0
chrisridd
8/23/2005 5:58:05 PM
--Boundary-00=_dwFED1cI8riTZGL
Content-Type: text/plain;
  charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Hi Rick,

would you be so kind to do the perl-ldap project a favour ?

Here's a patch for Net::LDAP::LDIF that should make it work with
LDIF files that have lines ending in CR+LF.

Would you mind to test it and report any problems with it

Thanks in advance
Peter

On Tuesday, 23. August 2005 18:46, Rick Greene wrote:
> Ok, I found the problem.  Somehow (probably a default action that I
> didn't know about), when taking in the LDIF formatted text from the
> textarea field of the web form, dumping to a local temporary text file,
> and then using Net::LDAP::LDIF's $ldif->read_entry(), ALL the attributes
> were ending up with a CR (ascii 13) character at the end, and the PERL
> chomp function wasn't removing it.  I got more brute-force-ish about it
> and it all works now.
>
> I did two things...after writing the $w->param('ldif') out to a file, I
> then did:
>
> system ("/usr/bin/dos2unix $tmp")
>
> Which probably took care of everything, but I also put in the following
> line in a couple of key places to be sure:
>
> if ( ord(substr($line,-1)) <= 32 ) { chop($line) ; }
>
> Sorry to have taken up everyone's time with this, thanks to Graham for
> the one hint, hopefully this thread will help someone else along the line.
>
> Rick
>
> Rick Greene wrote:
> > Ok, Graham supplied the missing bit, so now I know at least the basics
> > are working.
> >
> > Now the question remains, what is wrong with the original thing I was
> > trying, using the Net::LDAP::LDIF functionality?  Here's the code (part
> > of a script fed from a web form, cut out extraneous details):
> >
> > #Version to do it through LDIF read
> > use Net::LDAP::LDIF ;
> > local $tmp="/tmp/$$.ldif" ;
> > open OUTFILE,"> $tmp"; print OUTFILE $w->param('ldif') ; close OUTFILE ;
> > $ldif = Net::LDAP::LDIF->new($tmp,"r",onerror => 'warn');
> > $entry = $ldif->read_entry();
> > if ($debug) {
> >   print "${redon}ldif loaded with dn=",$entry->dn(),"${redoff}$br";
> >   @attributes=$entry->attributes;
> >   print "${redon}read entry:<BR>"; foreach $key (sort @attributes) {
> > print "$key=" ; print $entry->get_value($key); print "${br}"; } print
> > "${redoff}${br}";
> > }
> > $ldap = Net::LDAP->new($LDAPSERVER);
> > $result=$ldap->bind("$binddn",password=>"$bindpass",version=>"3");
> > $result=$ldap->add($entry);
> > $result->code && die "add error: ", $result->error;
> >
> > And here is the LDIF that is pasted into the form (a textarea field):
> >
> > dn: cn=kingr,o=PennLibraryStaff,dc=library,dc=upenn,dc=edu
> > objectclass: person
> > objectclass: organizationalPerson
> > objectclass: inetOrgPerson
> > objectclass: posixAccount
> > objectclass: upennEduPerson
> > cn: kingr
> > gn: Richard
> > sn: King
> > userid: kingr
> > uidNumber: 3019
> > gidNumber: 100
> > homeDirectory: /home/kingr
> > loginShell: /bin/bash
> > gecos: Richard P. King
> > ou: Reference
> > title: Systems Tech II
> >
> > And here's the results (some debug statements were omitted from the code
> > above, but the output is below):
> > In sub process_ldif
> > creating /tmp/19277.ldif
> > /tmp/19277.ldif contains
> >
> > dn: cn=kingr,o=PennLibraryStaff,dc=library,dc=upenn,dc=edu
> > objectclass: person
> > objectclass: organizationalPerson
> > objectclass: inetOrgPerson
> > objectclass: posixAccount
> > objectclass: upennEduPerson
> > cn: kingr
> > gn: Richard
> > sn: King
> > userid: kingr
> > uidNumber: 3019
> > gidNumber: 100
> > homeDirectory: /home/kingr
> > userPassword: {SHA}6wEWbSyjuY4/gp469HkIAxqj3vs=
> > loginShell: /bin/bash
> > gecos: Richard P. King
> > ou: Reference
> > mail: kingr@wharton.upenn.edu
> > telephonenumber: 215-898-5928
> > title: Systems Tech II
> >
> > ldif loaded with
> > dn=cn=kingr,o=PennLibraryStaff,dc=library,dc=upenn,dc=edu read entry:
> > cn=kingr
> > gecos=Richard P. King
> > gidnumber=100
> > gn=Richard
> > homedirectory=/home/kingr
> > loginshell=/bin/bash
> > mail=kingr@wharton.upenn.edu
> > objectclass=person organizationalPerson inetOrgPerson posixAccount
> > upennEduPerson
> > ou=Reference
> > sn=King
> > telephonenumber=215-898-5928
> > title=Systems Tech II
> > uidnumber=3019
> > userid=kingr
> > userpassword={SHA}6wEWbSyjuY4/gp469HkIAxqj3vs=
> >
> > add error: objectclass: value #0 invalid per syntax at
> > /var/www/html/bin/ldappasswd.cgi line 117, line 1.
> >
> > So, as far as I can tell the $entry reference has everything in it, and
> > I know the object classes in the LDIF are good, for they are the same as
> > every other entry in this particular LDAP instance.  In fact, if I use
> > this LDIF file from the command line with an ldapadd statement, it works
> > fine.  So again, I am missing something but can't tell what.  It's not
> > the bit I was missing doing it manually that Graham pointed out, for you
> > can see the debug code is correctly outputting $entry->dn() and showing
> > the value is set.
> >
> > Thanks again in advance,
> > Rick
> >
> >
> >
> > ______________________________________________________________________
> > This email has been scanned by the MessageLabs Email Security System.
> > For more information please visit http://www.messagelabs.com/email
> > ______________________________________________________________________
>
> ______________________________________________________________________
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit http://www.messagelabs.com/email
> ______________________________________________________________________

-- 
Peter Marschall
eMail: peter@adpm.de

--Boundary-00=_dwFED1cI8riTZGL
Content-Type: text/x-diff;
  charset="iso-8859-1";
  name="LDIF.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="LDIF.patch"

--- lib/Net/LDAP/LDIF.pm	(revision 455)
+++ lib/Net/LDAP/LDIF.pm	(working copy)
@@ -9,7 +9,7 @@
 require Net::LDAP::Entry;
 use vars qw($VERSION);
 
-$VERSION = "0.16";
+$VERSION = "0.16_01";
 
 my %mode = qw(w > r < a >>);
 
@@ -79,35 +79,49 @@
   
 sub _read_lines {
   my $self = shift;
-  my @ldif;
+  my $fh = $self->{'fh'};
+  my @ldif = ();
+  my $entry = '';
+  my $in_comment = 0;
+  my $entry_completed = 0;
+  my $ln;
 
-  {
-    local $/ = "";
-    my $fh = $self->{'fh'};
-    my $ln;
-    do {	# allow comments separated by blank lines
-      $ln = $self->{_next_lines} || scalar <$fh>;
-      unless ($ln) {
-         $self->{_next_lines} = '';
-         $self->{_current_lines} = '';
-         $self->eof(1);
-         return;
+  return @ldif  if ($self->eof());
+  
+  while (defined($ln = $self->{_buffered_line} || scalar <$fh>)) {
+    delete($self->{_buffered_line});
+    if ($ln =~ /^#/o) {		# ignore 1st line of comments
+      $in_comment = 1;
+    }
+    else {
+      if ($ln =~ /^[ \t]/o) {	# append wrapped line (if not in a comment)
+        $entry .= $ln  if (!$in_comment);
       }
-      $ln =~ s/\n //sg;
-      $ln =~ s/^#.*\n//mg;
-      chomp($ln);
-      $self->{_current_lines} = $ln;
-    } until ($self->{_current_lines} || $self->eof());
-    chomp(@ldif = split(/^/, $ln));
-    do {
-      $ln = scalar <$fh> || '';
-      $self->eof(1) unless $ln;
-      $ln =~ s/\n //sg;
-      $ln =~ s/^#.*\n//mg;
-      chomp($ln);
-      $self->{_next_lines} = $ln;
-    } until ($self->{_next_lines} || $self->eof());
+      else {
+        $in_comment = 0;
+        if ($ln =~ /^\r?\n$/o) {
+          # ignore empty line on start of entry
+          # empty line at non-empty entry indicate entry completion
+          $entry_completed++  if (length($entry));
+	}
+        else {
+	  if ($entry_completed) {
+	    $self->{_buffered_line} = $ln;
+	    last;
+	  }
+	  else {
+            # append non-empty line
+            $entry .= $ln;
+	  }  
+        }	
+      }
+    }
   }
+  $self->eof(1)  if (!defined($ln));
+  $entry =~ s/\r?\n //sgo;	# un-wrap wrapped lines
+  $entry =~ s/\r?\n\t/ /sgo;	# OpenLDAP extension !!!
+  @ldif = split(/^/, $entry);
+  map { s/\r?\n$//; } @ldif;
 
   @ldif;
 }
@@ -177,7 +191,7 @@
 
   my $dn = shift @ldif;
 
-  if (length($1)) {
+  if (length($1)) {	# $1 is the optional colon from above
     eval { require MIME::Base64 };
     if ($@) {
       $self->_error($@, @ldif);

--Boundary-00=_dwFED1cI8riTZGL--
0
peter
8/27/2005 12:27:09 PM
I would have loved to assist, however the project I was on that was 
utilizing this has ended for me, so I no longer have access to those systems.

I emailed myself copies of the config files and programs I wrote, if 
I can get a home system working with the same set up I could try 
there, but the next couple of weeks are going to be busy for me so 
I'm not sure how soon I'll be able to get to this.

Sorry,

Rick

At 08:27 AM 8/27/2005, Peter Marschall wrote:
>Hi Rick,
>
>would you be so kind to do the perl-ldap project a favour ?
>
>Here's a patch for Net::LDAP::LDIF that should make it work with
>LDIF files that have lines ending in CR+LF.
>
>Would you mind to test it and report any problems with it
>
>Thanks in advance
>Peter

0
rickg
8/27/2005 2:22:42 PM
Reply:

Similar Artilces:

Net::LDAP and Net:LDAP::LDIF read & add problems #2
I'm trying to read in a simple LDIF file to add an entry to my LDAP server. Here is the basic routine (extraneous details omitted for brevity and security): $ldif = Net::LDAP::LDIF->new($tmp,"r",onerror => 'warn'); $entry = $ldif->ready_entry(); $ldap = Net::LDAP->new($LDAPSERVER); $result=$ldap->bind("$binddn",password=>"$bindpass",version=>"3"); $result=$ldap->add($entry); Now, everything seems to work until I get to the $ldap->add method. From that I get various versions of the following: obj...

make Net::LDAP::LDIF more similar to Net::LDAP
Hi Graham, hi Chris, hi list, I would like to rework Net::LDAP::LDIF a bit so that its API resembles that of Net::LDAP a bit more while still keeping the traditional API. The reason for this is that in application I often need to distinguish between Net::LDAP and Net::LDAP::LDIF because some methods are only implemented on one side. I\'d like to start with a code() method that tries to mimic the Net::LDAP one and I\'d like to extend the Net::LDAP::Entry->update() method so that it takes a Net::LDAP::LDIF object as an argument. The latter one requires a...

[Fwd: make Net::LDAP::LDIF more similar to Net::LDAP]
--------------95D5815B06BDC2BD1A0ABFEB Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit --------------95D5815B06BDC2BD1A0ABFEB Content-Type: message/rfc822 Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Mozilla-Status2: 00000000 Message-ID: <40C7B13E.8864E5A0@cs.adelaide.edu.au> Date: Thu, 10 Jun 2004 10:54:22 +1000 From: Sion Camilleri <sion@cs.adelaide.edu.au> Reply-To: sion@cs.adelaide.edu.au X-Mailer: Mozilla 4.8 [en] (Windows NT 5.0; U) X-Accept-Language: en MIME-Version: 1.0 To: Graham Barr <gbarr@pobox.com>...

Fw: Re: make Net::LDAP::LDIF more similar to Net::LDAP
Am 08.06.2004 um 18:29 Uhr haben Sie geschrieben: > On 8 Jun 2004, at 16:56, peter@adpm.de wrote: > > I\'d like to start with a code() method that tries to mimic the >> Net::LDAP one and >I assume you mean better error handling ? My first goal is having a code() method in Net::LDAP::LDIF. > > I\'d like to extend the > > Net::LDAP::Entry->update() method so that it takes a > > Net::LDAP::LDIF object as an argument. The latter one > > requires a bit of work in Net::LDAP::LDIF to make it > > correct. > Not su...

Fw: Re: make Net::LDAP::LDIF more similar to Net::LDAP #2
Hi, Am 09.06.2004 um 01:44 Uhr haben Sie geschrieben: > Extending Net::LDAP::Entry to update against LDIF and LDAP objects > could allow the changetype modifications to be to produced. > > This would be really useful to produce changetypes for entry objects by > updating against an LDIF object to produce the changetype LDIF required > up to synchronise entry objects. as Graham posted you can to that already now. Simply create your Net::LDAP::Entry object with the changes option set to TRUE. Having created the ::LDIF object that way you autom...

Net::LDAP & LDAP Decoding Error
--mvpLiMfbWzRoNl4x Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hello! I have a question about an LDAP query with Net::LDAP. I send queries to an OpenLDAP server (version 2.2.24). The queries are very simple and intended to detect already existing user entries. The code that prepares and sends the query looks like this: $filter =3D "(uid=3D".$username.")"; $filterobj =3D Net::LDAP::Filter->new($filter); $lres =3D $ldap->search( base =3D> $base, s...

Net:Net:Net::LDAP::FAQ
------_=_NextPart_001_01C6429F.D89AA417 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hello, Net::LDAP Net::LDAPS Is there a possible to LDAP bind with an encrypted (SHA, SSHA, CRYPT, ....) password? I don't like to write the secret password to the perl file. Best regards Barbara Wilbert ------_=_NextPart_001_01C6429F.D89AA417-- Wilbert Barbara (CI/OSI) * wrote: > Hello, > > Net::LDAP > Net::LDAPS > > Is there a possible to LDAP bind with an encrypted (SHA, SSHA, CRYPT, > ......

Net::LDAP v0.28, bug in Net::LDAP::Constant, :all not supported
Net::LDAP::Constant no longer supports the :all tag in the export list due to the switch from Exporter to a manual export routine. So, while the following: perl -MNet::LDAP::Constant=:all -e 1 worked fine in 0.2701, it now dies with the error: ":all" is not exported by the Net::LDAP::Constant module at -e line 0 Can't continue after import errors at -e line 0 BEGIN failed--compilation aborted, <DATA> line 197. The documentation for Net::LDAP::Constant still documents the ':all' tag. I am not subscribed to the list, so if some...

Problems with Net::LDAP::LDIF;
Summary of the environment : perl5 (revision 5.0 version 8 subversion 1 RC3) running under Mac OS X with the stock perl load. I'm trying to run a dump extraction against a Sun Directory server, and instead of manually writing the output, I thought I'd use the Net::LDAP::LDIF; library instead of writing an entry to LDIF dump routine myself. However, it's not happy with the environment right now. use Net::LDAP; use Net::LDAP::LDIF; use Getopt::Long; $ldap = Net::LDAP->new( $server ) or die "$@"; $mesg = $ldap->bind; open (LDIFOUT, ">dum...

problems with Net::LDAP::LDIF module
I'm using FreeBSD 4.9 and latest p5-perl-ldap module version (0.32.02) from ports. My script doesn't start because of compilation problem: Too many arguments for open at /usr/local/lib/perl5/site_perl/5.005/Net/LDAP/LDIF.pm line 123, near "$url)" BEGIN failed--compilation aborted at ./csv_add_ldif line 32, <DATA> chunk 225. The fix is --------------------------------------------------------------- --- LDIF.pm.orig Mon Jul 19 21:18:24 2004 +++ LDIF.pm Sat Aug 21 15:02:12 2004 @@ -120,7 +120,7 @@ if ($url =~ s/^file:(?:\/\/)?//) { my $fh = $self-&...

Net::LDAP based LDAP server available?
Hi, has anybody tried to build an LDAP server based on Net::LDAP or Convert::ASN1 yet? Thanks for any hint. Enrik ...

Net::LDAPS and Net::SSLeay
------_=_NextPart_001_01C3EF1A.51A96530 Content-Type: text/plain Hello all: I am trying to use Net::LDAPS within a perl program in order to establish a secure socket connection with my ldap server. My program works fine if i use the bind function from Net::LDAP module. However, when I changed my source code to use the bind function from Net::LDAPS, my program failed because it complained about the need for IO::Socket::SSL module. Then, when i started to run make for IO::Socket::SSL, it complained about the need for Net::SSLeay. The compilation for Net::SSLeay versio...

Problem with Net::LDAP
Hi, I have a problem with perl-ldap-0.55. Code: #! /usr/bin/perl use Net::LDAP; my $ldap_server = "172.20.1.100"; my ldap = Net::LDAP -> new($ldap_server) or die "$@"; At runnig: >perl perl_test_ldap.pl IO::Socket::INET6: getaddrinfo: No such host is known. at perl_test_ldap.pl line 4, <DATA> line 747. I use Strawberry Perl 5.16.3.1 32bit on Windos XP Professional SP3 Any suggestion is welcome! Dragos Ignatescu On 24 April 2013 10:48, <ignatescu.dragos@stsnet.ro> wrote: Hi, > I have a problem with perl-ldap-0.55...

Net::LDAP add
Hello all, I'm a bit new to Net::LDAP and need little help. I am trying to script an LDAP->add to automate the insertion of new customers to our directory. I am successful when I insert attributes into ou=<company name>,ou=TradingPartners,o=marketsite,o=company.com. The problem occurs when I attempt to add an ou underneath this entry. I am trying to add ou=Contacts,ou=<company name>,ou=TradingPartners,o=marketsite,o=company.com. The script runs without producing any errors, but this sub-ou never shows up in LDAP browser. I also have difficulty deleting the en...

Web resources about - Net::LDAP and Net:LDAP::LDIF read & add problems - perl.ldap

Resources last updated: 1/19/2016 11:50:17 AM