2014-05-12 12:41:46 -04:00
|
|
|
/*
|
2016-01-14 16:50:22 -05: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.
|
2014-05-12 12:41:46 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "config.hpp"
|
2016-09-14 08:36:06 -04:00
|
|
|
#include "errno.hpp"
|
2016-10-19 09:28:06 -04:00
|
|
|
#include "fs_base_access.hpp"
|
2015-09-15 18:49:18 -04:00
|
|
|
#include "fs_path.hpp"
|
2014-08-03 15:50:28 -04:00
|
|
|
#include "rwlock.hpp"
|
2015-09-15 18:49:18 -04:00
|
|
|
#include "ugid.hpp"
|
2014-05-12 12:41:46 -04:00
|
|
|
|
|
|
|
using std::string;
|
|
|
|
using std::vector;
|
|
|
|
using mergerfs::Policy;
|
2015-06-25 17:55:16 -04:00
|
|
|
using mergerfs::Category;
|
2014-05-12 12:41:46 -04:00
|
|
|
|
|
|
|
static
|
|
|
|
int
|
2015-06-25 17:55:16 -04:00
|
|
|
_access(Policy::Func::Search searchFunc,
|
|
|
|
const vector<string> &srcmounts,
|
2016-07-10 12:44:29 -04:00
|
|
|
const uint64_t minfreespace,
|
2016-01-29 16:54:39 -05:00
|
|
|
const char *fusepath,
|
2015-06-25 17:55:16 -04:00
|
|
|
const int mask)
|
2014-05-12 12:41:46 -04:00
|
|
|
{
|
|
|
|
int rv;
|
2016-01-29 16:54:39 -05:00
|
|
|
string fullpath;
|
|
|
|
vector<const string*> basepaths;
|
2014-05-12 12:41:46 -04:00
|
|
|
|
2016-01-29 16:54:39 -05:00
|
|
|
rv = searchFunc(srcmounts,fusepath,minfreespace,basepaths);
|
2014-08-16 13:59:55 -04:00
|
|
|
if(rv == -1)
|
|
|
|
return -errno;
|
2014-05-12 12:41:46 -04:00
|
|
|
|
2016-01-29 16:54:39 -05:00
|
|
|
fs::path::make(basepaths[0],fusepath,fullpath);
|
2015-07-01 07:47:40 -04:00
|
|
|
|
2016-10-20 16:51:49 -04:00
|
|
|
rv = fs::eaccess(fullpath,mask);
|
2014-05-12 12:41:46 -04:00
|
|
|
|
|
|
|
return ((rv == -1) ? -errno : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace mergerfs
|
|
|
|
{
|
2015-07-15 10:04:57 -04:00
|
|
|
namespace fuse
|
2014-05-12 12:41:46 -04:00
|
|
|
{
|
|
|
|
int
|
|
|
|
access(const char *fusepath,
|
|
|
|
int mask)
|
|
|
|
{
|
2015-09-08 15:56:02 -04:00
|
|
|
const fuse_context *fc = fuse_get_context();
|
|
|
|
const Config &config = Config::get(fc);
|
|
|
|
const ugid::Set ugid(fc->uid,fc->gid);
|
|
|
|
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
2014-05-12 12:41:46 -04:00
|
|
|
|
2015-06-25 17:55:16 -04:00
|
|
|
return _access(config.access,
|
2014-05-12 12:41:46 -04:00
|
|
|
config.srcmounts,
|
2015-06-16 22:12:55 -04:00
|
|
|
config.minfreespace,
|
2014-05-12 12:41:46 -04:00
|
|
|
fusepath,
|
|
|
|
mask);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|