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

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
0
pe
8/25/2015 10:31:42 AM
perl.ldap 1268 articles. 0 followers. Follow

1 Replies
594 Views

Similar Articles

[PageSpeed] 47

I will try to explain it clearer. Currently you can read utf8 atributes out
of the box by using the "raW" option in the constructor:

    $ldap = Net::LDAP->new(
                              $server, 
                              port      =>  $port,
                              raw       =>  qr/not_utf_attrib/,
                          );

so you can look for entries, and all the attributes will be converted
automatically from utf8 (except "not_utf_attrib" attribute):

    $mesg = $ldap->search(
                             base    =>  "c=US",
                             filter  =>  "(&(sn=Barr) (o=Texas Instruments))",
                         );
    # Treat here entry attributes in $mesg without worrying on utf8 values.

But if you create an entry, you will have to manually convert all attributes 
into utf8 (except "not_utf_attrib" attribute):

    for my $c (keys %$attrs)
    {
        utf8::encode($attrs->{$c})
            if (not ref $attrs->{$c}  and  $c ne 'not_utf_attrib');
    }

    $mesg = $ldap->add( $dn, attrs => [ @$attrs ] );

This manual conversion should be unnecesary, since Net::LDAP already knows the
attributes that must be treated as utf8 and the attributes that mustn't (with
the "raw" option), so they could be converted automatically by Net::LDAP.

So I'm proposing to add an option (raw_for_writing) to the constructor, that 
will indicate Net::LDAP to automatically convert attributes into utf8 when 
creating/modifing entries:

    $ldap = Net::LDAP->new(
                              $server,
                              port              =>  $port,
                              raw               =>  qr/not_utf_attrib/,
                              raw_for_writing   =>  1,
                          );

Thank you


( Off topic: There is a delay, after a posted mail appears in the web page
http://www.nntp.perl.org/group/perl.ldap/2015/08.html . That is why I sent my
first post twice, I thought that subscription was required, since the mail
didn't appear in the web page )


25.08.2015, 20:42, "pe rl" <pe.rl@yandex.com>:
> 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
0
pe
8/26/2015 7:17:37 AM
Reply:

Similar Artilces:

(Net::LDAP) Automatically convert attributes into utf8 when writting
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 (attr...

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...

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...

How do I retrieve operational attributes for an LDAP entry using Net::LDAP?
how do I retrieve the values for 'creatorsName','createTimestamp', 'modifiersName', 'modifyTimestamp' using Net::LDAP module? pleae help ===== use Net::LDAP; use Net::LDAP::Util qw(ldap_error_text ldap_error_name ldap_error_desc); $host='xxxx.com'; $rdn='cn=manager,dc=xxxx,dc=com'; $ldappasswd='123456'; my $ldap=new Net::LDAP($host) or die; my $mesg=$ldap->bind("$rdn",password=>"$ldappasswd",version => 3) or die; my $mesg=$ldap->search(base=>"ou=people,dc=xxxx,dc=com",scope=>...

$ldap->search triggers Bug in ASN1 and utf8 Net::LDAP code
Dear perl programmers, I think I found bug in Net::LDAP in the part which is doing something with ASN.1 (Convert::ASN1). I'm writing small program for selecting and exporting part of oracle (with DBD::Oracle) doing nasty things with output, selecting from OpenLDAP server matching and non-matching entries and comparing them attribute by attribute, making ldif diff file from that, or producing new entries if $mesg->entries is 0. I'm not a professional programmer, but I *must* finish this application. :-( Output from oracle is in UTF-8, and it has many names with nati...

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...

LDAP attribute Map / LIst / extend the LDAP attributes
we are use ladp on netware 65, is there a list of the LDAP attributes avaliable that are used for eDirectory 8.7? is it possible to create a ldap attribute that contains more that one edirectory attribute content and extend it with a static variable? any ideas HELGE -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Most eDirectory attributes are available natively by their name (minus spaces and special characters). For example fullname works to retrieve the 'Full Name' and givenname works for 'Given Name' and sasloginconfiguration works for 'SAS:...

[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>...

Problems accessing Custom LDAP attributes with a .Net 2.0 application !
Hi All,I am in process of writing a .Net 2.0 application that talks to a version 3 LDAP server. My code below raises a very non helpful ‘Unknown Exception’ at a line that has comments against it. Apparently, I can connect to the LDAP server, search for nodes and access built-in attributes that come with LDAP but each time I try and access a custom attribute an exception with text ‘Unknown Exception’ is raised. The only thing I can think of is that with non-AD (Active Directory) platforms, we need to load the schema definition for the custom node attributes as the LDAP can not make ...

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...

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: object...

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...

Why Visual Studio 2005 ask me to convert a solution already got converted Somebody did the conversion of a solution from .net 1.1 to .net 2.0 by using the automatic conversion wizard of Visual Stu
Why Visual Studio 2005 ask me to convert a solution already got converted Somebody did the conversion of a solution from .net 1.1 to .net 2.0 by using the automatic conversion wizard of Visual Studio 2005. Then, he changed to another company. Now, I take over his job. Unfortunately, when I attempted to open that solution, Visual Studio 2005 prompted me the conversion wizard again to forced me to perform a conversion on the solution. Does someone know why?--Harish Patel www.MicrosoftSQLandASP.netpatelharish@gmail.com Hi, How many projects are in the solution, does it have UNLOADE...

Net::LDAP #2
I have script which running fine on FC5 (perl v 5.8.1) but not working on RH9(5.8.0). --- my $ldap = Net::LDAP->new($ldap_host); die "Unable to contact $ldap_host\n" unless defined $ldap; my $mesg = $ldap->bind; $mesg = $ldap->search( base => $ldap_base, scope => 'one', filter => "uid=$uid", attrs => ['uid'] ); --- If it run on RH9, it simply hanging. But if I change to: my $ldap_filter => "uid=test"; it works. $uid itself is valid (contains entry), this also did not works: ...

Web resources about - (Net::LDAP) Automatically convert attributes into utf8 when writting #2 - perl.ldap

Piccolo Automatically Sends Users Prints Of Their Photos On Facebook, Instagram
... a popular day for debuting Instagram applications and services, as startup Piccolo announced its beta launch, aimed at allowing users to automatically ...

Facebook Status Update Tagging Now Automatically Suggests Matches for People, Pages and Other Content ...
Facebook has just changed its status update tagging tool to automatically display a drop-down menu of friends, Pages, events and groups you might ...

Meekan - schedule meetings and events automatically on the App Store on iTunes
Get Meekan - schedule meetings and events automatically on the App Store. See screenshots and ratings, and read customer reviews.

Does Google see automatically generated content as a bad thing? - YouTube
Does Google see automatically generated content as a bad thing (i.e. spam)? If I publish uncopyrighted content on my site that is available from ...

Emailing porn at work not automatically sackable, court finds
The federal court has upheld a ruling that found emailing pornography in the workplace is not automatically a sackable offence.


Emailing porn at work not automatically sackable, court finds
Australia's federal court has upheld a ruling that emailing pornography in the workplace is not automatically a sackable offence.

Shazam iPhone app now listens for music, TV shows automatically
Shazam has updated its iPhone app to tag songs, TV shows and more on its own, no longer requiring users to open the app and tap a button.

App of the day: Human for iPhone automatically tracks your movements
Human for the iPhone is an activity tracker that automatically distinguishes between different types of movement.

iPhone 5 automatically rotates using Cycloramic App. - YouTube
[NEW VIDEO] Cycloramic 2.0 update teaser vid with panoramic photo preview: http://www.youtube.com/watch?v=cjHUID07xs4 Cycloramic has been Awarded ...

Resources last updated: 1/21/2016 2:17:54 PM