mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-10-26 19:01:56 -04:00
Merge pull request #172 from trapexit/setgroups
use SYS_setgroups rather than setgroups on linux
This commit is contained in:
commit
2d71229fe9
5 changed files with 24 additions and 23 deletions
|
|
@ -28,11 +28,16 @@
|
|||
#include <grp.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#if defined __linux__ and UGID_USE_RWLOCK == 0
|
||||
# include <sys/syscall.h>
|
||||
#endif
|
||||
|
||||
#include <cstdlib>
|
||||
#include <algorithm>
|
||||
|
||||
#include "gidcache.hpp"
|
||||
|
||||
inline
|
||||
bool
|
||||
gid_t_rec::operator<(const struct gid_t_rec &b) const
|
||||
{
|
||||
|
|
@ -123,21 +128,36 @@ gid_t_cache::cache(const uid_t uid,
|
|||
return rec;
|
||||
}
|
||||
|
||||
void
|
||||
static
|
||||
inline
|
||||
int
|
||||
setgroups(const gid_t_rec *rec)
|
||||
{
|
||||
#if defined __linux__ and UGID_USE_RWLOCK == 0
|
||||
return ::syscall(SYS_setgroups,rec->size,rec->gids);
|
||||
#else
|
||||
return ::setgroups(rec->size,rec->gids);
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
gid_t_cache::initgroups(const uid_t uid,
|
||||
const gid_t gid)
|
||||
{
|
||||
int rv;
|
||||
gid_t_rec *rec;
|
||||
|
||||
rec = lower_bound(begin(),end(),uid);
|
||||
if(rec == end() || rec->uid != uid)
|
||||
{
|
||||
rec = cache(uid,gid);
|
||||
::setgroups(rec->size,rec->gids);
|
||||
rv = ::setgroups(rec);
|
||||
std::sort(begin(),end());
|
||||
}
|
||||
else
|
||||
{
|
||||
::setgroups(rec->size,rec->gids);
|
||||
rv = ::setgroups(rec);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ private:
|
|||
const gid_t gid);
|
||||
|
||||
public:
|
||||
void
|
||||
int
|
||||
initgroups(const uid_t uid,
|
||||
const gid_t gid);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -30,15 +30,12 @@
|
|||
|
||||
#include <vector>
|
||||
|
||||
typedef std::vector<gid_t> gid_t_vector;
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace ugid
|
||||
{
|
||||
void init();
|
||||
void initgroups(const uid_t uid, const gid_t gid);
|
||||
void setgroups(const gid_t_vector &gidlist);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,8 +29,6 @@
|
|||
|
||||
#include <vector>
|
||||
|
||||
typedef std::vector<gid_t> gid_t_vector;
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace ugid
|
||||
|
|
@ -43,11 +41,5 @@ namespace mergerfs
|
|||
init()
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
setgroups(const gid_t_vector &gidlist)
|
||||
{
|
||||
return ::syscall(SYS_setgroups,gidlist.size(),&gidlist[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,8 +29,6 @@
|
|||
|
||||
#include <vector>
|
||||
|
||||
typedef std::vector<gid_t> gid_t_vector;
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace ugid
|
||||
|
|
@ -54,11 +52,5 @@ namespace mergerfs
|
|||
currentuid = ::geteuid();
|
||||
currentgid = ::getegid();
|
||||
}
|
||||
|
||||
int
|
||||
setgroups(const gid_t_vector &gidlist)
|
||||
{
|
||||
return ::setgroups(gidlist.size(),&gidlist[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue