Skip to content

Commit

Permalink
Item14512: more unicode fixes
Browse files Browse the repository at this point in the history
- make unicode login names work
- fixed transliteration
- added getDN() api to properly extract the DN from an LDAP entry
  • Loading branch information
MichaelDaum committed Oct 10, 2017
1 parent ce85cf0 commit de77fb9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
2 changes: 1 addition & 1 deletion data/System/LdapContrib.txt
Expand Up @@ -499,7 +499,7 @@ This work is partly sponsored by
---++ Change History

%TABLE{columnwidths="7em" tablewidth="100%"}%
| 09 Sep 2017: | fixed encoding errors of uncicode DN paths |
| 10 Oct 2017: | fixed encoding errors of uncicode DN paths |
| 30 Aug 2017: | fixed checking local groups; fixed recoding values coming from the LDAP directory |
| 16 Jan 2017: | fixed logging in via email using an ldap-apache login manager |
| 11 Jan 2017: | added config parameter to switch off mapping of login names to cUIDs |
Expand Down
29 changes: 22 additions & 7 deletions lib/Foswiki/Contrib/LdapContrib.pm
Expand Up @@ -30,8 +30,8 @@ use Encode ();
use Foswiki::Func ();
use Foswiki::Plugins ();

our $VERSION = '7.71';
our $RELEASE = '09 Sep 2017';
our $VERSION = '7.80';
our $RELEASE = '10 Oct 2017';
our $SHORTDESCRIPTION = 'LDAP services for Foswiki';
our $NO_PREFS_IN_TOPIC = 1;
our %sharedLdapContrib;
Expand Down Expand Up @@ -63,6 +63,7 @@ my $count = $result->count();
my @entries = $result->sorted('sn');
my $entry = $result->entry(0);
my $dn = $this->getDN($entry);
my $commonName = $this->getValue($entry, 'cn');
my $email = $this->getValue($entry, 'mail');
</verbatim>
Expand Down Expand Up @@ -741,7 +742,7 @@ sub cacheBlob {
$dir .= '/blobs';
mkdir $dir unless -d $dir;

my $key = Digest::MD5::md5_hex($entry->dn() . $attr);
my $key = Digest::MD5::md5_hex($this->getDN($entry) . $attr);
my $fileName = $dir . '/' . $key;

if ($refresh || !-f $fileName) {
Expand Down Expand Up @@ -1314,7 +1315,7 @@ sub cacheUserFromEntry {
$wikiNames ||= {};
$loginNames ||= {};

my $dn = $this->fromLdapCharSet($entry->dn());
my $dn = $this->getDN($entry);

# 1. get it
my $loginName = $this->getValue($entry, $this->{loginAttribute});
Expand Down Expand Up @@ -1494,7 +1495,7 @@ sub cacheGroupFromEntry {
$data ||= $this->{data};
$groupNames ||= {};

my $dn = $this->fromLdapCharSet($entry->dn());
my $dn = $this->getDN($entry);
writeDebug("caching group for $dn");

my $groupName = $this->getValue($entry, $this->{groupAttribute});
Expand Down Expand Up @@ -1715,7 +1716,7 @@ use http://www.ltg.ed.ac.uk/~richard/utf-8.html to add more recodings
sub transliterate {
my $string = shift;

if ($Foswiki::cfg{Site}{CharSet} =~ /^utf-?8$/i) {
if (!$Foswiki::UNICODE && $Foswiki::cfg{Site}{CharSet} =~ /^utf-?8$/i) {
$string =~ s/\xc3\xa0/a/go; # a grave
$string =~ s/\xc3\xa1/a/go; # a acute
$string =~ s/\xc3\xa2/a/go; # a circumflex
Expand Down Expand Up @@ -2676,6 +2677,21 @@ sub getValue {

=pod
---++ getDN($entry, $key) -> $value
returns the decoded distinguished name from an Net::LDAP::Entry object
=cut

sub getDN {
my ($this, $entry) = @_;

my $dn = $entry->dn();
return $this->fromLdapCharSet($dn);
}

=pod
---++ getValues($entry, $key) -> @values
returns a decoded an array of strings from an Net::LDAP::Entry object
Expand Down Expand Up @@ -2734,7 +2750,6 @@ sub loadSession {
if (defined $authUser) {

my $origAuthUser = $authUser;
$authUser = $this->fromLdapCharSet($authUser);
$authUser =~ s/^\s+|\s+$//g;

$authUser = lc($authUser) unless $this->{caseSensitiveLogin};
Expand Down
4 changes: 2 additions & 2 deletions tools/ldaptest
Expand Up @@ -18,7 +18,7 @@

use strict;
use warnings;
use open qw(:std :utf8);
#use open qw(:std :utf8);

use Net::LDAP qw(LDAP_REFERRAL);
use Authen::SASL ();
Expand All @@ -34,7 +34,7 @@ our $saslMechanism = 'GSSAPI';
our $sizeLimit = 10;
our $deref = "always";

require "ldaptest.conf";
do "./ldaptest.conf";

die "no server specified. please configure ldaptest.conf" unless $server;

Expand Down

0 comments on commit de77fb9

Please sign in to comment.