getgroups and getgrouplist functions

Vulpes Velox v.velox at vvelox.net
Tue Jan 2 12:52:33 PST 2007


On Tue, 2 Jan 2007 20:46:38 +1100
Peter Jeremy <peterjeremy at optushome.com.au> wrote:

> On Mon, 2007-Jan-01 23:35:25 -0600, Vulpes Velox wrote:
> >I am reading it as int *ngroups is not set to the number of groups
> >in the list if the number of groups is larger than the number
> >specified.
> 
> I read getgrouplist(3) as stating that it will always return the
> actual number of groups via ngroups.  The code in RELENG_6 actually
> returns the number of groups that are returned via groups - which is
> never be greater than was passed in.  I believe that the manpage
> does not match the implementation but I am not certain which is
> correct.

I am not reading at always in this case. The man pages for other
systems do specify always, but a bit iffy here. From testing it
appears it is not set and ngroups is left alone if it is to small. I
found it is set to the number if that number is less than the initial
ngroups value. So far I know NetBSD, glibc, and what ever Mac uses
makes the change.

I am lost on if this is a bug or if FreeBSD is not following some
standard in regards to this.

> >convinced this is a load of bull. And the proper way to get the
> >number of groups some one is in is to call getgroups(0).
> 
> At least in RELENG_6, getgroups(2) states that passing the first
> argument as 0 will return the number of groups: getgroups(0, NULL);
> This matches the code in the kernel.

Yeah. The patch I made for DBus last uses this upon failing the first
time.


More information about the freebsd-hackers mailing list