diff options
author | Gerry Weißbach <gerry.w@gammaproduction.de> | 2014-12-22 10:40:15 +0100 |
---|---|---|
committer | Gerry Weißbach <gerry.w@gammaproduction.de> | 2014-12-22 10:40:15 +0100 |
commit | fc30ac3acbd4e17e25955ccdd0c5539ee2c9beca (patch) | |
tree | 3d287ae466500a6072b84d14ff4911fa936d1479 /lib/plugins/authplain | |
parent | de4634ec87b1a277c1686990d993dafc43db05ed (diff) | |
parent | 8da2ebf4f4261eb8f54df5704b5d9af283b5402d (diff) | |
download | rpg-fc30ac3acbd4e17e25955ccdd0c5539ee2c9beca.tar.gz rpg-fc30ac3acbd4e17e25955ccdd0c5539ee2c9beca.tar.bz2 |
Merge branch 'master' into new_css.php
Diffstat (limited to 'lib/plugins/authplain')
-rw-r--r-- | lib/plugins/authplain/_test/escaping.test.php | 48 | ||||
-rw-r--r-- | lib/plugins/authplain/auth.php | 39 |
2 files changed, 79 insertions, 8 deletions
diff --git a/lib/plugins/authplain/_test/escaping.test.php b/lib/plugins/authplain/_test/escaping.test.php index cd5294157..9df96389a 100644 --- a/lib/plugins/authplain/_test/escaping.test.php +++ b/lib/plugins/authplain/_test/escaping.test.php @@ -12,13 +12,14 @@ * @group plugins */ class helper_plugin_authplain_escaping_test extends DokuWikiTest { - - protected $pluginsEnabled = array('authplain'); + + protected $pluginsEnabled = array('authplainharness'); + /** @var auth_plugin_authplain|auth_plugin_authplainharness */ protected $auth; - + protected function reloadUsers() { /* auth caches data loaded from file, but recreated object forces reload */ - $this->auth = new auth_plugin_authplain(); + $this->auth = new auth_plugin_authplainharness(); } function setUp() { @@ -76,7 +77,44 @@ class helper_plugin_authplain_escaping_test extends DokuWikiTest { $this->assertEquals($saved['name'], $user['name']); $this->assertTrue($this->auth->checkPass("testuser", $user['pass'])); } + + // really only required for developers to ensure this plugin will + // work with systems running on PCRE 6.6 and lower. + public function testLineSplit(){ + $this->auth->setPregsplit_safe(false); + + $names = array( + 'plain', + 'ut-fठ8', + 'colon:', + 'backslash\\', + 'alltogether\\ठ:' + ); + $userpass = 'user:password_hash:'; + $other_user_data = ':email@address:group1,group2'; + + foreach ($names as $testname) { + $escaped = str_replace(array('\\',':'),array('\\\\','\\:'),$testname); // escape : & \ + $test_line = $userpass.$escaped.$other_user_data; + $result = $this->auth->splitUserData($test_line); + + $this->assertEquals($escaped, $result[2]); + } + } } -?>
\ No newline at end of file +class auth_plugin_authplainharness extends auth_plugin_authplain { + + public function setPregsplit_safe($bool) { + $this->_pregsplit_safe = $bool; + } + + public function getPregsplit_safe(){ + return $this->_pregsplit_safe; + } + + public function splitUserData($line){ + return $this->_splitUserData($line); + } +} diff --git a/lib/plugins/authplain/auth.php b/lib/plugins/authplain/auth.php index e53f56667..fd2d0b249 100644 --- a/lib/plugins/authplain/auth.php +++ b/lib/plugins/authplain/auth.php @@ -17,6 +17,9 @@ class auth_plugin_authplain extends DokuWiki_Auth_Plugin { /** @var array filter pattern */ protected $_pattern = array(); + /** @var bool safe version of preg_split */ + protected $_pregsplit_safe = false; + /** * Constructor * @@ -44,6 +47,8 @@ class auth_plugin_authplain extends DokuWiki_Auth_Plugin { $this->cando['getUsers'] = true; $this->cando['getUserCount'] = true; } + + $this->_pregsplit_safe = version_compare(PCRE_VERSION,'6.7','>='); } /** @@ -76,9 +81,10 @@ class auth_plugin_authplain extends DokuWiki_Auth_Plugin { * * @author Andreas Gohr <andi@splitbrain.org> * @param string $user - * @return array|bool + * @param bool $requireGroups (optional) ignored by this plugin, grps info always supplied + * @return array|false */ - public function getUserData($user) { + public function getUserData($user, $requireGroups=true) { if($this->users === null) $this->_loadUserData(); return isset($this->users[$user]) ? $this->users[$user] : false; } @@ -328,7 +334,7 @@ class auth_plugin_authplain extends DokuWiki_Auth_Plugin { if(empty($line)) continue; /* NB: preg_split can be deprecated/replaced with str_getcsv once dokuwiki is min php 5.3 */ - $row = preg_split('/(?<![^\\\\]\\\\)\:/', $line, 5); // allow for : escaped as \: + $row = $this->_splitUserData($line); $row = str_replace('\\:', ':', $row); $row = str_replace('\\\\', '\\', $row); @@ -341,6 +347,33 @@ class auth_plugin_authplain extends DokuWiki_Auth_Plugin { } } + protected function _splitUserData($line){ + // due to a bug in PCRE 6.6, preg_split will fail with the regex we use here + // refer github issues 877 & 885 + if ($this->_pregsplit_safe){ + return preg_split('/(?<![^\\\\]\\\\)\:/', $line, 5); // allow for : escaped as \: + } + + $row = array(); + $piece = ''; + $len = strlen($line); + for($i=0; $i<$len; $i++){ + if ($line[$i]=='\\'){ + $piece .= $line[$i]; + $i++; + if ($i>=$len) break; + } else if ($line[$i]==':'){ + $row[] = $piece; + $piece = ''; + continue; + } + $piece .= $line[$i]; + } + $row[] = $piece; + + return $row; + } + /** * return true if $user + $info match $filter criteria, false otherwise * |