Skip to content

Commit ca94443

Browse files
committed
1st draft
1 parent a28ff42 commit ca94443

File tree

4 files changed

+33
-37
lines changed

4 files changed

+33
-37
lines changed

defaults/config.ini.default

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,14 @@ pass = "password" ; Admin bind password
2626
custom_user_mappings_dir = "deployment/custom_user_mappings" ; for internal use only
2727
basedn = "dc=unityhpc,dc=test" ; Base search DN
2828
user_ou = "ou=users,dc=unityhpc,dc=test" ; User organizational unit (may contain more than user group)
29-
qualified_user_group = "cn=unityusers,dc=unityhpc,dc=test" ; Qualified user group (in at least one PI group)
3029
group_ou = "ou=groups,dc=unityhpc,dc=test" ; Group organizational unit
3130
pigroup_ou = "ou=pi_groups,dc=unityhpc,dc=test" ; PI Group organizational unit
3231
orggroup_ou = "ou=org_groups,dc=unityhpc,dc=test" ; ORG group organizational unit
3332
admin_group = "cn=web_admins,dc=unityhpc,dc=test" ; admin dn (members of this group are admins on the web portal)
33+
qualified_user_group = "cn=unityusers,dc=unityhpc,dc=test" ; Qualified user group (in at least one PI group)
34+
locked_user_group = "cn=locked,dc=unityhpc,dc=test" ; locked user group dn
35+
idlelocked_user_group = "cn=idlelocked,dc=unityhpc,dc=test" ; idlelocked user group dn
36+
ghost_user_group = "cn=ghost,dc=unityhpc,dc=test" ; ghost user group dn
3437
def_user_shell = "/bin/bash" ; Default shell for new users
3538
offset_UIDGID = 1000000 ; start point when allocating new UID/GID pairs for a new user
3639
offset_PIGID = 2000000 ; start point when allocating new GID for a new PI group

resources/lib/UnityLDAP.php

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use UnityWebPortal\lib\exceptions\EntryNotFoundException;
66
use PHPOpenLDAPer\LDAPConn;
77
use PHPOpenLDAPer\LDAPEntry;
8+
use UnityWebPortal\lib\PosixGroup;
89

910
/**
1011
* An LDAP connection class which extends LDAPConn tailored for the Unity Cluster
@@ -35,8 +36,12 @@ class UnityLDAP extends LDAPConn
3536
private LDAPEntry $groupOU;
3637
private LDAPEntry $pi_groupOU;
3738
private LDAPEntry $org_groupOU;
38-
private LDAPEntry $adminGroup;
39-
private LDAPEntry $qualifiedUserGroup;
39+
40+
public PosixGroup $adminGroup;
41+
public PosixGroup $qualifiedUserGroup;
42+
public PosixGroup $lockedUserGroup;
43+
public PosixGroup $idlelockedUserGroup;
44+
public PosixGroup $ghostUserGroup;
4045

4146
public function __construct()
4247
{
@@ -46,8 +51,21 @@ public function __construct()
4651
$this->groupOU = $this->getEntry(CONFIG["ldap"]["group_ou"]);
4752
$this->pi_groupOU = $this->getEntry(CONFIG["ldap"]["pigroup_ou"]);
4853
$this->org_groupOU = $this->getEntry(CONFIG["ldap"]["orggroup_ou"]);
49-
$this->adminGroup = $this->getEntry(CONFIG["ldap"]["admin_group"]);
50-
$this->qualifiedUserGroup = $this->getEntry(CONFIG["ldap"]["qualified_user_group"]);
54+
$this->adminGroup = new PosixGroup(
55+
new LDAPEntry($this->conn, CONFIG["ldap"]["admin_group"]),
56+
);
57+
$this->qualifiedUserGroup = new PosixGroup(
58+
new LDAPEntry($this->conn, CONFIG["ldap"]["qualified_user_group"]),
59+
);
60+
$this->lockedUserGroup = new PosixGroup(
61+
new LDAPEntry($this->conn, CONFIG["ldap"]["locked_user_group"]),
62+
);
63+
$this->idlelockedUserGroup = new PosixGroup(
64+
new LDAPEntry($this->conn, CONFIG["ldap"]["idlelocked_user_group"]),
65+
);
66+
$this->ghostUserGroup = new PosixGroup(
67+
new LDAPEntry($this->conn, CONFIG["ldap"]["ghost_user_group"]),
68+
);
5169
}
5270

5371
public function getUserOU(): LDAPEntry
@@ -70,16 +88,6 @@ public function getOrgGroupOU(): LDAPEntry
7088
return $this->org_groupOU;
7189
}
7290

73-
public function getAdminGroup(): LDAPEntry
74-
{
75-
return $this->adminGroup;
76-
}
77-
78-
public function getQualifiedUserGroup(): LDAPEntry
79-
{
80-
return $this->qualifiedUserGroup;
81-
}
82-
8391
public function getDefUserShell(): string
8492
{
8593
return $this->def_user_shell;
@@ -191,7 +199,7 @@ public function getQualifiedUsersUIDs(): array
191199
{
192200
// should not use $user_ou->getChildren or $base_ou->getChildren(objectClass=posixAccount)
193201
// qualified users might be outside user ou, and not all users in LDAP tree are qualified users
194-
return $this->qualifiedUserGroup->getAttribute("memberuid");
202+
return $this->qualifiedUserGroup->getMemberUIDs();
195203
}
196204

197205
public function getQualifiedUsers($UnitySQL, $UnityMailer, $UnityWebhook): array

resources/lib/UnityUser.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function init(
9999

100100
public function isQualified(): bool
101101
{
102-
return $this->LDAP->getQualifiedUserGroup()->attributeValueExists("memberUid", $this->uid);
102+
return $this->LDAP->qualifiedUserGroup->memberUIDExists($this->uid);
103103
}
104104

105105
public function setIsQualified(bool $newIsQualified, bool $doSendMail = true): void
@@ -109,19 +109,15 @@ public function setIsQualified(bool $newIsQualified, bool $doSendMail = true): v
109109
return;
110110
}
111111
if ($newIsQualified) {
112-
$this->LDAP->getQualifiedUserGroup()->appendAttribute("memberuid", $this->uid);
113-
$this->LDAP->getQualifiedUserGroup()->write();
112+
$this->LDAP->qualifiedUserGroup->addMemberUID($this->uid);
114113
if ($doSendMail) {
115114
$this->MAILER->sendMail($this->getMail(), "user_qualified", [
116115
"user" => $this->uid,
117116
"org" => $this->getOrg(),
118117
]);
119118
}
120119
} else {
121-
$this->LDAP
122-
->getQualifiedUserGroup()
123-
->removeAttributeEntryByValue("memberuid", $this->uid);
124-
$this->LDAP->getQualifiedUserGroup()->write();
120+
$this->LDAP->qualifiedUserGroup->removeMemberUID($this->uid);
125121
if ($doSendMail) {
126122
$this->MAILER->sendMail($this->getMail(), "user_dequalified", [
127123
"user" => $this->uid,
@@ -324,8 +320,7 @@ public function getHomeDir(): string
324320
*/
325321
public function isAdmin(): bool
326322
{
327-
$admins = $this->LDAP->getAdminGroup()->getAttribute("memberuid");
328-
return in_array($this->uid, $admins);
323+
return $this->LDAP->adminGroup->memberUIDExists($this->uid);
329324
}
330325

331326
/**

test/phpunit-bootstrap.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -186,18 +186,8 @@ function ensureUserDoesNotExist()
186186
$USER->getGroupEntry()->delete();
187187
ensure(!$USER->getGroupEntry()->exists());
188188
}
189-
$qualified_users_group = $LDAP->getQualifiedUserGroup();
190-
$all_member_uids = $qualified_users_group->getAttribute("memberuid");
191-
if (in_array($USER->uid, $all_member_uids)) {
192-
$qualified_users_group->setAttribute(
193-
"memberuid",
194-
// array_diff will break the contiguity of the array indexes
195-
// ldap_mod_replace requires contiguity, array_values restores contiguity
196-
array_values(array_diff($all_member_uids, [$USER->uid])),
197-
);
198-
$qualified_users_group->write();
199-
ensure(!in_array($USER->uid, $qualified_users_group->getAttribute("memberuid")));
200-
}
189+
$USER->setIsQualified(false);
190+
ensure(!$LDAP->qualifiedUserGroup->memberUIDExists($USER->uid));
201191
}
202192

203193
function ensureOrgGroupDoesNotExist()

0 commit comments

Comments
 (0)