bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: getgrouplist


From: Jim Meyering
Subject: Re: getgrouplist
Date: Fri, 26 May 2006 12:00:25 +0200

Bruno Haible <address@hidden> wrote:
> Jim Meyering wrote:
>> It'd be great if someone would write a gnulib-style getgrouplist
>> replacement function that provides a poor-man's implementation (using
>> something like coreutils' existing code) for systems that lack a useful
>> function by that name.
>
> Here is an implementation of the getgrouplist module you ask for.
>
> It is based on the getugroups.c file.
>
> About the glibc-2.3.2 bug workaround:
>   - I don't know how to write an autoconf test for the bug (take e.g. a
>     system where all users are only in their primary group).

Thanks for working on that.
How about an autoconf run test that does this:

#include <stdlib.h>
#include <grp.h>
int
main ()
{
  int ng = 0;
  gid_t buf = 0;
  getgrouplist ("root", 0, &buf, &ng);
  return buf != 0;
}

If at all possible, I'd like to avoid trying to detect the bug at run time.

That would have another advantage: for the few glibc-2.3.2 (debian sarge)
systems on which I've run the test program, none failed, so I suspect it's
been fixed there.  We shouldn't penalize such systems.

Here's the code (from the man page) that used to get a seg fault.

#include <stdio.h>
#include <stdlib.h>
#include <grp.h>
#include <pwd.h>

int
main ()
{
  int i, ng = 0;
  char *user = "who";           /* username here */
  gid_t *groups = NULL;
  struct passwd *pw = getpwnam (user);
  if (pw == NULL)
    return 0;

  if (getgrouplist (user, pw->pw_gid, NULL, &ng) < 0)
    {
      groups = (gid_t *) malloc (ng * sizeof (gid_t));
      getgrouplist (user, pw->pw_gid, groups, &ng);
    }

  for (i = 0; i < ng; i++)
    printf ("%d\n", groups[i]);

  return 0;
}
-------------------------

Can any of you try the above programs on systems with 2.3.x or older
to see if they fail (nonzero exit status for the first, crash for the
second)?  If you do try, please report back either way.  If affected
systems are rare enough, maybe we don't need to worry about that bug
any more.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]