From 113ab02f54d37ed68f0721c4414b30e0fd3af245 Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Tue, 12 Jan 2021 16:56:23 +0000 Subject: [PATCH 1/2] reformat; add to CHANGELOG --- CHANGELOG.TXT | 4 ++++ functions.inc.php | 4 +--- tests/PacryptTest.php | 31 ++++++++++--------------------- 3 files changed, 15 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.TXT b/CHANGELOG.TXT index 129ceeb1..c0dd040f 100644 --- a/CHANGELOG.TXT +++ b/CHANGELOG.TXT @@ -6,6 +6,10 @@ # # Further details on the project are available at https://github.com/postfixadmin/postfixadmin +Version 3.3.2 - 2021/01/12 +------------------------------------------------- + - Add in the ability to specify a hash prefix (useful for Dovecot replacement) see also: https://github.com/postfixadmin/postfixadmin/issues/344 + Version 3.3.1 - 2021/01/11 ------------------------------------------------- diff --git a/functions.inc.php b/functions.inc.php index 555d8c02..f7fbf28a 100644 --- a/functions.inc.php +++ b/functions.inc.php @@ -1084,8 +1084,7 @@ function _pacrypt_dovecot($pw, $pw_db = '') { * @param string $pw_db (can be empty if setting a new password) * @return string crypt'ed password; if it matches $pw_db then $pw is the original password. */ -function _pacrypt_php_crypt($pw, $pw_db) -{ +function _pacrypt_php_crypt($pw, $pw_db) { $configEncrypt = Config::read_string('encrypt'); // use PHPs crypt(), which uses the system's crypt() @@ -1110,7 +1109,6 @@ function _pacrypt_php_crypt($pw, $pw_db) $salt = $method_matches[2]; $prefix = "{" . $method_matches[1] . "}"; } - } else { $salt_method = 'SHA512'; // hopefully a reasonable default (better than MD5) $hash_difficulty = ''; diff --git a/tests/PacryptTest.php b/tests/PacryptTest.php index 8cbeb946..614fbf17 100644 --- a/tests/PacryptTest.php +++ b/tests/PacryptTest.php @@ -1,9 +1,7 @@ assertNotEmpty($hash); @@ -12,8 +10,7 @@ class PaCryptTest extends \PHPUnit\Framework\TestCase $this->assertEquals($hash, _pacrypt_md5crypt('test', $hash)); } - public function testCrypt() - { + public function testCrypt() { // E_NOTICE if we pass in '' for the salt $hash = _pacrypt_crypt('test', 'sa'); @@ -24,8 +21,7 @@ class PaCryptTest extends \PHPUnit\Framework\TestCase $this->assertEquals($hash, _pacrypt_crypt('test', $hash)); } - public function testMySQLEncrypt() - { + public function testMySQLEncrypt() { if (!db_mysql()) { $this->markTestSkipped('Not using MySQL'); } @@ -49,8 +45,7 @@ class PaCryptTest extends \PHPUnit\Framework\TestCase ); } - public function testAuthlib() - { + public function testAuthlib() { global $CONF; // too many options! @@ -71,8 +66,7 @@ class PaCryptTest extends \PHPUnit\Framework\TestCase } } - public function testPacryptDovecot() - { + public function testPacryptDovecot() { global $CONF; if (!file_exists('/usr/bin/doveadm')) { $this->markTestSkipped("No /usr/bin/doveadm"); @@ -88,8 +82,7 @@ class PaCryptTest extends \PHPUnit\Framework\TestCase $this->assertEquals($expected_hash, _pacrypt_dovecot('test', $expected_hash)); } - public function testPhpCrypt() - { + public function testPhpCrypt() { $config = Config::getInstance(); Config::write('encrypt', 'php_crypt:MD5'); @@ -103,11 +96,9 @@ class PaCryptTest extends \PHPUnit\Framework\TestCase $this->assertEquals($enc, $expected); $fail = _pacrypt_php_crypt('bar', $expected); - } - public function testPhpCryptHandlesPrefixAndOrRounds() - { + public function testPhpCryptHandlesPrefixAndOrRounds() { // try with 1000 rounds Config::write('encrypt', 'php_crypt:SHA256:1000'); $password = 'hello'; @@ -140,8 +131,7 @@ class PaCryptTest extends \PHPUnit\Framework\TestCase $this->assertGreaterThan(20, strlen($enc)); } - public function testPhpCryptRandomString() - { + public function testPhpCryptRandomString() { $str1 = _php_crypt_random_string('abcdefg123456789', 2); $str2 = _php_crypt_random_string('abcdefg123456789', 2); $str3 = _php_crypt_random_string('abcdefg123456789', 2); @@ -155,8 +145,7 @@ class PaCryptTest extends \PHPUnit\Framework\TestCase $this->assertFalse(strcmp($str1, $str2) == 0 && strcmp($str1, $str3) == 0); } - public function testSha512B64() - { + public function testSha512B64() { $str1 = _pacrypt_sha512_b64('test', ''); $str2 = _pacrypt_sha512_b64('test', ''); From c56983c6dec173c6350b4d5bb5748de5f9fd2efb Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Tue, 12 Jan 2021 16:57:30 +0000 Subject: [PATCH 2/2] try and improve the debian postinst script for (templates_c) --- debian/postfixadmin.postinst | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/debian/postfixadmin.postinst b/debian/postfixadmin.postinst index fd38931b..9e15b504 100644 --- a/debian/postfixadmin.postinst +++ b/debian/postfixadmin.postinst @@ -19,16 +19,25 @@ if [ "$(readlink /etc/lighttpd/conf-available/postfixadmin)" = "../../postfixadm rm -f /etc/lighttpd/conf-available/postfixadmin fi +# Try and avoid templates_c being in /usr/share/postfixadmin and ensure it's writeable by the webserver +if [ ! -d /var/cache/postfixadmin ]; then + mkdir -p /var/cache/postfixadmin + chown www-data:root /var/cache/postfixadmin + chmod 700 /var/cache/postfixadmin + ln -s /var/cache/postfixadmin /usr/share/postfixadmin/templates_c +fi + # See : https://sourceforge.net/p/postfixadmin/bugs/376/ - remove any existing templates_c files on upgrade. if [ -d /usr/share/postfixadmin/templates_c ]; then - find /usr/share/postfixadmin/templates_c -type f -exec rm -r {} \; + find /usr/share/postfixadmin/templates_c -type f -delete fi + if [ -d /usr/share/postfixadmin/templates_c ]; then chown www-data /usr/share/postfixadmin/templates_c fi if [ -d /var/cache/postfixadmin ]; then - find /var/cache/postfixadmin -type f -exec rm -r {} \; + find /var/cache/postfixadmin -type f -delete chown www-data /var/cache/postfixadmin fi