]> granicus.if.org Git - python/commitdiff
Expose setgroups. Fixes feature request #468116.
authorMartin v. Löwis <martin@v.loewis.de>
Thu, 18 Oct 2001 04:06:00 +0000 (04:06 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Thu, 18 Oct 2001 04:06:00 +0000 (04:06 +0000)
Doc/lib/libos.tex
Misc/NEWS
Modules/posixmodule.c
configure
configure.in
pyconfig.h.in

index 8adcbd5a34d66e5b0821d8fe25fbc6941f787479..70552c40070fa998367e23e4b3223afbc73bb1cc 100644 (file)
@@ -204,6 +204,13 @@ Set the current process' group id.
 Availability: \UNIX{}.
 \end{funcdesc}
 
+\begin{funcdesc}{setgroups}{groups}
+Set list of supplemental group ids associated with the current
+process to \var{groups}.
+Availability: \UNIX{}.
+\versionadded{2.2}
+\end{funcdesc}
+
 \begin{funcdesc}{setpgrp}{}
 Calls the system call \cfunction{setpgrp()} or \cfunction{setpgrp(0,
 0)} depending on which version is implemented (if any).  See the
index 74327c4dfabe75e3c02adec00209b324190df38b..e2e9683344a68a46fed5c975607693f6f3af07d7 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -44,7 +44,7 @@ Extension modules
 
 - readline now supports setting the startup_hook and the pre_event_hook.
 
-- posix supports chroot where available.
+- posix supports chroot and setgroups where available.
 
 - Decompression objects in the zlib module now accept an optional
   second parameter to decompress() that specifies the maximum amount
index c21f7f85296c45749e5fe071da22b2fcdee22179..b26c89eccfc642f91776ddcfa1bc7fd1ddd6356d 100644 (file)
@@ -3127,6 +3127,51 @@ posix_setgid(PyObject *self, PyObject *args)
 }
 #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
 static char posix_waitpid__doc__[] =
@@ -5467,6 +5512,9 @@ static PyMethodDef posix_methods[] = {
 #ifdef HAVE_SETGID
        {"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__},
 #endif /* HAVE_SETPGRP */
index 260ea3fd1eb66371d9aae5df1d97dc1f8cfc2340..be57265229763f96a17794bd52d8e0e7d352eb3a 100755 (executable)
--- a/configure
+++ b/configure
@@ -1,6 +1,6 @@
 #! /bin/sh
 
-# From configure.in Revision: 1.268 
+# From configure.in Revision: 1.269 
 
 # Guess values for system-dependent variables and create Makefiles.
 # Generated automatically using autoconf version 2.13 
@@ -4804,7 +4804,7 @@ for ac_func in alarm chown chroot clock confstr ctermid ctermid_r execv \
  hstrerror inet_pton kill link lstat mkfifo mktime mremap \
  nice pathconf pause plock poll pthread_init \
  putenv readlink \
- select setegid seteuid setgid \
+ select setegid seteuid setgid setgroups \
  setlocale setregid setreuid setsid setpgid setuid setvbuf snprintf \
  sigaction siginterrupt sigrelse strftime strptime symlink sysconf \
  tcgetpgrp tcsetpgrp tempnam timegm times tmpfile tmpnam tmpnam_r \
index 108d2399269a9dc816a70a01d7ff91ca78bbaf30..1c2f45996f847acdc6a737288a562d4dccb73937 100644 (file)
@@ -1391,7 +1391,7 @@ AC_CHECK_FUNCS(alarm chown chroot clock confstr ctermid ctermid_r execv \
  hstrerror inet_pton kill link lstat mkfifo mktime mremap \
  nice pathconf pause plock poll pthread_init \
  putenv readlink \
- select setegid seteuid setgid \
+ select setegid seteuid setgid setgroups \
  setlocale setregid setreuid setsid setpgid setuid setvbuf snprintf \
  sigaction siginterrupt sigrelse strftime strptime symlink sysconf \
  tcgetpgrp tcsetpgrp tempnam timegm times tmpfile tmpnam tmpnam_r \
index 7057895fa5d2b526a384d3e814bcdceb34bd5b3b..8967cc6b74a62154b7794a1ce02b261ba4c7b7a7 100644 (file)
 /* Define if you have the setgid function.  */
 #undef HAVE_SETGID
 
+/* Define if you have the setgroups function.  */
+#undef HAVE_SETGROUPS
+
 /* Define if you have the setlocale function.  */
 #undef HAVE_SETLOCALE