Browse Source

use SYS_setgroups rather than setgroups

pull/172/head
Antonio SJ Musumeci 9 years ago
parent
commit
5e880bddba
  1. 26
      src/gidcache.cpp
  2. 2
      src/gidcache.hpp
  3. 3
      src/ugid.hpp
  4. 8
      src/ugid_linux.ipp
  5. 8
      src/ugid_rwlock.ipp

26
src/gidcache.cpp

@ -28,11 +28,16 @@
#include <grp.h> #include <grp.h>
#include <unistd.h> #include <unistd.h>
#if defined __linux__ and UGID_USE_RWLOCK == 0
# include <sys/syscall.h>
#endif
#include <cstdlib> #include <cstdlib>
#include <algorithm> #include <algorithm>
#include "gidcache.hpp" #include "gidcache.hpp"
inline
bool bool
gid_t_rec::operator<(const struct gid_t_rec &b) const 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; 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, gid_t_cache::initgroups(const uid_t uid,
const gid_t gid) const gid_t gid)
{ {
int rv;
gid_t_rec *rec; gid_t_rec *rec;
rec = lower_bound(begin(),end(),uid); rec = lower_bound(begin(),end(),uid);
if(rec == end() || rec->uid != uid) if(rec == end() || rec->uid != uid)
{ {
rec = cache(uid,gid); rec = cache(uid,gid);
::setgroups(rec->size,rec->gids);
rv = ::setgroups(rec);
std::sort(begin(),end()); std::sort(begin(),end());
} }
else else
{ {
::setgroups(rec->size,rec->gids);
rv = ::setgroups(rec);
} }
return rv;
} }

2
src/gidcache.hpp

@ -58,7 +58,7 @@ private:
const gid_t gid); const gid_t gid);
public: public:
void
int
initgroups(const uid_t uid, initgroups(const uid_t uid,
const gid_t gid); const gid_t gid);
}; };

3
src/ugid.hpp

@ -30,15 +30,12 @@
#include <vector> #include <vector>
typedef std::vector<gid_t> gid_t_vector;
namespace mergerfs namespace mergerfs
{ {
namespace ugid namespace ugid
{ {
void init(); void init();
void initgroups(const uid_t uid, const gid_t gid); void initgroups(const uid_t uid, const gid_t gid);
void setgroups(const gid_t_vector &gidlist);
} }
} }

8
src/ugid_linux.ipp

@ -29,8 +29,6 @@
#include <vector> #include <vector>
typedef std::vector<gid_t> gid_t_vector;
namespace mergerfs namespace mergerfs
{ {
namespace ugid namespace ugid
@ -43,11 +41,5 @@ namespace mergerfs
init() init()
{ {
} }
int
setgroups(const gid_t_vector &gidlist)
{
return ::syscall(SYS_setgroups,gidlist.size(),&gidlist[0]);
}
} }
} }

8
src/ugid_rwlock.ipp

@ -29,8 +29,6 @@
#include <vector> #include <vector>
typedef std::vector<gid_t> gid_t_vector;
namespace mergerfs namespace mergerfs
{ {
namespace ugid namespace ugid
@ -54,11 +52,5 @@ namespace mergerfs
currentuid = ::geteuid(); currentuid = ::geteuid();
currentgid = ::getegid(); currentgid = ::getegid();
} }
int
setgroups(const gid_t_vector &gidlist)
{
return ::setgroups(gidlist.size(),&gidlist[0]);
}
} }
} }
Loading…
Cancel
Save