(Net::LDAP) Automatically convert attributes into utf8 when writting

pe rl <[email protected]> Tue, 25 Aug 2015 12:54:26 +0200
Newsgroups gmane.comp.lang.perl.modules.ldap
Message-ID <[email protected]>
Hi, we are using an old version of Net::LDAP (0.39) in an old perl
installation (5.10.1). Recently we have changed the ldap server, and now =
it=20
uses utf8 in the entry attributes, so we are getting problems with readin=
g and=20
writting attributes with Net::LDAP.

To solve it, I have read the documentation of Net::LDAP 0.39 ( at
https://metacpan.org/pod/release/GBARR/perl-ldap-0.39/lib/Net/LDAP.pod ),=
 and
I see there is an option ("raw") in the constructor to indicate attribute=
s
that should be treated as utf8. I have tested it, and it works por readin=
g
from the ldap server (attribute strings are marked as utf8, so they a tre=
ated
correctly by our programs), but it doesn't work for writting (our latin1=20
strings are not being converted automatically into utf8 before being sent=
).=20

So it looks like the "raw" option works for reading but not for writting.=
 Is
there any quick way to use the "raw" regex also for writting? The alterna=
tive
would be to review all of our code and manually encode all the values to =
utf8
before passing them to Net::LDAP, but it would mean a lot of work. It wou=
ld be
better if we could change the Net::LDAP library itself to convert
automatically attributes into utf8, same as for reading. For example, a n=
ew=20
option "raw_for_writing" could be added to the constructor:

=9A=9A=9A=9A=9A=9A$ldap =3D Net::LDAP->new(
=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=
=9A=9A=9A=9A=9A=9A=9A$server,=20
=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=
=9A=9A=9A=9A=9A=9A=9Aport =3D> $port,
=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=
=9A=9A=9A=9A=9A=9A=9Araw =3D> qr/(?i:^jpegPhoto|;binary)/,
=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=
=9A=9A=9A=9A=9A=9A=9Araw_for_writing =3D> 1,
=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=
=9A=9A=9A)

I see that the automatic conversion for reading is done at the "decode"
function of "Entry.pm":

=9A=9A=9A=9Asub decode {

=9A=9A=9A=9A=9A=9A...

=9A=9A=9A=9A=9A=9Aif (CHECK_UTF8 && $arg{raw}) {
=9A=9A=9A=9A=9A=9A=9A=9A$result->{objectName} =3D Encode::decode_utf8($re=
sult->{objectName})
=9A=9A=9A=9A=9A=9A=9A=9A=9A=9Aif ('dn' !~ /$arg{raw}/);

=9A=9A=9A=9A=9A=9A...

=9A=9A=9A=9A=9A=9A=9A=9Aforeach my $elem (@{$self->{asn}{attributes}}) {
=9A=9A=9A=9A=9A=9A=9A=9A=9A=9Amap { $_ =3D Encode::decode_utf8($_) } @{$e=
lem->{vals}}
=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9Aif ($elem->{type} !~ /$arg{raw}/);
=9A=9A=9A=9A=9A=9A=9A=9A}
=9A=9A=9A=9A=9A=9A}

And I see that there is an "encode" function in "Entry.pm", that doesn't =
do
the magic:

=9A=9A=9A=9Asub encode {
=9A=9A=9A=9A=9A=9A$LDAPEntry->encode( shift->{asn} );
=9A=9A=9A=9A}

Would it be sufficient to add some similar code to the "Entry::encode"=20
function in order to automatically encode attributes to utf8 before being=
 sent?

Any suggestion to reduce the amount of code to be changed in our programs=
?

Thank you