summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2009-11-27 14:09:49 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2009-11-27 14:09:49 (GMT)
commit7aed61ae466570fc9fbb8cb26c31e02c1a57e82d (patch)
tree6eb60ddb67a4866abff4f431ce43b1c2bd3e51b9 /Modules
parent03f6c11f07f7f7163186c7f8cb9da086ba703162 (diff)
downloadcpython-7aed61ae466570fc9fbb8cb26c31e02c1a57e82d.zip
cpython-7aed61ae466570fc9fbb8cb26c31e02c1a57e82d.tar.gz
cpython-7aed61ae466570fc9fbb8cb26c31e02c1a57e82d.tar.bz2
Merged revisions 76550 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r76550 | martin.v.loewis | 2009-11-27 14:56:01 +0100 (Fr, 27 Nov 2009) | 2 lines Issue #6508: Add posix.{getresuid,getresgid,setresuid,setresgid}. ........
Diffstat (limited to 'Modules')
-rw-r--r--Modules/posixmodule.c89
1 files changed, 89 insertions, 0 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 22b637e..eaf5b40 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -6953,6 +6953,82 @@ vms_urandom(PyObject *self, PyObject *args)
}
#endif
+#ifdef HAVE_SETRESUID
+PyDoc_STRVAR(posix_setresuid__doc__,
+"setresuid(ruid, euid, suid)\n\n\
+Set the current process's real, effective, and saved user ids.");
+
+static PyObject*
+posix_setresuid (PyObject *self, PyObject *args)
+{
+ /* We assume uid_t is no larger than a long. */
+ long ruid, euid, suid;
+ if (!PyArg_ParseTuple(args, "lll", &ruid, &euid, &suid))
+ return NULL;
+ if (setresuid(ruid, euid, suid) < 0)
+ return posix_error();
+ Py_RETURN_NONE;
+}
+#endif
+
+#ifdef HAVE_SETRESGID
+PyDoc_STRVAR(posix_setresgid__doc__,
+"setresgid(rgid, egid, sgid)\n\n\
+Set the current process's real, effective, and saved group ids.");
+
+static PyObject*
+posix_setresgid (PyObject *self, PyObject *args)
+{
+ /* We assume uid_t is no larger than a long. */
+ long rgid, egid, sgid;
+ if (!PyArg_ParseTuple(args, "lll", &rgid, &egid, &sgid))
+ return NULL;
+ if (setresgid(rgid, egid, sgid) < 0)
+ return posix_error();
+ Py_RETURN_NONE;
+}
+#endif
+
+#ifdef HAVE_GETRESUID
+PyDoc_STRVAR(posix_getresuid__doc__,
+"getresuid() -> (ruid, euid, suid)\n\n\
+Get tuple of the current process's real, effective, and saved user ids.");
+
+static PyObject*
+posix_getresuid (PyObject *self, PyObject *noargs)
+{
+ uid_t ruid, euid, suid;
+ long l_ruid, l_euid, l_suid;
+ if (getresuid(&ruid, &euid, &suid) < 0)
+ return posix_error();
+ /* Force the values into long's as we don't know the size of uid_t. */
+ l_ruid = ruid;
+ l_euid = euid;
+ l_suid = suid;
+ return Py_BuildValue("(lll)", l_ruid, l_euid, l_suid);
+}
+#endif
+
+#ifdef HAVE_GETRESGID
+PyDoc_STRVAR(posix_getresgid__doc__,
+"getresgid() -> (rgid, egid, sgid)\n\n\
+Get tuple of the current process's real, effective, and saved user ids.");
+
+static PyObject*
+posix_getresgid (PyObject *self, PyObject *noargs)
+{
+ uid_t rgid, egid, sgid;
+ long l_rgid, l_egid, l_sgid;
+ if (getresgid(&rgid, &egid, &sgid) < 0)
+ return posix_error();
+ /* Force the values into long's as we don't know the size of uid_t. */
+ l_rgid = rgid;
+ l_egid = egid;
+ l_sgid = sgid;
+ return Py_BuildValue("(lll)", l_rgid, l_egid, l_sgid);
+}
+#endif
+
static PyMethodDef posix_methods[] = {
{"access", posix_access, METH_VARARGS, posix_access__doc__},
#ifdef HAVE_TTYNAME
@@ -7242,6 +7318,19 @@ static PyMethodDef posix_methods[] = {
#ifdef __VMS
{"urandom", vms_urandom, METH_VARARGS, vms_urandom__doc__},
#endif
+#ifdef HAVE_SETRESUID
+ {"setresuid", posix_setresuid, METH_VARARGS, posix_setresuid__doc__},
+#endif
+#ifdef HAVE_SETRESGID
+ {"setresgid", posix_setresgid, METH_VARARGS, posix_setresgid__doc__},
+#endif
+#ifdef HAVE_GETRESUID
+ {"getresuid", posix_getresuid, METH_NOARGS, posix_getresuid__doc__},
+#endif
+#ifdef HAVE_GETRESGID
+ {"getresgid", posix_getresgid, METH_NOARGS, posix_getresgid__doc__},
+#endif
+
{NULL, NULL} /* Sentinel */
};