mirror of https://github.com/trapexit/mergerfs.git
Antonio SJ Musumeci
11 years ago
39 changed files with 323 additions and 131 deletions
-
8Makefile
-
3src/access.cpp
-
3src/chmod.cpp
-
3src/chown.cpp
-
5src/create.cpp
-
2src/fallocate.cpp
-
2src/fgetattr.cpp
-
3src/flush.cpp
-
2src/fsync.cpp
-
2src/ftruncate.cpp
-
3src/getattr.cpp
-
5src/getxattr.cpp
-
2src/ioctl.cpp
-
5src/link.cpp
-
5src/listxattr.cpp
-
5src/mkdir.cpp
-
5src/mknod.cpp
-
3src/open.cpp
-
1src/read.cpp
-
1src/read_buf.cpp
-
3src/readdir.cpp
-
3src/readlink.cpp
-
1src/release.cpp
-
5src/removexattr.cpp
-
5src/rename.cpp
-
5src/rmdir.cpp
-
5src/setxattr.cpp
-
3src/statfs.cpp
-
3src/symlink.cpp
-
3src/truncate.cpp
-
31src/ugid.cpp
-
72src/ugid.hpp
-
64src/ugid_linux.hpp
-
68src/ugid_mutex.hpp
-
58src/ugid_osx.hpp
-
5src/unlink.cpp
-
9src/utimens.cpp
-
1src/write.cpp
-
2src/write_buf.cpp
@ -0,0 +1,31 @@ |
|||||
|
/*
|
||||
|
The MIT License (MIT) |
||||
|
|
||||
|
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link> |
||||
|
|
||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
|
of this software and associated documentation files (the "Software"), to deal |
||||
|
in the Software without restriction, including without limitation the rights |
||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
|
copies of the Software, and to permit persons to whom the Software is |
||||
|
furnished to do so, subject to the following conditions: |
||||
|
|
||||
|
The above copyright notice and this permission notice shall be included in |
||||
|
all copies or substantial portions of the Software. |
||||
|
|
||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||||
|
THE SOFTWARE. |
||||
|
*/ |
||||
|
|
||||
|
#include "ugid.hpp"
|
||||
|
|
||||
|
#if defined LINUX
|
||||
|
#elif defined OSX
|
||||
|
#else
|
||||
|
pthread_mutex_t mergerfs::ugid::SetResetGuard::lock = PTHREAD_MUTEX_INITIALIZER; |
||||
|
#endif
|
@ -0,0 +1,64 @@ |
|||||
|
/*
|
||||
|
The MIT License (MIT) |
||||
|
|
||||
|
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link> |
||||
|
|
||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
|
of this software and associated documentation files (the "Software"), to deal |
||||
|
in the Software without restriction, including without limitation the rights |
||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
|
copies of the Software, and to permit persons to whom the Software is |
||||
|
furnished to do so, subject to the following conditions: |
||||
|
|
||||
|
The above copyright notice and this permission notice shall be included in |
||||
|
all copies or substantial portions of the Software. |
||||
|
|
||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||||
|
THE SOFTWARE. |
||||
|
*/ |
||||
|
|
||||
|
#include <sys/types.h>
|
||||
|
#include <sys/stat.h>
|
||||
|
#include <unistd.h>
|
||||
|
#include <sys/syscall.h>
|
||||
|
|
||||
|
namespace mergerfs |
||||
|
{ |
||||
|
namespace ugid |
||||
|
{ |
||||
|
struct SetResetGuard |
||||
|
{ |
||||
|
SetResetGuard(const uid_t _newuid, |
||||
|
const gid_t _newgid) |
||||
|
{ |
||||
|
olduid = ::geteuid(); |
||||
|
oldgid = ::getegid(); |
||||
|
newuid = _newuid; |
||||
|
newgid = _newgid; |
||||
|
|
||||
|
if(newgid != oldgid) |
||||
|
::syscall(SYS_setregid,-1,newgid); |
||||
|
if(newuid != olduid) |
||||
|
::syscall(SYS_setreuid,-1,newuid); |
||||
|
} |
||||
|
|
||||
|
~SetResetGuard() |
||||
|
{ |
||||
|
if(olduid != newuid) |
||||
|
::syscall(SYS_setreuid,-1,olduid); |
||||
|
if(oldgid != newgid) |
||||
|
::syscall(SYS_setregid,-1,oldgid); |
||||
|
} |
||||
|
|
||||
|
uid_t olduid; |
||||
|
gid_t oldgid; |
||||
|
uid_t newuid; |
||||
|
gid_t newgid; |
||||
|
}; |
||||
|
} |
||||
|
} |
@ -0,0 +1,68 @@ |
|||||
|
/*
|
||||
|
The MIT License (MIT) |
||||
|
|
||||
|
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link> |
||||
|
|
||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
|
of this software and associated documentation files (the "Software"), to deal |
||||
|
in the Software without restriction, including without limitation the rights |
||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
|
copies of the Software, and to permit persons to whom the Software is |
||||
|
furnished to do so, subject to the following conditions: |
||||
|
|
||||
|
The above copyright notice and this permission notice shall be included in |
||||
|
all copies or substantial portions of the Software. |
||||
|
|
||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||||
|
THE SOFTWARE. |
||||
|
*/ |
||||
|
|
||||
|
#include <sys/types.h>
|
||||
|
#include <sys/stat.h>
|
||||
|
#include <unistd.h>
|
||||
|
#include <pthread.h>
|
||||
|
|
||||
|
namespace mergerfs |
||||
|
{ |
||||
|
namespace ugid |
||||
|
{ |
||||
|
struct SetResetGuard |
||||
|
{ |
||||
|
SetResetGuard(const uid_t _newuid, |
||||
|
const gid_t _newgid) |
||||
|
{ |
||||
|
pthread_mutex_lock(&lock); |
||||
|
|
||||
|
olduid = ::geteuid(); |
||||
|
oldgid = ::getegid(); |
||||
|
newuid = _newuid; |
||||
|
newgid = _newgid; |
||||
|
|
||||
|
if(newgid != oldgid) |
||||
|
setegid(newgid); |
||||
|
if(newuid != olduid) |
||||
|
seteuid(newuid); |
||||
|
} |
||||
|
|
||||
|
~SetResetGuard() |
||||
|
{ |
||||
|
if(olduid != newuid) |
||||
|
seteuid(newuid); |
||||
|
if(oldgid != newgid) |
||||
|
setegid(newgid); |
||||
|
} |
||||
|
|
||||
|
uid_t olduid; |
||||
|
gid_t oldgid; |
||||
|
uid_t newuid; |
||||
|
gid_t newgid; |
||||
|
|
||||
|
static pthread_mutex_t lock; |
||||
|
}; |
||||
|
} |
||||
|
} |
@ -0,0 +1,58 @@ |
|||||
|
/*
|
||||
|
The MIT License (MIT) |
||||
|
|
||||
|
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link> |
||||
|
|
||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
|
of this software and associated documentation files (the "Software"), to deal |
||||
|
in the Software without restriction, including without limitation the rights |
||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
|
copies of the Software, and to permit persons to whom the Software is |
||||
|
furnished to do so, subject to the following conditions: |
||||
|
|
||||
|
The above copyright notice and this permission notice shall be included in |
||||
|
all copies or substantial portions of the Software. |
||||
|
|
||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||||
|
THE SOFTWARE. |
||||
|
*/ |
||||
|
|
||||
|
#include <sys/types.h>
|
||||
|
#include <sys/unistd.h>
|
||||
|
|
||||
|
namespace mergerfs |
||||
|
{ |
||||
|
namespace ugid |
||||
|
{ |
||||
|
struct SetResetGuard |
||||
|
{ |
||||
|
SetResetGuard(const uid_t _newuid, |
||||
|
const gid_t _newgid) |
||||
|
{ |
||||
|
olduid = ::geteuid(); |
||||
|
oldgid = ::getegid(); |
||||
|
newuid = _newuid; |
||||
|
newgid = _newgid; |
||||
|
|
||||
|
if(newgid != oldgid || newuid != olduid) |
||||
|
pthread_setugid_np(newuid,newgid); |
||||
|
} |
||||
|
|
||||
|
~SetResetGuard() |
||||
|
{ |
||||
|
if(newgid != oldgid || newuid != olduid) |
||||
|
pthread_setugid_np(newuid,newgid); |
||||
|
} |
||||
|
|
||||
|
uid_t olduid; |
||||
|
gid_t oldgid; |
||||
|
uid_t newuid; |
||||
|
gid_t newgid; |
||||
|
}; |
||||
|
} |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue