Skip to content

Commit 0ee2abd

Browse files
committed
fix update-ldap-cache.php
1 parent 3dffd6c commit 0ee2abd

File tree

2 files changed

+9
-41
lines changed

2 files changed

+9
-41
lines changed

resources/lib/UnityLDAP.php

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -332,35 +332,4 @@ public function getOrgGroupEntry($gid)
332332
$gid = ldap_escape($gid, LDAP_ESCAPE_DN);
333333
return $this->getEntry(unityLDAP::RDN . "=$gid," . $this->STR_ORGGROUPOU);
334334
}
335-
336-
public static function parseUserChildrenArray(array $userChildrenArray): array
337-
{
338-
// input comes from LdapEntry::getChildrenArray on a UnityUser
339-
$output = [];
340-
$required_string_attributes = [
341-
"gidnumber",
342-
"givenname",
343-
"homedirectory",
344-
"loginshell",
345-
"mail",
346-
"o",
347-
"sn",
348-
"uid",
349-
"uidnumber",
350-
"gecos",
351-
];
352-
foreach ($required_string_attributes as $key) {
353-
$output[$key] = $userChildrenArray[$key][0];
354-
}
355-
$output["firstname"] = $output["givenname"];
356-
$output["lastname"] = $output["sn"];
357-
$output["org"] = $output["o"];
358-
$output["objectclass"] = $userChildrenArray["objectclass"];
359-
if (array_key_exists("sspublickey", $userChildrenArray)) {
360-
$output["sshpublickey"] = $userChildrenArray["sshpublickey"];
361-
} else {
362-
$output["sshpublickey"] = [];
363-
}
364-
return $output;
365-
}
366335
}

workers/update-ldap-cache.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,36 +21,35 @@
2121

2222
if ((!is_null($REDIS->getCache("initialized", "")) and (!array_key_exists("u", $options)))) {
2323
echo "cache is already initialized, nothing doing.";
24-
echo " use -f argument to flush cache, or -u argument to update without flush.";
24+
echo " use -f argument to flush cache, or -u argument to update without flush.\n";
2525
} else {
2626
echo "updating cache...\n";
27-
$user_ou = new LDAPEntry($LDAP->getConn(), $CONFIG["ldap"]["user_ou"]);
2827
echo "waiting for LDAP response (users)...\n";
29-
$users = $user_ou->getChildrenArray(true);
28+
$users = $LDAP->search("objectClass=posixAccount", $CONFIG["ldap"]["basedn"]);
3029
echo "response received.\n";
3130
// phpcs:disable
32-
$user_CNs = array_map(function ($x){return $x["cn"][0];}, $users);
31+
$user_CNs = array_map(function ($x){return $x->getAttribute("cn")[0];}, $users);
3332
// phpcs:enable
3433
sort($user_CNs);
3534
$REDIS->setCache("sorted_users", "", $user_CNs);
3635
foreach ($users as $user) {
37-
$attribute_array = UnityLDAP::parseUserChildrenArray($user);
38-
foreach ($attribute_array as $key => $val) {
39-
$REDIS->setCache($user["cn"][0], $key, $val);
36+
$cn = $user->getAttribute("cn")[0];
37+
foreach ($user->getAttributes() as $key => $val) {
38+
$REDIS->setCache($cn, $key, $val);
4039
}
4140
}
4241

4342
$org_group_ou = new LDAPEntry($LDAP->getConn(), $CONFIG["ldap"]["orggroup_ou"]);
4443
echo "waiting for LDAP response (org_groups)...\n";
45-
$org_groups = $org_group_ou->getChildrenArray(true);
44+
$org_groups = $LDAP->search("objectClass=posixGroup", $CONFIG["ldap"]["basedn"]);
4645
echo "response received.\n";
4746
// phpcs:disable
48-
$org_group_CNs = array_map(function($x){return $x["cn"][0];}, $org_groups);
47+
$org_group_CNs = array_map(function($x){return $x->getAttribute("cn")[0];}, $org_groups);
4948
// phpcs:enable
5049
sort($org_group_CNs);
5150
$REDIS->setCache("sorted_orgs", "", $org_group_CNs);
5251
foreach ($org_groups as $org_group) {
53-
$REDIS->setCache($org_group["cn"][0], "members", $org_group["memberuid"]);
52+
$REDIS->setCache($org_group->getAttribute("cn")[0], "members", $org_group->getAttribute("memberuid"));
5453
}
5554

5655
$pi_group_ou = new LDAPEntry($LDAP->getConn(), $CONFIG["ldap"]["pigroup_ou"]);

0 commit comments

Comments
 (0)