* grp.cc (get_groups): Convert to void function.

(initgroups32): Accommodate the aforementioned change.
	(getgrouplist): Ditto.
This commit is contained in:
Corinna Vinschen 2013-05-14 09:07:30 +00:00
parent ee6ed1db45
commit ccd40e46d7
3 changed files with 31 additions and 32 deletions

View File

@ -1,3 +1,9 @@
2013-05-14 Corinna Vinschen <corinna@vinschen.de>
* grp.cc (get_groups): Convert to void function.
(initgroups32): Accommodate the aforementioned change.
(getgrouplist): Ditto.
2013-05-14 Corinna Vinschen <corinna@vinschen.de> 2013-05-14 Corinna Vinschen <corinna@vinschen.de>
* grp.cc (get_groups): Never return error. Always create a group list, * grp.cc (get_groups): Never return error. Always create a group list,

View File

@ -438,7 +438,7 @@ getgroups (int gidsetsize, __gid16_t *grouplist)
#endif #endif
/* Core functionality of initgroups and getgrouplist. */ /* Core functionality of initgroups and getgrouplist. */
static int static void
get_groups (const char *user, gid_t gid, cygsidlist &gsids) get_groups (const char *user, gid_t gid, cygsidlist &gsids)
{ {
cygheap->user.deimpersonate (); cygheap->user.deimpersonate ();
@ -450,26 +450,21 @@ get_groups (const char *user, gid_t gid, cygsidlist &gsids)
if (grpsid.getfromgr (gr)) if (grpsid.getfromgr (gr))
gsids += grpsid; gsids += grpsid;
cygheap->user.reimpersonate (); cygheap->user.reimpersonate ();
return 0;
} }
extern "C" int extern "C" int
initgroups32 (const char *user, gid_t gid) initgroups32 (const char *user, gid_t gid)
{ {
int ret;
assert (user != NULL); assert (user != NULL);
cygsidlist tmp_gsids (cygsidlist_auto, 12); cygsidlist tmp_gsids (cygsidlist_auto, 12);
if (!(ret = get_groups (user, gid, tmp_gsids))) get_groups (user, gid, tmp_gsids);
{
cygsidlist new_gsids (cygsidlist_alloc, tmp_gsids.count ()); cygsidlist new_gsids (cygsidlist_alloc, tmp_gsids.count ());
for (int i = 0; i < tmp_gsids.count (); i++) for (int i = 0; i < tmp_gsids.count (); i++)
new_gsids.sids[i] = tmp_gsids.sids[i]; new_gsids.sids[i] = tmp_gsids.sids[i];
new_gsids.count (tmp_gsids.count ()); new_gsids.count (tmp_gsids.count ());
cygheap->user.groups.update_supp (new_gsids); cygheap->user.groups.update_supp (new_gsids);
} syscall_printf ( "0 = initgroups(%s, %u)", user, gid);
syscall_printf ( "%d = initgroups(%s, %u)", ret, user, gid); return 0;
return ret;
} }
#ifdef __x86_64__ #ifdef __x86_64__
@ -485,7 +480,9 @@ initgroups (const char *user, __gid16_t gid)
extern "C" int extern "C" int
getgrouplist (const char *user, gid_t gid, gid_t *groups, int *ngroups) getgrouplist (const char *user, gid_t gid, gid_t *groups, int *ngroups)
{ {
int ret; int ret = 0;
int cnt = 0;
struct group *gr;
/* Note that it's not defined if groups or ngroups may be NULL! /* Note that it's not defined if groups or ngroups may be NULL!
GLibc does not check the pointers on entry and just uses them. GLibc does not check the pointers on entry and just uses them.
@ -496,23 +493,18 @@ getgrouplist (const char *user, gid_t gid, gid_t *groups, int *ngroups)
assert (ngroups != NULL); assert (ngroups != NULL);
cygsidlist tmp_gsids (cygsidlist_auto, 12); cygsidlist tmp_gsids (cygsidlist_auto, 12);
if (!(ret = get_groups (user, gid, tmp_gsids))) get_groups (user, gid, tmp_gsids);
{
int cnt = 0;
for (int i = 0; i < tmp_gsids.count (); i++) for (int i = 0; i < tmp_gsids.count (); i++)
{ if ((gr = internal_getgrsid (tmp_gsids.sids[i])) != NULL)
struct group *gr = internal_getgrsid (tmp_gsids.sids[i]);
if (gr)
{ {
if (groups && cnt < *ngroups) if (groups && cnt < *ngroups)
groups[cnt] = gr->gr_gid; groups[cnt] = gr->gr_gid;
++cnt; ++cnt;
} }
}
if (cnt > *ngroups) if (cnt > *ngroups)
ret = -1; ret = -1;
*ngroups = cnt; *ngroups = cnt;
}
syscall_printf ( "%d = getgrouplist(%s, %u, %p, %d)", syscall_printf ( "%d = getgrouplist(%s, %u, %p, %d)",
ret, user, gid, groups, *ngroups); ret, user, gid, groups, *ngroups);
return ret; return ret;

View File

@ -12,3 +12,4 @@ What's new:
Bug fixes: Bug fixes:
---------- ----------
- getgrouplist