On 8/2/07 8:53, "Christian Felsing" <[EMAIL PROTECTED]> wrote:

> Hello,
> 
> I experienced a strange problem with following function and Net::LDAP
> 
> --- cut here ---
> 
> sub CreateLDAPentry {
> my ($uid,$name,$vorname,$st) = @_;
> my $salt="/%";
> my $pwd=crypt($word, $salt);
> 
> my $ldap = Net::LDAP->new ("localhost",async => 0) or die "$@";
> 
> my $mesg = $ldap->bind ( "$LDAP_ADM_DN",
>                           password => "$LDAP_ADM_PWD",
>                           version => 3 );
> 
> my $DNbranch = "ou=freemail, dc=my, dc=domain";
> my @CreateArray;
>   $CreateArray = [
>    objectClass => [ "top", "inetOrgPerson" ],
>    uid => "$uid",
>    cn => "$vorname $name",
>    sn => "$name",
>    gn => "$vorname",
>    userPassword => "{crypt}$pwd",
>    st => "$st",
>    ];
> 
> my $NewDN = "[EMAIL PROTECTED], ".$DNbranch;
> 
> my $result = $ldap->add ( $NewDN, attrs => [ @$CreateArray ] );
> if ($result->code) {
>   LDAPerror ("CreateLDAPentry",$result);
>   }
> $ldap->unbind;
> return 0;
> }
> 
> --- cut here ---
> 
> User can enter german special characters for $name, $vorname or $st, eg.
> Müller for name, but not for uid. After $ldap->add I get following error:
> 
> Return code: 21
> Message: LDAP_INVALID_SYNTAX :Some part of the request contained an
> invalid syntax. It could be a search
> with an invalid filter or a request to modify the schema and the given
> schema has a bad syntax.
> MessageID: 29
> DN:
> 
> uid was [EMAIL PROTECTED] and did not cause any problems while tested w/o
> special characters in other attributes.
> 
> Any hints ?

You should definitely set version => 3 when you create the Net::LDAP object,
as that will allow you to use UTF-8 later on. The default is to use LDAPv2,
and you're at the mercy of your server vendor as to what character set they
decided to implement instead of the standard T.61. Just use LDAPv3 and avoid
the problem.

Then you may need to do something to change the characters being passed in
by the user from their character set into UTF-8, and pass those UTF-8
characters to the add operation.

Cheers,

Chris


Reply via email to