Fix getgrouplist for OpenBSD/MacOS X

OpenBSD/Mach provide getgrouplist function that behaves differently from the
Linux/FreeBSD one. While the latter will happily return the number of groups
available when queried with a NULL buffer, the OpenBSD version does not
provide similar functionality. List size needs to be searched for (duplicating
buffer size uppon each call).

This commit adds a more or less independent implementation for OpenBSD and
MacOS X.