Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ rm "$prod" && ln -s "$old" "$prod"

### Version-specific update instructions:

### 1.3 -> 1.4

- the `[ldap]user_group` option has been renamed to `[ldap]qualified_user_group`

### 1.2 -> 1.3

- SQL:
Expand Down
2 changes: 1 addition & 1 deletion defaults/config.ini.default
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pass = "password" ; Admin bind password
custom_user_mappings_dir = "deployment/custom_user_mappings" ; for internal use only
basedn = "dc=unityhpc,dc=test" ; Base search DN
user_ou = "ou=users,dc=unityhpc,dc=test" ; User organizational unit (may contain more than user group)
user_group = "cn=unityusers,dc=unityhpc,dc=test" ; User group
qualified_user_group = "cn=unityusers,dc=unityhpc,dc=test" ; User group
group_ou = "ou=groups,dc=unityhpc,dc=test" ; Group organizational unit
pigroup_ou = "ou=pi_groups,dc=unityhpc,dc=test" ; PI Group organizational unit
orggroup_ou = "ou=org_groups,dc=unityhpc,dc=test" ; ORG group organizational unit
Expand Down
34 changes: 17 additions & 17 deletions resources/lib/UnityLDAP.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class UnityLDAP extends ldapConn
private LDAPEntry $pi_groupOU;
private LDAPEntry $org_groupOU;
private LDAPEntry $adminGroup;
private LDAPEntry $userGroup;
private LDAPEntry $qualifiedUserGroup;

public function __construct()
{
Expand All @@ -46,7 +46,7 @@ public function __construct()
$this->pi_groupOU = $this->getEntry(CONFIG["ldap"]["pigroup_ou"]);
$this->org_groupOU = $this->getEntry(CONFIG["ldap"]["orggroup_ou"]);
$this->adminGroup = $this->getEntry(CONFIG["ldap"]["admin_group"]);
$this->userGroup = $this->getEntry(CONFIG["ldap"]["user_group"]);
$this->qualifiedUserGroup = $this->getEntry(CONFIG["ldap"]["qualified_user_group"]);
}

public function getUserOU(): LDAPEntry
Expand Down Expand Up @@ -74,9 +74,9 @@ public function getAdminGroup(): LDAPEntry
return $this->adminGroup;
}

public function getUserGroup(): LDAPEntry
public function getQualifiedUserGroup(): LDAPEntry
{
return $this->userGroup;
return $this->qualifiedUserGroup;
}

public function getDefUserShell(): string
Expand Down Expand Up @@ -182,11 +182,11 @@ private function getAllGIDNumbersInUse(): array
);
}

public function getAllUsersUIDs(): array
public function getQualifiedUsersUIDs(): array
{
// should not use $user_ou->getChildren or $base_ou->getChildren(objectClass=posixAccount)
// Unity users might be outside user ou, and not all users in LDAP tree are unity users
return $this->userGroup->getAttribute("memberuid");
// qualified users might be outside user ou, and not all users in LDAP tree are qualified users
return $this->qualifiedUserGroup->getAttribute("memberuid");
}

public function getAllUsers(
Expand All @@ -199,9 +199,9 @@ public function getAllUsers(
$out = [];

if (!$ignorecache) {
$users = $UnityRedis->getCache("sorted_users", "");
if (!is_null($users)) {
foreach ($users as $user) {
$qualifiedUsers = $UnityRedis->getCache("sorted_qualified_users", "");
if (!is_null($qualifiedUsers)) {
foreach ($qualifiedUsers as $user) {
array_push(
$out,
new UnityUser(
Expand All @@ -218,18 +218,18 @@ public function getAllUsers(
}
}

$users = $this->getAllUsersUIDs();
sort($users);
foreach ($users as $user) {
$qualifiedUsers = $this->getQualifiedUsersUIDs();
sort($qualifiedUsers);
foreach ($qualifiedUsers as $user) {
$params = [$user, $this, $UnitySQL, $UnityMailer, $UnityRedis, $UnityWebhook];
array_push($out, new UnityUser(...$params));
}
return $out;
}

public function getAllUsersAttributes(array $attributes): array
public function getQualifiedUsersAttributes(array $attributes): array
{
$include_uids = $this->getAllUsersUIDs();
$include_uids = $this->getQualifiedUsersUIDs();
$user_attributes = $this->baseOU->getChildrenArray(
$attributes,
true, // recursive
Expand Down Expand Up @@ -307,7 +307,7 @@ public function getAllPIGroupOwnerAttributes(array $attributes): array
fn($x) => UnityGroup::GID2OwnerUID($x),
array_map(fn($x) => $x["cn"][0], $this->pi_groupOU->getChildrenArray(["cn"])),
);
$owner_attributes = $this->getAllUsersAttributes($attributes);
$owner_attributes = $this->getQualifiedUsersAttributes($attributes);
foreach ($owner_attributes as $i => $attributes) {
if (!in_array($attributes["uid"][0], $owner_uids)) {
unset($owner_attributes[$i]);
Expand All @@ -333,7 +333,7 @@ public function getAllPIGroupOwnerAttributes(array $attributes): array
public function getAllUID2PIGIDs(): array
{
// initialize output so each UID is a key with an empty array as its value
$uids = $this->getAllUsersUIDs();
$uids = $this->getQualifiedUsersUIDs();
$uid2pigids = array_combine($uids, array_fill(0, count($uids), []));
// for each PI group, append that GID to the member list for each of its member UIDs
foreach ($this->getAllPIGroupsAttributes(["cn", "memberuid"]) as $array) {
Expand Down
6 changes: 3 additions & 3 deletions resources/lib/UnityUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ public function init(
$org->addUser($this);
}

$this->LDAP->getUserGroup()->appendAttribute("memberuid", $this->uid);
$this->LDAP->getUserGroup()->write();
$this->LDAP->getQualifiedUserGroup()->appendAttribute("memberuid", $this->uid);
$this->LDAP->getQualifiedUserGroup()->write();

$this->REDIS->appendCacheArray("sorted_users", "", $this->uid);
$this->REDIS->appendCacheArray("sorted_qualified_users", "", $this->uid);

$this->SQL->addLog($this->uid, $_SERVER["REMOTE_ADDR"], "user_added", $this->uid);

Expand Down
25 changes: 17 additions & 8 deletions test/functional/NewUserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private function ensureUserDoesNotExist()
$USER->getGroupEntry()->delete();
ensure(!$USER->getGroupEntry()->exists());
}
$all_users_group = $LDAP->getUserGroup();
$all_users_group = $LDAP->getQualifiedUserGroup();
$all_member_uids = $all_users_group->getAttribute("memberuid");
if (in_array($USER->uid, $all_member_uids)) {
$all_users_group->setAttribute(
Expand All @@ -120,7 +120,7 @@ private function ensureUserDoesNotExist()
$all_users_group->write();
ensure(!in_array($USER->uid, $all_users_group->getAttribute("memberuid")));
}
$REDIS->removeCacheArray("sorted_users", "", $USER->uid);
$REDIS->removeCacheArray("sorted_qualified_users", "", $USER->uid);
}

private function ensureOrgGroupDoesNotExist()
Expand Down Expand Up @@ -204,9 +204,12 @@ public function testCreateUserByJoinGoupByPI($user_to_create_args, $expected_uid
$this->assertTrue($newOrg->exists());

$user_entry = $LDAP->getUserEntry($approve_uid);
$user_group_entry = $LDAP->getGroupEntry($approve_uid);
$qualified_user_group_entry = $LDAP->getGroupEntry($approve_uid);
$this->assertEquals($expected_uid_gid, $user_entry->getAttribute("uidnumber")[0]);
$this->assertEquals($expected_uid_gid, $user_group_entry->getAttribute("gidnumber")[0]);
$this->assertEquals(
$expected_uid_gid,
$qualified_user_group_entry->getAttribute("gidnumber")[0],
);

// $third_request_failed = false;
// try {
Expand Down Expand Up @@ -309,9 +312,12 @@ public function testCreateUserByJoinGoupByAdmin($user_to_create_args, $expected_
$this->assertTrue($newOrg->exists());

$user_entry = $LDAP->getUserEntry($approve_uid);
$user_group_entry = $LDAP->getGroupEntry($approve_uid);
$qualified_user_group_entry = $LDAP->getGroupEntry($approve_uid);
$this->assertEquals($expected_uid_gid, $user_entry->getAttribute("uidnumber")[0]);
$this->assertEquals($expected_uid_gid, $user_group_entry->getAttribute("gidnumber")[0]);
$this->assertEquals(
$expected_uid_gid,
$qualified_user_group_entry->getAttribute("gidnumber")[0],
);

// $third_request_failed = false;
// try {
Expand Down Expand Up @@ -372,9 +378,12 @@ public function testCreateUserByCreateGroup($user_to_create_args, $expected_uid_
$this->assertTrue($newOrg->exists());

$user_entry = $LDAP->getUserEntry($approve_uid);
$user_group_entry = $LDAP->getGroupEntry($approve_uid);
$qualified_user_group_entry = $LDAP->getGroupEntry($approve_uid);
$this->assertEquals($expected_uid_gid, $user_entry->getAttribute("uidnumber")[0]);
$this->assertEquals($expected_uid_gid, $user_group_entry->getAttribute("gidnumber")[0]);
$this->assertEquals(
$expected_uid_gid,
$qualified_user_group_entry->getAttribute("gidnumber")[0],
);

// $third_request_failed = false;
// try {
Expand Down
2 changes: 1 addition & 1 deletion webroot/admin/user-mgmt.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class="filterSearch"

<?php
$UID2PIGIDs = $LDAP->getAllUID2PIGIDs();
$user_attributes = $LDAP->getAllUsersAttributes(["uid", "gecos", "o", "mail"]);
$user_attributes = $LDAP->getQualifiedUsersAttributes(["uid", "gecos", "o", "mail"]);
usort($user_attributes, fn ($a, $b) => strcmp($a["uid"][0], $b["uid"][0]));
foreach ($user_attributes as $attributes) {
$uid = $attributes["uid"][0];
Expand Down
4 changes: 2 additions & 2 deletions workers/update-ldap-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
echo "waiting for LDAP search (users)...\n";
$users = $LDAP->search("objectClass=posixAccount", CONFIG["ldap"]["basedn"], []);
echo "response received.\n";
$user_CNs = $LDAP->getUserGroup()->getAttribute("memberuid");
$user_CNs = $LDAP->getQualifiedUserGroup()->getAttribute("memberuid");
sort($user_CNs);
$REDIS->setCache("sorted_users", "", $user_CNs);
$REDIS->setCache("sorted_qualified_users", "", $user_CNs);
foreach ($users as $user) {
$uid = $user->getAttribute("cn")[0];
if (!in_array($uid, $user_CNs)) {
Expand Down
Loading