2019-01-25 07:03:46 -05:00
|
|
|
/*
|
2026-02-23 13:22:21 -06:00
|
|
|
ISC License
|
|
|
|
|
|
|
|
|
|
Copyright (c) 2026, Antonio SJ Musumeci <trapexit@spawn.link>
|
2019-01-25 07:03:46 -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.
|
|
|
|
|
*/
|
|
|
|
|
|
2025-07-25 17:53:48 -05:00
|
|
|
#include "fuse_removexattr.hpp"
|
|
|
|
|
|
2019-01-25 07:03:46 -05:00
|
|
|
#include "config.hpp"
|
|
|
|
|
#include "errno.hpp"
|
2020-08-17 16:29:22 -04:00
|
|
|
#include "fs_lremovexattr.hpp"
|
2019-01-25 07:03:46 -05:00
|
|
|
#include "fs_path.hpp"
|
2020-09-13 00:25:24 -04:00
|
|
|
#include "policy_rv.hpp"
|
2019-01-25 07:03:46 -05:00
|
|
|
|
2020-12-19 15:06:08 -05:00
|
|
|
#include "fuse.h"
|
2019-01-25 07:03:46 -05:00
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
2020-09-13 00:25:24 -04:00
|
|
|
|
2025-07-25 17:53:48 -05:00
|
|
|
static
|
|
|
|
|
void
|
2025-09-17 23:51:16 -04:00
|
|
|
_removexattr_loop_core(const fs::path &basepath_,
|
|
|
|
|
const fs::path &fusepath_,
|
|
|
|
|
const char *attrname_,
|
|
|
|
|
PolicyRV *prv_)
|
2025-07-25 17:53:48 -05:00
|
|
|
{
|
2026-03-10 19:37:57 -05:00
|
|
|
int rv;
|
2025-09-17 23:51:16 -04:00
|
|
|
fs::path fullpath;
|
2025-07-25 17:53:48 -05:00
|
|
|
|
2025-09-17 23:51:16 -04:00
|
|
|
fullpath = basepath_ / fusepath_;
|
2025-07-25 17:53:48 -05:00
|
|
|
|
2026-03-10 19:37:57 -05:00
|
|
|
rv = fs::lremovexattr(fullpath,attrname_);
|
2025-07-25 17:53:48 -05:00
|
|
|
|
2026-03-10 19:37:57 -05:00
|
|
|
prv_->insert(rv,basepath_);
|
2025-07-25 17:53:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
|
void
|
|
|
|
|
_removexattr_loop(const std::vector<Branch*> &branches_,
|
2025-09-17 23:51:16 -04:00
|
|
|
const fs::path &fusepath_,
|
2025-07-25 17:53:48 -05:00
|
|
|
const char *attrname_,
|
|
|
|
|
PolicyRV *prv_)
|
|
|
|
|
{
|
|
|
|
|
for(auto &branch : branches_)
|
|
|
|
|
{
|
|
|
|
|
::_removexattr_loop_core(branch->path,fusepath_,attrname_,prv_);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
|
int
|
|
|
|
|
_removexattr(const Policy::Action &actionFunc_,
|
|
|
|
|
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 ibranches_,
|
2025-09-17 23:51:16 -04:00
|
|
|
const fs::path &fusepath_,
|
2025-07-25 17:53:48 -05:00
|
|
|
const char *attrname_)
|
2019-01-25 07:03:46 -05:00
|
|
|
{
|
2025-07-25 17:53:48 -05:00
|
|
|
int rv;
|
|
|
|
|
PolicyRV prv;
|
|
|
|
|
std::vector<Branch*> obranches;
|
|
|
|
|
|
|
|
|
|
rv = actionFunc_(ibranches_,fusepath_,obranches);
|
|
|
|
|
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(obranches.empty())
|
|
|
|
|
return -ENOENT;
|
2025-07-25 17:53:48 -05:00
|
|
|
|
|
|
|
|
::_removexattr_loop(obranches,fusepath_,attrname_,&prv);
|
|
|
|
|
if(prv.errors.empty())
|
|
|
|
|
return 0;
|
|
|
|
|
if(prv.successes.empty())
|
|
|
|
|
return prv.errors[0].rv;
|
|
|
|
|
|
|
|
|
|
obranches.clear();
|
|
|
|
|
rv = searchFunc_(ibranches_,fusepath_,obranches);
|
|
|
|
|
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(obranches.empty())
|
|
|
|
|
return -ENOENT;
|
2025-07-25 17:53:48 -05:00
|
|
|
|
|
|
|
|
return prv.get_error(obranches[0]->path);
|
2019-01-25 07:03:46 -05:00
|
|
|
}
|
|
|
|
|
|
2025-07-25 17:53:48 -05:00
|
|
|
int
|
2025-10-13 00:21:36 -04:00
|
|
|
FUSE::removexattr(const fuse_req_ctx_t *ctx_,
|
|
|
|
|
const char *fusepath_,
|
|
|
|
|
const char *attrname_)
|
2019-01-25 07:03:46 -05:00
|
|
|
{
|
2025-09-17 23:51:16 -04:00
|
|
|
const fs::path fusepath{fusepath_};
|
|
|
|
|
|
|
|
|
|
if(Config::is_ctrl_file(fusepath))
|
2025-07-25 17:53:48 -05:00
|
|
|
return -ENOATTR;
|
|
|
|
|
|
2025-09-06 12:03:51 -04:00
|
|
|
if(cfg.xattr.to_int())
|
|
|
|
|
return -cfg.xattr.to_int();
|
2025-07-25 17:53:48 -05:00
|
|
|
|
2025-09-06 12:03:51 -04:00
|
|
|
return ::_removexattr(cfg.func.removexattr.policy,
|
|
|
|
|
cfg.func.getxattr.policy,
|
|
|
|
|
cfg.branches,
|
2025-09-17 23:51:16 -04:00
|
|
|
fusepath,
|
2025-07-25 17:53:48 -05:00
|
|
|
attrname_);
|
2019-01-25 07:03:46 -05:00
|
|
|
}
|