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