Using the current ldap_authorization code, mapping rules like the following can't possibly work:

CN=administrators,OU=Groups,DC=example,DC=com|administrator
CN=underlings,OU=Groups,DC=example,DC=com|underling

I can't see how line 401 of the following code (ldap_authorization.inc lines 388-405) could be reached in the most common (where cn is a required attribute for group object):

$derive_from_entry_authorizations = array();
388:  if ($consumer_conf->deriveFromEntry) {
389:    foreach ($consumer_conf->deriveFromEntryEntries as $branch) {
390:      $filter = '(' . $consumer_conf->deriveFromEntryAttr . '=' . $user_ldap_entry['dn'] . ')';
391:      $entries = $ldap_server->search($branch, $filter, array('cn'));
392:      if (empty($entries) || $entries['count'] == 0) {
393:        $filter = '(' . $consumer_conf->deriveFromEntryAttr . '=' . $user->name . ')';
394:        $entries = $ldap_server->search($branch, $filter, array('cn'));
395:      }
396:      foreach ($entries as $entry) {
397:        if (isset($entry['cn'])) {
398:          $derive_from_entry_authorizations[$entry['cn'][0]] = $entry['cn'][0];
399:        }
400:        elseif (isset($entry['dn'])) {
401:          $derive_from_entry_authorizations[$entry['dn']] = (string)$entry['dn'];
402:        }
403:      }
404:    }
405:  }

Line 401 won't ever be reached because:
1. Lines 391 and 394 explicitly ask for cn attribute.
2. The cn attribute is a manditory naming attribute for group objects in most schemas, so (because of #1 above) will be returned in results.
3. cn being return in results (always) will cause excution of line 398 -- which causes the group cn to be compared against the mapping

Conclusion: Bug. I can't think of a scenario where (for "Strategy 3: groups as entries.") a user would want to use the group CN in the mapping rules. The MUCH more common approach would be to use the group's distinguished name in the mapping rules.

Suggestion: Consider explicitly requesting "dn" (not "cn" in searches) and eliminate the conditional at line 397-399. The only other way to preserve evaluation by either DN or CN would be to add a configuration setting -- which would just confuse the user since what they really want to do is use group DNs in the mapping. There's no advantage (only ambiguity in using group CNs in rules).

CommentFileSizeAuthor
#4 1412076.patch8.33 KBjohnbarclay

Comments

johnbarclay’s picture

Category: bug » support
Status: Active » Closed (won't fix)

7.x-2.x is not an active branch and this is not a bug and this issue either a feature request or support request. "Conclusion:" uses poor logic that if you can't figure out how to do what you want its a bug.

johnbarclay’s picture

Title: group's distinguished can't be used to map LDAP to drupal role » LDAP Authorization: rework Strategy 3: groups as entries to meet more use cases
Status: Closed (won't fix) » Needs work
johnbarclay’s picture

Title: LDAP Authorization: rework Strategy 3: groups as entries to meet more use cases » LDAP Authorization: Rework Strategy 3: groups as entries to meet more use cases
Category: support » feature

Merging issue #1280798: LDAP Authorization: Roles not being granted to this one. Could be called feature request, could be called bug. Should be fixed in 7.x-1 and 7.x-2 as seems to be broken for most use cases.

johnbarclay’s picture

StatusFileSize
new8.33 KB

I understand that dn may be more confusing than useful, but its clearly labelled as defaulting to 'dn' it shouldn't be too much of an issue. Attached is a patch and below is the critical code to look at. The patch is confusing because it retains the old possible broken functionality for existing users of the 1.x branch.

So if a property named "deriveFromEntryUserLdapAttr" which was "dn" by default was configurable, would the following work?

foreach ($consumer_conf->deriveFromEntryEntries as $branch) {
        $filter = '(' . $consumer_conf->deriveFromEntryAttr . '=' . $user_ldap_entry[$consumer_conf->deriveFromEntryUserLdapAttr] . ')';
        $entries = $ldap_server->search($branch, $filter, array('dn'));
        if ($entries !== FALSE) {
          foreach ($entries as $entry) {
            if (isset($entry['dn'])) {
              $derive_from_entry_authorizations[$entry['dn']] = (string)$entry['dn'];
            }
          }
        }
      }
johnbarclay’s picture

Version: 7.x-2.x-dev » 7.x-1.x-dev

(this is 7.x-1.x-dev).

Also the test mock server test entry for the search is:

$servers['ldapauthor1']['search_results']['(member=cn=verykool,ou=special guests,ou=guest accounts,dc=ad,dc=myuniveristy,dc=edu)']['ou=groups,dc=ad,dc=myuniveristy,dc=edu'] = array(
    0 => array('count' => 1, 'dn' => 'ou=content editors,ou=groups,dc=ad,dc=myuniveristy,dc=edu'),
    1 => array('count' => 1, 'dn' => 'ou=content approvers,ou=groups,dc=ad,dc=myuniveristy,dc=edu'),
    'count' => 2,
  );

which should work correctly if 'dn' is selected.

johnbarclay’s picture

Status: Needs work » Needs review
johnbarclay’s picture

Status: Needs review » Closed (duplicate)

this is a duplicate of #1066608: module is not checking the OU roles object by looking for a member that is the DN, since basically II.C. has been completely reworked. After adding documentation and checking everything in, I'll update #1066608: module is not checking the OU roles object by looking for a member that is the DN.

kenorb’s picture