Skip to content

Commit 4329317

Browse files
committed
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 <[email protected]>
1 parent 74396a2 commit 4329317

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

  • apps/files_external/lib/Lib/Storage

apps/files_external/lib/Lib/Storage/SFTP.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,14 @@ private function absPath($path) {
194194
*/
195195
private function hostKeysPath() {
196196
try {
197-
$storage_view = \OCP\Files::getStorage('files_external');
198-
if ($storage_view) {
199-
return \OC::$server->getConfig()->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') .
200-
$storage_view->getAbsolutePath('') .
201-
'ssh_hostKeys';
197+
$userId = \OC_User::getUser();
198+
if (!$userId) {
199+
return false;
202200
}
201+
202+
$view = new \OC\Files\View('/' . $userId . '/files_external');
203+
204+
return $view->getLocalFile('ssh_hostKeys');
203205
} catch (\Exception $e) {
204206
}
205207
return false;

0 commit comments

Comments
 (0)