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

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.

> ORIGINAL ENTRY
> dn: uid=ricardo,ou=people,o=example
> objectclass: top
> objectclass: person
> mailautoreplytext::
> WWEgaGUgcmVjaWJpZG8gdHUgbWVuc2FqZS4NClRlIHJlc3BvbmRlcsOpI
>  HBlcnNvbmFsbWVudGUgbG8gYW50ZXMgcG9zaWJsZS4NClVuIHNhbHVkbzogUmljYXJkbw==
> mailautoreplytext;lang-es: $
>
> MODIFIED ENTRY
> dn: uid=ricardo,ou=people,o=example
> objectclass: top
> objectclass: person
> mailautoreplytext: Ya he recibido tu mensaje.^M
> Te responderé personalmente lo antes posible.^M
> Un saludo: Ricardo
> mailautoreplytext;lang-es: $
>
> If I add:
>
> $v =~ s/\n/\n /g;
>
> before printing printing the value I can "fix" this entry but I'd rather
> keep the original encoding.
>
> 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();



-- 
Peter Marschall
eMail: [EMAIL PROTECTED]

Reply via email to