Skip to content

Commit

Permalink
Merge branch 'MDL-51723-29' of git://github.com/andrewnicols/moodle i…
Browse files Browse the repository at this point in the history
…nto MOODLE_29_STABLE
  • Loading branch information
David Monllao committed Feb 8, 2016
2 parents 80b0902 + 2dcf1da commit 5f90d5f
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions enrol/ldap/lib.php
Expand Up @@ -33,6 +33,13 @@ class enrol_ldap_plugin extends enrol_plugin {
protected $enroltype = 'enrol_ldap';
protected $errorlogtag = '[ENROL LDAP] ';

/**
* The object class to use when finding users.
*
* @var string $userobjectclass
*/
protected $userobjectclass;

/**
* Constructor for the plugin. In addition to calling the parent
* constructor, we define and 'fix' some settings depending on the
Expand All @@ -59,6 +66,26 @@ public function __construct() {
unset($ldap_usertypes);

$default = ldap_getdefaults();

// The objectclass in the defaults is for a user.
// This will be required later, but enrol_ldap uses 'objectclass' for its group objectclass.
// Save the normalised user objectclass for later.
$this->userobjectclass = $default['objectclass'][$this->get_config('user_type')];

if (empty($this->userobjectclass)) {
// Can't send empty filter.
$this->userobjectclass = '(objectClass=*)';
} else if (stripos($this->userobjectclass, 'objectClass=') === 0) {
// Value is 'objectClass=some-string-here', so just add ()
// around the value (filter _must_ have them).
$this->userobjectclass = '(' . $this->userobjectclass . ')';
} else if (stripos($this->userobjectclass, '(') !== 0) {
// Value is 'some-string-not-starting-with-left-parentheses',
// which is assumed to be the objectClass matching value.
// So build a valid filter with it.
$this->userobjectclass = '(objectClass=' . $this->userobjectclass . ')';
}

// Remove the objectclass default, as the values specified there are for
// users, and we are dealing with groups here.
unset($default['objectclass']);
Expand Down Expand Up @@ -490,7 +517,7 @@ public function sync_enrolments(progress_trace $trace, $onecourse = null) {
// as the idnumber does not match their dn and we get dn's from membership.
$memberidnumbers = array();
foreach ($ldapmembers as $ldapmember) {
$result = ldap_read($this->ldapconnection, $ldapmember, '(objectClass=*)',
$result = ldap_read($this->ldapconnection, $ldapmember, $this->userobjectclass,
array($this->config->idnumber_attribute));
$entry = ldap_first_entry($this->ldapconnection, $result);
$values = ldap_get_values($this->ldapconnection, $entry, $this->config->idnumber_attribute);
Expand Down Expand Up @@ -838,10 +865,9 @@ protected function ldap_find_userdn($userid) {
require_once($CFG->libdir.'/ldaplib.php');

$ldap_contexts = explode(';', $this->get_config('user_contexts'));
$ldap_defaults = ldap_getdefaults();

return ldap_find_userdn($this->ldapconnection, $userid, $ldap_contexts,
'(objectClass='.$ldap_defaults['objectclass'][$this->get_config('user_type')].')',
$this->userobjectclass,
$this->get_config('idnumber_attribute'), $this->get_config('user_search_sub'));
}

Expand Down

0 comments on commit 5f90d5f

Please sign in to comment.