Skip to content

Commit adc68d4

Browse files
committed
don't store extra variable for $this->entry
1 parent 1ffa363 commit adc68d4

File tree

2 files changed

+51
-72
lines changed

2 files changed

+51
-72
lines changed

resources/lib/UnityGroup.php

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,8 @@ public function cancelGroupJoinRequest($user, $send_mail = true)
257257
// $users = $this->getGroupMembers();
258258

259259
// // now we delete the ldap entry
260-
// $ldapPiGroupEntry = $this->entry;
261-
// if ($ldapPiGroupEntry->exists()) {
262-
// $ldapPiGroupEntry->delete();
260+
// if ($this->entry->exists()) {
261+
// $this->entry->delete();
263262
// $this->REDIS->removeCacheArray("sorted_groups", "", $this->gid);
264263
// foreach ($users as $user) {
265264
// $this->REDIS->removeCacheArray($user->uid, "groups", $this->gid);
@@ -488,8 +487,7 @@ public function getGroupMemberUIDs($ignorecache = false)
488487
}
489488
$updatecache = false;
490489
if (!isset($members)) {
491-
$pi_group = $this->entry;
492-
$members = $pi_group->getAttribute("memberuid");
490+
$members = $this->entry->getAttribute("memberuid");
493491
$updatecache = true;
494492
}
495493
if (!$ignorecache && $updatecache) {
@@ -522,16 +520,13 @@ private function init()
522520
// make this user a PI
523521
$owner = $this->getOwner();
524522

525-
// (1) Create LDAP PI group
526-
$ldapPiGroupEntry = $this->entry;
527-
528-
if (!$ldapPiGroupEntry->exists()) {
523+
if (!$this->entry->exists()) {
529524
$nextGID = $this->LDAP->getNextPiGIDNumber($this->SQL);
530525

531-
$ldapPiGroupEntry->setAttribute("objectclass", UnityLDAP::POSIX_GROUP_CLASS);
532-
$ldapPiGroupEntry->setAttribute("gidnumber", strval($nextGID));
533-
$ldapPiGroupEntry->setAttribute("memberuid", array($owner->uid));
534-
$ldapPiGroupEntry->write();
526+
$this->entry->setAttribute("objectclass", UnityLDAP::POSIX_GROUP_CLASS);
527+
$this->entry->setAttribute("gidnumber", strval($nextGID));
528+
$this->entry->setAttribute("memberuid", array($owner->uid));
529+
$this->entry->write();
535530
}
536531

537532
$this->REDIS->appendCacheArray("sorted_groups", "", $this->gid);
@@ -542,21 +537,19 @@ private function init()
542537
private function addUserToGroup($new_user)
543538
{
544539
// Add to LDAP Group
545-
$pi_group = $this->entry;
546-
$pi_group->appendAttribute("memberuid", $new_user->uid);
547-
$pi_group->write();
548-
$this->REDIS->appendCacheArray($this->gid, "members", $new_user->uid);
549-
$this->REDIS->appendCacheArray($new_user->uid, "groups", $this->gid);
540+
$this->entry->appendAttribute("memberuid", $new_user->getUID());
541+
$this->entry->write();
542+
$this->REDIS->appendCacheArray($this->getPIUID(), "members", $new_user->uid);
543+
$this->REDIS->appendCacheArray($new_user->getUID(), "groups", $this->gid);
550544
}
551545

552546
private function removeUserFromGroup($old_user)
553547
{
554548
// Remove from LDAP Group
555-
$pi_group = $this->entry;
556-
$pi_group->removeAttributeEntryByValue("memberuid", $old_user->uid);
557-
$pi_group->write();
558-
$this->REDIS->removeCacheArray($this->gid, "members", $old_user->uid);
559-
$this->REDIS->removeCacheArray($old_user->uid, "groups", $this->gid);
549+
$this->entry->removeAttributeEntryByValue("memberuid", $old_user->uid);
550+
$this->entry->write();
551+
$this->REDIS->removeCacheArray($this->getPIUID(), "members", $old_user->uid);
552+
$this->REDIS->removeCacheArray($old_user->getUID(), "groups", $this->gid);
560553
}
561554

562555
public function userExists($user)

resources/lib/UnityUser.php

Lines changed: 35 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -72,24 +72,22 @@ public function init($firstname, $lastname, $email, $org, $send_mail = true)
7272
//
7373
// Create LDAP user
7474
//
75-
$ldapUserEntry = $this->entry;
76-
77-
if (!$ldapUserEntry->exists()) {
78-
$ldapUserEntry->setAttribute("objectclass", UnityLDAP::POSIX_ACCOUNT_CLASS);
79-
$ldapUserEntry->setAttribute("uid", $this->uid);
80-
$ldapUserEntry->setAttribute("givenname", $firstname);
81-
$ldapUserEntry->setAttribute("sn", $lastname);
82-
$ldapUserEntry->setAttribute(
75+
if (!$this->entry->exists()) {
76+
$this->entry->setAttribute("objectclass", UnityLDAP::POSIX_ACCOUNT_CLASS);
77+
$this->entry->setAttribute("uid", $this->uid);
78+
$this->entry->setAttribute("givenname", $firstname);
79+
$this->entry->setAttribute("sn", $lastname);
80+
$this->entry->setAttribute(
8381
"gecos",
8482
\transliterator_transliterate("Latin-ASCII", "$firstname $lastname")
8583
);
86-
$ldapUserEntry->setAttribute("mail", $email);
87-
$ldapUserEntry->setAttribute("o", $org);
88-
$ldapUserEntry->setAttribute("homedirectory", self::HOME_DIR . $this->uid);
89-
$ldapUserEntry->setAttribute("loginshell", $this->LDAP->getDefUserShell());
90-
$ldapUserEntry->setAttribute("uidnumber", strval($id));
91-
$ldapUserEntry->setAttribute("gidnumber", strval($id));
92-
$ldapUserEntry->write();
84+
$this->entry->setAttribute("mail", $email);
85+
$this->entry->setAttribute("o", $org);
86+
$this->entry->setAttribute("homedirectory", self::HOME_DIR . $this->uid);
87+
$this->entry->setAttribute("loginshell", $this->LDAP->getDefUserShell());
88+
$this->entry->setAttribute("uidnumber", strval($id));
89+
$this->entry->setAttribute("gidnumber", strval($id));
90+
$this->entry->write();
9391
}
9492

9593
// update cache
@@ -164,9 +162,8 @@ public function exists()
164162

165163
public function setOrg($org)
166164
{
167-
$ldap_user = $this->entry;
168-
$ldap_user->setAttribute("o", $org);
169-
$ldap_user->write();
165+
$this->entry->setAttribute("o", $org);
166+
$this->entry->write();
170167
$this->REDIS->setCache($this->uid, "org", $org);
171168
}
172169

@@ -200,9 +197,8 @@ public function getOrg($ignorecache = false)
200197
*/
201198
public function setFirstname($firstname, $operator = null)
202199
{
203-
$ldap_user = $this->entry;
204-
$ldap_user->setAttribute("givenname", $firstname);
205-
$operator = is_null($operator) ? $this->uid : $operator->uid;
200+
$this->entry->setAttribute("givenname", $firstname);
201+
$operator = is_null($operator) ? $this->getUID() : $operator->uid;
206202

207203
$this->SQL->addLog(
208204
$operator,
@@ -211,7 +207,7 @@ public function setFirstname($firstname, $operator = null)
211207
$this->uid
212208
);
213209

214-
$ldap_user->write();
210+
$this->entry->write();
215211
$this->REDIS->setCache($this->uid, "firstname", $firstname);
216212
}
217213

@@ -250,9 +246,8 @@ public function getFirstname($ignorecache = false)
250246
*/
251247
public function setLastname($lastname, $operator = null)
252248
{
253-
$ldap_user = $this->entry;
254-
$ldap_user->setAttribute("sn", $lastname);
255-
$operator = is_null($operator) ? $this->uid : $operator->uid;
249+
$this->entry->setAttribute("sn", $lastname);
250+
$operator = is_null($operator) ? $this->getUID() : $operator->uid;
256251

257252
$this->SQL->addLog(
258253
$operator,
@@ -306,9 +301,8 @@ public function getFullname()
306301
*/
307302
public function setMail($email, $operator = null)
308303
{
309-
$ldap_user = $this->entry;
310-
$ldap_user->setAttribute("mail", $email);
311-
$operator = is_null($operator) ? $this->uid : $operator->uid;
304+
$this->entry->setAttribute("mail", $email);
305+
$operator = is_null($operator) ? $this->getUID() : $operator->uid;
312306

313307
$this->SQL->addLog(
314308
$operator,
@@ -356,12 +350,11 @@ public function getMail($ignorecache = false)
356350
*/
357351
public function setSSHKeys($keys, $operator = null, $send_mail = true)
358352
{
359-
$ldapUser = $this->entry;
360353
$operator = is_null($operator) ? $this->getUID() : $operator->uid;
361354
$keys_filt = array_values(array_unique($keys));
362-
if ($ldapUser->exists()) {
363-
$ldapUser->setAttribute("sshpublickey", $keys_filt);
364-
$ldapUser->write();
355+
if ($this->entry->exists()) {
356+
$this->entry->setAttribute("sshpublickey", $keys_filt);
357+
$this->entry->write();
365358
}
366359

367360
$this->REDIS->setCache($this->uid, "sshkeys", $keys_filt);
@@ -401,8 +394,7 @@ public function getSSHKeys($ignorecache = false)
401394
}
402395

403396
if ($this->exists()) {
404-
$ldapUser = $this->entry;
405-
$result = $ldapUser->getAttribute("sshpublickey");
397+
$result = $this->entry->getAttribute("sshpublickey");
406398
if (is_null($result)) {
407399
$keys = array();
408400
} else {
@@ -436,10 +428,9 @@ public function setLoginShell($shell, $operator = null, $send_mail = true)
436428
if (empty($shell)) {
437429
throw new Exception("login shell must not be empty!");
438430
}
439-
$ldapUser = $this->entry;
440-
if ($ldapUser->exists()) {
441-
$ldapUser->setAttribute("loginshell", $shell);
442-
$ldapUser->write();
431+
if ($this->entry->exists()) {
432+
$this->entry->setAttribute("loginshell", $shell);
433+
$this->entry->write();
443434
}
444435

445436
$operator = is_null($operator) ? $this->uid : $operator->uid;
@@ -478,9 +469,7 @@ public function getLoginShell($ignorecache = false)
478469
}
479470

480471
if ($this->exists()) {
481-
$ldapUser = $this->entry;
482-
483-
$loginshell = $ldapUser->getAttribute("loginshell")[0];
472+
$loginshell = $this->entry->getAttribute("loginshell")[0];
484473

485474
if (!$ignorecache) {
486475
$this->REDIS->setCache($this->uid, "loginshell", $loginshell);
@@ -494,11 +483,10 @@ public function getLoginShell($ignorecache = false)
494483

495484
public function setHomeDir($home, $operator = null)
496485
{
497-
$ldapUser = $this->entry;
498-
if ($ldapUser->exists()) {
499-
$ldapUser->setAttribute("homedirectory", $home);
500-
$ldapUser->write();
501-
$operator = is_null($operator) ? $this->uid : $operator->uid;
486+
if ($this->entry->exists()) {
487+
$this->entry->setAttribute("homedirectory", $home);
488+
$this->entry->write();
489+
$operator = is_null($operator) ? $this->getUID() : $operator->uid;
502490

503491
$this->SQL->addLog(
504492
$operator,
@@ -527,9 +515,7 @@ public function getHomeDir($ignorecache = false)
527515
}
528516

529517
if ($this->exists()) {
530-
$ldapUser = $this->entry;
531-
532-
$homedir = $ldapUser->getAttribute("homedirectory");
518+
$homedir = $this->entry->getAttribute("homedirectory");
533519

534520
if (!$ignorecache) {
535521
$this->REDIS->setCache($this->uid, "homedir", $homedir);

0 commit comments

Comments
 (0)