}
#endif /* HAVE_GETPID */
+#ifdef NGROUPS_MAX
+#define MAX_GROUPS NGROUPS_MAX
+#else
+ /* defined to be 16 on Solaris7, so this should be a small number */
+#define MAX_GROUPS 64
+#endif
+
#ifdef HAVE_GETGROUPLIST
/* AC 3.5: funny apple logic below */
static PyObject *
posix_getgrouplist(PyObject *self, PyObject *args)
{
-#ifdef NGROUPS_MAX
-#define MAX_GROUPS NGROUPS_MAX
-#else
- /* defined to be 16 on Solaris7, so this should be a small number */
-#define MAX_GROUPS 64
-#endif
-
const char *user;
int i, ngroups;
PyObject *list;
#else
gid_t *groups, basegid;
#endif
- ngroups = MAX_GROUPS;
+
+ /*
+ * NGROUPS_MAX is defined by POSIX.1 as the maximum
+ * number of supplimental groups a users can belong to.
+ * We have to increment it by one because
+ * getgrouplist() returns both the supplemental groups
+ * and the primary group, i.e. all of the groups the
+ * user belongs to.
+ */
+ ngroups = 1 + MAX_GROUPS;
#ifdef __APPLE__
if (!PyArg_ParseTuple(args, "si:getgrouplist", &user, &basegid))
/*[clinic end generated code: output=42b0c17758561b56 input=d3f109412e6a155c]*/
{
PyObject *result = NULL;
-
-#ifdef NGROUPS_MAX
-#define MAX_GROUPS NGROUPS_MAX
-#else
- /* defined to be 16 on Solaris7, so this should be a small number */
-#define MAX_GROUPS 64
-#endif
gid_t grouplist[MAX_GROUPS];
/* On MacOSX getgroups(2) can return more than MAX_GROUPS results