diff options
author | Daniel Calviño Sánchez <danxuliu@gmail.com> | 2024-06-18 06:37:06 +0200 |
---|---|---|
committer | Daniel Calviño Sánchez <danxuliu@gmail.com> | 2024-06-18 07:06:30 +0200 |
commit | 733e3f62fde59f53e747c5d0f98965b4cd93db9f (patch) | |
tree | 302dbd9131f536b7a896eda6621a558a2865473a /apps | |
parent | 74396a245d4f86795f79721aef5a95359b8c436a (diff) | |
download | nextcloud-server-733e3f62fde59f53e747c5d0f98965b4cd93db9f.tar.gz nextcloud-server-733e3f62fde59f53e747c5d0f98965b4cd93db9f.zip |
fix: Do not log an error when connecting to SFTP without a logged in user
When connecting to a SFTP server from a SFTP storage the host key is
checked against the known host keys stored in a file in the data
directory of the logged in Nextcloud user. The path to the file is
(indirectly) got using "OC_App::getStorage", which logs an error if
called when there is no logged in user; this can happen, for example, if
the storage is used from a background job or a command.
Not being able to read or write the file just causes the host key check
to be skipped, but it has no other consequence. Moreover, even with
logged in users it is likely that the file can not be read either and
the check is also skipped, as the file needs to have been manually
created by an admin.
Due to all that now the path to the file is directly created using a
View rather than relying on "OC_App::getStorage" to prevent the unneeded
error from being logged.
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Diffstat (limited to 'apps')
-rw-r--r-- | apps/files_external/lib/Lib/Storage/SFTP.php | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/apps/files_external/lib/Lib/Storage/SFTP.php b/apps/files_external/lib/Lib/Storage/SFTP.php index 2a60c996974..6046b7266f5 100644 --- a/apps/files_external/lib/Lib/Storage/SFTP.php +++ b/apps/files_external/lib/Lib/Storage/SFTP.php @@ -194,12 +194,14 @@ class SFTP extends Common { */ private function hostKeysPath() { try { - $storage_view = \OCP\Files::getStorage('files_external'); - if ($storage_view) { - return \OC::$server->getConfig()->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . - $storage_view->getAbsolutePath('') . - 'ssh_hostKeys'; + $userId = \OC_User::getUser(); + if ($userId === false) { + return false; } + + $view = new \OC\Files\View('/' . $userId . '/files_external'); + + return $view->getLocalFile('ssh_hostKeys'); } catch (\Exception $e) { } return false; |