Skip to content

Commit 2ace549

Browse files
committed
remove checks on write success
1 parent 970414b commit 2ace549

File tree

4 files changed

+16
-67
lines changed

4 files changed

+16
-67
lines changed

resources/lib/UnityGroup.php

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -487,10 +487,7 @@ private function init()
487487
$ldapPiGroupEntry->setAttribute("objectclass", UnityLDAP::POSIX_GROUP_CLASS);
488488
$ldapPiGroupEntry->setAttribute("gidnumber", strval($nextGID));
489489
$ldapPiGroupEntry->setAttribute("memberuid", array($owner->getUID()));
490-
491-
if (!$ldapPiGroupEntry->write()) {
492-
throw new Exception("Failed to create POSIX group for " . $owner->getUID()); // this shouldn't execute
493-
}
490+
$ldapPiGroupEntry->write();
494491
}
495492

496493
$this->REDIS->appendCacheArray("sorted_groups", "", $this->getPIUID());
@@ -503,11 +500,7 @@ private function addUserToGroup($new_user)
503500
// Add to LDAP Group
504501
$pi_group = $this->getLDAPPiGroup();
505502
$pi_group->appendAttribute("memberuid", $new_user->getUID());
506-
507-
if (!$pi_group->write()) {
508-
throw new Exception("Unable to write PI group");
509-
}
510-
503+
$pi_group->write();
511504
$this->REDIS->appendCacheArray($this->getPIUID(), "members", $new_user->getUID());
512505
$this->REDIS->appendCacheArray($new_user->getUID(), "groups", $this->getPIUID());
513506
}
@@ -517,11 +510,7 @@ private function removeUserFromGroup($old_user)
517510
// Remove from LDAP Group
518511
$pi_group = $this->getLDAPPiGroup();
519512
$pi_group->removeAttributeEntryByValue("memberuid", $old_user->getUID());
520-
521-
if (!$pi_group->write()) {
522-
throw new Exception("Unable to write PI group");
523-
}
524-
513+
$pi_group->write();
525514
$this->REDIS->removeCacheArray($this->getPIUID(), "members", $old_user->getUID());
526515
$this->REDIS->removeCacheArray($old_user->getUID(), "groups", $this->getPIUID());
527516
}

resources/lib/UnityOrg.php

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,7 @@ public function init()
3434

3535
$org_group->setAttribute("objectclass", UnityLDAP::POSIX_GROUP_CLASS);
3636
$org_group->setAttribute("gidnumber", strval($nextGID));
37-
38-
if (!$org_group->write()) {
39-
throw new Exception("Failed to create POSIX group for " . $this->orgid); // this shouldn't execute
40-
}
37+
$org_group->write();
4138
}
4239

4340
$this->REDIS->appendCacheArray("sorted_orgs", "", $this->getOrgID());
@@ -101,23 +98,15 @@ public function addUser($user)
10198
{
10299
$org_group = $this->getLDAPOrgGroup();
103100
$org_group->appendAttribute("memberuid", $user->getUID());
104-
105-
if (!$org_group->write()) {
106-
throw new Exception("Unable to write to org group");
107-
}
108-
101+
$org_group->write();
109102
$this->REDIS->appendCacheArray($this->getOrgID(), "members", $user->getUID());
110103
}
111104

112105
public function removeUser($user)
113106
{
114107
$org_group = $this->getLDAPOrgGroup();
115108
$org_group->removeAttributeEntryByValue("memberuid", $user->getUID());
116-
117-
if (!$org_group->write()) {
118-
throw new Exception("Unable to write to org group");
119-
}
120-
109+
$org_group->write();
121110
$this->REDIS->removeCacheArray($this->getOrgID(), "members", $user->getUID());
122111
}
123112
}

resources/lib/UnityUser.php

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,7 @@ public function init($send_mail = true)
5858
if (!$ldapGroupEntry->exists()) {
5959
$ldapGroupEntry->setAttribute("objectclass", UnityLDAP::POSIX_GROUP_CLASS);
6060
$ldapGroupEntry->setAttribute("gidnumber", strval($id));
61-
62-
if (!$ldapGroupEntry->write()) {
63-
throw new Exception("Failed to create POSIX group for $this->uid");
64-
}
61+
$ldapGroupEntry->write();
6562
}
6663

6764
//
@@ -80,11 +77,7 @@ public function init($send_mail = true)
8077
$ldapUserEntry->setAttribute("loginshell", $this->LDAP->getDefUserShell());
8178
$ldapUserEntry->setAttribute("uidnumber", strval($id));
8279
$ldapUserEntry->setAttribute("gidnumber", strval($id));
83-
84-
if (!$ldapUserEntry->write()) {
85-
$ldapGroupEntry->delete(); // Cleanup previous group
86-
throw new Exception("Failed to create POSIX user for $this->uid");
87-
}
80+
$ldapUserEntry->write();
8881
}
8982

9083
// update cache
@@ -177,11 +170,7 @@ public function setOrg($org)
177170
{
178171
$ldap_user = $this->getLDAPUser();
179172
$ldap_user->setAttribute("o", $org);
180-
181-
if (!$ldap_user->write()) {
182-
throw new Exception("Error updating LDAP entry $this->uid");
183-
}
184-
173+
$ldap_user->write();
185174
$this->REDIS->setCache($this->uid, "org", $org);
186175
}
187176

@@ -225,10 +214,7 @@ public function setFirstname($firstname, $operator = null)
225214
$this->getUID()
226215
);
227216

228-
if (!$ldap_user->write()) {
229-
throw new Exception("Error updating LDAP entry $this->uid");
230-
}
231-
217+
$ldap_user->write();
232218
$this->REDIS->setCache($this->uid, "firstname", $firstname);
233219
}
234220

@@ -277,10 +263,7 @@ public function setLastname($lastname, $operator = null)
277263
$this->getUID()
278264
);
279265

280-
if (!$this->getLDAPUser()->write()) {
281-
throw new Exception("Error updating LDAP entry $this->uid");
282-
}
283-
266+
$this->getLDAPUser()->write();
284267
$this->REDIS->setCache($this->uid, "lastname", $lastname);
285268
}
286269

@@ -334,10 +317,7 @@ public function setMail($email, $operator = null)
334317
$this->getUID()
335318
);
336319

337-
if (!$this->getLDAPUser()->write()) {
338-
throw new Exception("Error updating LDAP entry $this->uid");
339-
}
340-
320+
$this->getLDAPUser()->write();
341321
$this->REDIS->setCache($this->uid, "mail", $email);
342322
}
343323

@@ -380,9 +360,7 @@ public function setSSHKeys($keys, $operator = null, $send_mail = true)
380360
$keys_filt = array_values(array_unique($keys));
381361
if ($ldapUser->exists()) {
382362
$ldapUser->setAttribute("sshpublickey", $keys_filt);
383-
if (!$ldapUser->write()) {
384-
throw new Exception("Failed to modify SSH keys for $this->uid");
385-
}
363+
$ldapUser->write();
386364
}
387365

388366
$this->REDIS->setCache($this->uid, "sshkeys", $keys_filt);
@@ -451,9 +429,7 @@ public function setLoginShell($shell, $operator = null, $send_mail = true)
451429
$ldapUser = $this->getLDAPUser();
452430
if ($ldapUser->exists()) {
453431
$ldapUser->setAttribute("loginshell", $shell);
454-
if (!$ldapUser->write()) {
455-
throw new Exception("Failed to modify login shell for $this->uid");
456-
}
432+
$ldapUser->write();
457433
}
458434

459435
$operator = is_null($operator) ? $this->getUID() : $operator->getUID();
@@ -510,10 +486,7 @@ public function setHomeDir($home, $operator = null)
510486
$ldapUser = $this->getLDAPUser();
511487
if ($ldapUser->exists()) {
512488
$ldapUser->setAttribute("homedirectory", $home);
513-
if (!$ldapUser->write()) {
514-
throw new Exception("Failed to modify home directory for $this->uid");
515-
}
516-
489+
$ldapUser->write();
517490
$operator = is_null($operator) ? $this->getUID() : $operator->getUID();
518491

519492
$this->SQL->addLog(

test/functional/PiDisbandTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ public function testDisband()
4747
$this->assertEmpty($SQL->getRequests($piGroup->getPIUID()));
4848
} finally {
4949
$piGroupEntry->setAttributes($piGroupAttributesBefore);
50-
if (!$piGroupEntry->write()) {
51-
throw new Exception("Failed to recreate POSIX group $piGroupName");
52-
}
50+
$piGroupEntry->write();
5351
}
5452
}
5553
}

0 commit comments

Comments
 (0)