Hi,
> On Monday, 29. August 2005 14:38, Joan wrote:
> > Hi, is there any way to avoid base64 decoding an attribute value?
> > I open an existing ldif (300000 users), modify some entries, and print
> > to standard output the result.
> > Everything works as expected but the encoded attributes are converted to
> > plain text.
> > When I try to import it to the LDAP server I get errors because those
> > attributes values get interpreted as attributes themselves.
>
> Base64-encoding is required in the LDIF format if the values of
> attributes are
> not representable as printable ASCII characters (e.g. non-ASCII letters
> [e.g.
> é], binary values [certificates, images, ...], letters from the ASCII
> control
> range [0x00 - 0x32], ...).
> I.e. The LDIF standard uses Base64 as transport encoding to protect
> values
> from being interpreted falsely
I know, that's what I want to KEEP the base64 encoding. My problem was
that the "get_value" method was decoding the attributes and I was
printing that to STDOUT.
>
> If you want to use Net::LDAP::LDIF or ldapmodify / ldapadd to import
> data
> into the directory you need to Base64-encode thase values that may cause
> trouble.
>
> One of the easier ways to do this is to use Net::LDAP::LDIF for writing.
>
> See below for an untested version.
that did the trick, and my code is cleaner too :)
thx Peter!
s/ldifnew/ldifout/
> > CODE SNIP
> >
> > my $ldifmig = Net::LDAP::LDIF->new( $ldif_a_migrar, "r", onerror =>
> > 'undef' );
> my $ldifnew = Net::LDAP::LDIF->new('-', 'w'); # - means STDOUT
> > while( not $ldifmig->eof() ) {
> > my $entry = $ldifmig->read_entry();
> > if ( $ldifmig->error() ) {
> > print "Error msg: ",$ldifmig->error(),"\n";
> > print "Error lines:\n",$ldifmig->error_lines(),"\n";
> > }
> > else {
> > my $dn = $entry->dn();
> >
> > if ( $entry->exists('mail') ) {
> > $entry->add ( 'objectclass' => [
> > 'inetadmin',
> > 'inetlocalmailrecipient',
> > 'ipuser'
> > ]);
> > }
> >
> $ldifout->write_entry($entry);
> > }
> > }
> >
> > $ldifmig->done();
> $ldifout->done();