From ccd40e46d70bea835a39ab20f7baa2724e82e11b Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Tue, 14 May 2013 09:07:30 +0000 Subject: [PATCH] * grp.cc (get_groups): Convert to void function. (initgroups32): Accommodate the aforementioned change. (getgrouplist): Ditto. --- winsup/cygwin/ChangeLog | 6 ++++ winsup/cygwin/grp.cc | 56 ++++++++++++++++-------------------- winsup/cygwin/release/1.7.19 | 1 + 3 files changed, 31 insertions(+), 32 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 4c2693f71..6b7829abd 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,9 @@ +2013-05-14 Corinna Vinschen + + * grp.cc (get_groups): Convert to void function. + (initgroups32): Accommodate the aforementioned change. + (getgrouplist): Ditto. + 2013-05-14 Corinna Vinschen * grp.cc (get_groups): Never return error. Always create a group list, diff --git a/winsup/cygwin/grp.cc b/winsup/cygwin/grp.cc index 59ec5becc..7ff9e59b2 100644 --- a/winsup/cygwin/grp.cc +++ b/winsup/cygwin/grp.cc @@ -438,7 +438,7 @@ getgroups (int gidsetsize, __gid16_t *grouplist) #endif /* Core functionality of initgroups and getgrouplist. */ -static int +static void get_groups (const char *user, gid_t gid, cygsidlist &gsids) { cygheap->user.deimpersonate (); @@ -450,26 +450,21 @@ get_groups (const char *user, gid_t gid, cygsidlist &gsids) if (grpsid.getfromgr (gr)) gsids += grpsid; cygheap->user.reimpersonate (); - return 0; } extern "C" int initgroups32 (const char *user, gid_t gid) { - int ret; - assert (user != NULL); cygsidlist tmp_gsids (cygsidlist_auto, 12); - if (!(ret = get_groups (user, gid, tmp_gsids))) - { - cygsidlist new_gsids (cygsidlist_alloc, tmp_gsids.count ()); - for (int i = 0; i < tmp_gsids.count (); i++) - new_gsids.sids[i] = tmp_gsids.sids[i]; - new_gsids.count (tmp_gsids.count ()); - cygheap->user.groups.update_supp (new_gsids); - } - syscall_printf ( "%d = initgroups(%s, %u)", ret, user, gid); - return ret; + get_groups (user, gid, tmp_gsids); + cygsidlist new_gsids (cygsidlist_alloc, tmp_gsids.count ()); + for (int i = 0; i < tmp_gsids.count (); i++) + new_gsids.sids[i] = tmp_gsids.sids[i]; + new_gsids.count (tmp_gsids.count ()); + cygheap->user.groups.update_supp (new_gsids); + syscall_printf ( "0 = initgroups(%s, %u)", user, gid); + return 0; } #ifdef __x86_64__ @@ -485,7 +480,9 @@ initgroups (const char *user, __gid16_t gid) extern "C" int 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! 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); cygsidlist tmp_gsids (cygsidlist_auto, 12); - if (!(ret = get_groups (user, gid, tmp_gsids))) - { - int cnt = 0; - for (int i = 0; i < tmp_gsids.count (); i++) - { - struct group *gr = internal_getgrsid (tmp_gsids.sids[i]); - if (gr) - { - if (groups && cnt < *ngroups) - groups[cnt] = gr->gr_gid; - ++cnt; - } - } - if (cnt > *ngroups) - ret = -1; - *ngroups = cnt; - } + get_groups (user, gid, tmp_gsids); + for (int i = 0; i < tmp_gsids.count (); i++) + if ((gr = internal_getgrsid (tmp_gsids.sids[i])) != NULL) + { + if (groups && cnt < *ngroups) + groups[cnt] = gr->gr_gid; + ++cnt; + } + if (cnt > *ngroups) + ret = -1; + *ngroups = cnt; + syscall_printf ( "%d = getgrouplist(%s, %u, %p, %d)", ret, user, gid, groups, *ngroups); return ret; diff --git a/winsup/cygwin/release/1.7.19 b/winsup/cygwin/release/1.7.19 index 7e6779772..1513bb945 100644 --- a/winsup/cygwin/release/1.7.19 +++ b/winsup/cygwin/release/1.7.19 @@ -12,3 +12,4 @@ What's new: Bug fixes: ---------- +- getgrouplist -- 2.43.5