the list of a users groups has the spaces removed from it in:

function _ldapgroups_filter($account, $groups) {
  if (_ldapgroups_ldap_info($account, 'ldapgroups_mappings_filter') && count(_ldapgroups_ldap_info($account, 'ldapgroups_mappings') > 0)) {
    $groups_new = array();
    foreach ($groups as $group) {
      $group = preg_replace('/\s+/', '', $group);
      foreach (_ldapgroups_ldap_info($account, 'ldapgroups_mappings') as $group_approved => $role) {
        $group_approved = preg_replace('/\s+/', '', $group_approved);
        if (strcasecmp($group_approved, $group) == 0)
          $groups_new[] = $group;
      }
    }
    $groups = $groups_new;
  }

  if ($code = _ldapgroups_ldap_info($account, 'ldapgroups_filter_php'))
    $groups = eval($code);

  return $groups;
}

but when doing the mapping to existing groups spaces are not stripped

function _ldapgroups_mapping($user, $group) {
  $ldapgroups_mappings = _ldapgroups_ldap_info($user, 'ldapgroups_mappings');
  if (isset($ldapgroups_mappings[$group]))
    return $ldapgroups_mappings[$group];
  else if (preg_match('/^[^=]+=([^,]+),.*$/', $group, $matches))
    return $matches[1];
  else
    return $group;
}

so if groups have spaces in and are correctly identified with their spaces, groups are not mapped to roles.

I believe spaces should not be stripped as in reality it would be possible to have 2 distinct groups that may have the same name after spaces are stripped.

Comments

miglius’s picture

Assigned: Unassigned » miglius
Status: Active » Postponed (maintainer needs more info)

I don't remember now why spaces are removed in the _ldapgroups_filter() function, but agree that it will cause problem in the mapping function.

So I see two options here:
1. Delete the lines where spaces are removed;
2. Remove spaces before comparing the groups (as it is now), but add to the $groups_new array the original group with a spaces.

Again, I took this code from the config file example which was used in the previous versions and was not written by me, so it might be we oversee some hidden obstacles.

Any suggestions?

silid’s picture

For my purposes I have commented out the 2 lines that strip spaces. I haven't noticed any strange side effects but it isn't in production use yet.

Si

miglius’s picture

Status: Postponed (maintainer needs more info) » Fixed

I went with the option 1 - deleted the lines where spaces are removed. Please file a separate issue in case of some side effects.

Status: Fixed » Closed (fixed)
Issue tags: -ldapgroups

Automatically closed -- issue fixed for 2 weeks with no activity.