torsava / rpms / python3

Forked from rpms/python3 2 years ago
Clone
1c94c1
diff -up Python-3.3.0b1/Include/modsupport.h.uid-gid-overflows Python-3.3.0b1/Include/modsupport.h
1c94c1
--- Python-3.3.0b1/Include/modsupport.h.uid-gid-overflows	2012-06-26 16:19:40.000000000 -0400
1c94c1
+++ Python-3.3.0b1/Include/modsupport.h	2012-07-20 14:21:46.854688763 -0400
a25ec0
@@ -8,6 +8,7 @@ extern "C" {
a25ec0
 /* Module support interface */
a25ec0
 
a25ec0
 #include <stdarg.h>
a25ec0
+#include <sys types.h="">
a25ec0
 
a25ec0
 /* If PY_SSIZE_T_CLEAN is defined, each functions treats #-specifier
a25ec0
    to mean Py_ssize_t */
1c94c1
@@ -125,6 +126,17 @@ PyAPI_FUNC(PyObject *) PyModule_Create2(
798936
 PyAPI_DATA(char *) _Py_PackageContext;
798936
 #endif
798936
 
798936
+/*
798936
+  Non-standard extension: support for dealing with uid_t and gid_t without
798936
+  integer overflow
798936
+ */
798936
+
798936
+PyAPI_FUNC(PyObject *) _PyObject_FromUid(uid_t uid);
798936
+PyAPI_FUNC(PyObject *) _PyObject_FromGid(gid_t gid);
798936
+
798936
+PyAPI_FUNC(int) _PyArg_ParseUid(PyObject *in_obj, uid_t *out_uid);
798936
+PyAPI_FUNC(int) _PyArg_ParseGid(PyObject *in_obj, gid_t *out_gid);
798936
+
798936
 #ifdef __cplusplus
798936
 }
798936
 #endif
1c94c1
diff -up Python-3.3.0b1/Lib/test/test_os.py.uid-gid-overflows Python-3.3.0b1/Lib/test/test_os.py
1c94c1
--- Python-3.3.0b1/Lib/test/test_os.py.uid-gid-overflows	2012-06-26 16:19:48.000000000 -0400
1c94c1
+++ Python-3.3.0b1/Lib/test/test_os.py	2012-07-20 14:21:46.856688739 -0400
1c94c1
@@ -1174,30 +1174,36 @@ if sys.platform != 'win32':
798936
             def test_setuid(self):
798936
                 if os.getuid() != 0:
798936
                     self.assertRaises(os.error, os.setuid, 0)
798936
+                self.assertRaises(TypeError, os.setuid, 'not an int')
798936
                 self.assertRaises(OverflowError, os.setuid, 1<<32)
798936
 
798936
         if hasattr(os, 'setgid'):
798936
             def test_setgid(self):
798936
                 if os.getuid() != 0:
798936
                     self.assertRaises(os.error, os.setgid, 0)
798936
+                self.assertRaises(TypeError, os.setgid, 'not an int')
798936
                 self.assertRaises(OverflowError, os.setgid, 1<<32)
798936
 
798936
         if hasattr(os, 'seteuid'):
798936
             def test_seteuid(self):
798936
                 if os.getuid() != 0:
798936
                     self.assertRaises(os.error, os.seteuid, 0)
798936
+                self.assertRaises(TypeError, os.seteuid, 'not an int')
798936
                 self.assertRaises(OverflowError, os.seteuid, 1<<32)
798936
 
798936
         if hasattr(os, 'setegid'):
798936
             def test_setegid(self):
798936
                 if os.getuid() != 0:
798936
                     self.assertRaises(os.error, os.setegid, 0)
798936
+                self.assertRaises(TypeError, os.setegid, 'not an int')
798936
                 self.assertRaises(OverflowError, os.setegid, 1<<32)
798936
 
798936
         if hasattr(os, 'setreuid'):
798936
             def test_setreuid(self):
798936
                 if os.getuid() != 0:
798936
                     self.assertRaises(os.error, os.setreuid, 0, 0)
798936
+                self.assertRaises(TypeError, os.setreuid, 'not an int', 0)
798936
+                self.assertRaises(TypeError, os.setreuid, 0, 'not an int')
798936
                 self.assertRaises(OverflowError, os.setreuid, 1<<32, 0)
798936
                 self.assertRaises(OverflowError, os.setreuid, 0, 1<<32)
798936
 
1c94c1
@@ -1212,6 +1218,8 @@ if sys.platform != 'win32':
798936
             def test_setregid(self):
798936
                 if os.getuid() != 0:
798936
                     self.assertRaises(os.error, os.setregid, 0, 0)
798936
+                self.assertRaises(TypeError, os.setregid, 'not an int', 0)
798936
+                self.assertRaises(TypeError, os.setregid, 0, 'not an int')
798936
                 self.assertRaises(OverflowError, os.setregid, 1<<32, 0)
798936
                 self.assertRaises(OverflowError, os.setregid, 0, 1<<32)
798936
 
1c94c1
diff -up Python-3.3.0b1/Lib/test/test_posix.py.uid-gid-overflows Python-3.3.0b1/Lib/test/test_posix.py
1c94c1
--- Python-3.3.0b1/Lib/test/test_posix.py.uid-gid-overflows	2012-06-26 16:19:48.000000000 -0400
1c94c1
+++ Python-3.3.0b1/Lib/test/test_posix.py	2012-07-20 14:21:46.857688726 -0400
1c94c1
@@ -387,10 +387,17 @@ class PosixTester(unittest.TestCase):
798936
         else:
798936
             self.assertTrue(stat.S_ISFIFO(posix.stat(support.TESTFN).st_mode))
798936
 
798936
-    def _test_all_chown_common(self, chown_func, first_param):
798936
+    def _test_all_chown_common(self, chown_func, stat_func, first_param):
798936
         """Common code for chown, fchown and lchown tests."""
798936
         # test a successful chown call
798936
         chown_func(first_param, os.getuid(), os.getgid())
798936
+        self.assertEqual(stat_func(first_param).st_uid, os.getuid())
798936
+        self.assertEqual(stat_func(first_param).st_gid, os.getgid())
798936
+
798936
+        # verify that -1 works as a "do-nothing" option:
798936
+        chown_func(first_param, -1, -1)
798936
+        self.assertEqual(stat_func(first_param).st_uid, os.getuid())
798936
+        self.assertEqual(stat_func(first_param).st_gid, os.getgid())
798936
 
1c94c1
         if os.getuid() == 0:
1c94c1
             try:
1c94c1
@@ -421,7 +428,7 @@ class PosixTester(unittest.TestCase):
798936
 
798936
         # re-create the file
1c94c1
         support.create_empty_file(support.TESTFN)
798936
-        self._test_all_chown_common(posix.chown, support.TESTFN)
798936
+        self._test_all_chown_common(posix.chown, posix.stat, support.TESTFN)
798936
 
798936
     @unittest.skipUnless(hasattr(posix, 'fchown'), "test needs os.fchown()")
798936
     def test_fchown(self):
1c94c1
@@ -431,7 +438,7 @@ class PosixTester(unittest.TestCase):
798936
         test_file = open(support.TESTFN, 'w')
798936
         try:
798936
             fd = test_file.fileno()
798936
-            self._test_all_chown_common(posix.fchown, fd)
798936
+            self._test_all_chown_common(posix.fchown, posix.fstat, fd)
798936
         finally:
798936
             test_file.close()
798936
 
1c94c1
@@ -440,7 +447,7 @@ class PosixTester(unittest.TestCase):
798936
         os.unlink(support.TESTFN)
798936
         # create a symlink
798936
         os.symlink(_DUMMY_SYMLINK, support.TESTFN)
798936
-        self._test_all_chown_common(posix.lchown, support.TESTFN)
798936
+        self._test_all_chown_common(posix.lchown, posix.lstat, support.TESTFN)
798936
 
798936
     def test_chdir(self):
798936
         if hasattr(posix, 'chdir'):
1c94c1
diff -up Python-3.3.0b1/Lib/test/test_pwd.py.uid-gid-overflows Python-3.3.0b1/Lib/test/test_pwd.py
1c94c1
--- Python-3.3.0b1/Lib/test/test_pwd.py.uid-gid-overflows	2012-06-26 16:19:48.000000000 -0400
1c94c1
+++ Python-3.3.0b1/Lib/test/test_pwd.py	2012-07-20 14:21:46.857688726 -0400
798936
@@ -87,9 +87,9 @@ class PwdTest(unittest.TestCase):
798936
         # In some cases, byuids isn't a complete list of all users in the
798936
         # system, so if we try to pick a value not in byuids (via a perturbing
798936
         # loop, say), pwd.getpwuid() might still be able to find data for that
798936
-        # uid. Using sys.maxint may provoke the same problems, but hopefully
798936
+        # uid. Using 2**32 - 2 may provoke the same problems, but hopefully
798936
         # it will be a more repeatable failure.
798936
-        fakeuid = sys.maxsize
798936
+        fakeuid = 2**32 - 2
798936
         self.assertNotIn(fakeuid, byuids)
798936
         self.assertRaises(KeyError, pwd.getpwuid, fakeuid)
798936
 
1c94c1
diff -up Python-3.3.0b1/Modules/grpmodule.c.uid-gid-overflows Python-3.3.0b1/Modules/grpmodule.c
1c94c1
--- Python-3.3.0b1/Modules/grpmodule.c.uid-gid-overflows	2012-06-26 16:19:54.000000000 -0400
1c94c1
+++ Python-3.3.0b1/Modules/grpmodule.c	2012-07-20 14:21:46.858688713 -0400
798936
@@ -69,7 +69,7 @@ mkgrent(struct group *p)
798936
             Py_INCREF(Py_None);
798936
     }
798936
 #endif
798936
-    SET(setIndex++, PyLong_FromLong((long) p->gr_gid));
798936
+    SET(setIndex++, _PyObject_FromGid(p->gr_gid));
798936
     SET(setIndex++, w);
798936
 #undef SET
798936
 
798936
@@ -84,18 +84,16 @@ mkgrent(struct group *p)
798936
 static PyObject *
798936
 grp_getgrgid(PyObject *self, PyObject *pyo_id)
798936
 {
798936
-    PyObject *py_int_id;
798936
-    unsigned int gid;
798936
+    gid_t gid;
798936
     struct group *p;
798936
 
798936
-    py_int_id = PyNumber_Long(pyo_id);
798936
-    if (!py_int_id)
798936
-            return NULL;
798936
-    gid = PyLong_AS_LONG(py_int_id);
798936
-    Py_DECREF(py_int_id);
798936
+    if (!_PyArg_ParseGid(pyo_id, &gid)) {
798936
+        return NULL;
798936
+    }
798936
 
798936
     if ((p = getgrgid(gid)) == NULL) {
798936
-        PyErr_Format(PyExc_KeyError, "getgrgid(): gid not found: %d", gid);
798936
+        PyErr_Format(PyExc_KeyError,
798936
+                     "getgrgid(): gid not found: %lu", (unsigned long)gid);
798936
         return NULL;
798936
     }
798936
     return mkgrent(p);
1c94c1
diff -up Python-3.3.0b1/Modules/posixmodule.c.uid-gid-overflows Python-3.3.0b1/Modules/posixmodule.c
1c94c1
--- Python-3.3.0b1/Modules/posixmodule.c.uid-gid-overflows	2012-07-20 14:21:46.788689588 -0400
1c94c1
+++ Python-3.3.0b1/Modules/posixmodule.c	2012-07-20 14:24:19.626778849 -0400
1c94c1
@@ -2151,8 +2151,8 @@ _pystat_fromstructstat(STRUCT_STAT *st)
798936
     PyStructSequence_SET_ITEM(v, 2, PyLong_FromLong((long)st->st_dev));
798936
 #endif
798936
     PyStructSequence_SET_ITEM(v, 3, PyLong_FromLong((long)st->st_nlink));
798936
-    PyStructSequence_SET_ITEM(v, 4, PyLong_FromLong((long)st->st_uid));
798936
-    PyStructSequence_SET_ITEM(v, 5, PyLong_FromLong((long)st->st_gid));
798936
+    PyStructSequence_SET_ITEM(v, 4, _PyObject_FromUid(st->st_uid));
798936
+    PyStructSequence_SET_ITEM(v, 5, _PyObject_FromGid(st->st_gid));
798936
 #ifdef HAVE_LARGEFILE_SUPPORT
798936
     PyStructSequence_SET_ITEM(v, 6,
798936
                               PyLong_FromLongLong((PY_LONG_LONG)st->st_size));
1c94c1
@@ -2957,7 +2957,6 @@ static PyObject *
1c94c1
 posix_chown(PyObject *self, PyObject *args, PyObject *kwargs)
798936
 {
1c94c1
     path_t path;
1c94c1
-    long uid_l, gid_l;
1c94c1
     uid_t uid;
1c94c1
     gid_t gid;
1c94c1
     int dir_fd = DEFAULT_DIR_FD;
1c94c1
@@ -2971,9 +2970,10 @@ posix_chown(PyObject *self, PyObject *ar
1c94c1
 #ifdef HAVE_FCHOWN
1c94c1
     path.allow_fd = 1;
1c94c1
 #endif
1c94c1
-    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&ll|$O&p:chown", keywords,
1c94c1
+    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&O&O&|$O&p:chown", keywords,
1c94c1
                                      path_converter, &path,
1c94c1
-                                     &uid_l, &gid_l,
1c94c1
+                                     _PyArg_ParseUid, &uid,
1c94c1
+                                     _PyArg_ParseGid, &gid,
1c94c1
 #ifdef HAVE_FCHOWNAT
1c94c1
                                      dir_fd_converter, &dir_fd,
1c94c1
 #else
1c94c1
@@ -3004,8 +3004,6 @@ posix_chown(PyObject *self, PyObject *ar
1c94c1
 #endif
1c94c1
 
798936
     Py_BEGIN_ALLOW_THREADS
1c94c1
-    uid = (uid_t)uid_l;
1c94c1
-    gid = (uid_t)gid_l;
1c94c1
 #ifdef HAVE_FCHOWN
1c94c1
     if (path.fd != -1)
1c94c1
         result = fchown(path.fd, uid, gid);
1c94c1
@@ -3049,12 +3047,15 @@ static PyObject *
798936
 posix_fchown(PyObject *self, PyObject *args)
798936
 {
798936
     int fd;
798936
-    long uid, gid;
798936
+    uid_t uid;
798936
+    gid_t gid;
798936
     int res;
798936
-    if (!PyArg_ParseTuple(args, "ill:fchown", &fd, &uid, &gid))
798936
+    if (!PyArg_ParseTuple(args, "iO&O&:chown", &fd,
798936
+                          _PyArg_ParseUid, &uid,
798936
+                          _PyArg_ParseGid, &gid))
798936
         return NULL;
798936
     Py_BEGIN_ALLOW_THREADS
798936
-    res = fchown(fd, (uid_t) uid, (gid_t) gid);
798936
+    res = fchown(fd, uid, gid);
798936
     Py_END_ALLOW_THREADS
798936
     if (res < 0)
798936
         return posix_error();
1c94c1
@@ -3074,15 +3075,17 @@ posix_lchown(PyObject *self, PyObject *a
798936
 {
798936
     PyObject *opath;
798936
     char *path;
798936
-    long uid, gid;
798936
+    uid_t uid;
798936
+    gid_t gid;
798936
     int res;
798936
-    if (!PyArg_ParseTuple(args, "O&ll:lchown",
798936
+    if (!PyArg_ParseTuple(args, "O&O&O&:lchown",
798936
                           PyUnicode_FSConverter, &opath,
798936
-                          &uid, &gid))
798936
+                          _PyArg_ParseUid, &uid,
798936
+                          _PyArg_ParseGid, &gid))
798936
         return NULL;
798936
     path = PyBytes_AsString(opath);
798936
     Py_BEGIN_ALLOW_THREADS
798936
-    res = lchown(path, (uid_t) uid, (gid_t) gid);
798936
+    res = lchown(path, uid, gid);
798936
     Py_END_ALLOW_THREADS
798936
     if (res < 0)
798936
         return posix_error_with_allocated_filename(opath);
1c94c1
@@ -6184,7 +6187,7 @@ Return the current process's effective g
798936
 static PyObject *
798936
 posix_getegid(PyObject *self, PyObject *noargs)
798936
 {
798936
-    return PyLong_FromLong((long)getegid());
798936
+  return _PyObject_FromGid(getegid());
798936
 }
798936
 #endif
798936
 
1c94c1
@@ -6197,7 +6200,7 @@ Return the current process's effective u
798936
 static PyObject *
798936
 posix_geteuid(PyObject *self, PyObject *noargs)
798936
 {
798936
-    return PyLong_FromLong((long)geteuid());
798936
+    return _PyObject_FromUid(geteuid());
798936
 }
798936
 #endif
798936
 
1c94c1
@@ -6210,7 +6213,7 @@ Return the current process's group id.")
798936
 static PyObject *
798936
 posix_getgid(PyObject *self, PyObject *noargs)
798936
 {
798936
-    return PyLong_FromLong((long)getgid());
798936
+    return _PyObject_FromGid(getgid());
798936
 }
798936
 #endif
798936
 
1c94c1
@@ -6349,7 +6352,7 @@ posix_getgroups(PyObject *self, PyObject
798936
     if (result != NULL) {
798936
         int i;
798936
         for (i = 0; i < n; ++i) {
798936
-            PyObject *o = PyLong_FromLong((long)alt_grouplist[i]);
798936
+            PyObject *o = _PyObject_FromGid(alt_grouplist[i]);
798936
             if (o == NULL) {
798936
                 Py_DECREF(result);
798936
                 result = NULL;
1c94c1
@@ -6380,14 +6383,15 @@ posix_initgroups(PyObject *self, PyObjec
798936
     PyObject *oname;
798936
     char *username;
798936
     int res;
798936
-    long gid;
798936
+    gid_t gid;
798936
 
798936
-    if (!PyArg_ParseTuple(args, "O&l:initgroups",
798936
-                          PyUnicode_FSConverter, &oname, &gid))
798936
+    if (!PyArg_ParseTuple(args, "O&O&:initgroups",
798936
+                          PyUnicode_FSConverter, &oname,
798936
+                          _PyArg_ParseGid, &gid))
798936
         return NULL;
798936
     username = PyBytes_AS_STRING(oname);
798936
 
798936
-    res = initgroups(username, (gid_t) gid);
798936
+    res = initgroups(username, gid);
798936
     Py_DECREF(oname);
798936
     if (res == -1)
798936
         return PyErr_SetFromErrno(PyExc_OSError);
1c94c1
@@ -6562,7 +6566,7 @@ Return the current process's user id.");
798936
 static PyObject *
798936
 posix_getuid(PyObject *self, PyObject *noargs)
798936
 {
798936
-    return PyLong_FromLong((long)getuid());
798936
+    return _PyObject_FromUid(getuid());
798936
 }
798936
 #endif
798936
 
1c94c1
@@ -6702,15 +6706,9 @@ Set the current process's user id.");
798936
 static PyObject *
798936
 posix_setuid(PyObject *self, PyObject *args)
798936
 {
798936
-    long uid_arg;
798936
     uid_t uid;
798936
-    if (!PyArg_ParseTuple(args, "l:setuid", &uid_arg))
798936
-        return NULL;
798936
-    uid = uid_arg;
798936
-    if (uid != uid_arg) {
798936
-        PyErr_SetString(PyExc_OverflowError, "user id too big");
798936
+    if (!PyArg_ParseTuple(args, "O&:setuid", _PyArg_ParseUid, &uid))
798936
         return NULL;
798936
-    }
798936
     if (setuid(uid) < 0)
798936
         return posix_error();
798936
     Py_INCREF(Py_None);
1c94c1
@@ -6727,15 +6725,9 @@ Set the current process's effective user
798936
 static PyObject *
798936
 posix_seteuid (PyObject *self, PyObject *args)
798936
 {
798936
-    long euid_arg;
798936
     uid_t euid;
798936
-    if (!PyArg_ParseTuple(args, "l", &euid_arg))
1c94c1
+    if (!PyArg_ParseTuple(args, "O&:seteuid", _PyArg_ParseUid, &euid))
1c94c1
         return NULL;
798936
-    euid = euid_arg;
798936
-    if (euid != euid_arg) {
798936
-        PyErr_SetString(PyExc_OverflowError, "user id too big");
1c94c1
-        return NULL;
798936
-    }
798936
     if (seteuid(euid) < 0) {
798936
         return posix_error();
798936
     } else {
1c94c1
@@ -6753,15 +6745,9 @@ Set the current process's effective grou
798936
 static PyObject *
798936
 posix_setegid (PyObject *self, PyObject *args)
798936
 {
798936
-    long egid_arg;
798936
     gid_t egid;
798936
-    if (!PyArg_ParseTuple(args, "l", &egid_arg))
798936
-        return NULL;
798936
-    egid = egid_arg;
798936
-    if (egid != egid_arg) {
798936
-        PyErr_SetString(PyExc_OverflowError, "group id too big");
798936
+    if (!PyArg_ParseTuple(args, "O&:setegid", _PyArg_ParseGid, &egid))
798936
         return NULL;
798936
-    }
798936
     if (setegid(egid) < 0) {
798936
         return posix_error();
798936
     } else {
1c94c1
@@ -6779,23 +6765,11 @@ Set the current process's real and effec
798936
 static PyObject *
798936
 posix_setreuid (PyObject *self, PyObject *args)
798936
 {
798936
-    long ruid_arg, euid_arg;
798936
     uid_t ruid, euid;
798936
-    if (!PyArg_ParseTuple(args, "ll", &ruid_arg, &euid_arg))
798936
-        return NULL;
798936
-    if (ruid_arg == -1)
798936
-        ruid = (uid_t)-1;  /* let the compiler choose how -1 fits */
798936
-    else
798936
-        ruid = ruid_arg;  /* otherwise, assign from our long */
798936
-    if (euid_arg == -1)
798936
-        euid = (uid_t)-1;
798936
-    else
798936
-        euid = euid_arg;
798936
-    if ((euid_arg != -1 && euid != euid_arg) ||
798936
-        (ruid_arg != -1 && ruid != ruid_arg)) {
798936
-        PyErr_SetString(PyExc_OverflowError, "user id too big");
798936
+    if (!PyArg_ParseTuple(args, "O&O&",
798936
+			  _PyArg_ParseUid, &ruid,
798936
+			  _PyArg_ParseUid, &euid))
798936
         return NULL;
798936
-    }
798936
     if (setreuid(ruid, euid) < 0) {
798936
         return posix_error();
798936
     } else {
1c94c1
@@ -6813,23 +6787,11 @@ Set the current process's real and effec
798936
 static PyObject *
798936
 posix_setregid (PyObject *self, PyObject *args)
798936
 {
798936
-    long rgid_arg, egid_arg;
798936
     gid_t rgid, egid;
798936
-    if (!PyArg_ParseTuple(args, "ll", &rgid_arg, &egid_arg))
798936
-        return NULL;
798936
-    if (rgid_arg == -1)
798936
-        rgid = (gid_t)-1;  /* let the compiler choose how -1 fits */
798936
-    else
798936
-        rgid = rgid_arg;  /* otherwise, assign from our long */
798936
-    if (egid_arg == -1)
798936
-        egid = (gid_t)-1;
798936
-    else
798936
-        egid = egid_arg;
798936
-    if ((egid_arg != -1 && egid != egid_arg) ||
798936
-        (rgid_arg != -1 && rgid != rgid_arg)) {
798936
-        PyErr_SetString(PyExc_OverflowError, "group id too big");
798936
+    if (!PyArg_ParseTuple(args, "O&O&",
798936
+			  _PyArg_ParseGid, &rgid,
798936
+			  _PyArg_ParseGid, &egid))
798936
         return NULL;
798936
-    }
798936
     if (setregid(rgid, egid) < 0) {
798936
         return posix_error();
798936
     } else {
1c94c1
@@ -6847,15 +6809,9 @@ Set the current process's group id.");
798936
 static PyObject *
798936
 posix_setgid(PyObject *self, PyObject *args)
798936
 {
798936
-    long gid_arg;
798936
     gid_t gid;
798936
-    if (!PyArg_ParseTuple(args, "l:setgid", &gid_arg))
798936
+    if (!PyArg_ParseTuple(args, "O&:setgid", _PyArg_ParseGid, &gid))
798936
         return NULL;
798936
-    gid = gid_arg;
798936
-    if (gid != gid_arg) {
798936
-        PyErr_SetString(PyExc_OverflowError, "group id too big");
798936
-        return NULL;
798936
-    }
798936
     if (setgid(gid) < 0)
798936
         return posix_error();
798936
     Py_INCREF(Py_None);
1c94c1
@@ -6888,27 +6844,9 @@ posix_setgroups(PyObject *self, PyObject
798936
         elem = PySequence_GetItem(groups, i);
798936
         if (!elem)
798936
             return NULL;
798936
-        if (!PyLong_Check(elem)) {
798936
-            PyErr_SetString(PyExc_TypeError,
798936
-                            "groups must be integers");
798936
+        if (!_PyArg_ParseGid(elem, &grouplist[i])) {
798936
             Py_DECREF(elem);
798936
             return NULL;
798936
-        } else {
798936
-            unsigned long x = PyLong_AsUnsignedLong(elem);
798936
-            if (PyErr_Occurred()) {
798936
-                PyErr_SetString(PyExc_TypeError,
798936
-                                "group id too big");
798936
-                Py_DECREF(elem);
798936
-                return NULL;
798936
-            }
798936
-            grouplist[i] = x;
798936
-            /* read back the value to see if it fitted in gid_t */
798936
-            if (grouplist[i] != x) {
798936
-                PyErr_SetString(PyExc_TypeError,
798936
-                                "group id too big");
798936
-                Py_DECREF(elem);
798936
-                return NULL;
798936
-            }
798936
         }
798936
         Py_DECREF(elem);
798936
     }
1c94c1
@@ -10388,9 +10326,11 @@ Set the current process's real, effectiv
798936
 static PyObject*
798936
 posix_setresuid (PyObject *self, PyObject *args)
798936
 {
798936
-    /* We assume uid_t is no larger than a long. */
798936
-    long ruid, euid, suid;
798936
-    if (!PyArg_ParseTuple(args, "lll", &ruid, &euid, &suid))
798936
+    uid_t ruid, euid, suid;
798936
+    if (!PyArg_ParseTuple(args, "O&O&O&",
798936
+                          _PyArg_ParseUid, &ruid,
798936
+                          _PyArg_ParseUid, &euid,
798936
+                          _PyArg_ParseUid, &suid))
798936
         return NULL;
798936
     if (setresuid(ruid, euid, suid) < 0)
798936
         return posix_error();
1c94c1
@@ -10406,9 +10346,11 @@ Set the current process's real, effectiv
798936
 static PyObject*
798936
 posix_setresgid (PyObject *self, PyObject *args)
798936
 {
798936
-    /* We assume uid_t is no larger than a long. */
798936
-    long rgid, egid, sgid;
798936
-    if (!PyArg_ParseTuple(args, "lll", &rgid, &egid, &sgid))
798936
+    gid_t rgid, egid, sgid;
798936
+    if (!PyArg_ParseTuple(args, "O&O&O&",
798936
+                          _PyArg_ParseGid, &rgid,
798936
+                          _PyArg_ParseGid, &egid,
798936
+                          _PyArg_ParseGid, &sgid))
798936
         return NULL;
798936
     if (setresgid(rgid, egid, sgid) < 0)
798936
         return posix_error();
1c94c1
@@ -10425,14 +10367,13 @@ static PyObject*
798936
 posix_getresuid (PyObject *self, PyObject *noargs)
798936
 {
798936
     uid_t ruid, euid, suid;
798936
-    long l_ruid, l_euid, l_suid;
798936
+    PyObject *obj_ruid, *obj_euid, *obj_suid;
798936
     if (getresuid(&ruid, &euid, &suid) < 0)
798936
         return posix_error();
798936
-    /* Force the values into long's as we don't know the size of uid_t. */
798936
-    l_ruid = ruid;
798936
-    l_euid = euid;
798936
-    l_suid = suid;
798936
-    return Py_BuildValue("(lll)", l_ruid, l_euid, l_suid);
798936
+    obj_ruid = _PyObject_FromUid(ruid);
798936
+    obj_euid = _PyObject_FromUid(euid);
798936
+    obj_suid = _PyObject_FromUid(suid);
798936
+    return Py_BuildValue("(NNN)", obj_ruid, obj_euid, obj_suid);
798936
 }
798936
 #endif
798936
 
1c94c1
@@ -10445,14 +10386,13 @@ static PyObject*
798936
 posix_getresgid (PyObject *self, PyObject *noargs)
798936
 {
798936
     uid_t rgid, egid, sgid;
798936
-    long l_rgid, l_egid, l_sgid;
798936
+    PyObject *obj_rgid, *obj_egid, *obj_sgid;
798936
     if (getresgid(&rgid, &egid, &sgid) < 0)
798936
         return posix_error();
798936
-    /* Force the values into long's as we don't know the size of uid_t. */
798936
-    l_rgid = rgid;
798936
-    l_egid = egid;
798936
-    l_sgid = sgid;
798936
-    return Py_BuildValue("(lll)", l_rgid, l_egid, l_sgid);
798936
+    obj_rgid = _PyObject_FromGid(rgid);
798936
+    obj_egid = _PyObject_FromGid(egid);
798936
+    obj_sgid = _PyObject_FromGid(sgid);
798936
+    return Py_BuildValue("(NNN)", obj_rgid, obj_egid, obj_sgid);
798936
 }
798936
 #endif
798936
 
1c94c1
diff -up Python-3.3.0b1/Modules/pwdmodule.c.uid-gid-overflows Python-3.3.0b1/Modules/pwdmodule.c
1c94c1
--- Python-3.3.0b1/Modules/pwdmodule.c.uid-gid-overflows	2012-06-26 16:19:54.000000000 -0400
1c94c1
+++ Python-3.3.0b1/Modules/pwdmodule.c	2012-07-20 14:21:46.861688675 -0400
798936
@@ -74,8 +74,8 @@ mkpwent(struct passwd *p)
798936
 #else
798936
     SETS(setIndex++, p->pw_passwd);
798936
 #endif
798936
-    SETI(setIndex++, p->pw_uid);
798936
-    SETI(setIndex++, p->pw_gid);
798936
+    PyStructSequence_SET_ITEM(v, setIndex++, _PyObject_FromUid(p->pw_uid));
798936
+    PyStructSequence_SET_ITEM(v, setIndex++, _PyObject_FromGid(p->pw_gid));
798936
 #ifdef __VMS
798936
     SETS(setIndex++, "");
798936
 #else
798936
@@ -104,13 +104,14 @@ See help(pwd) for more on password datab
798936
 static PyObject *
798936
 pwd_getpwuid(PyObject *self, PyObject *args)
798936
 {
798936
-    unsigned int uid;
798936
+    uid_t uid;
798936
     struct passwd *p;
798936
-    if (!PyArg_ParseTuple(args, "I:getpwuid", &uid))
798936
+    if (!PyArg_ParseTuple(args, "O&:getpwuid",
798936
+                          _PyArg_ParseUid, &uid))
798936
         return NULL;
798936
     if ((p = getpwuid(uid)) == NULL) {
798936
         PyErr_Format(PyExc_KeyError,
798936
-                     "getpwuid(): uid not found: %d", uid);
798936
+                     "getpwuid(): uid not found: %lu", (unsigned long)uid);
798936
         return NULL;
798936
     }
798936
     return mkpwent(p);
1c94c1
diff -up Python-3.3.0b1/Python/getargs.c.uid-gid-overflows Python-3.3.0b1/Python/getargs.c
1c94c1
--- Python-3.3.0b1/Python/getargs.c.uid-gid-overflows	2012-06-26 16:19:57.000000000 -0400
1c94c1
+++ Python-3.3.0b1/Python/getargs.c	2012-07-20 14:21:46.861688675 -0400
798936
@@ -4,6 +4,7 @@
798936
 #include "Python.h"
798936
 
798936
 #include <ctype.h>
798936
+#include <limits.h>
798936
 
798936
 
798936
 #ifdef __cplusplus
1c94c1
@@ -1807,6 +1808,102 @@ _PyArg_NoKeywords(const char *funcname, 
798936
                     funcname);
798936
     return 0;
798936
 }
798936
+
798936
+PyObject *
798936
+_PyObject_FromUid(uid_t uid)
798936
+{
798936
+    return PyLong_FromUnsignedLong((uid_t)uid);
798936
+}
798936
+
798936
+PyObject *
798936
+_PyObject_FromGid(gid_t gid)
798936
+{
798936
+    return PyLong_FromUnsignedLong((gid_t)gid);
798936
+}
798936
+
798936
+int
798936
+_PyArg_ParseUid(PyObject *in_obj, uid_t *out_uid)
798936
+{
798936
+    PyObject *index, *number = NULL;
798936
+    long sl;
798936
+    unsigned long ul;
798936
+
798936
+    assert(out_uid);
798936
+
798936
+    index = PyNumber_Index(in_obj);
798936
+    if (index != NULL) {
798936
+        number = PyNumber_Long(index);
798936
+        Py_DECREF(index);
798936
+    }
798936
+    if (number == NULL) {
798936
+        PyErr_SetString(PyExc_TypeError, "user id must be integer");
798936
+        return 0;
798936
+    }
798936
+
798936
+    /* Special case: support -1 (e.g. for use by chown) */
798936
+    sl = PyLong_AsLong(number);
798936
+    if (PyErr_Occurred()) {
798936
+        PyErr_Clear();
798936
+    } else if (sl == -1) {
798936
+        Py_DECREF(number);
798936
+        *out_uid = (uid_t)-1;
798936
+        return 1;
798936
+    }
798936
+
798936
+    /* Otherwise, it must be >= 0 */
798936
+    ul = PyLong_AsUnsignedLong(number);
798936
+    Py_DECREF(number);
798936
+    *out_uid = ul;
798936
+    /* read back the value to see if it fitted in uid_t */
798936
+    if (PyErr_Occurred() || *out_uid != ul) {
798936
+        PyErr_SetString(PyExc_OverflowError,
798936
+			"user id is not in range(-1, 2^32-1)");
798936
+	return 0;
798936
+    }
798936
+    return 1;
798936
+}
798936
+
798936
+int
798936
+_PyArg_ParseGid(PyObject *in_obj, gid_t *out_gid)
798936
+{
798936
+    PyObject *index, *number = NULL;
798936
+    long sl;
798936
+    unsigned long ul;
798936
+
798936
+    assert(out_gid);
798936
+
798936
+    index = PyNumber_Index(in_obj);
798936
+    if (index != NULL) {
798936
+        number = PyNumber_Long(index);
798936
+	Py_DECREF(index);
798936
+    }
798936
+    if (number == NULL) {
798936
+        PyErr_SetString(PyExc_TypeError, "group id must be integer");
798936
+	return 0;
798936
+    }
798936
+
798936
+    /* Special case: support -1 (e.g. for use by chown) */
798936
+    sl = PyLong_AsLong(number);
798936
+    if (PyErr_Occurred()) {
798936
+        PyErr_Clear();
798936
+    } else if (sl == -1) {
798936
+        Py_DECREF(number);
798936
+	*out_gid = (gid_t)-1;
798936
+	return 1;
798936
+    }
798936
+
798936
+    ul = PyLong_AsUnsignedLong(number);
798936
+    Py_DECREF(number);
798936
+    *out_gid = ul;
798936
+    /* read back the value to see if it fitted in gid_t */
798936
+    if (PyErr_Occurred() || *out_gid != ul) {
798936
+        PyErr_SetString(PyExc_OverflowError,
798936
+			"group id is not in range(-1, 2^32-1)");
798936
+	return 0;
798936
+    }
798936
+    return 1;
798936
+}
798936
+
798936
 #ifdef __cplusplus
798936
 };
798936
 #endif