This commit is contained in:
the-djmaze 2024-07-11 00:25:26 +02:00
parent 57d1021d51
commit 95436347e5
8 changed files with 22 additions and 20 deletions

View file

@ -722,4 +722,19 @@ abstract class Utils
$aParts[] = $sDomain; $aParts[] = $sDomain;
return \implode('@', $aParts); return \implode('@', $aParts);
} }
public static function mkdir(string $directory) : void
{
if (!\is_dir($directory)) {
if (!\mkdir($directory, 0700, true)) {
throw new \RuntimeException("Failed to create directory {$directory}");
}
\clearstatcache();
}
/*
if (!\is_writable($directory)) {
throw new \Exception("Failed to access directory {$directory}");
}
*/
}
} }

View file

@ -25,6 +25,7 @@ class File implements \MailSo\Cache\DriverInterface
function __construct(string $sCacheFolder) function __construct(string $sCacheFolder)
{ {
$this->sCacheFolder = \rtrim(\trim($sCacheFolder), '\\/').'/'; $this->sCacheFolder = \rtrim(\trim($sCacheFolder), '\\/').'/';
\MailSo\Base\Utils::mkdir($this->sCacheFolder);
// http://www.brynosaurus.com/cachedir/ // http://www.brynosaurus.com/cachedir/
$tag = $this->sCacheFolder . 'CACHEDIR.TAG'; $tag = $this->sCacheFolder . 'CACHEDIR.TAG';

View file

@ -59,9 +59,7 @@ trait Pgp
\RainLoop\Providers\Storage\Enumerations\StorageType::ROOT \RainLoop\Providers\Storage\Enumerations\StorageType::ROOT
), '/') . '/.gnupg'; ), '/') . '/.gnupg';
if (!\is_dir($homedir)) { \MailSo\Base\Utils::mkdir($homedir);
\mkdir($homedir, 0700, true);
}
if (!\is_writable($homedir)) { if (!\is_writable($homedir)) {
throw new \Exception("gpg homedir '{$homedir}' not writable"); throw new \Exception("gpg homedir '{$homedir}' not writable");
} }

View file

@ -22,9 +22,7 @@ trait SMime
\RainLoop\Providers\Storage\Enumerations\StorageType::ROOT \RainLoop\Providers\Storage\Enumerations\StorageType::ROOT
), '/') . '/.smime'; ), '/') . '/.smime';
if (!\is_dir($homedir)) { \MailSo\Base\Utils::mkdir($homedir);
\mkdir($homedir, 0700, true);
}
if (!\is_writable($homedir)) { if (!\is_writable($homedir)) {
throw new \Exception("smime homedir '{$homedir}' not writable"); throw new \Exception("smime homedir '{$homedir}' not writable");
} }

View file

@ -147,9 +147,7 @@ class FileStorage implements \RainLoop\Providers\Files\IFiles
.($sSubEmail ? '/'.\MailSo\Base\Utils::SecureFileName($sSubEmail) : '') .($sSubEmail ? '/'.\MailSo\Base\Utils::SecureFileName($sSubEmail) : '')
.'/.files/'.\sha1($sKey); .'/.files/'.\sha1($sKey);
if ($bMkDir && !\is_dir(\dirname($sFilePath)) && !\mkdir(\dirname($sFilePath), 0700, true)) { $bMkDir && \MailSo\Base\Utils::mkdir(\dirname($sFilePath));
throw new \RuntimeException('Can\'t make storage directory "'.$sFilePath.'"');
}
return $sFilePath; return $sFilePath;
} }

View file

@ -143,10 +143,7 @@ class FileStorage implements \RainLoop\Providers\Storage\IStorage
} }
} }
if ($bMkDir && !empty($sFilePath) && !\is_dir($sFilePath) && !\mkdir($sFilePath, 0700, true)) $bMkDir && !empty($sFilePath) && \MailSo\Base\Utils::mkdir($sFilePath);
{
throw new \RuntimeException('Can\'t make storage directory "'.$sFilePath.'"');
}
return $sFilePath; return $sFilePath;
} }

View file

@ -10,13 +10,7 @@ class Temporary
{ {
$tmpdir = \sys_get_temp_dir() . '/snappymail'; $tmpdir = \sys_get_temp_dir() . '/snappymail';
// if (\RainLoop\Utils::inOpenBasedir($tmpdir) && // if (\RainLoop\Utils::inOpenBasedir($tmpdir) &&
\is_dir($tmpdir) || \mkdir($tmpdir, 0700); \MailSo\Base\Utils::mkdir($tmpdir);
if (!\is_dir($tmpdir)) {
throw new \Exception("Failed to create directory {$tmpdir}");
}
if (!\is_writable($tmpdir)) {
// throw new \Exception("Failed to access directory {$tmpdir}");
}
if ($prefix) { if ($prefix) {
$this->filename = @\tempnam($tmpdir, $name); $this->filename = @\tempnam($tmpdir, $name);
} else { } else {

View file

@ -17,6 +17,7 @@ abstract class Upgrade
$sNewDir = $sDataPath $sNewDir = $sDataPath
.'/'.\MailSo\Base\Utils::SecureFileName($sDomain ?: 'unknown.tld') .'/'.\MailSo\Base\Utils::SecureFileName($sDomain ?: 'unknown.tld')
.'/'.\MailSo\Base\Utils::SecureFileName(\implode('@', $aEmail) ?: '.unknown'); .'/'.\MailSo\Base\Utils::SecureFileName(\implode('@', $aEmail) ?: '.unknown');
// \MailSo\Base\Utils::mkdir($sNewDir)
if (\is_dir($sNewDir) || \mkdir($sNewDir, 0700, true)) { if (\is_dir($sNewDir) || \mkdir($sNewDir, 0700, true)) {
foreach (\glob("{$sDomainDir}/*") as $sItem) { foreach (\glob("{$sDomainDir}/*") as $sItem) {
$sName = \basename($sItem); $sName = \basename($sItem);