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 national
characters in them.

On one part (only one) I must mangle some national chars to produce
valid UNIX uids (for example: Šime Ćevap > scevap).

like this:
    $tmpname = substr ($n_final_ime , 0, 1);
    $tmpname =~ tr/\x{010C}\x{0106}\x{017D}\x{0160}\x{0110}/cczsd/;
    $tmpname =~ tr/\x{010D}\x{0107}\x{017E}\x{0161}\x{0111}/cczsd/;

    etc ...

For some reason tr/// with utf8 is *only* working if I include this in
program:

use encoding 'utf8';

But when I include encoding 'utf8' I get my tr/// to do job corectly,
*but* ... $ldap->search will die with this error:

(mvz){lav}[o2l]$ perl o2l.pl 
Bad ASN PDU at /usr/local/lib/perl5/site_perl/5.8.0/Convert/ASN1/IO.pm
line 178, <RAZLIKA> line 1.

However! If I put "attrs => ['someValidLDAPAttr']" in $ldap->search I
don't get this ASN PDU error message! But I cannot do that because I
need entire LDAP entry out of LDAP. "attrs => ['*']" or "attrs => ['ALL']"
doesn't help, first one is triggering ASN.1 bug like when there is no
attrs, and second one is returning only "dn" - because of this
behaviour I think this is Net::LDAP bug, not a Convert::ASN1 bug.

I have extracted part of the code from my program to reproduce the bug
(see below).

Can somebody help me? Is there some workaround? I'm not very good with
perl. :-(

Here is sample script that will trigger the bug. If you comment out
use encoding 'utf8' it will work. I have tried with "no encoding
'utf8'" after tr/// lines, but it doesn't help.


This is extracted script for triggering bug, part of program that must
use tr/// with utf8 chars in "else" statement in the same function
(sub ldapcmp() ...):
-----------------------------------------------------------------------
use strict;
use Net::LDAP;

my $static_part_of_filter = "(&(objectclass=hrHacPerson)(hrHacPersonWorkKey=";
my $filt;
my $diff_file = "./ora.dump";

my $ldap_server = 'hijena.hac';
my $ldap_pass = "veryverysecret";
my $bind_dn = 'cn=ldapadm,dc=hac,dc=hr';
my $search_base = 'ou=Accounts,dc=hac,dc=hr';
my $mesg;

my ($n_final_ime, $n_final_prezime);

my ($n_datprad, $n_datkrad,
    $n_jmbg, $n_radnik, $n_suborgcjekadr, $n_orgcje_kadr,
    $n_final_naziv, $n_final_ulica, $n_final_naziv2,
    $n_vrrada, $n_rmnaziv);

my $ldap = Net::LDAP->new($ldap_server) or die "Cannot connect: $!";

    $ldap->bind ($bind_dn, password => $ldap_pass, version => 3);

    open(RAZLIKA, "$diff_file") or die "$diff_file: cannot open: $!";


    while(<RAZLIKA>)
    {
           ($n_final_ime, $n_final_prezime, $n_datprad, $n_datkrad,
            $n_jmbg, $n_radnik, $n_suborgcjekadr, $n_orgcje_kadr,
            $n_final_naziv, $n_final_ulica, $n_final_naziv2,
            $n_vrrada, $n_rmnaziv) = split(/[|\n]/, $_, 9999);

    $filt = ($static_part_of_filter . $n_radnik . "))");

    # this doesn't help:
    no encoding 'utf8';

    $mesg = ($ldap->search (base => $search_base, scope => 'sub',filter => "$filt"));
    $mesg->error if $mesg->code;

           use encoding 'utf8';

           # $tmpname comes from oracle dump
           my $tmpname = "Ä?Ä?Ĺ˝Ĺ?Ä?Ä?Ä?ŞťÄ?";
           $tmpname =~ tr/\x{010C}\x{0106}\x{017D}\x{0160}\x{0110}/cczsd/;
           $tmpname =~ tr/\x{010D}\x{0107}\x{017E}\x{0161}\x{0111}/cczsd/;

           print "$tmpname\n"
           # the rest is very long and boring ...

         }
-----------------------------------------------------------------------

this is input file ora.dump:
-----------------------------------------------------------------------
Drago|Visinski|12042001|:|3104347391214|361|5|501040004|Kutina|A.Mihanovieva 
112|Kutina|1|:|
Foo|Ä?Ä?Ĺ˝Ĺ?Ä?Ä?Ä?ŞťÄ?|12042001|:|1101974390028|99997|6|601050001|:|:|Oroslavje|1|:|
-----------------------------------------------------------------------


P. S.
Please include `Cc: <[EMAIL PROTECTED]>' if you replay to that mail on list.

P. P. S.
Please help! ... I want to go on my summer vacation(1) :-)


-- 
                The Network is the Filesystem

Reply via email to