Commit 2c76b996 authored by Côme Chilliet's avatar Côme Chilliet

🚑 fix(plugins) Adapt code to prepare_save returning errors

Also made sure POSIX primary group creation errors were clearer and
 returned by prepare_save.

issue #5789
parent 074e07ba
......@@ -832,7 +832,7 @@ class dnsZone extends simplePlugin
}
$this->attributesAccess['sOARecord']->attributes[2]->setValue($serial);
}
parent::prepare_save();
return parent::prepare_save();
}
function ldap_save ()
......
......@@ -156,7 +156,10 @@ class mixedGroup extends simplePlugin
}
}
parent::prepare_save();
$errors = parent::prepare_save();
if (!empty($errors)) {
return $errors;
}
if ($this->trustMode == 'fullaccess') {
$this->attrs['host'] = array('*');
......@@ -168,6 +171,8 @@ class mixedGroup extends simplePlugin
} elseif (($this->trustMode == "") && (($key = array_search('hostObject', $this->attrs['objectClass'])) !== FALSE)) {
unset($this->attrs['objectClass'][$key]);
}
return $errors;
}
function save()
......
......@@ -158,7 +158,7 @@ class netgroup extends simplePlugin
$this->nisNetgroupTriple = $triples;
parent::prepare_save();
return parent::prepare_save();
}
}
?>
......@@ -175,7 +175,10 @@ class posixGroup extends simplePlugin
}
}
parent::prepare_save();
$errors = parent::prepare_save();
if (!empty($errors)) {
return $errors;
}
if ($this->trustMode == 'fullaccess') {
$this->attrs['host'] = array('*');
......@@ -187,6 +190,8 @@ class posixGroup extends simplePlugin
} elseif (($this->trustMode == "") && (($key = array_search('hostObject', $this->attrs['objectClass'])) !== FALSE)) {
unset($this->attrs['objectClass'][$key]);
}
return $errors;
}
function save()
......
......@@ -453,6 +453,7 @@ class posixAccount extends simplePlugin
protected function prepare_save()
{
global $config;
/* Fill gecos */
if (isset($this->parent) && $this->parent !== NULL) {
$this->gecos = rewrite($this->parent->getBaseObject()->cn);
......@@ -554,7 +555,11 @@ class posixAccount extends simplePlugin
$errors = $tabObject->save();
if (!empty($errors)) {
msg_dialog::displayChecks($errors);
array_unshift(
$errors,
sprintf(_('Could not create automatic primary group (using gidNumber "%s"), because of the following errors'), $this->gidNumber)
);
return $errors;
} else {
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
sprintf('Primary group "%s" created, using gidNumber "%s".', $tabObject->dn, $this->gidNumber), '');
......@@ -586,7 +591,10 @@ class posixAccount extends simplePlugin
}
}
parent::prepare_save();
$errors = parent::prepare_save();
if (!empty($errors)) {
return $errors;
}
if ($this->trustMode == 'fullaccess') {
$this->attrs['host'] = array('*');
......@@ -612,6 +620,8 @@ class posixAccount extends simplePlugin
}
$this->attrs['mustchangepassword'] = ($this->mustchangepassword ? 'TRUE' : 'FALSE');
}
return $errors;
}
protected function shouldSave()
......
......@@ -111,12 +111,13 @@ class ppolicyAccount extends simplePlugin
protected function prepare_save ()
{
parent::prepare_save();
$errors = parent::prepare_save();
if (!empty($this->pwdReset)) {
$this->attrs['pwdAccountLockedTime'] = array();
} else {
unset($this->attrs['pwdAccountLockedTime']);
}
return $errors;
}
function remove($fulldelete = FALSE)
......
......@@ -127,7 +127,10 @@ class sambaGroup extends simplePlugin
function prepare_save()
{
global $config;
parent::prepare_save();
$errors = parent::prepare_save();
if (!empty($errors)) {
return $errors;
}
// Generate rid / primaryGroupId
if (!isset($config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'])) {
......@@ -149,6 +152,8 @@ class sambaGroup extends simplePlugin
} else {
$this->attrs['sambaSID'] = $this->sambaSID;
}
return $errors;
}
/*! \brief Get a new SambaSID for a group */
......
......@@ -111,7 +111,10 @@ class sambaSystemTab extends simplePlugin
{
global $config;
$this->update_uid();
parent::prepare_save();
$errors = parent::prepare_save();
if (!empty($errors)) {
return $errors;
}
// Check if the sambaSID exist and that it is correct
// If not get it from config and generate a new sid
......@@ -133,6 +136,8 @@ class sambaSystemTab extends simplePlugin
$this->attrs['sambaSID'] = $sid;
$this->attrs['uidNumber'] = $uidNumber + $this->ridBase;
}
return $errors;
}
}
?>
......@@ -500,7 +500,12 @@ class sambaAccount extends simplePlugin
function prepare_save()
{
global $config;
parent::prepare_save();
$errors = parent::prepare_save();
if (!empty($errors)) {
return $errors;
}
/* Load uid and gid of this 'dn' */
$posixAccount = $this->parent->by_object['posixAccount'];
$uidNumber = $posixAccount->uidNumber;
......@@ -605,6 +610,8 @@ class sambaAccount extends simplePlugin
$this->attrs['sambaKickoffTime'] = array();
}
}
return $errors;
}
function adapt_from_template($attrs, $skip = array())
......
......@@ -568,7 +568,7 @@ class supannAccount extends simplePlugin
{
$this->attributesAccess['supannEtuInscription']->supannPrepareSave();
$this->attributesAccess['supannRoleEntite']->supannPrepareSave();
parent::prepare_save();
return parent::prepare_save();
}
}
?>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment