From 13b76d9b1e56d5a20d854515932e7d055b2b92fd Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Sat, 4 Jun 2016 08:56:16 +0200 Subject: [PATCH] Enigma: Add possibility to configure gpg binary location (enigma_pgp_binary) --- CHANGELOG | 1 + plugins/enigma/config.inc.php.dist | 4 +++ plugins/enigma/lib/enigma_driver_gnupg.php | 34 +++++++++++++++------- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 715e65ea2..90db2ba5d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -21,6 +21,7 @@ CHANGELOG Roundcube Webmail - Fix bug where "no body" alert could be displayed when sending mailvelope email - Enigma: Fix keys import from inside of an encrypted message (#5285) - Enigma: Fix malformed signed messages with force_7bit=true (#5292) +- Enigma: Add possibility to configure gpg binary location (enigma_pgp_binary) - Fix searching by email address in contacts with multiple addresses (#5291) - Fix handling of --delete argument in moduserprefs.sh script (#5296) - Workaround PHP issue by calling closelog() on script shutdown when using log_driver=syslog (#5289) diff --git a/plugins/enigma/config.inc.php.dist b/plugins/enigma/config.inc.php.dist index 2b9b84641..d65aba7bb 100644 --- a/plugins/enigma/config.inc.php.dist +++ b/plugins/enigma/config.inc.php.dist @@ -16,6 +16,10 @@ $config['enigma_debug'] = false; // Must be writeable by PHP process $config['enigma_pgp_homedir'] = null; +// Location of gpg binary. By default it will be auto-detected. +// This is also a way to force gpg2 use if there are both 1.x and 2.x on the system. +$config['enigma_pgp_binary'] = ''; + // Enables signatures verification feature. $config['enigma_signatures'] = true; diff --git a/plugins/enigma/lib/enigma_driver_gnupg.php b/plugins/enigma/lib/enigma_driver_gnupg.php index 9a8e59eea..2732f489d 100644 --- a/plugins/enigma/lib/enigma_driver_gnupg.php +++ b/plugins/enigma/lib/enigma_driver_gnupg.php @@ -41,41 +41,53 @@ class enigma_driver_gnupg extends enigma_driver { $homedir = $this->rc->config->get('enigma_pgp_homedir', INSTALL_PATH . 'plugins/enigma/home'); $debug = $this->rc->config->get('enigma_debug'); + $binary = $this->rc->config->get('enigma_pgp_binary'); - if (!$homedir) + if (!$homedir) { return new enigma_error(enigma_error::INTERNAL, "Option 'enigma_pgp_homedir' not specified"); + } // check if homedir exists (create it if not) and is readable - if (!file_exists($homedir)) + if (!file_exists($homedir)) { return new enigma_error(enigma_error::INTERNAL, "Keys directory doesn't exists: $homedir"); - if (!is_writable($homedir)) + } + if (!is_writable($homedir)) { return new enigma_error(enigma_error::INTERNAL, "Keys directory isn't writeable: $homedir"); + } $homedir = $homedir . '/' . $this->user; // check if user's homedir exists (create it if not) and is readable - if (!file_exists($homedir)) + if (!file_exists($homedir)) { mkdir($homedir, 0700); + } - if (!file_exists($homedir)) + if (!file_exists($homedir)) { return new enigma_error(enigma_error::INTERNAL, "Unable to create keys directory: $homedir"); - if (!is_writable($homedir)) + } + if (!is_writable($homedir)) { return new enigma_error(enigma_error::INTERNAL, "Unable to write to keys directory: $homedir"); + } $this->homedir = $homedir; + $options = array('homedir' => $this->homedir); + + if ($debug) { + $options['debug'] = array($this, 'debug'); + } + if ($binary) { + $options['binary'] = $binary; + } + // Create Crypt_GPG object try { - $this->gpg = new Crypt_GPG(array( - 'homedir' => $this->homedir, - // 'binary' => '/usr/bin/gpg2', - 'debug' => $debug ? array($this, 'debug') : false, - )); + $this->gpg = new Crypt_GPG($options); } catch (Exception $e) { return $this->get_error_from_exception($e);