@@ -6722,6 +6722,13 @@ os_getpid_impl(PyObject *module)
6722
6722
}
6723
6723
#endif /* HAVE_GETPID */
6724
6724
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
+
6725
6732
#ifdef HAVE_GETGROUPLIST
6726
6733
6727
6734
/* AC 3.5: funny apple logic below */
@@ -6734,13 +6741,6 @@ Returns a list of groups to which a user belongs.\n\n\
6734
6741
static PyObject *
6735
6742
posix_getgrouplist (PyObject * self , PyObject * args )
6736
6743
{
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
-
6744
6744
const char * user ;
6745
6745
int i , ngroups ;
6746
6746
PyObject * list ;
@@ -6749,7 +6749,16 @@ posix_getgrouplist(PyObject *self, PyObject *args)
6749
6749
#else
6750
6750
gid_t * groups , basegid ;
6751
6751
#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 ;
6753
6762
6754
6763
#ifdef __APPLE__
6755
6764
if (!PyArg_ParseTuple (args , "si:getgrouplist" , & user , & basegid ))
@@ -6818,13 +6827,6 @@ os_getgroups_impl(PyObject *module)
6818
6827
/*[clinic end generated code: output=42b0c17758561b56 input=d3f109412e6a155c]*/
6819
6828
{
6820
6829
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
6828
6830
gid_t grouplist [MAX_GROUPS ];
6829
6831
6830
6832
/* On MacOSX getgroups(2) can return more than MAX_GROUPS results
0 commit comments