From a00f68b4c10dd802ad4ca7f3abcde6038034a75d Mon Sep 17 00:00:00 2001 From: exi Date: Sun, 3 Mar 2024 22:44:26 +0100 Subject: [PATCH] feat: make search path for BinaryFinder customizable. This feature is important for nextcloud running on distributions like NixOS, where all the standard search paths do not exist. This fixes issue #43922 Signed-off-by: exi --- config/config.sample.php | 18 +++++++++++++++++- lib/private/BinaryFinder.php | 29 +++++++++++++++++++---------- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/config/config.sample.php b/config/config.sample.php index c21291cd3da03..47bc87d128a26 100644 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -1962,7 +1962,7 @@ /** * Blacklist characters from being used in filenames. This is useful if you * have a filesystem or OS which does not support certain characters like windows. - * + * * The '/' and '\' characters are always forbidden. * * Example for windows systems: ``array('?', '<', '>', ':', '*', '|', '"', chr(0), "\n", "\r")`` @@ -2431,4 +2431,20 @@ * Defaults to ``true`` */ 'enable_non-accessible_features' => true, + +/** + * Directories where nextcloud looks for binaries. + * This is used to find external binaries like libreoffice, sendmail, ffmpeg and more. + * + * Defaults to ``['/usr/local/sbin','/usr/local/bin','/usr/sbin','/usr/bin','/sbin','/bin','/opt/bin']`` + */ +'binary_search_paths' => [ + '/usr/local/sbin', + '/usr/local/bin', + '/usr/sbin', + '/usr/bin', + '/sbin', + '/bin', + '/opt/bin', +], ]; diff --git a/lib/private/BinaryFinder.php b/lib/private/BinaryFinder.php index 17427e9261932..30c80d8987c70 100644 --- a/lib/private/BinaryFinder.php +++ b/lib/private/BinaryFinder.php @@ -3,6 +3,7 @@ declare(strict_types = 1); /** * @copyright 2022 Carl Schwan + * @copyright 2024 Reno Reckling * @license GNU AGPL version 3 or any later version * * This program is free software: you can redistribute it and/or modify @@ -25,15 +26,28 @@ use OCP\IBinaryFinder; use OCP\ICache; use OCP\ICacheFactory; +use OCP\IConfig; use Symfony\Component\Process\ExecutableFinder; /** * Service that find the binary path for a program */ class BinaryFinder implements IBinaryFinder { + public const DEFAULT_BINARY_SEARCH_PATHS = [ + '/usr/local/sbin', + '/usr/local/bin', + '/usr/sbin', + '/usr/bin', + '/sbin', + '/bin', + '/opt/bin', + ]; private ICache $cache; - public function __construct(ICacheFactory $cacheFactory) { + public function __construct( + ICacheFactory $cacheFactory, + private IConfig $config + ) { $this->cache = $cacheFactory->createLocal('findBinaryPath'); } @@ -51,15 +65,10 @@ public function findBinaryPath(string $program) { if (\OCP\Util::isFunctionEnabled('exec')) { $exeSniffer = new ExecutableFinder(); // Returns null if nothing is found - $result = $exeSniffer->find($program, null, [ - '/usr/local/sbin', - '/usr/local/bin', - '/usr/sbin', - '/usr/bin', - '/sbin', - '/bin', - '/opt/bin', - ]); + $result = $exeSniffer->find( + $program, + null, + $this->config->getSystemValue('binary_search_paths', self::DEFAULT_BINARY_SEARCH_PATHS)); if ($result === null) { $result = false; }