Skip to content

Commit f46cc39

Browse files
committed
don't store extra variable for $this->entry
1 parent 932b89e commit f46cc39

File tree

2 files changed

+43
-64
lines changed

2 files changed

+43
-64
lines changed

resources/lib/UnityGroup.php

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,8 @@ public function cancelGroupJoinRequest($user, $send_mail = true)
267267
// $users = $this->getGroupMembers();
268268

269269
// // now we delete the ldap entry
270-
// $ldapPiGroupEntry = $this->entry;
271-
// if ($ldapPiGroupEntry->exists()) {
272-
// $ldapPiGroupEntry->delete();
270+
// if ($this->entry->exists()) {
271+
// $this->entry->delete();
273272
// $this->REDIS->removeCacheArray("sorted_groups", "", $this->getPIUID());
274273
// foreach ($users as $user) {
275274
// $this->REDIS->removeCacheArray($user->getUID(), "groups", $this->getPIUID());
@@ -503,8 +502,7 @@ public function getGroupMemberUIDs($ignorecache = false)
503502
}
504503
$updatecache = false;
505504
if (!isset($members)) {
506-
$pi_group = $this->entry;
507-
$members = $pi_group->getAttribute("memberuid");
505+
$members = $this->entry->getAttribute("memberuid");
508506
$updatecache = true;
509507
}
510508
if (!$ignorecache && $updatecache) {
@@ -537,16 +535,13 @@ private function init()
537535
// make this user a PI
538536
$owner = $this->getOwner();
539537

540-
// (1) Create LDAP PI group
541-
$ldapPiGroupEntry = $this->entry;
542-
543-
if (!$ldapPiGroupEntry->exists()) {
538+
if (!$this->entry->exists()) {
544539
$nextGID = $this->LDAP->getNextPiGIDNumber($this->SQL);
545540

546-
$ldapPiGroupEntry->setAttribute("objectclass", UnityLDAP::POSIX_GROUP_CLASS);
547-
$ldapPiGroupEntry->setAttribute("gidnumber", strval($nextGID));
548-
$ldapPiGroupEntry->setAttribute("memberuid", array($owner->getUID()));
549-
$ldapPiGroupEntry->write();
541+
$this->entry->setAttribute("objectclass", UnityLDAP::POSIX_GROUP_CLASS);
542+
$this->entry->setAttribute("gidnumber", strval($nextGID));
543+
$this->entry->setAttribute("memberuid", array($owner->getUID()));
544+
$this->entry->write();
550545
}
551546

552547
$this->REDIS->appendCacheArray("sorted_groups", "", $this->getPIUID());
@@ -557,19 +552,17 @@ private function init()
557552
private function addUserToGroup($new_user)
558553
{
559554
// Add to LDAP Group
560-
$pi_group = $this->entry;
561-
$pi_group->appendAttribute("memberuid", $new_user->getUID());
562-
$pi_group->write();
555+
$this->entry->appendAttribute("memberuid", $new_user->getUID());
556+
$this->entry->write();
563557
$this->REDIS->appendCacheArray($this->getPIUID(), "members", $new_user->getUID());
564558
$this->REDIS->appendCacheArray($new_user->getUID(), "groups", $this->getPIUID());
565559
}
566560

567561
private function removeUserFromGroup($old_user)
568562
{
569563
// Remove from LDAP Group
570-
$pi_group = $this->entry;
571-
$pi_group->removeAttributeEntryByValue("memberuid", $old_user->getUID());
572-
$pi_group->write();
564+
$this->entry->removeAttributeEntryByValue("memberuid", $old_user->getUID());
565+
$this->entry->write();
573566
$this->REDIS->removeCacheArray($this->getPIUID(), "members", $old_user->getUID());
574567
$this->REDIS->removeCacheArray($old_user->getUID(), "groups", $this->getPIUID());
575568
}

resources/lib/UnityUser.php

Lines changed: 31 additions & 45 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
@@ -174,9 +172,8 @@ public function getUID()
174172

175173
public function setOrg($org)
176174
{
177-
$ldap_user = $this->entry;
178-
$ldap_user->setAttribute("o", $org);
179-
$ldap_user->write();
175+
$this->entry->setAttribute("o", $org);
176+
$this->entry->write();
180177
$this->REDIS->setCache($this->uid, "org", $org);
181178
}
182179

@@ -210,8 +207,7 @@ public function getOrg($ignorecache = false)
210207
*/
211208
public function setFirstname($firstname, $operator = null)
212209
{
213-
$ldap_user = $this->entry;
214-
$ldap_user->setAttribute("givenname", $firstname);
210+
$this->entry->setAttribute("givenname", $firstname);
215211
$operator = is_null($operator) ? $this->getUID() : $operator->getUID();
216212

217213
$this->SQL->addLog(
@@ -221,7 +217,7 @@ public function setFirstname($firstname, $operator = null)
221217
$this->getUID()
222218
);
223219

224-
$ldap_user->write();
220+
$this->entry->write();
225221
$this->REDIS->setCache($this->uid, "firstname", $firstname);
226222
}
227223

@@ -260,8 +256,7 @@ public function getFirstname($ignorecache = false)
260256
*/
261257
public function setLastname($lastname, $operator = null)
262258
{
263-
$ldap_user = $this->entry;
264-
$ldap_user->setAttribute("sn", $lastname);
259+
$this->entry->setAttribute("sn", $lastname);
265260
$operator = is_null($operator) ? $this->getUID() : $operator->getUID();
266261

267262
$this->SQL->addLog(
@@ -316,8 +311,7 @@ public function getFullname()
316311
*/
317312
public function setMail($email, $operator = null)
318313
{
319-
$ldap_user = $this->entry;
320-
$ldap_user->setAttribute("mail", $email);
314+
$this->entry->setAttribute("mail", $email);
321315
$operator = is_null($operator) ? $this->getUID() : $operator->getUID();
322316

323317
$this->SQL->addLog(
@@ -366,12 +360,11 @@ public function getMail($ignorecache = false)
366360
*/
367361
public function setSSHKeys($keys, $operator = null, $send_mail = true)
368362
{
369-
$ldapUser = $this->entry;
370363
$operator = is_null($operator) ? $this->getUID() : $operator->getUID();
371364
$keys_filt = array_values(array_unique($keys));
372-
if ($ldapUser->exists()) {
373-
$ldapUser->setAttribute("sshpublickey", $keys_filt);
374-
$ldapUser->write();
365+
if ($this->entry->exists()) {
366+
$this->entry->setAttribute("sshpublickey", $keys_filt);
367+
$this->entry->write();
375368
}
376369

377370
$this->REDIS->setCache($this->uid, "sshkeys", $keys_filt);
@@ -411,8 +404,7 @@ public function getSSHKeys($ignorecache = false)
411404
}
412405

413406
if ($this->exists()) {
414-
$ldapUser = $this->entry;
415-
$result = $ldapUser->getAttribute("sshpublickey");
407+
$result = $this->entry->getAttribute("sshpublickey");
416408
if (is_null($result)) {
417409
$keys = array();
418410
} else {
@@ -446,10 +438,9 @@ public function setLoginShell($shell, $operator = null, $send_mail = true)
446438
if (empty($shell)) {
447439
throw new Exception("login shell must not be empty!");
448440
}
449-
$ldapUser = $this->entry;
450-
if ($ldapUser->exists()) {
451-
$ldapUser->setAttribute("loginshell", $shell);
452-
$ldapUser->write();
441+
if ($this->entry->exists()) {
442+
$this->entry->setAttribute("loginshell", $shell);
443+
$this->entry->write();
453444
}
454445

455446
$operator = is_null($operator) ? $this->getUID() : $operator->getUID();
@@ -488,9 +479,7 @@ public function getLoginShell($ignorecache = false)
488479
}
489480

490481
if ($this->exists()) {
491-
$ldapUser = $this->entry;
492-
493-
$loginshell = $ldapUser->getAttribute("loginshell")[0];
482+
$loginshell = $this->entry->getAttribute("loginshell")[0];
494483

495484
if (!$ignorecache) {
496485
$this->REDIS->setCache($this->getUID(), "loginshell", $loginshell);
@@ -504,10 +493,9 @@ public function getLoginShell($ignorecache = false)
504493

505494
public function setHomeDir($home, $operator = null)
506495
{
507-
$ldapUser = $this->entry;
508-
if ($ldapUser->exists()) {
509-
$ldapUser->setAttribute("homedirectory", $home);
510-
$ldapUser->write();
496+
if ($this->entry->exists()) {
497+
$this->entry->setAttribute("homedirectory", $home);
498+
$this->entry->write();
511499
$operator = is_null($operator) ? $this->getUID() : $operator->getUID();
512500

513501
$this->SQL->addLog(
@@ -537,9 +525,7 @@ public function getHomeDir($ignorecache = false)
537525
}
538526

539527
if ($this->exists()) {
540-
$ldapUser = $this->entry;
541-
542-
$homedir = $ldapUser->getAttribute("homedirectory");
528+
$homedir = $this->entry->getAttribute("homedirectory");
543529

544530
if (!$ignorecache) {
545531
$this->REDIS->setCache($this->getUID(), "homedir", $homedir);

0 commit comments

Comments
 (0)