Verified Commit ea63add5 authored by Côme Chilliet's avatar Côme Chilliet
Browse files

:ambulance: fix(plugins) Use new class for LDAP errors

issue #6061
parent afdfd343
No related merge requests found
Showing with 95 additions and 22 deletions
+95 -22
......@@ -148,7 +148,13 @@ class dhcpConfiguration extends simplePlugin
$ldap->rmdir_recursive($dn);
if (!$ldap->success()) {
$this->ldap_error = $ldap->get_error();
$errors[] = msgPool::ldaperror($ldap->get_error(), $dn, LDAP_MOD, get_class());
$errors[] = new SimplePluginLdapError(
$this,
$dn,
LDAP_DEL,
$ldap->get_error(),
$ldap->get_errno()
);
}
}
}
......@@ -201,13 +207,25 @@ class dhcpConfiguration extends simplePlugin
$ldap->modify($attrs);
if (!$ldap->success()) {
$this->ldap_error = $ldap->get_error();
$errors[] = msgPool::ldaperror($ldap->get_error(), $dn, LDAP_MOD, get_class());
$errors[] = new SimplePluginLdapError(
$this,
$dn,
LDAP_MOD,
$ldap->get_error(),
$ldap->get_errno()
);
}
} else {
$ldap->add($attrs);
if (!$ldap->success()) {
$this->ldap_error = $ldap->get_error();
$errors[] = msgPool::ldaperror($ldap->get_error(), $dn, LDAP_ADD, get_class());
$errors[] = new SimplePluginLdapError(
$this,
$dn,
LDAP_ADD,
$ldap->get_error(),
$ldap->get_errno()
);
}
}
}
......
......@@ -97,7 +97,13 @@ class pgpServerInfo extends simplePlugin
$ldap->cd($config->current['BASE']);
$ldap->create_missing_trees($this->pgpBaseKeySpaceDN);
if (!$ldap->success()) {
$errors[] = msgPool::ldaperror($ldap->get_error(), $this->pgpBaseKeySpaceDN, LDAP_MOD, get_class());
$errors[] = new SimplePluginLdapError(
$this,
$this->pgpBaseKeySpaceDN,
LDAP_ADD,
$ldap->get_error(),
$ldap->get_errno()
);
}
}
/* Delete the old branch if empty */
......
......@@ -150,7 +150,10 @@ class invitation extends simplePlugin
}
$registrations = objects::count('registration', NULL, '(fdRegistrationEmailAddress='.ldap_escape_f($email).')');
if ($registrations > 0) {
$errors[] = sprintf(_('There is already a registration object for "%s"'), $email);
$errors[] = new SimplePluginError(
$this,
htmlescape(sprintf(_('There is already a registration object for "%s"'), $email))
);
$failed[] = $email;
continue;
}
......@@ -169,13 +172,19 @@ class invitation extends simplePlugin
$messages = $tabObject->save();
if (!empty($messages)) {
$errors[] = sprintf(_('Failed to create registration object for "%s", because of the following errors: %s'), $email, implode("\n", $messages));
$errors[] = new SimplePluginError(
$this,
nl2br(htmlescape(sprintf(_('Failed to create registration object for "%s", because of the following errors: %s'), $email, implode("\n", $messages))))
);
$failed[] = $email;
} else {
$success++;
}
} else {
$errors[] = sprintf(_('Failed to send invitation email to "%s". Check your email settings.'), $email);
$errors[] = new SimplePluginError(
$this,
htmlescape(sprintf(_('Failed to send invitation email to "%s". Check your email settings.'), $email))
);
$failed[] = $email;
}
}
......
......@@ -340,10 +340,16 @@ class mailGroup extends simplePlugin
if (!$this->is_template) {
$this->mailMethod->connect();
if (!$this->mailMethod->is_connected()) {
$errors[] = sprintf(_('Mail method cannot connect: %s'), $this->mailMethod->get_error());
$errors[] = new SimplePluginError(
$this,
htmlescape(sprintf(_('Mail method cannot connect: %s'), $this->mailMethod->get_error()))
);
} else {
if (!$this->mailMethod->updateMailbox()) {
$errors[] = sprintf(_('Cannot update mailbox: %s'), $this->mailMethod->get_error());
$errors[] = new SimplePluginError(
$this,
htmlescape(sprintf(_('Cannot update mailbox: %s'), $this->mailMethod->get_error()))
);
}
if ($this->mailMethod->groupAclsEnabled()) {
$acls = [
......
......@@ -367,10 +367,16 @@ class mailAccount extends simplePlugin
if (!$this->is_template) {
$this->mailMethod->connect();
if (!$this->mailMethod->is_connected()) {
$errors[] = sprintf(_('Mail method cannot connect: %s'), $this->mailMethod->get_error());
$errors[] = new SimplePluginError(
$this,
htmlescape(sprintf(_('Mail method cannot connect: %s'), $this->mailMethod->get_error()))
);
} else {
if (!$this->mailMethod->updateMailbox()) {
$errors[] = sprintf(_('Cannot update mailbox: %s'), $this->mailMethod->get_error());
$errors[] = new SimplePluginError(
$this,
htmlescape(sprintf(_('Cannot update mailbox: %s'), $this->mailMethod->get_error()))
);
}
if (!$this->mailMethod->setQuota($this->gosaMailQuota)) {
msg_dialog::display(_('Mail error'), sprintf(_('Cannot write quota settings: %s'), $this->mailMethod->get_error()), ERROR_DIALOG);
......
......@@ -629,7 +629,12 @@ class posixAccount extends simplePlugin
$errors = array_merge($errors, $msg);
}
} catch (FusionDirectoryException $e) {
$errors[] = 'Exception: '.$e->getMessage();
$errors[] = new SimplePluginError(
$this,
htmlescape('Exception: '.$e->getMessage()),
0,
$e
);
}
}
}
......@@ -647,7 +652,12 @@ class posixAccount extends simplePlugin
$errors = array_merge($errors, $msg);
}
} catch (FusionDirectoryException $e) {
$errors[] = 'Exception: '.$e->getMessage();
$errors[] = new SimplePluginError(
$this,
htmlescape('Exception: '.$e->getMessage()),
0,
$e
);
}
}
}
......
......@@ -171,10 +171,16 @@ class sympaAliasPartage extends simplePlugin
if (!$this->is_template) {
$this->mailMethod->connect();
if (!$this->mailMethod->is_connected()) {
$errors[] = sprintf(_('Mail method cannot connect: %s'), $this->mailMethod->get_error());
$errors[] = new SimplePluginError(
$this,
htmlescape(sprintf(_('Mail method cannot connect: %s'), $this->mailMethod->get_error()))
);
} else {
if (!$this->mailMethod->updateMailbox()) {
$errors[] = sprintf(_('Cannot update mailbox: %s'), $this->mailMethod->get_error());
$errors[] = new SimplePluginError(
$this,
htmlescape(sprintf(_('Cannot update mailbox: %s'), $this->mailMethod->get_error()))
);
}
}
}
......
......@@ -198,7 +198,13 @@ class etablissement extends simplePlugin
$ldap->cd($config->current['BASE']);
$ldap->modify($rootAttrs);
if (!$ldap->success()) {
$errors[] = msgPool::ldaperror($ldap->get_error(), $config->current['BASE'], 0, get_class());
$errors[] = new SimplePluginLdapError(
$this,
$config->current['BASE'],
LDAP_MOD,
$ldap->get_error(),
$ldap->get_errno()
);
}
}
......@@ -256,7 +262,13 @@ class etablissement extends simplePlugin
$ldap->cd($config->current['BASE']);
$ldap->modify($rootAttrs);
if (!$ldap->success()) {
$errors[] = msgPool::ldaperror($ldap->get_error(), $config->current['BASE'], 0, get_class());
$errors[] = new SimplePluginLdapError(
$this,
$config->current['BASE'],
LDAP_MOD,
$ldap->get_error(),
$ldap->get_errno()
);
}
}
......
......@@ -552,7 +552,7 @@ class fdRPCService
}
$tabobject->by_object[$tab]->attributesAccess[$name]->setValue($attrvalues);
} else {
throw new WebServiceError(msgPool::permModify($dn, $name), 403);
throw new WebServiceError(htmlunescape(msgPool::permModify($dn, $name)), 403);
}
} else {
throw new WebServiceError(sprintf(_('Unknown field "%s"'), $name), 404);
......@@ -609,7 +609,7 @@ class fdRPCService
// Check permissions, are we allowed to remove this object?
$acl = $ui->get_permissions($dn, $infos['aclCategory'].'/'.$infos['mainTab']);
if (strpos($acl, 'd') === FALSE) {
throw new WebServiceError(msgPool::permDelete($dn), 403);
throw new WebServiceError(htmlunescape(msgPool::permDelete($dn)), 403);
}
if ($user = get_lock($dn)) {
......@@ -645,7 +645,7 @@ class fdRPCService
}
}
if (count($disallowed)) {
throw new WebServiceError(msgPool::permModify($disallowed), 403);
throw new WebServiceError(htmlunescape(msgPool::permModify($disallowed)), 403);
}
// Try to lock/unlock the entries.
......@@ -714,7 +714,7 @@ class fdRPCService
}
}
if (count($disallowed)) {
throw new WebServiceError(msgPool::permView($disallowed), 403);
throw new WebServiceError(htmlunescape(msgPool::permView($disallowed)), 403);
}
// Try to lock/unlock the entries.
......@@ -765,7 +765,7 @@ class fdRPCService
if ($dn !== FALSE) {
/* No errors */
if (strpos($ui->get_permissions($dn, 'user/user', 'userPassword'), 'w') === FALSE) {
throw new WebServiceError(msgPool::permModify($dn), 403);
throw new WebServiceError(htmlunescape(msgPool::permModify($dn)), 403);
}
$token = $pwRecovery->generateAndStoreToken();
if ($token !== FALSE) {
......
Supports Markdown
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