@@ -6120,6 +6120,13 @@ os_getpid_impl(PyObject *module)
6120
6120
}
6121
6121
#endif /* HAVE_GETPID */
6122
6122
6123
+ #ifdef NGROUPS_MAX
6124
+ #define MAX_GROUPS NGROUPS_MAX
6125
+ #else
6126
+ /* defined to be 16 on Solaris7, so this should be a small number */
6127
+ #define MAX_GROUPS 64
6128
+ #endif
6129
+
6123
6130
#ifdef HAVE_GETGROUPLIST
6124
6131
6125
6132
/* AC 3.5: funny apple logic below */
@@ -6132,13 +6139,6 @@ Returns a list of groups to which a user belongs.\n\n\
6132
6139
static PyObject *
6133
6140
posix_getgrouplist (PyObject * self , PyObject * args )
6134
6141
{
6135
- #ifdef NGROUPS_MAX
6136
- #define MAX_GROUPS NGROUPS_MAX
6137
- #else
6138
- /* defined to be 16 on Solaris7, so this should be a small number */
6139
- #define MAX_GROUPS 64
6140
- #endif
6141
-
6142
6142
const char * user ;
6143
6143
int i , ngroups ;
6144
6144
PyObject * list ;
@@ -6147,7 +6147,16 @@ posix_getgrouplist(PyObject *self, PyObject *args)
6147
6147
#else
6148
6148
gid_t * groups , basegid ;
6149
6149
#endif
6150
- ngroups = MAX_GROUPS ;
6150
+
6151
+ /*
6152
+ * NGROUPS_MAX is defined by POSIX.1 as the maximum
6153
+ * number of supplimental groups a users can belong to.
6154
+ * We have to increment it by one because
6155
+ * getgrouplist() returns both the supplemental groups
6156
+ * and the primary group, i.e. all of the groups the
6157
+ * user belongs to.
6158
+ */
6159
+ ngroups = 1 + MAX_GROUPS ;
6151
6160
6152
6161
#ifdef __APPLE__
6153
6162
if (!PyArg_ParseTuple (args , "si:getgrouplist" , & user , & basegid ))
@@ -6216,13 +6225,6 @@ os_getgroups_impl(PyObject *module)
6216
6225
/*[clinic end generated code: output=42b0c17758561b56 input=d3f109412e6a155c]*/
6217
6226
{
6218
6227
PyObject * result = NULL ;
6219
-
6220
- #ifdef NGROUPS_MAX
6221
- #define MAX_GROUPS NGROUPS_MAX
6222
- #else
6223
- /* defined to be 16 on Solaris7, so this should be a small number */
6224
- #define MAX_GROUPS 64
6225
- #endif
6226
6228
gid_t grouplist [MAX_GROUPS ];
6227
6229
6228
6230
/* On MacOSX getgroups(2) can return more than MAX_GROUPS results
0 commit comments