]> granicus.if.org Git - python/commitdiff
Fixes issue #7999: os.setreuid() and os.setregid() would refuse to accept
authorGregory P. Smith <greg@mad-scientist.com>
Mon, 1 Mar 2010 05:43:43 +0000 (05:43 +0000)
committerGregory P. Smith <greg@mad-scientist.com>
Mon, 1 Mar 2010 05:43:43 +0000 (05:43 +0000)
a -1 parameter on some platforms such as OS X.

Lib/test/test_os.py
Misc/NEWS
Modules/posixmodule.c

index f8bb16bca33242fab80fd3e760aa60d59d4278d5..44cc4cb7134ab0dcb6e19544b99e90ef4c5238de 100644 (file)
@@ -642,6 +642,7 @@ if sys.platform != 'win32':
                     self.assertRaises(os.error, os.setreuid, 0, 0)
                 self.assertRaises(OverflowError, os.setreuid, 1<<32, 0)
                 self.assertRaises(OverflowError, os.setreuid, 0, 1<<32)
+                os.setreuid(-1, -1)  # Does nothing, but it needs to accept -1
 
         if hasattr(os, 'setregid'):
             def test_setregid(self):
@@ -649,6 +650,7 @@ if sys.platform != 'win32':
                     self.assertRaises(os.error, os.setregid, 0, 0)
                 self.assertRaises(OverflowError, os.setregid, 1<<32, 0)
                 self.assertRaises(OverflowError, os.setregid, 0, 1<<32)
+                os.setregid(-1, -1)  # Does nothing, but it needs to accept -1
 else:
     class PosixUidGidTests(unittest.TestCase):
         pass
index b1105590af8ed4837d590b30636a1f3b2521dbb8..319d128bc0663c86103a0c19da8e8079138c9c4b 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -93,6 +93,9 @@ Extension Modules
   thread could raise an incorrect RuntimeError about not holding the import
   lock.  The import lock is now reinitialized after fork.
 
+- Issue #7999: os.setreuid() and os.setregid() would refuse to accept a -1
+  parameter on some platforms such as OS X.
+
 Tests
 -----
 
index 26c6e461005150b0f4bb3c1a14d2b91a6eca0f64..f729e88dab1372f51a5dce26f91e00f43f0ba822 100644 (file)
@@ -5650,9 +5650,16 @@ posix_setreuid (PyObject *self, PyObject *args)
        uid_t ruid, euid;
        if (!PyArg_ParseTuple(args, "ll", &ruid_arg, &euid_arg))
                return NULL;
-       ruid = ruid_arg;
-       euid = euid_arg;
-       if (euid != euid_arg || ruid != ruid_arg) {
+       if (ruid_arg == -1)
+               ruid = (uid_t)-1;  /* let the compiler choose how -1 fits */
+       else
+               ruid = ruid_arg;  /* otherwise, assign from our long */
+       if (euid_arg == -1)
+               euid = (uid_t)-1;
+       else
+               euid = euid_arg;
+       if ((euid_arg != -1 && euid != euid_arg) || 
+           (ruid_arg != -1 && ruid != ruid_arg)) {
                PyErr_SetString(PyExc_OverflowError, "user id too big");
                return NULL;
        }
@@ -5677,9 +5684,16 @@ posix_setregid (PyObject *self, PyObject *args)
        gid_t rgid, egid;
        if (!PyArg_ParseTuple(args, "ll", &rgid_arg, &egid_arg))
                return NULL;
-       rgid = rgid_arg;
-       egid = egid_arg;
-       if (egid != egid_arg || rgid != rgid_arg) {
+       if (rgid_arg == -1)
+               rgid = (gid_t)-1;  /* let the compiler choose how -1 fits */
+       else
+               rgid = rgid_arg;  /* otherwise, assign from our long */
+       if (egid_arg == -1)
+               egid = (gid_t)-1;
+       else
+               egid = egid_arg;
+       if ((egid_arg != -1 && egid != egid_arg) || 
+           (rgid_arg != -1 && rgid != rgid_arg)) {
                PyErr_SetString(PyExc_OverflowError, "group id too big");
                return NULL;
        }