[Python-checkins] CVS: python/dist/src/Modules posixmodule.c,2.200,2.201
Martin v. L?wis
loewis@users.sourceforge.net
Wed, 17 Oct 2001 21:06:02 -0700
Update of /cvsroot/python/python/dist/src/Modules
In directory usw-pr-cvs1:/tmp/cvs-serv21278/Modules
Modified Files:
posixmodule.c
Log Message:
Expose setgroups. Fixes feature request #468116.
Index: posixmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/posixmodule.c,v
retrieving revision 2.200
retrieving revision 2.201
diff -C2 -d -r2.200 -r2.201
*** posixmodule.c 2001/10/04 22:44:26 2.200
--- posixmodule.c 2001/10/18 04:06:00 2.201
***************
*** 3128,3131 ****
--- 3128,3176 ----
#endif /* HAVE_SETGID */
+ #ifdef HAVE_SETGROUPS
+ static char posix_setgroups__doc__[] =
+ "setgroups(list) -> None\n\
+ Set the groups of the current process to list.";
+
+ static PyObject *
+ posix_setgroups(PyObject *self, PyObject *args)
+ {
+ PyObject *groups;
+ int i, len;
+ gid_t grouplist[MAX_GROUPS];
+
+ if (!PyArg_ParseTuple(args, "O:setgid", &groups))
+ return NULL;
+ if (!PySequence_Check(groups)) {
+ PyErr_SetString(PyExc_TypeError, "setgroups argument must be a sequence");
+ return NULL;
+ }
+ len = PySequence_Size(groups);
+ if (len > MAX_GROUPS) {
+ PyErr_SetString(PyExc_ValueError, "too many groups");
+ return NULL;
+ }
+ for(i = 0; i < len; i++) {
+ PyObject *elem;
+ elem = PySequence_GetItem(groups, i);
+ if (!elem)
+ return NULL;
+ if (!PyInt_Check(elem)) {
+ PyErr_SetString(PyExc_TypeError,
+ "groups must be integers");
+ Py_DECREF(elem);
+ return NULL;
+ }
+ /* XXX: check that value fits into gid_t. */
+ grouplist[i] = PyInt_AsLong(elem);
+ Py_DECREF(elem);
+ }
+
+ if (setgroups(len, grouplist) < 0)
+ return posix_error();
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+ #endif /* HAVE_SETGROUPS */
#ifdef HAVE_WAITPID
***************
*** 5468,5471 ****
--- 5513,5519 ----
{"setgid", posix_setgid, METH_VARARGS, posix_setgid__doc__},
#endif /* HAVE_SETGID */
+ #ifdef HAVE_SETGROUPS
+ {"setgroups", posix_setgroups, METH_VARARGS, posix_setgroups__doc__},
+ #endif /* HAVE_SETGROUPS */
#ifdef HAVE_SETPGRP
{"setpgrp", posix_setpgrp, METH_VARARGS, posix_setpgrp__doc__},