From db9faf025cf129d15a086a803e8056e977975d76 Mon Sep 17 00:00:00 2001 From: Patrick Brown Date: Wed, 6 May 2015 01:30:59 -0400 Subject: Report more meaningful errors when an auth backend fails. closes #1093 --- lib/plugins/authplain/auth.php | 33 +++++++++++++++---------- lib/plugins/authplain/lang/af/lang.php | 6 +++++ lib/plugins/authplain/lang/ar/lang.php | 6 +++++ lib/plugins/authplain/lang/az/lang.php | 6 +++++ lib/plugins/authplain/lang/bg/lang.php | 6 +++++ lib/plugins/authplain/lang/bn/lang.php | 6 +++++ lib/plugins/authplain/lang/ca-valencia/lang.php | 6 +++++ lib/plugins/authplain/lang/ca/lang.php | 6 +++++ lib/plugins/authplain/lang/cs/lang.php | 6 +++++ lib/plugins/authplain/lang/da/lang.php | 6 +++++ lib/plugins/authplain/lang/de-informal/lang.php | 6 +++++ lib/plugins/authplain/lang/de/lang.php | 6 +++++ lib/plugins/authplain/lang/el/lang.php | 6 +++++ lib/plugins/authplain/lang/en/lang.php | 8 ++++++ lib/plugins/authplain/lang/eo/lang.php | 6 +++++ lib/plugins/authplain/lang/es/lang.php | 6 +++++ lib/plugins/authplain/lang/et/lang.php | 6 +++++ lib/plugins/authplain/lang/eu/lang.php | 6 +++++ lib/plugins/authplain/lang/fa/lang.php | 6 +++++ lib/plugins/authplain/lang/fi/lang.php | 6 +++++ lib/plugins/authplain/lang/fo/lang.php | 6 +++++ lib/plugins/authplain/lang/fr/lang.php | 6 +++++ lib/plugins/authplain/lang/gl/lang.php | 6 +++++ lib/plugins/authplain/lang/he/lang.php | 6 +++++ lib/plugins/authplain/lang/hr/lang.php | 6 +++++ lib/plugins/authplain/lang/hu/lang.php | 6 +++++ lib/plugins/authplain/lang/ia/lang.php | 6 +++++ lib/plugins/authplain/lang/id-ni/lang.php | 6 +++++ lib/plugins/authplain/lang/id/lang.php | 6 +++++ lib/plugins/authplain/lang/is/lang.php | 6 +++++ lib/plugins/authplain/lang/it/lang.php | 6 +++++ lib/plugins/authplain/lang/ja/lang.php | 6 +++++ lib/plugins/authplain/lang/ka/lang.php | 6 +++++ lib/plugins/authplain/lang/kk/lang.php | 6 +++++ lib/plugins/authplain/lang/km/lang.php | 6 +++++ lib/plugins/authplain/lang/ko/lang.php | 6 +++++ lib/plugins/authplain/lang/ku/lang.php | 6 +++++ lib/plugins/authplain/lang/la/lang.php | 6 +++++ lib/plugins/authplain/lang/lb/lang.php | 6 +++++ lib/plugins/authplain/lang/lt/lang.php | 6 +++++ lib/plugins/authplain/lang/lv/lang.php | 6 +++++ lib/plugins/authplain/lang/mg/lang.php | 6 +++++ lib/plugins/authplain/lang/mk/lang.php | 6 +++++ lib/plugins/authplain/lang/mr/lang.php | 6 +++++ lib/plugins/authplain/lang/ms/lang.php | 6 +++++ lib/plugins/authplain/lang/ne/lang.php | 6 +++++ lib/plugins/authplain/lang/nl/lang.php | 6 +++++ lib/plugins/authplain/lang/no/lang.php | 6 +++++ lib/plugins/authplain/lang/pl/lang.php | 6 +++++ lib/plugins/authplain/lang/pt-br/lang.php | 6 +++++ lib/plugins/authplain/lang/pt/lang.php | 6 +++++ lib/plugins/authplain/lang/ro/lang.php | 6 +++++ lib/plugins/authplain/lang/ru/lang.php | 6 +++++ lib/plugins/authplain/lang/sk/lang.php | 6 +++++ lib/plugins/authplain/lang/sl/lang.php | 6 +++++ lib/plugins/authplain/lang/sq/lang.php | 6 +++++ lib/plugins/authplain/lang/sr/lang.php | 6 +++++ lib/plugins/authplain/lang/sv/lang.php | 6 +++++ lib/plugins/authplain/lang/th/lang.php | 6 +++++ lib/plugins/authplain/lang/tr/lang.php | 6 +++++ lib/plugins/authplain/lang/uk/lang.php | 6 +++++ lib/plugins/authplain/lang/vi/lang.php | 6 +++++ lib/plugins/authplain/lang/zh-tw/lang.php | 6 +++++ lib/plugins/authplain/lang/zh/lang.php | 6 +++++ 64 files changed, 400 insertions(+), 13 deletions(-) create mode 100644 lib/plugins/authplain/lang/af/lang.php create mode 100644 lib/plugins/authplain/lang/ar/lang.php create mode 100644 lib/plugins/authplain/lang/az/lang.php create mode 100644 lib/plugins/authplain/lang/bg/lang.php create mode 100644 lib/plugins/authplain/lang/bn/lang.php create mode 100644 lib/plugins/authplain/lang/ca-valencia/lang.php create mode 100644 lib/plugins/authplain/lang/ca/lang.php create mode 100644 lib/plugins/authplain/lang/cs/lang.php create mode 100644 lib/plugins/authplain/lang/da/lang.php create mode 100644 lib/plugins/authplain/lang/de-informal/lang.php create mode 100644 lib/plugins/authplain/lang/de/lang.php create mode 100644 lib/plugins/authplain/lang/el/lang.php create mode 100644 lib/plugins/authplain/lang/en/lang.php create mode 100644 lib/plugins/authplain/lang/eo/lang.php create mode 100644 lib/plugins/authplain/lang/es/lang.php create mode 100644 lib/plugins/authplain/lang/et/lang.php create mode 100644 lib/plugins/authplain/lang/eu/lang.php create mode 100644 lib/plugins/authplain/lang/fa/lang.php create mode 100644 lib/plugins/authplain/lang/fi/lang.php create mode 100644 lib/plugins/authplain/lang/fo/lang.php create mode 100644 lib/plugins/authplain/lang/fr/lang.php create mode 100644 lib/plugins/authplain/lang/gl/lang.php create mode 100644 lib/plugins/authplain/lang/he/lang.php create mode 100644 lib/plugins/authplain/lang/hr/lang.php create mode 100644 lib/plugins/authplain/lang/hu/lang.php create mode 100644 lib/plugins/authplain/lang/ia/lang.php create mode 100644 lib/plugins/authplain/lang/id-ni/lang.php create mode 100644 lib/plugins/authplain/lang/id/lang.php create mode 100644 lib/plugins/authplain/lang/is/lang.php create mode 100644 lib/plugins/authplain/lang/it/lang.php create mode 100644 lib/plugins/authplain/lang/ja/lang.php create mode 100644 lib/plugins/authplain/lang/ka/lang.php create mode 100644 lib/plugins/authplain/lang/kk/lang.php create mode 100644 lib/plugins/authplain/lang/km/lang.php create mode 100644 lib/plugins/authplain/lang/ko/lang.php create mode 100644 lib/plugins/authplain/lang/ku/lang.php create mode 100644 lib/plugins/authplain/lang/la/lang.php create mode 100644 lib/plugins/authplain/lang/lb/lang.php create mode 100644 lib/plugins/authplain/lang/lt/lang.php create mode 100644 lib/plugins/authplain/lang/lv/lang.php create mode 100644 lib/plugins/authplain/lang/mg/lang.php create mode 100644 lib/plugins/authplain/lang/mk/lang.php create mode 100644 lib/plugins/authplain/lang/mr/lang.php create mode 100644 lib/plugins/authplain/lang/ms/lang.php create mode 100644 lib/plugins/authplain/lang/ne/lang.php create mode 100644 lib/plugins/authplain/lang/nl/lang.php create mode 100644 lib/plugins/authplain/lang/no/lang.php create mode 100644 lib/plugins/authplain/lang/pl/lang.php create mode 100644 lib/plugins/authplain/lang/pt-br/lang.php create mode 100644 lib/plugins/authplain/lang/pt/lang.php create mode 100644 lib/plugins/authplain/lang/ro/lang.php create mode 100644 lib/plugins/authplain/lang/ru/lang.php create mode 100644 lib/plugins/authplain/lang/sk/lang.php create mode 100644 lib/plugins/authplain/lang/sl/lang.php create mode 100644 lib/plugins/authplain/lang/sq/lang.php create mode 100644 lib/plugins/authplain/lang/sr/lang.php create mode 100644 lib/plugins/authplain/lang/sv/lang.php create mode 100644 lib/plugins/authplain/lang/th/lang.php create mode 100644 lib/plugins/authplain/lang/tr/lang.php create mode 100644 lib/plugins/authplain/lang/uk/lang.php create mode 100644 lib/plugins/authplain/lang/vi/lang.php create mode 100644 lib/plugins/authplain/lang/zh-tw/lang.php create mode 100644 lib/plugins/authplain/lang/zh/lang.php (limited to 'lib/plugins') diff --git a/lib/plugins/authplain/auth.php b/lib/plugins/authplain/auth.php index b31c02fc8..bd46c61a7 100644 --- a/lib/plugins/authplain/auth.php +++ b/lib/plugins/authplain/auth.php @@ -134,7 +134,10 @@ class auth_plugin_authplain extends DokuWiki_Auth_Plugin { global $config_cascade; // user mustn't already exist - if($this->getUserData($user) !== false) return false; + if($this->getUserData($user) !== false) { + msg($this->getLang('userexists'), -1); + return false; + } $pass = auth_cryptPassword($pwd); @@ -144,16 +147,13 @@ class auth_plugin_authplain extends DokuWiki_Auth_Plugin { // prepare user line $userline = $this->_createUserLine($user, $pass, $name, $mail, $grps); - if(io_saveFile($config_cascade['plainauth.users']['default'], $userline, true)) { - $this->users[$user] = compact('pass', 'name', 'mail', 'grps'); - return $pwd; + if(!io_saveFile($config_cascade['plainauth.users']['default'], $userline, true)) { + msg($this->getLang('writefail'), -1); + return null; } - msg( - 'The '.$config_cascade['plainauth.users']['default']. - ' file is not writable. Please inform the Wiki-Admin', -1 - ); - return null; + $this->users[$user] = compact('pass', 'name', 'mail', 'grps'); + return $pwd; } /** @@ -169,7 +169,10 @@ class auth_plugin_authplain extends DokuWiki_Auth_Plugin { global $config_cascade; // sanity checks, user must already exist and there must be something to change - if(($userinfo = $this->getUserData($user)) === false) return false; + if(($userinfo = $this->getUserData($user)) === false) { + msg($this->getLang('usernotexists'), -1); + return false; + } if(!is_array($changes) || !count($changes)) return true; // update userinfo with new data, remembering to encrypt any password @@ -186,13 +189,14 @@ class auth_plugin_authplain extends DokuWiki_Auth_Plugin { $userline = $this->_createUserLine($newuser, $userinfo['pass'], $userinfo['name'], $userinfo['mail'], $userinfo['grps']); if(!$this->deleteUsers(array($user))) { - msg('Unable to modify user data. Please inform the Wiki-Admin', -1); + msg($this->getLang('writefail'), -1); return false; } if(!io_saveFile($config_cascade['plainauth.users']['default'], $userline, true)) { msg('There was an error modifying your user data. You should register again.', -1); // FIXME, user has been deleted but not recreated, should force a logout and redirect to login page + // Should replace the delete/save hybrid modify with an atomic io_replaceInFile $ACT = 'register'; return false; } @@ -223,7 +227,10 @@ class auth_plugin_authplain extends DokuWiki_Auth_Plugin { if(empty($deleted)) return 0; $pattern = '/^('.join('|', $deleted).'):/'; - io_deleteFromFile($config_cascade['plainauth.users']['default'], $pattern, true); + if (!io_deleteFromFile($config_cascade['plainauth.users']['default'], $pattern, true)) { + msg($this->getLang('writefail'), -1); + return 0; + } // reload the user list and count the difference $count = count($this->users); @@ -407,4 +414,4 @@ class auth_plugin_authplain extends DokuWiki_Auth_Plugin { $this->_pattern[$item] = '/'.str_replace('/', '\/', $pattern).'/i'; // allow regex characters } } -} \ No newline at end of file +} diff --git a/lib/plugins/authplain/lang/af/lang.php b/lib/plugins/authplain/lang/af/lang.php new file mode 100644 index 000000000..29742cfd2 --- /dev/null +++ b/lib/plugins/authplain/lang/af/lang.php @@ -0,0 +1,6 @@ + Date: Wed, 6 May 2015 15:31:08 -0400 Subject: Error reporting for database auth plugins --- lib/plugins/authad/auth.php | 8 ++++++-- lib/plugins/authad/lang/en/lang.php | 6 ++++-- lib/plugins/authldap/auth.php | 8 ++++---- lib/plugins/authldap/lang/en/lang.php | 11 +++++++++++ lib/plugins/authmysql/auth.php | 19 +++++++++++++++++-- lib/plugins/authmysql/lang/en/lang.php | 13 +++++++++++++ 6 files changed, 55 insertions(+), 10 deletions(-) create mode 100644 lib/plugins/authldap/lang/en/lang.php create mode 100644 lib/plugins/authmysql/lang/en/lang.php (limited to 'lib/plugins') diff --git a/lib/plugins/authad/auth.php b/lib/plugins/authad/auth.php index 40c56ef09..60c68efc4 100644 --- a/lib/plugins/authad/auth.php +++ b/lib/plugins/authad/auth.php @@ -522,7 +522,10 @@ class auth_plugin_authad extends DokuWiki_Auth_Plugin { public function modifyUser($user, $changes) { $return = true; $adldap = $this->_adldap($this->_userDomain($user)); - if(!$adldap) return false; + if(!$adldap) { + msg($this->getLang('connectfail'), -1); + return false; + } // password changing if(isset($changes['pass'])) { @@ -532,7 +535,7 @@ class auth_plugin_authad extends DokuWiki_Auth_Plugin { if ($this->conf['debug']) msg('AD Auth: '.$e->getMessage(), -1); $return = false; } - if(!$return) msg('AD Auth: failed to change the password. Maybe the password policy was not met?', -1); + if(!$return) msg($this->getLang('passchangefail'), -1); } // changing user data @@ -554,6 +557,7 @@ class auth_plugin_authad extends DokuWiki_Auth_Plugin { if ($this->conf['debug']) msg('AD Auth: '.$e->getMessage(), -1); $return = false; } + if(!$return) msg($this->getLang('userchangefail'), -1); } return $return; diff --git a/lib/plugins/authad/lang/en/lang.php b/lib/plugins/authad/lang/en/lang.php index 4f96a71fd..751aa9f47 100644 --- a/lib/plugins/authad/lang/en/lang.php +++ b/lib/plugins/authad/lang/en/lang.php @@ -6,7 +6,9 @@ * @author Andreas Gohr */ -$lang['domain'] = 'Logon Domain'; -$lang['authpwdexpire'] = 'Your password will expire in %d days, you should change it soon.'; +$lang['domain'] = 'Logon Domain'; +$lang['authpwdexpire'] = 'Your password will expire in %d days, you should change it soon.'; +$lang['passchangefail'] = 'Failed to change the password. Maybe the password policy was not met?'; +$lang['connectfail'] = 'Failed to connect to Active Directory server.'; //Setup VIM: ex: et ts=4 : diff --git a/lib/plugins/authldap/auth.php b/lib/plugins/authldap/auth.php index 9d031c049..247a0fec2 100644 --- a/lib/plugins/authldap/auth.php +++ b/lib/plugins/authldap/auth.php @@ -281,14 +281,14 @@ class auth_plugin_authldap extends DokuWiki_Auth_Plugin { // open the connection to the ldap if(!$this->_openLDAP()){ - msg('LDAP cannot connect: '. htmlspecialchars(ldap_error($this->con))); + $this->_debug('LDAP cannot connect: '. htmlspecialchars(ldap_error($this->con)), 0, __LINE__, __FILE__); return false; } // find the information about the user, in particular the "dn" $info = $this->getUserData($user,true); if(empty($info['dn'])) { - msg('LDAP cannot find your user dn'); + $this->_debug('LDAP cannot find your user dn', 0, __LINE__, __FILE__); return false; } $dn = $info['dn']; @@ -301,7 +301,7 @@ class auth_plugin_authldap extends DokuWiki_Auth_Plugin { // bind with the ldap if(!@ldap_bind($this->con, $dn, $pass)){ - msg('LDAP user bind failed: '. htmlspecialchars($dn) .': '.htmlspecialchars(ldap_error($this->con)), 0, __LINE__, __FILE__); + $this->_debug('LDAP user bind failed: '. htmlspecialchars($dn) .': '.htmlspecialchars(ldap_error($this->con)), 0, __LINE__, __FILE__); return false; } } elseif ($this->getConf('binddn') && $this->getConf('bindpw')) { @@ -322,7 +322,7 @@ class auth_plugin_authldap extends DokuWiki_Auth_Plugin { // change the password if(!@ldap_mod_replace($this->con, $dn,array('userpassword' => $hash))){ - msg('LDAP mod replace failed: '. htmlspecialchars($dn) .': '.htmlspecialchars(ldap_error($this->con))); + $this->_debug('LDAP mod replace failed: '. htmlspecialchars($dn) .': '.htmlspecialchars(ldap_error($this->con)), 0, __LINE__, __FILE__); return false; } diff --git a/lib/plugins/authldap/lang/en/lang.php b/lib/plugins/authldap/lang/en/lang.php new file mode 100644 index 000000000..db06efb4c --- /dev/null +++ b/lib/plugins/authldap/lang/en/lang.php @@ -0,0 +1,11 @@ +_openDB()) { if(($info = $this->_getUserInfo($user)) !== false) { + msg($this->getLang('userexists'), -1); return false; // user already exists } @@ -235,7 +236,13 @@ class auth_plugin_authmysql extends DokuWiki_Auth_Plugin { $rc = $this->_addUser($user, $pwd, $name, $mail, $grps); $this->_unlockTables(); $this->_closeDB(); - if($rc) return true; + if(!$rc) { + msg($this->getLang('writefail')); + return null; + } + return true; + } else { + msg($this->getLang('connectfail'), -1); } return null; // return error } @@ -279,7 +286,9 @@ class auth_plugin_authmysql extends DokuWiki_Auth_Plugin { $rc = $this->_updateUserInfo($user, $changes); - if($rc && isset($changes['grps']) && $this->cando['modGroups']) { + if(!$rc) { + msg($this->getLang('usernotexists'), -1); + } elseif(isset($changes['grps']) && $this->cando['modGroups']) { $groups = $this->_getGroups($user); $grpadd = array_diff($changes['grps'], $groups); $grpdel = array_diff($groups, $changes['grps']); @@ -295,10 +304,14 @@ class auth_plugin_authmysql extends DokuWiki_Auth_Plugin { $rc = false; } } + + if(!$rc) msg($this->getLang('writefail')); } $this->_unlockTables(); $this->_closeDB(); + } else { + msg($this->getLang('connectfail'), -1); } return $rc; } @@ -328,6 +341,8 @@ class auth_plugin_authmysql extends DokuWiki_Auth_Plugin { $this->_unlockTables(); } $this->_closeDB(); + } else { + msg($this->getLang('connectfail'), -1); } return $count; } diff --git a/lib/plugins/authmysql/lang/en/lang.php b/lib/plugins/authmysql/lang/en/lang.php new file mode 100644 index 000000000..8313616c6 --- /dev/null +++ b/lib/plugins/authmysql/lang/en/lang.php @@ -0,0 +1,13 @@ + Date: Thu, 7 May 2015 01:43:32 -0400 Subject: Fix scrutinizer issues with auth --- lib/plugins/auth.php | 2 +- lib/plugins/authldap/lang/en/lang.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/plugins') diff --git a/lib/plugins/auth.php b/lib/plugins/auth.php index 4799b3a38..036cb0d77 100644 --- a/lib/plugins/auth.php +++ b/lib/plugins/auth.php @@ -295,7 +295,7 @@ class DokuWiki_Auth_Plugin extends DokuWiki_Plugin { */ public function deleteUsers($users) { msg("authorisation method does not allow deleting of users", -1); - return false; + return 0; } /** diff --git a/lib/plugins/authldap/lang/en/lang.php b/lib/plugins/authldap/lang/en/lang.php index db06efb4c..8185a84fa 100644 --- a/lib/plugins/authldap/lang/en/lang.php +++ b/lib/plugins/authldap/lang/en/lang.php @@ -6,6 +6,6 @@ */ $lang['connectfail'] = 'LDAP cannot connect: %s'; -$lang['domainfail' = 'LDAP cannot find your user dn'; +$lang['domainfail'] = 'LDAP cannot find your user dn'; //Setup VIM: ex: et ts=4 : -- cgit v1.2.3