Browse Source

Merge pull request #394 from trapexit/getgrouplist

work around getgrouplist signature difference on osx
pull/395/head
Antonio SJ Musumeci 8 years ago
committed by GitHub
parent
commit
8cfb1cbee4
  1. 20
      src/gidcache.cpp

20
src/gidcache.cpp

@ -22,6 +22,8 @@
#if defined __linux__ and UGID_USE_RWLOCK == 0 #if defined __linux__ and UGID_USE_RWLOCK == 0
# include <sys/syscall.h> # include <sys/syscall.h>
#elif __APPLE__
# include <sys/param.h>
#endif #endif
#include <cstdlib> #include <cstdlib>
@ -90,6 +92,20 @@ gid_t_cache::lower_bound(gid_t_rec *begin,
return begin; return begin;
} }
static
int
_getgrouplist(const char *user,
const gid_t group,
gid_t *groups,
int *ngroups)
{
#if __APPLE__
return ::getgrouplist(user,group,(int*)groups,ngroups);
#else
return ::getgrouplist(user,group,groups,ngroups);
#endif
}
gid_t_rec * gid_t_rec *
gid_t_cache::cache(const uid_t uid, gid_t_cache::cache(const uid_t uid,
const gid_t gid) const gid_t gid)
@ -107,9 +123,9 @@ gid_t_cache::cache(const uid_t uid,
if(pwdrv != NULL && rv == 0) if(pwdrv != NULL && rv == 0)
{ {
rec->size = 0; rec->size = 0;
::getgrouplist(pwd.pw_name,gid,NULL,&rec->size);
::_getgrouplist(pwd.pw_name,gid,NULL,&rec->size);
rec->size = std::min(MAXGIDS,rec->size); rec->size = std::min(MAXGIDS,rec->size);
rv = ::getgrouplist(pwd.pw_name,gid,rec->gids,&rec->size);
rv = ::_getgrouplist(pwd.pw_name,gid,rec->gids,&rec->size);
if(rv == -1) if(rv == -1)
{ {
rec->gids[0] = gid; rec->gids[0] = gid;

Loading…
Cancel
Save