pe rl
2015-08-25 10:54:26 UTC
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
uses utf8 in the entry attributes, so we are getting problems with reading and
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 attributes
that should be treated as utf8. I have tested it, and it works por reading
from the ldap server (attribute strings are marked as utf8, so they a treated
correctly by our programs), but it doesn't work for writting (our latin1
strings are not being converted automatically into utf8 before being sent).
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 alternative
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 would be
better if we could change the Net::LDAP library itself to convert
automatically attributes into utf8, same as for reading. For example, a new
option "raw_for_writing" could be added to the constructor:
$ldap = Net::LDAP->new(
$server,
port => $port,
raw => qr/(?i:^jpegPhoto|;binary)/,
raw_for_writing => 1,
)
I see that the automatic conversion for reading is done at the "decode"
function of "Entry.pm":
sub decode {
...
if (CHECK_UTF8 && $arg{raw}) {
$result->{objectName} = Encode::decode_utf8($result->{objectName})
if ('dn' !~ /$arg{raw}/);
...
foreach my $elem (@{$self->{asn}{attributes}}) {
map { $_ = Encode::decode_utf8($_) } @{$elem->{vals}}
if ($elem->{type} !~ /$arg{raw}/);
}
}
And I see that there is an "encode" function in "Entry.pm", that doesn't do
the magic:
sub encode {
$LDAPEntry->encode( shift->{asn} );
}
Would it be sufficient to add some similar code to the "Entry::encode"
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
installation (5.10.1). Recently we have changed the ldap server, and now it
uses utf8 in the entry attributes, so we are getting problems with reading and
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 attributes
that should be treated as utf8. I have tested it, and it works por reading
from the ldap server (attribute strings are marked as utf8, so they a treated
correctly by our programs), but it doesn't work for writting (our latin1
strings are not being converted automatically into utf8 before being sent).
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 alternative
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 would be
better if we could change the Net::LDAP library itself to convert
automatically attributes into utf8, same as for reading. For example, a new
option "raw_for_writing" could be added to the constructor:
$ldap = Net::LDAP->new(
$server,
port => $port,
raw => qr/(?i:^jpegPhoto|;binary)/,
raw_for_writing => 1,
)
I see that the automatic conversion for reading is done at the "decode"
function of "Entry.pm":
sub decode {
...
if (CHECK_UTF8 && $arg{raw}) {
$result->{objectName} = Encode::decode_utf8($result->{objectName})
if ('dn' !~ /$arg{raw}/);
...
foreach my $elem (@{$self->{asn}{attributes}}) {
map { $_ = Encode::decode_utf8($_) } @{$elem->{vals}}
if ($elem->{type} !~ /$arg{raw}/);
}
}
And I see that there is an "encode" function in "Entry.pm", that doesn't do
the magic:
sub encode {
$LDAPEntry->encode( shift->{asn} );
}
Would it be sufficient to add some similar code to the "Entry::encode"
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