-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
add option zimbra in ldap app #4567
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -120,6 +120,34 @@ public function inGroup($uid, $gid) { | |
| return false; | ||
| } | ||
|
|
||
| if(strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'zimbramailforwardingaddress') { | ||
| // array containing domains | ||
| $dns = array(); | ||
| // loop througth array members | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo |
||
| foreach($members as $mailOfMember) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems this can take a lot of time on big groups with many members. Do you think it is possible to use the provided |
||
| // split the email of each member eg. [email protected] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. intendentation here and the following four lines appears wrong |
||
| // once splitted ['member_name', 'zimbra.com']; | ||
| $memberEmailParts = explode("@", $mailOfMember); | ||
| // get the first part of email | ||
| $memberEmailName = $memberEmailParts[0]; | ||
| // (&(&(objectclass=zimbraAccount)(!(objectclass=zimbraCalendarResource))(!(zimbraHideInGal=TRUE))(zimbraAccountStatus=active))(|(uid=%uid)(|(mailPrimaryAddress=%uid)(mail=%uid)))) | ||
| // with the query above we need to replace each %uid for our $memberEmailName | ||
| // once replaced is done, we have this: assuming our $memberEmailName = "johuder" | ||
| // (&(&(objectclass=zimbraAccount)(!(objectclass=zimbraCalendarResource))(!(zimbraHideInGal=TRUE))(zimbraAccountStatus=active))(|(uid=johuder)(|(mailPrimaryAddress=johuder)(mail=johuder)))) | ||
| $filter = str_replace('%uid', $memberEmailName, $this->access->connection->ldapLoginFilter); | ||
| // request query to LDAP | ||
| $ldap_users = $this->access->fetchListOfUsers($filter, 'dn'); | ||
| if(count($ldap_users) < 1) { | ||
| // if is not found any user, continue to the next user in the foreach loop | ||
| continue; | ||
| } | ||
| // if user were found, we push it into the array result | ||
| array_push($dns, $ldap_users[0]); | ||
| } | ||
| // update the last value in $members with the found users. | ||
| $members = $dns; | ||
| } | ||
|
|
||
| //extra work if we don't get back user DNs | ||
| if(strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') { | ||
| $dns = array(); | ||
|
|
@@ -642,7 +670,21 @@ public function getUserGroups($uid) { | |
| ); | ||
| if ($userMatch !== false) { | ||
| // match found so this user is in this group | ||
| $pos = strpos($dynamicGroup['dn'][0], ','); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. did you test this against groups having a , in their cn? |
||
| //assuming $dynamicGroup['dn'][0] has: cn=myGroup,ou=people,dc=domain,dc=com | ||
| // we look for the first , into the string, in the string above | ||
| // $pos variable will contain 10 | ||
| if ($pos !== false) { | ||
| $membershipGroup = substr($dynamicGroup['dn'][0], 3, $pos - 3); | ||
| // we need to extract the group name | ||
| // so we extracted from cn=myGroup,ou=people,dc=domain,dc=com | ||
| // we extract from position 3 to 7 in the string above, so we have: myGroup | ||
| $groups[] = $membershipGroup; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be dealt with |
||
| // then we add the group found to the array groups | ||
| } | ||
|
|
||
| $groupName = $this->access->dn2groupname($dynamicGroup['dn'][0]); | ||
|
|
||
| if(is_string($groupName)) { | ||
| // be sure to never return false if the dn could not be | ||
| // resolved to a name, for whatever reason. | ||
|
|
@@ -697,6 +739,11 @@ public function getUserGroups($uid) { | |
| $this->access->connection->ldapHost, \OCP\Util::DEBUG); | ||
| } | ||
| $uid = $result[0]; | ||
| } else if(strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'zimbramailforwardingaddress'){ | ||
| // if ldapGroupMemberAssocAttr match with zimbramailforwardingaddress | ||
| // we look into the zimbra LDAP | ||
| $result = $this->access->readAttribute($userDN, 'uid'); | ||
| $uid = $result[0].'@*'; | ||
| } else { | ||
| // just in case | ||
| $uid = $userDN; | ||
|
|
@@ -814,6 +861,7 @@ public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) { | |
|
|
||
| $groupUsers = array(); | ||
| $isMemberUid = (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid'); | ||
| $isZimbraUid = (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'zimbramailforwardingaddress'); | ||
| $attrs = $this->access->userManager->getAttributes(true); | ||
| foreach($members as $member) { | ||
| if($isMemberUid) { | ||
|
|
@@ -827,6 +875,26 @@ public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) { | |
| continue; | ||
| } | ||
| $groupUsers[] = $this->access->dn2username($ldap_users[0]['dn'][0]); | ||
| } else if($isZimbraUid) { | ||
| // if our LDAP config point to zimbra platform | ||
| $memberParts = explode('@', $member); | ||
| // extract the first part of email member | ||
| $member = $memberParts[0]; | ||
|
|
||
| // replace all '%uid' with the value of $member and get the filter query | ||
| $filter = $this->access->combineFilterWidthAnd(array( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo in method name, it should be |
||
| \OCP\Util::mb_str_replace('%uid', $member, | ||
| $this->access->connection->ldapLoginFilter, 'UTF-8'), | ||
| $this->access->getFilterPartForUserSearch($search) | ||
| )); | ||
| // exec the query we got above | ||
| $ldap_users = $this->access->fetchListOfUsers($filter, 'dn'); | ||
| // if we not found any user, let's continue | ||
| if (count($ldap_users) < 1) { | ||
| continue; | ||
| } | ||
| // if we found the user, add it to the array | ||
| $groupUsers[] = $this->access->dn2username($ldap_users[0]); | ||
| } else { | ||
| //we got DNs, check if we need to filter by search or we can give back all of them | ||
| if ($search !== '') { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these days you can use short notation
$dns = [];:)