[PATCH] cyrus-imapd: use getgrouplist instead of set/getgrent on systems supporting it
Ken Murchison
murch at andrew.cmu.edu
Mon Sep 17 09:49:38 EDT 2007
Tomas Janousek wrote:
> Hi Simon,
>
> On Tue, Jun 12, 2007 at 03:52:27PM +0200, Simon Matter wrote:
>> I have slightly modified the patch to make older GCC happy with it. Does
>> it still look okay?
>
> Yeah, it's fine, thanks.
I applied Simon's version to CVS, but then I realized that it causes
myfreestate() to crash on my Linux box, because the newstate->groups
array doesn't get entirely populated. The following patch fixes the
problem of having gaps in newstate->groups, but I'm not sure why we're
skipping groups anyways. Also, will getgrouplist() really return -1 for
anything other than the output array being too small (wondering if we
need the 'do' loop)?
--- auth_unix.c.~1.42.~ 2007-09-13 13:24:42.000000000 -0400
+++ auth_unix.c 2007-09-17 09:38:45.000000000 -0400
@@ -270,11 +270,14 @@
goto err;
}
- newstate->group = (char **)xmalloc(newstate->ngroups * sizeof(char *));
- for (i = 0; i < newstate->ngroups; ++i ) {
+ newstate->ngroups = 0;
+ newstate->group = (char **)xmalloc(ngroups * sizeof(char *));
+ for (i = 0; i < ngroups; i++) {
if (pwd || groupids[i] != gid) {
- if ((grp = getgrgid(groupids[i])))
- newstate->group[i] = xstrdup(grp->gr_name);
+ if ((grp = getgrgid(groupids[i]))) {
+ newstate->ngroups++;
+ newstate->group[newstate->ngroups-1] = xstrdup(grp->gr_name);
+ }
}
}
--
Kenneth Murchison
Systems Programmer
Project Cyrus Developer/Maintainer
Carnegie Mellon University
More information about the Cyrus-devel
mailing list