Skip to content

Commit 31d0221

Browse files
authored
qualified user group (#347)
1 parent bd70464 commit 31d0221

File tree

7 files changed

+45
-32
lines changed

7 files changed

+45
-32
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ rm "$prod" && ln -s "$old" "$prod"
114114

115115
### Version-specific update instructions:
116116

117+
### 1.3 -> 1.4
118+
119+
- the `[ldap]user_group` option has been renamed to `[ldap]qualified_user_group`
120+
117121
### 1.2 -> 1.3
118122

119123
- SQL:

defaults/config.ini.default

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pass = "password" ; Admin bind password
2525
custom_user_mappings_dir = "deployment/custom_user_mappings" ; for internal use only
2626
basedn = "dc=unityhpc,dc=test" ; Base search DN
2727
user_ou = "ou=users,dc=unityhpc,dc=test" ; User organizational unit (may contain more than user group)
28-
user_group = "cn=unityusers,dc=unityhpc,dc=test" ; User group
28+
qualified_user_group = "cn=unityusers,dc=unityhpc,dc=test" ; User group
2929
group_ou = "ou=groups,dc=unityhpc,dc=test" ; Group organizational unit
3030
pigroup_ou = "ou=pi_groups,dc=unityhpc,dc=test" ; PI Group organizational unit
3131
orggroup_ou = "ou=org_groups,dc=unityhpc,dc=test" ; ORG group organizational unit

resources/lib/UnityLDAP.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class UnityLDAP extends ldapConn
3535
private LDAPEntry $pi_groupOU;
3636
private LDAPEntry $org_groupOU;
3737
private LDAPEntry $adminGroup;
38-
private LDAPEntry $userGroup;
38+
private LDAPEntry $qualifiedUserGroup;
3939

4040
public function __construct()
4141
{
@@ -46,7 +46,7 @@ public function __construct()
4646
$this->pi_groupOU = $this->getEntry(CONFIG["ldap"]["pigroup_ou"]);
4747
$this->org_groupOU = $this->getEntry(CONFIG["ldap"]["orggroup_ou"]);
4848
$this->adminGroup = $this->getEntry(CONFIG["ldap"]["admin_group"]);
49-
$this->userGroup = $this->getEntry(CONFIG["ldap"]["user_group"]);
49+
$this->qualifiedUserGroup = $this->getEntry(CONFIG["ldap"]["qualified_user_group"]);
5050
}
5151

5252
public function getUserOU(): LDAPEntry
@@ -74,9 +74,9 @@ public function getAdminGroup(): LDAPEntry
7474
return $this->adminGroup;
7575
}
7676

77-
public function getUserGroup(): LDAPEntry
77+
public function getQualifiedUserGroup(): LDAPEntry
7878
{
79-
return $this->userGroup;
79+
return $this->qualifiedUserGroup;
8080
}
8181

8282
public function getDefUserShell(): string
@@ -182,11 +182,11 @@ private function getAllGIDNumbersInUse(): array
182182
);
183183
}
184184

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

192192
public function getAllUsers(
@@ -199,9 +199,9 @@ public function getAllUsers(
199199
$out = [];
200200

201201
if (!$ignorecache) {
202-
$users = $UnityRedis->getCache("sorted_users", "");
203-
if (!is_null($users)) {
204-
foreach ($users as $user) {
202+
$qualifiedUsers = $UnityRedis->getCache("sorted_qualified_users", "");
203+
if (!is_null($qualifiedUsers)) {
204+
foreach ($qualifiedUsers as $user) {
205205
array_push(
206206
$out,
207207
new UnityUser(
@@ -218,18 +218,18 @@ public function getAllUsers(
218218
}
219219
}
220220

221-
$users = $this->getAllUsersUIDs();
222-
sort($users);
223-
foreach ($users as $user) {
221+
$qualifiedUsers = $this->getQualifiedUsersUIDs();
222+
sort($qualifiedUsers);
223+
foreach ($qualifiedUsers as $user) {
224224
$params = [$user, $this, $UnitySQL, $UnityMailer, $UnityRedis, $UnityWebhook];
225225
array_push($out, new UnityUser(...$params));
226226
}
227227
return $out;
228228
}
229229

230-
public function getAllUsersAttributes(array $attributes): array
230+
public function getQualifiedUsersAttributes(array $attributes): array
231231
{
232-
$include_uids = $this->getAllUsersUIDs();
232+
$include_uids = $this->getQualifiedUsersUIDs();
233233
$user_attributes = $this->baseOU->getChildrenArray(
234234
$attributes,
235235
true, // recursive
@@ -307,7 +307,7 @@ public function getAllPIGroupOwnerAttributes(array $attributes): array
307307
fn($x) => UnityGroup::GID2OwnerUID($x),
308308
array_map(fn($x) => $x["cn"][0], $this->pi_groupOU->getChildrenArray(["cn"])),
309309
);
310-
$owner_attributes = $this->getAllUsersAttributes($attributes);
310+
$owner_attributes = $this->getQualifiedUsersAttributes($attributes);
311311
foreach ($owner_attributes as $i => $attributes) {
312312
if (!in_array($attributes["uid"][0], $owner_uids)) {
313313
unset($owner_attributes[$i]);
@@ -333,7 +333,7 @@ public function getAllPIGroupOwnerAttributes(array $attributes): array
333333
public function getAllUID2PIGIDs(): array
334334
{
335335
// initialize output so each UID is a key with an empty array as its value
336-
$uids = $this->getAllUsersUIDs();
336+
$uids = $this->getQualifiedUsersUIDs();
337337
$uid2pigids = array_combine($uids, array_fill(0, count($uids), []));
338338
// for each PI group, append that GID to the member list for each of its member UIDs
339339
foreach ($this->getAllPIGroupsAttributes(["cn", "memberuid"]) as $array) {

resources/lib/UnityUser.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ public function init(
105105
$org->addUser($this);
106106
}
107107

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

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

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

test/functional/NewUserTest.php

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ private function ensureUserDoesNotExist()
108108
$USER->getGroupEntry()->delete();
109109
ensure(!$USER->getGroupEntry()->exists());
110110
}
111-
$all_users_group = $LDAP->getUserGroup();
111+
$all_users_group = $LDAP->getQualifiedUserGroup();
112112
$all_member_uids = $all_users_group->getAttribute("memberuid");
113113
if (in_array($USER->uid, $all_member_uids)) {
114114
$all_users_group->setAttribute(
@@ -120,7 +120,7 @@ private function ensureUserDoesNotExist()
120120
$all_users_group->write();
121121
ensure(!in_array($USER->uid, $all_users_group->getAttribute("memberuid")));
122122
}
123-
$REDIS->removeCacheArray("sorted_users", "", $USER->uid);
123+
$REDIS->removeCacheArray("sorted_qualified_users", "", $USER->uid);
124124
}
125125

126126
private function ensureOrgGroupDoesNotExist()
@@ -204,9 +204,12 @@ public function testCreateUserByJoinGoupByPI($user_to_create_args, $expected_uid
204204
$this->assertTrue($newOrg->exists());
205205

206206
$user_entry = $LDAP->getUserEntry($approve_uid);
207-
$user_group_entry = $LDAP->getGroupEntry($approve_uid);
207+
$qualified_user_group_entry = $LDAP->getGroupEntry($approve_uid);
208208
$this->assertEquals($expected_uid_gid, $user_entry->getAttribute("uidnumber")[0]);
209-
$this->assertEquals($expected_uid_gid, $user_group_entry->getAttribute("gidnumber")[0]);
209+
$this->assertEquals(
210+
$expected_uid_gid,
211+
$qualified_user_group_entry->getAttribute("gidnumber")[0],
212+
);
210213

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

311314
$user_entry = $LDAP->getUserEntry($approve_uid);
312-
$user_group_entry = $LDAP->getGroupEntry($approve_uid);
315+
$qualified_user_group_entry = $LDAP->getGroupEntry($approve_uid);
313316
$this->assertEquals($expected_uid_gid, $user_entry->getAttribute("uidnumber")[0]);
314-
$this->assertEquals($expected_uid_gid, $user_group_entry->getAttribute("gidnumber")[0]);
317+
$this->assertEquals(
318+
$expected_uid_gid,
319+
$qualified_user_group_entry->getAttribute("gidnumber")[0],
320+
);
315321

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

374380
$user_entry = $LDAP->getUserEntry($approve_uid);
375-
$user_group_entry = $LDAP->getGroupEntry($approve_uid);
381+
$qualified_user_group_entry = $LDAP->getGroupEntry($approve_uid);
376382
$this->assertEquals($expected_uid_gid, $user_entry->getAttribute("uidnumber")[0]);
377-
$this->assertEquals($expected_uid_gid, $user_group_entry->getAttribute("gidnumber")[0]);
383+
$this->assertEquals(
384+
$expected_uid_gid,
385+
$qualified_user_group_entry->getAttribute("gidnumber")[0],
386+
);
378387

379388
// $third_request_failed = false;
380389
// try {

webroot/admin/user-mgmt.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class="filterSearch"
4444

4545
<?php
4646
$UID2PIGIDs = $LDAP->getAllUID2PIGIDs();
47-
$user_attributes = $LDAP->getAllUsersAttributes(["uid", "gecos", "o", "mail"]);
47+
$user_attributes = $LDAP->getQualifiedUsersAttributes(["uid", "gecos", "o", "mail"]);
4848
usort($user_attributes, fn ($a, $b) => strcmp($a["uid"][0], $b["uid"][0]));
4949
foreach ($user_attributes as $attributes) {
5050
$uid = $attributes["uid"][0];

workers/update-ldap-cache.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@
3838
echo "waiting for LDAP search (users)...\n";
3939
$users = $LDAP->search("objectClass=posixAccount", CONFIG["ldap"]["basedn"], []);
4040
echo "response received.\n";
41-
$user_CNs = $LDAP->getUserGroup()->getAttribute("memberuid");
41+
$user_CNs = $LDAP->getQualifiedUserGroup()->getAttribute("memberuid");
4242
sort($user_CNs);
43-
$REDIS->setCache("sorted_users", "", $user_CNs);
43+
$REDIS->setCache("sorted_qualified_users", "", $user_CNs);
4444
foreach ($users as $user) {
4545
$uid = $user->getAttribute("cn")[0];
4646
if (!in_array($uid, $user_CNs)) {

0 commit comments

Comments
 (0)