Skip to content

Commit

Permalink
Item14511: fixed encodig errors in dn
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDaum committed Oct 9, 2017
1 parent c5d40b3 commit ce85cf0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 30 deletions.
4 changes: 2 additions & 2 deletions data/System/LdapContrib.txt
Expand Up @@ -487,7 +487,7 @@ time to reflect the specific settings required to connect your LDAP server.

---++ Acknowledgement

This work was partly sponsored by
This work is partly sponsored by

* [[http://www.spanlink.com][Spanlink Communications]]
* [[http://www.trivadis.com][Trivadis]]
Expand All @@ -496,10 +496,10 @@ This work was partly sponsored by
* [[http://www.testo.de][Testo]]
* [[http://www.1and1.com][1&1]]


---++ Change History

%TABLE{columnwidths="7em" tablewidth="100%"}%
| 09 Sep 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
56 changes: 28 additions & 28 deletions lib/Foswiki/Contrib/LdapContrib.pm
Expand Up @@ -30,8 +30,8 @@ use Encode ();
use Foswiki::Func ();
use Foswiki::Plugins ();

our $VERSION = '7.70';
our $RELEASE = '30 Aug 2017';
our $VERSION = '7.71';
our $RELEASE = '09 Sep 2017';
our $SHORTDESCRIPTION = 'LDAP services for Foswiki';
our $NO_PREFS_IN_TOPIC = 1;
our %sharedLdapContrib;
Expand Down Expand Up @@ -384,12 +384,14 @@ sub connect {
writeWarning($msg->{errorMessage}) if $msg->{errorMessage};
}

$passwd = $this->toSiteCharSet($passwd) if $passwd;
$passwd = $this->toLdapCharSet($passwd) if $passwd;

# authenticated bind
my $msg;
if (defined($dn)) {
die "illegal call to connect()" unless defined($passwd);

$dn = $this->toLdapCharSet($dn);
$msg = $this->{ldap}->bind($dn, password => $passwd);
#writeDebug("bind for $dn");
}
Expand Down Expand Up @@ -609,11 +611,11 @@ sub search {
my ($this, %args) = @_;

$args{base} = $this->{base} unless $args{base};
$args{base} = $this->toSiteCharSet($args{base});
$args{base} = $this->toLdapCharSet($args{base});
$args{scope} = 'sub' unless $args{scope};
$args{sizelimit} = 0 unless $args{sizelimit};
$args{attrs} = ['*'] unless $args{attrs};
$args{filter} = $this->toSiteCharSet($args{filter}) if $args{filter};
$args{filter} = $this->toLdapCharSet($args{filter}) if $args{filter};

if (defined($args{callback}) && !defined($args{_origCallback})) {

Expand Down Expand Up @@ -1312,7 +1314,7 @@ sub cacheUserFromEntry {
$wikiNames ||= {};
$loginNames ||= {};

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

# 1. get it
my $loginName = $this->getValue($entry, $this->{loginAttribute});
Expand Down Expand Up @@ -1442,8 +1444,7 @@ sub cacheUserFromEntry {

if ($emails) {
foreach my $email (@$emails) {
$email =~ s/^\s+//o;
$email =~ s/\s+$//o;
$email =~ s/^\s+|\s+$//g;
my $prevMapping = $data->{"EMAIL2U::$email"};
my %emails = ();
if ($prevMapping) {
Expand Down Expand Up @@ -1493,7 +1494,7 @@ sub cacheGroupFromEntry {
$data ||= $this->{data};
$groupNames ||= {};

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

my $groupName = $this->getValue($entry, $this->{groupAttribute});
Expand Down Expand Up @@ -1550,8 +1551,7 @@ sub cacheGroupFromEntry {
my $member;
while ($member = shift) {
next unless defined $member;
$member =~ s/^\s+//o;
$member =~ s/\s+$//o;
$member =~ s/^\s+|\s+$//g;
$this->{_groups}{$groupName}{$member} = 1; # delay til all groups have been fetched
}
};
Expand Down Expand Up @@ -2367,7 +2367,7 @@ sub removeUserFromCache {
$this->tieCache('read');
}

=begin text
=begin tml
---++ renameWikiName($loginName, $oldWikiName, $newWikiName)
Expand Down Expand Up @@ -2641,6 +2641,22 @@ sub fromLdapCharSet {
return Encode::decode($ldapCharSet, $string);
}

=begin tml
---++ toLdapCharSet($string) -> $string
encode strings coming from the site to be used talking to the ldap directory
=cut

sub toLdapCharSet {
my ($this, $string) = @_;

my $ldapCharSet = $Foswiki::cfg{Ldap}{CharSet} || 'utf-8';
return Encode::encode($ldapCharSet, $string);
}


=pod
---++ getValue($entry, $key) -> $value
Expand Down Expand Up @@ -2702,22 +2718,6 @@ sub getValueMap {
return $map;
}


=begin text
---++ toLdapCharSet($string) -> $string
encode strings coming from the site to be used talking to the ldap directory
=cut

sub toSiteCharSet {
my ($this, $string) = @_;

my $ldapCharSet = $Foswiki::cfg{Ldap}{CharSet} || 'utf-8';
return Encode::encode($ldapCharSet, $string);
}

=begin TML
---++ ObjectMethod loadSession()
Expand Down

0 comments on commit ce85cf0

Please sign in to comment.