2014-05-12 12:41:46 -04:00
|
|
|
/*
|
2026-02-23 13:22:21 -06:00
|
|
|
ISC License
|
|
|
|
|
|
|
|
|
|
Copyright (c) 2026, Antonio SJ Musumeci <trapexit@spawn.link>
|
2016-01-14 16:50:22 -05:00
|
|
|
|
|
|
|
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
|
purpose with or without fee is hereby granted, provided that the above
|
|
|
|
|
copyright notice and this permission notice appear in all copies.
|
|
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
2014-05-12 12:41:46 -04:00
|
|
|
*/
|
|
|
|
|
|
2025-09-17 23:51:16 -04:00
|
|
|
#include "fuse_access.hpp"
|
|
|
|
|
|
2014-05-12 12:41:46 -04:00
|
|
|
#include "config.hpp"
|
2016-09-14 08:36:06 -04:00
|
|
|
#include "errno.hpp"
|
2020-08-17 16:29:22 -04:00
|
|
|
#include "fs_eaccess.hpp"
|
2015-09-15 18:49:18 -04:00
|
|
|
#include "fs_path.hpp"
|
2014-05-12 12:41:46 -04:00
|
|
|
|
2019-09-24 10:27:46 -04:00
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
2020-12-19 15:06:08 -05:00
|
|
|
|
2025-09-17 23:51:16 -04:00
|
|
|
static
|
|
|
|
|
int
|
|
|
|
|
_access(const Policy::Search &searchFunc_,
|
FUSE: pass Branches::Ptr by value with empty-branches guards
Previously most FUSE ops took a reference to the live cfg.branches
object. With atomic_load now producing a shared_ptr snapshot, pass
it by value: the op works against a single stable view of the
configuration for its whole lifetime, immune to concurrent
reconfiguration.
Also bail out with -ENOENT when the policy returns an empty branch
set rather than dereferencing branches[0]. This was reachable if a
policy rejected every branch (e.g. everything readonly while
looking for a writable target).
Covers access, chmod, chown, create, getattr, getxattr, ioctl,
link, listxattr, mkdir, mknod, open, readdir (cor/cosr),
readlink, removexattr, rename, rmdir, setxattr, statfs, statx,
symlink, truncate, unlink, utimens.
While here, in _getattr only dereference st_->st_mode when lstat
succeeded (it is otherwise uninitialized).
2026-04-18 00:56:15 -04:00
|
|
|
const Branches::Ptr branches_,
|
2025-09-17 23:51:16 -04:00
|
|
|
const fs::path &fusepath_,
|
|
|
|
|
const int mask_)
|
2014-05-12 12:41:46 -04:00
|
|
|
{
|
2025-09-17 23:51:16 -04:00
|
|
|
int rv;
|
|
|
|
|
StrVec basepaths;
|
|
|
|
|
fs::path fullpath;
|
|
|
|
|
std::vector<Branch*> branches;
|
2014-05-12 12:41:46 -04:00
|
|
|
|
2025-09-17 23:51:16 -04:00
|
|
|
rv = searchFunc_(branches_,fusepath_,branches);
|
|
|
|
|
if(rv < 0)
|
|
|
|
|
return rv;
|
FUSE: pass Branches::Ptr by value with empty-branches guards
Previously most FUSE ops took a reference to the live cfg.branches
object. With atomic_load now producing a shared_ptr snapshot, pass
it by value: the op works against a single stable view of the
configuration for its whole lifetime, immune to concurrent
reconfiguration.
Also bail out with -ENOENT when the policy returns an empty branch
set rather than dereferencing branches[0]. This was reachable if a
policy rejected every branch (e.g. everything readonly while
looking for a writable target).
Covers access, chmod, chown, create, getattr, getxattr, ioctl,
link, listxattr, mkdir, mknod, open, readdir (cor/cosr),
readlink, removexattr, rename, rmdir, setxattr, statfs, statx,
symlink, truncate, unlink, utimens.
While here, in _getattr only dereference st_->st_mode when lstat
succeeded (it is otherwise uninitialized).
2026-04-18 00:56:15 -04:00
|
|
|
if(branches.empty())
|
|
|
|
|
return -ENOENT;
|
2014-05-12 12:41:46 -04:00
|
|
|
|
2025-09-17 23:51:16 -04:00
|
|
|
fullpath = branches[0]->path / fusepath_;
|
2015-07-01 07:47:40 -04:00
|
|
|
|
2025-09-17 23:51:16 -04:00
|
|
|
rv = fs::eaccess(fullpath,mask_);
|
2014-05-12 12:41:46 -04:00
|
|
|
|
2025-09-17 23:51:16 -04:00
|
|
|
return rv;
|
2014-05-12 12:41:46 -04:00
|
|
|
}
|
|
|
|
|
|
2025-09-17 23:51:16 -04:00
|
|
|
int
|
2025-10-13 00:21:36 -04:00
|
|
|
FUSE::access(const fuse_req_ctx_t *ctx_,
|
|
|
|
|
const char *fusepath_,
|
|
|
|
|
int mask_)
|
2014-05-12 12:41:46 -04:00
|
|
|
{
|
2025-12-05 21:03:48 -06:00
|
|
|
const fs::path fusepath{fusepath_};
|
2014-05-12 12:41:46 -04:00
|
|
|
|
2025-09-17 23:51:16 -04:00
|
|
|
return ::_access(cfg.func.access.policy,
|
|
|
|
|
cfg.branches,
|
|
|
|
|
fusepath,
|
|
|
|
|
mask_);
|
2014-05-12 12:41:46 -04:00
|
|
|
}
|