2019-01-25 20:03:46 +08:00
|
|
|
/*
|
|
|
|
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.hpp"
|
|
|
|
#include "errno.hpp"
|
2020-08-18 04:29:22 +08:00
|
|
|
#include "fs_lremovexattr.hpp"
|
2019-01-25 20:03:46 +08:00
|
|
|
#include "fs_path.hpp"
|
2020-09-13 12:25:24 +08:00
|
|
|
#include "policy_rv.hpp"
|
2019-01-25 20:03:46 +08:00
|
|
|
#include "ugid.hpp"
|
|
|
|
|
2020-12-20 04:06:08 +08:00
|
|
|
#include "fuse.h"
|
2019-01-25 20:03:46 +08:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
using std::string;
|
|
|
|
using std::vector;
|
|
|
|
|
2020-09-13 12:25:24 +08:00
|
|
|
|
2019-01-25 20:03:46 +08:00
|
|
|
namespace l
|
|
|
|
{
|
|
|
|
static
|
|
|
|
int
|
2020-09-13 12:25:24 +08:00
|
|
|
get_error(const PolicyRV &prv_,
|
|
|
|
const string &basepath_)
|
|
|
|
{
|
|
|
|
for(int i = 0, ei = prv_.success.size(); i < ei; i++)
|
|
|
|
{
|
|
|
|
if(prv_.success[i].basepath == basepath_)
|
|
|
|
return prv_.success[i].rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int i = 0, ei = prv_.error.size(); i < ei; i++)
|
|
|
|
{
|
|
|
|
if(prv_.error[i].basepath == basepath_)
|
|
|
|
return prv_.error[i].rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
void
|
2019-09-24 22:27:46 +08:00
|
|
|
removexattr_loop_core(const string &basepath_,
|
2019-01-25 20:03:46 +08:00
|
|
|
const char *fusepath_,
|
|
|
|
const char *attrname_,
|
2020-09-13 12:25:24 +08:00
|
|
|
PolicyRV *prv_)
|
2019-01-25 20:03:46 +08:00
|
|
|
{
|
|
|
|
string fullpath;
|
|
|
|
|
|
|
|
fullpath = fs::path::make(basepath_,fusepath_);
|
|
|
|
|
2020-09-13 12:25:24 +08:00
|
|
|
errno = 0;
|
|
|
|
fs::lremovexattr(fullpath,attrname_);
|
2019-01-25 20:03:46 +08:00
|
|
|
|
2020-09-13 12:25:24 +08:00
|
|
|
prv_->insert(errno,basepath_);
|
2019-01-25 20:03:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static
|
2020-09-13 12:25:24 +08:00
|
|
|
void
|
2019-09-24 22:27:46 +08:00
|
|
|
removexattr_loop(const vector<string> &basepaths_,
|
|
|
|
const char *fusepath_,
|
2020-09-13 12:25:24 +08:00
|
|
|
const char *attrname_,
|
|
|
|
PolicyRV *prv_)
|
2019-01-25 20:03:46 +08:00
|
|
|
{
|
|
|
|
for(size_t i = 0, ei = basepaths_.size(); i != ei; i++)
|
|
|
|
{
|
2020-09-13 12:25:24 +08:00
|
|
|
l::removexattr_loop_core(basepaths_[i],fusepath_,attrname_,prv_);
|
2019-01-25 20:03:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
int
|
2020-12-20 04:06:08 +08:00
|
|
|
removexattr(const Policy::Action &actionFunc_,
|
|
|
|
const Policy::Search &searchFunc_,
|
2019-01-25 20:03:46 +08:00
|
|
|
const Branches &branches_,
|
|
|
|
const char *fusepath_,
|
|
|
|
const char *attrname_)
|
|
|
|
{
|
|
|
|
int rv;
|
2020-09-13 12:25:24 +08:00
|
|
|
PolicyRV prv;
|
2019-09-24 22:27:46 +08:00
|
|
|
vector<string> basepaths;
|
2019-01-25 20:03:46 +08:00
|
|
|
|
2020-08-21 06:47:04 +08:00
|
|
|
rv = actionFunc_(branches_,fusepath_,&basepaths);
|
2019-01-25 20:03:46 +08:00
|
|
|
if(rv == -1)
|
|
|
|
return -errno;
|
|
|
|
|
2020-09-13 12:25:24 +08:00
|
|
|
l::removexattr_loop(basepaths,fusepath_,attrname_,&prv);
|
|
|
|
if(prv.error.empty())
|
|
|
|
return 0;
|
|
|
|
if(prv.success.empty())
|
|
|
|
return prv.error[0].rv;
|
|
|
|
|
|
|
|
basepaths.clear();
|
|
|
|
rv = searchFunc_(branches_,fusepath_,&basepaths);
|
|
|
|
if(rv == -1)
|
|
|
|
return -errno;
|
|
|
|
|
|
|
|
return l::get_error(prv,basepaths[0]);
|
2019-01-25 20:03:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace FUSE
|
|
|
|
{
|
|
|
|
int
|
|
|
|
removexattr(const char *fusepath_,
|
|
|
|
const char *attrname_)
|
|
|
|
{
|
2020-12-20 04:06:08 +08:00
|
|
|
Config::Read cfg;
|
2019-01-25 20:03:46 +08:00
|
|
|
|
2020-12-20 04:06:08 +08:00
|
|
|
if(fusepath_ == CONTROLFILE)
|
2019-01-25 20:03:46 +08:00
|
|
|
return -ENOATTR;
|
2020-12-20 04:06:08 +08:00
|
|
|
|
|
|
|
if(cfg->xattr.to_int())
|
|
|
|
return -cfg->xattr.to_int();
|
2019-01-25 20:03:46 +08:00
|
|
|
|
2019-09-24 22:27:46 +08:00
|
|
|
const fuse_context *fc = fuse_get_context();
|
|
|
|
const ugid::Set ugid(fc->uid,fc->gid);
|
2019-01-25 20:03:46 +08:00
|
|
|
|
2020-12-20 04:06:08 +08:00
|
|
|
return l::removexattr(cfg->func.removexattr.policy,
|
|
|
|
cfg->func.getxattr.policy,
|
|
|
|
cfg->branches,
|
2019-01-25 20:03:46 +08:00
|
|
|
fusepath_,
|
|
|
|
attrname_);
|
|
|
|
}
|
|
|
|
}
|