From 561ad6221dd53bd1c4295073e67a6ad41b0cbf7b Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Mon, 11 Sep 2006 23:51:41 +0200 Subject: [PATCH] LiCoM::Group: Encode all strings as UTF-8 when sending to the LDAP-server. Also decode them into Perl's internal format when receiving them. --- lib/LiCoM/Group.pm | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/lib/LiCoM/Group.pm b/lib/LiCoM/Group.pm index a5cade9..8ebc7ac 100644 --- a/lib/LiCoM/Group.pm +++ b/lib/LiCoM/Group.pm @@ -3,6 +3,8 @@ package LiCoM::Group; use strict; use warnings; +use Encode (qw(encode decode)); + use LiCoM::Config (qw(get_config)); use LiCoM::Connection (qw($Ldap)); use Net::LDAP; @@ -22,9 +24,9 @@ sub new my $entry = shift; my $obj = {}; - $obj->{'name'} = $entry->get_value ('cn', asref => 0); - $obj->{'description'} = $entry->get_value ('description', asref => 0); - $obj->{'members'} = [map { m/cn=([^,]+)/i; $1; } ($entry->get_value ('member', asref => 0))]; + $obj->{'name'} = decode ('utf-8', $entry->get_value ('cn', asref => 0)); + $obj->{'description'} = decode ('utf-8', $entry->get_value ('description', asref => 0)); + $obj->{'members'} = [map { m/cn=([^,]+)/i; decode ('utf-8', $1); } ($entry->get_value ('member', asref => 0))]; $obj->{'ldap'} = $entry; return (bless ($obj, $pkg)); @@ -114,12 +116,12 @@ sub create ($$$@) my $entry = Net::LDAP::Entry->new (); - $entry->add (objectClass => [qw(top groupOfNames)]); - $entry->add (ou => $ou); - $entry->add (cn => $name); - $entry->add (member => [map { _cn_to_dn ($_) } (@members)]); - $entry->add (description => $desc) if ($desc); - $entry->dn ($dn); + $entry->add (objectClass => [map { encode ('UTF-8', $_) } (qw(top groupOfNames))]); + $entry->add (ou => encode ('UTF-8', $ou)); + $entry->add (cn => encode ('UTF-8', $name)); + $entry->add (member => [map { encode ('UTF-8', _cn_to_dn ($_)) } (@members)]); + $entry->add (description => encode ('UTF-8', $desc)) if ($desc); + $entry->dn (encode ('UTF-8', $dn)); $entry->changetype ('add'); my $mesg = $entry->update ($Ldap); @@ -270,6 +272,7 @@ sub name my $entry = $obj->{'ldap'}; $obj->{'name'} = shift; + # FIXME $entry->changetype ('modify'); $entry->replace (cn => $obj->{'name'}); $entry->update ($Ldap); @@ -296,7 +299,7 @@ sub description $obj->{'description'} = shift; $entry->changetype ('modify'); - $entry->replace (description => [$obj->{'description'}]); + $entry->replace (description => [encode ('UTF-8', $obj->{'description'})]); $entry->update ($Ldap); } @@ -317,6 +320,8 @@ sub _update_members my $entry = $obj->{'ldap'}; my @tmp = map { _cn_to_dn ($_); } (@{$obj->{'members'}}); + $_ = encode ('UTF-8', $_) for (@tmp); + $entry->changetype ('modify'); $entry->replace (member => \@tmp); $entry->update ($Ldap); -- 2.11.0