setgroups problems on FreeBSD - proposed fix

Bjoern Jacke bjoern at j3e.de
Mon Jun 4 15:08:11 GMT 2007


On Wed, May 23, 2007 at 08:35:46AM -0700, James Peach wrote:
> FWIW, Darwin does the same as FreeBSD ...

attached you find FreeBSD's sys_kern/kern_prot.c containing the
setgroups() implementation of FreeBSD. There is a comment saying:

--snip--
* Get effective group ID.  The "egid" is groups[0], and could be obtained
* via getgroups.  This syscall exists because it is somewhat painful to do
* correctly in a library function.
--snap--

however that does not neccessarily mean that the groups[0] handed over to
the setgroups() call is being overwritten.

On the other hand the above pasted comment about "egid" being groups[0]
can also be found in the NetBSD and OpenBSD sources. BUT: Some tests I
did showed that NetBSD, OpenBSD and Tru64 (which is also based on
4.x BSD) do *not* silently overwrite the groups[0] provided to the
setgroups() call.

All in all it looks to me like the setgroups() call ignoring the first
group of the array is in fact a bug that was introduced by the FreeBSD
people and which was inheritted to Darwin.

Timur and James, can you please try to find something about the
background of this?

Just in case this is really a FreeBSD bug I would vote for enabling the
patch only by an #ifdef FREEBSD/DARWIN and leave the code for other
systems as it is.

Bjoern
-------------- next part --------------
A non-text attachment was scrubbed...
Name: kern_prot.c.gz
Type: application/octet-stream
Size: 11112 bytes
Desc: not available
Url : http://lists.samba.org/archive/samba-technical/attachments/20070604/d861d088/kern_prot.c.obj


More information about the samba-technical mailing list