From 7f1b870d302421972c4f6221ae6d93b5979d51dd Mon Sep 17 00:00:00 2001 From: KernelDeimos Date: Tue, 8 Oct 2024 18:31:39 -0400 Subject: [PATCH] feat: support readdir for directory symlinks --- .../src/filesystem/hl_operations/hl_readdir.js | 15 +++++++++++++-- .../src/filesystem/ll_operations/ll_readdir.js | 16 +++++++++++++++- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/backend/src/filesystem/hl_operations/hl_readdir.js b/src/backend/src/filesystem/hl_operations/hl_readdir.js index 1c4dd19a..a6bb9c0e 100644 --- a/src/backend/src/filesystem/hl_operations/hl_readdir.js +++ b/src/backend/src/filesystem/hl_operations/hl_readdir.js @@ -18,7 +18,7 @@ */ const APIError = require("../../api/APIError"); const { chkperm } = require("../../helpers"); -const { TYPE_DIRECTORY } = require("../FSNodeContext"); +const { TYPE_DIRECTORY, TYPE_SYMLINK } = require("../FSNodeContext"); const { LLListUsers } = require("../ll_operations/ll_listusers"); const { LLReadDir } = require("../ll_operations/ll_readdir"); const { LLReadShares } = require("../ll_operations/ll_readshares"); @@ -26,12 +26,23 @@ const { HLFilesystemOperation } = require("./definitions"); class HLReadDir extends HLFilesystemOperation { async _run () { - const { subject, user, no_thumbs, no_assocs, actor } = this.values; + const { subject: subject_let, user, no_thumbs, no_assocs, actor } = this.values; + let subject = subject_let; if ( ! await subject.exists() ) { throw APIError.create('subject_does_not_exist'); } + if ( await subject.get('type') === TYPE_SYMLINK ) { + const { context } = this; + const svc_acl = context.get('services').get('acl'); + if ( ! await svc_acl.check(actor, subject, 'read') ) { + throw await svc_acl.get_safe_acl_error(actor, subject, 'read'); + } + const target = await subject.getTarget(); + subject = target; + } + if ( await subject.get('type') !== TYPE_DIRECTORY ) { const { context } = this; const svc_acl = context.get('services').get('acl'); diff --git a/src/backend/src/filesystem/ll_operations/ll_readdir.js b/src/backend/src/filesystem/ll_operations/ll_readdir.js index 288f305e..5a07dcbb 100644 --- a/src/backend/src/filesystem/ll_operations/ll_readdir.js +++ b/src/backend/src/filesystem/ll_operations/ll_readdir.js @@ -17,6 +17,7 @@ * along with this program. If not, see . */ const APIError = require("../../api/APIError"); +const { TYPE_SYMLINK } = require("../FSNodeContext"); const { RootNodeSelector } = require("../node/selectors"); const { NodeUIDSelector, NodeChildSelector } = require("../node/selectors"); const { LLFilesystemOperation } = require("./definitions"); @@ -24,7 +25,8 @@ const { LLFilesystemOperation } = require("./definitions"); class LLReadDir extends LLFilesystemOperation { async _run () { const { context } = this; - const { subject, user, actor, no_acl } = this.values; + const { subject: subject_let, user, actor, no_acl } = this.values; + let subject = subject_let; if ( ! await subject.exists() ) { throw APIError.create('subject_does_not_exist'); @@ -37,6 +39,18 @@ class LLReadDir extends LLFilesystemOperation { } } + // TODO: DRY ACL check here + const subject_type = await subject.get('type'); + if ( subject_type === TYPE_SYMLINK ) { + const target = await subject.getTarget(); + if ( ! no_acl ) { + if ( ! await svc_acl.check(actor, target, 'list') ) { + throw await svc_acl.get_safe_acl_error(actor, target, 'list'); + } + } + subject = target; + } + const subject_uuid = await subject.get('uid'); const svc = context.get('services');