Skip to content

Commit

Permalink
Merge pull request #360 from trapexit/posix-acl
Browse files Browse the repository at this point in the history
check for system.posix_acl_default before setting umask
  • Loading branch information
trapexit authored Jan 17, 2017
2 parents 10a9918 + d67d5de commit 078e4ba
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 15 deletions.
25 changes: 21 additions & 4 deletions src/create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "config.hpp"
#include "errno.hpp"
#include "fileinfo.hpp"
#include "fs_acl.hpp"
#include "fs_base_open.hpp"
#include "fs_clonepath.hpp"
#include "fs_path.hpp"
Expand All @@ -30,16 +31,30 @@

using std::string;
using std::vector;
using mergerfs::Policy;
using namespace mergerfs;

static
inline
int
_create_core(const string &fullpath,
mode_t mode,
const mode_t umask,
const int flags)
{
if(!fs::acl::dir_has_defaults(fullpath))
mode &= ~umask;

return fs::open(fullpath,flags,mode);
}

static
int
_create_core(const string &existingpath,
const string &createpath,
const char *fusepath,
const char *fusedirpath,
const mode_t mode,
const mode_t umask,
const int flags,
uint64_t &fh)
{
Expand All @@ -56,7 +71,7 @@ _create_core(const string &existingpath,

fs::path::make(&createpath,fusepath,fullpath);

rv = fs::open(fullpath,flags,mode);
rv = _create_core(fullpath,mode,umask,flags);
if(rv == -1)
return -errno;

Expand All @@ -73,6 +88,7 @@ _create(Policy::Func::Search searchFunc,
const uint64_t minfreespace,
const char *fusepath,
const mode_t mode,
const mode_t umask,
const int flags,
uint64_t &fh)
{
Expand All @@ -97,7 +113,7 @@ _create(Policy::Func::Search searchFunc,

return _create_core(*existingpaths[0],*createpaths[0],
fusepath,fusedirpathcstr,
mode,flags,fh);
mode,umask,flags,fh);
}

namespace mergerfs
Expand All @@ -119,7 +135,8 @@ namespace mergerfs
config.srcmounts,
config.minfreespace,
fusepath,
(mode & ~fc->umask),
mode,
fc->umask,
ffi->flags,
ffi->fh);
}
Expand Down
43 changes: 43 additions & 0 deletions src/fs_acl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
ISC License
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 <string>

#include "fs_base_getxattr.hpp"
#include "fs_path.hpp"

const char POSIX_ACL_DEFAULT_XATTR[] = "system.posix_acl_default";

namespace fs
{
namespace acl
{
bool
dir_has_defaults(const std::string &fullpath)
{
int rv;
std::string dirpath = fullpath;

fs::path::dirname(dirpath);

rv = fs::lgetxattr(dirpath,POSIX_ACL_DEFAULT_XATTR,NULL,0);

return (rv != -1);
}
}
}
28 changes: 28 additions & 0 deletions src/fs_acl.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
ISC License
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 <string>

namespace fs
{
namespace acl
{
bool
dir_has_defaults(const std::string &fullpath);
}
}
1 change: 1 addition & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ namespace mergerfs
{
ugid::init();

conn->want |= FUSE_CAP_DONT_MASK;
#ifdef FUSE_CAP_IOCTL_DIR
conn->want |= FUSE_CAP_IOCTL_DIR;
#endif
Expand Down
31 changes: 24 additions & 7 deletions src/mkdir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "config.hpp"
#include "errno.hpp"
#include "fs_acl.hpp"
#include "fs_base_mkdir.hpp"
#include "fs_clonepath.hpp"
#include "fs_path.hpp"
Expand All @@ -30,16 +31,29 @@

using std::string;
using std::vector;
using mergerfs::Policy;
using namespace mergerfs;

static
inline
int
_mkdir_core(const string &fullpath,
mode_t mode,
const mode_t umask)
{
if(!fs::acl::dir_has_defaults(fullpath))
mode &= ~umask;

return fs::mkdir(fullpath,mode);
}

static
int
_mkdir_loop_core(const string &existingpath,
const string &createpath,
const char *fusepath,
const char *fusedirpath,
const mode_t mode,
const mode_t umask,
const int error)
{
int rv;
Expand All @@ -55,7 +69,7 @@ _mkdir_loop_core(const string &existingpath,

fs::path::make(&createpath,fusepath,fullpath);

rv = fs::mkdir(fullpath,mode);
rv = _mkdir_core(fullpath,mode,umask);

return calc_error(rv,error,errno);
}
Expand All @@ -66,15 +80,16 @@ _mkdir_loop(const string &existingpath,
const vector<const string*> &createpaths,
const char *fusepath,
const char *fusedirpath,
const mode_t mode)
const mode_t mode,
const mode_t umask)
{
int error;

error = -1;
for(size_t i = 0, ei = createpaths.size(); i != ei; i++)
{
error = _mkdir_loop_core(existingpath,*createpaths[i],
fusepath,fusedirpath,mode,error);
fusepath,fusedirpath,mode,umask,error);
}

return -error;
Expand All @@ -87,7 +102,8 @@ _mkdir(Policy::Func::Search searchFunc,
const vector<string> &srcmounts,
const uint64_t minfreespace,
const char *fusepath,
const mode_t mode)
const mode_t mode,
const mode_t umask)
{
int rv;
string fusedirpath;
Expand All @@ -108,7 +124,7 @@ _mkdir(Policy::Func::Search searchFunc,
return -errno;

return _mkdir_loop(*existingpaths[0],createpaths,
fusepath,fusedirpathcstr,mode);
fusepath,fusedirpathcstr,mode,umask);
}

namespace mergerfs
Expand All @@ -129,7 +145,8 @@ namespace mergerfs
config.srcmounts,
config.minfreespace,
fusepath,
(mode & ~fc->umask));
mode,
fc->umask);
}
}
}
27 changes: 23 additions & 4 deletions src/mknod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "config.hpp"
#include "errno.hpp"
#include "fs_acl.hpp"
#include "fs_base_mknod.hpp"
#include "fs_clonepath.hpp"
#include "fs_path.hpp"
Expand All @@ -32,13 +33,28 @@ using std::string;
using std::vector;
using namespace mergerfs;

static
inline
int
_mknod_core(const string &fullpath,
mode_t mode,
const mode_t umask,
const dev_t dev)
{
if(!fs::acl::dir_has_defaults(fullpath))
mode &= ~umask;

return fs::mknod(fullpath,mode,dev);
}

static
int
_mknod_loop_core(const string &existingpath,
const string &createpath,
const char *fusepath,
const char *fusedirpath,
const mode_t mode,
const mode_t umask,
const dev_t dev,
const int error)
{
Expand All @@ -55,7 +71,7 @@ _mknod_loop_core(const string &existingpath,

fs::path::make(&createpath,fusepath,fullpath);

rv = fs::mknod(fullpath,mode,dev);
rv = _mknod_core(fullpath,mode,umask,dev);

return calc_error(rv,error,errno);
}
Expand All @@ -67,6 +83,7 @@ _mknod_loop(const string &existingpath,
const char *fusepath,
const char *fusedirpath,
const mode_t mode,
const mode_t umask,
const dev_t dev)
{
int error;
Expand All @@ -76,7 +93,7 @@ _mknod_loop(const string &existingpath,
{
error = _mknod_loop_core(existingpath,*createpaths[i],
fusepath,fusedirpath,
mode,dev,error);
mode,umask,dev,error);
}

return -error;
Expand All @@ -90,6 +107,7 @@ _mknod(Policy::Func::Search searchFunc,
const uint64_t minfreespace,
const char *fusepath,
const mode_t mode,
const mode_t umask,
const dev_t dev)
{
int rv;
Expand All @@ -112,7 +130,7 @@ _mknod(Policy::Func::Search searchFunc,

return _mknod_loop(*existingpaths[0],createpaths,
fusepath,fusedirpathcstr,
mode,dev);
mode,umask,dev);
}

namespace mergerfs
Expand All @@ -134,7 +152,8 @@ namespace mergerfs
config.srcmounts,
config.minfreespace,
fusepath,
(mode & ~fc->umask),
mode,
fc->umask,
rdev);
}
}
Expand Down

0 comments on commit 078e4ba

Please sign in to comment.