summaryrefslogtreecommitdiff
path: root/program
diff options
context:
space:
mode:
authoralecpl <alec@alec.pl>2012-04-10 08:39:36 +0000
committeralecpl <alec@alec.pl>2012-04-10 08:39:36 +0000
commit097dbc68700c0c15e78d3643f1f478269f13f1ac (patch)
tree3bf7bfc4b902e263044c1f45d8f6dde548e38c6d /program
parent559446dfed55749810644ddcb7ecb6e268110b4a (diff)
- Improved member attribute detection with fallback in create_group()
Diffstat (limited to 'program')
-rw-r--r--program/include/rcube_ldap.php62
1 files changed, 41 insertions, 21 deletions
diff --git a/program/include/rcube_ldap.php b/program/include/rcube_ldap.php
index 9f8086bd9..f42abf1ed 100644
--- a/program/include/rcube_ldap.php
+++ b/program/include/rcube_ldap.php
@@ -1673,23 +1673,7 @@ class rcube_ldap extends rcube_addressbook
$groups[$group_id]['ID'] = $group_id;
$groups[$group_id]['dn'] = $ldap_data[$i]['dn'];
$groups[$group_id]['name'] = $group_name;
- $groups[$group_id]['member_attr'] = $this->prop['member_attr'];
-
- // check objectClass attributes of group and act accordingly
- for ($j=0; $j < $ldap_data[$i]['objectclass']['count']; $j++) {
- switch (strtolower($ldap_data[$i]['objectclass'][$j])) {
- case 'group':
- case 'groupofnames':
- case 'kolabgroupofnames':
- $groups[$group_id]['member_attr'] = 'member';
- break;
-
- case 'groupofuniquenames':
- case 'kolabgroupofuniquenames':
- $groups[$group_id]['member_attr'] = 'uniqueMember';
- break;
- }
- }
+ $groups[$group_id]['member_attr'] = $this->get_group_member_attr($ldap_data[$i]['objectclass']);
// list email attributes of a group
for ($j=0; $ldap_data[$i][$email_attr] && $j < $ldap_data[$i][$email_attr]['count']; $j++) {
@@ -1750,8 +1734,8 @@ class rcube_ldap extends rcube_addressbook
$base_dn = $this->groups_base_dn;
$new_dn = "cn=$group_name,$base_dn";
$new_gid = self::dn_encode($group_name);
- $member_attr = $this->prop['groups']['member_attr'];
- $name_attr = $this->prop['groups']['name_attr'];
+ $member_attr = $this->get_group_member_attr();
+ $name_attr = $this->prop['groups']['name_attr'] ? $this->prop['groups']['name_attr'] : 'cn';
$new_entry = array(
'objectClass' => $this->prop['groups']['object_classes'],
@@ -1903,8 +1887,8 @@ class rcube_ldap extends rcube_addressbook
$base_dn = $this->groups_base_dn;
$contact_dn = self::dn_decode($contact_id);
- $name_attr = $this->prop['groups']['name_attr'];
- $member_attr = $this->prop['member_attr'];
+ $name_attr = $this->prop['groups']['name_attr'] ? $this->prop['groups']['name_attr'] : 'cn';
+ $member_attr = $this->get_group_member_attr();
$add_filter = '';
if ($member_attr != 'member' && $member_attr != 'uniqueMember')
$add_filter = "($member_attr=$contact_dn)";
@@ -1931,6 +1915,42 @@ class rcube_ldap extends rcube_addressbook
return $groups;
}
+ /**
+ * Detects group member attribute name
+ */
+ private function get_group_member_attr($object_classes = array())
+ {
+ if (empty($object_classes)) {
+ $object_classes = $this->prop['groups']['object_classes'];
+ }
+ if (!empty($object_classes)) {
+ foreach ((array)$object_classes as $oc) {
+ switch (strtolower($oc)) {
+ case 'group':
+ case 'groupofnames':
+ case 'kolabgroupofnames':
+ $member_attr = 'member';
+ break;
+
+ case 'groupofuniquenames':
+ case 'kolabgroupofuniquenames':
+ $member_attr = 'uniqueMember';
+ break;
+ }
+ }
+ }
+
+ if (!empty($member_attr)) {
+ return $member_attr;
+ }
+
+ if (!empty($this->prop['groups']['member_attr'])) {
+ return $this->prop['groups']['member_attr'];
+ }
+
+ return 'member';
+ }
+
/**
* Generate BER encoded string for Virtual List View option