Improved GPGP homedir detection for #208

This commit is contained in:
the-djmaze 2022-02-04 14:44:38 +01:00
parent 3aa319b230
commit 7fec4e849b

View file

@ -30,6 +30,7 @@ trait Pgp
if (80 < \strlen($homedir)) {
// First try a symbolic link
$tmpdir = \sys_get_temp_dir() . '/snappymail';
// if (\RainLoop\Utils::inOpenBasedir($tmpdir) &&
if (\is_dir($tmpdir) || \mkdir($tmpdir, 0700, true)) {
$link = $tmpdir . '/' . \md5($homedir);
if (\is_link($link) || \symlink($homedir, $link)) {
@ -38,11 +39,15 @@ trait Pgp
}
// Else try ~/.gnupg/ + hash(email address)
if (80 < \strlen($homedir)) {
$homedir = ($_SERVER['HOME'] ?: \exec('echo ~')) . '/.gnupg/';
$tmpdir = ($_SERVER['HOME'] ?: \exec('echo ~') ?: \dirname(getcwd())) . '/.gnupg/';
if ($oAccount instanceof \RainLoop\Model\AdditionalAccount) {
$homedir .= \sha1($oAccount->ParentEmail());
$tmpdir .= \sha1($oAccount->ParentEmail());
} else {
$homedir .= \sha1($oAccount->Email());
$tmpdir .= \sha1($oAccount->Email());
}
// if (\RainLoop\Utils::inOpenBasedir($tmpdir) &&
if (\is_dir($tmpdir) || \mkdir($tmpdir, 0700, true)) {
$homedir = $link;
}
}
}