@@ -6722,6 +6722,13 @@ os_getpid_impl(PyObject *module)
67226722}
67236723#endif /* HAVE_GETPID */
67246724
6725+ #ifdef NGROUPS_MAX
6726+ #define MAX_GROUPS NGROUPS_MAX
6727+ #else
6728+ /* defined to be 16 on Solaris7, so this should be a small number */
6729+ #define MAX_GROUPS 64
6730+ #endif
6731+
67256732#ifdef HAVE_GETGROUPLIST
67266733
67276734/* AC 3.5: funny apple logic below */
@@ -6734,13 +6741,6 @@ Returns a list of groups to which a user belongs.\n\n\
67346741static PyObject *
67356742posix_getgrouplist (PyObject * self , PyObject * args )
67366743{
6737- #ifdef NGROUPS_MAX
6738- #define MAX_GROUPS NGROUPS_MAX
6739- #else
6740- /* defined to be 16 on Solaris7, so this should be a small number */
6741- #define MAX_GROUPS 64
6742- #endif
6743-
67446744 const char * user ;
67456745 int i , ngroups ;
67466746 PyObject * list ;
@@ -6749,7 +6749,16 @@ posix_getgrouplist(PyObject *self, PyObject *args)
67496749#else
67506750 gid_t * groups , basegid ;
67516751#endif
6752- ngroups = MAX_GROUPS ;
6752+
6753+ /*
6754+ * NGROUPS_MAX is defined by POSIX.1 as the maximum
6755+ * number of supplimental groups a users can belong to.
6756+ * We have to increment it by one because
6757+ * getgrouplist() returns both the supplemental groups
6758+ * and the primary group, i.e. all of the groups the
6759+ * user belongs to.
6760+ */
6761+ ngroups = 1 + MAX_GROUPS ;
67536762
67546763#ifdef __APPLE__
67556764 if (!PyArg_ParseTuple (args , "si:getgrouplist" , & user , & basegid ))
@@ -6818,13 +6827,6 @@ os_getgroups_impl(PyObject *module)
68186827/*[clinic end generated code: output=42b0c17758561b56 input=d3f109412e6a155c]*/
68196828{
68206829 PyObject * result = NULL ;
6821-
6822- #ifdef NGROUPS_MAX
6823- #define MAX_GROUPS NGROUPS_MAX
6824- #else
6825- /* defined to be 16 on Solaris7, so this should be a small number */
6826- #define MAX_GROUPS 64
6827- #endif
68286830 gid_t grouplist [MAX_GROUPS ];
68296831
68306832 /* On MacOSX getgroups(2) can return more than MAX_GROUPS results
0 commit comments