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}. ........
This commit is contained in:
parent
03f6c11f07
commit
7aed61ae46
|
@ -196,6 +196,19 @@ process and user.
|
|||
|
||||
Return the parent's process id. Availability: Unix.
|
||||
|
||||
.. function:: getresgid()
|
||||
|
||||
Return a tuple (ruid, euid, suid) denoting the current process's
|
||||
real, effective, and saved user ids. Availability: Unix.
|
||||
|
||||
.. versionadded:: 2.7/3.2
|
||||
|
||||
.. function:: getresuid()
|
||||
|
||||
Return a tuple (rgid, egid, sgid) denoting the current process's
|
||||
real, effective, and saved user ids. Availability: Unix.
|
||||
|
||||
.. versionadded:: 2.7/3.2
|
||||
|
||||
.. function:: getuid()
|
||||
|
||||
|
@ -267,15 +280,28 @@ process and user.
|
|||
for the semantics. Availability: Unix.
|
||||
|
||||
|
||||
.. function:: setreuid(ruid, euid)
|
||||
|
||||
Set the current process's real and effective user ids. Availability: Unix.
|
||||
|
||||
|
||||
.. function:: setregid(rgid, egid)
|
||||
|
||||
Set the current process's real and effective group ids. Availability: Unix.
|
||||
|
||||
.. function:: setresgid(rgid, egid, sgid)
|
||||
|
||||
Set the current process's real, effective, and saved group ids.
|
||||
Availability: Unix.
|
||||
|
||||
.. versionadded:: 2.7/3.2
|
||||
|
||||
.. function:: setresuid(ruid, euid, suid)
|
||||
|
||||
Set the current process's real, effective, and saved user ids.
|
||||
Availibility: Unix.
|
||||
|
||||
.. versionadded:: 2.7/3.2
|
||||
|
||||
.. function:: setreuid(ruid, euid)
|
||||
|
||||
Set the current process's real and effective user ids. Availability: Unix.
|
||||
|
||||
|
||||
.. function:: getsid(pid)
|
||||
|
||||
|
|
|
@ -40,6 +40,48 @@ class PosixTester(unittest.TestCase):
|
|||
posix_func()
|
||||
self.assertRaises(TypeError, posix_func, 1)
|
||||
|
||||
if hasattr(posix, 'getresuid'):
|
||||
def test_getresuid(self):
|
||||
user_ids = posix.getresuid()
|
||||
self.assertEqual(len(user_ids), 3)
|
||||
for val in user_ids:
|
||||
self.assertGreaterEqual(val, 0)
|
||||
|
||||
if hasattr(posix, 'getresgid'):
|
||||
def test_getresgid(self):
|
||||
group_ids = posix.getresgid()
|
||||
self.assertEqual(len(group_ids), 3)
|
||||
for val in group_ids:
|
||||
self.assertGreaterEqual(val, 0)
|
||||
|
||||
if hasattr(posix, 'setresuid'):
|
||||
def test_setresuid(self):
|
||||
current_user_ids = posix.getresuid()
|
||||
self.assertIsNone(posix.setresuid(*current_user_ids))
|
||||
# -1 means don't change that value.
|
||||
self.assertIsNone(posix.setresuid(-1, -1, -1))
|
||||
|
||||
def test_setresuid_exception(self):
|
||||
# Don't do this test if someone is silly enough to run us as root.
|
||||
current_user_ids = posix.getresuid()
|
||||
if 0 not in current_user_ids:
|
||||
new_user_ids = (current_user_ids[0]+1, -1, -1)
|
||||
self.assertRaises(OSError, posix.setresuid, *new_user_ids)
|
||||
|
||||
if hasattr(posix, 'setresgid'):
|
||||
def test_setresgid(self):
|
||||
current_group_ids = posix.getresgid()
|
||||
self.assertIsNone(posix.setresgid(*current_group_ids))
|
||||
# -1 means don't change that value.
|
||||
self.assertIsNone(posix.setresgid(-1, -1, -1))
|
||||
|
||||
def test_setresgid_exception(self):
|
||||
# Don't do this test if someone is silly enough to run us as root.
|
||||
current_group_ids = posix.getresgid()
|
||||
if 0 not in current_group_ids:
|
||||
new_group_ids = (current_group_ids[0]+1, -1, -1)
|
||||
self.assertRaises(OSError, posix.setresgid, *new_group_ids)
|
||||
|
||||
def test_statvfs(self):
|
||||
if hasattr(posix, 'statvfs'):
|
||||
self.assertTrue(posix.statvfs(os.curdir))
|
||||
|
|
|
@ -388,6 +388,8 @@ Library
|
|||
Extension Modules
|
||||
-----------------
|
||||
|
||||
- Issue #6508: Add posix.{getresuid,getresgid,setresuid,setresgid}.
|
||||
|
||||
- Issue #7078: Set struct.__doc__ from _struct.__doc__.
|
||||
|
||||
- Issue #3366: Add gamma function to math module.
|
||||
|
|
|
@ -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 */
|
||||
};
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#! /bin/sh
|
||||
# From configure.in Revision: 76328 .
|
||||
# From configure.in Revision: 76405 .
|
||||
# Guess values for system-dependent variables and create Makefiles.
|
||||
# Generated by GNU Autoconf 2.61 for python 3.2.
|
||||
#
|
||||
|
@ -3800,7 +3800,7 @@ else
|
|||
{ echo "$as_me:$LINENO: result: no" >&5
|
||||
echo "${ECHO_T}no" >&6; }
|
||||
fi
|
||||
rm -f -r conftest*
|
||||
rm -f conftest*
|
||||
|
||||
|
||||
|
||||
|
@ -5338,7 +5338,7 @@ if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
|
|||
else
|
||||
ac_cv_header_stdc=no
|
||||
fi
|
||||
rm -f -r conftest*
|
||||
rm -f conftest*
|
||||
|
||||
fi
|
||||
|
||||
|
@ -5359,7 +5359,7 @@ if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
|
|||
else
|
||||
ac_cv_header_stdc=no
|
||||
fi
|
||||
rm -f -r conftest*
|
||||
rm -f conftest*
|
||||
|
||||
fi
|
||||
|
||||
|
@ -6457,7 +6457,7 @@ _ACEOF
|
|||
|
||||
|
||||
fi
|
||||
rm -f -r conftest*
|
||||
rm -f conftest*
|
||||
|
||||
{ echo "$as_me:$LINENO: result: $was_it_defined" >&5
|
||||
echo "${ECHO_T}$was_it_defined" >&6; }
|
||||
|
@ -6987,7 +6987,7 @@ if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
|
|||
else
|
||||
ac_cv_type_uid_t=no
|
||||
fi
|
||||
rm -f -r conftest*
|
||||
rm -f conftest*
|
||||
|
||||
fi
|
||||
{ echo "$as_me:$LINENO: result: $ac_cv_type_uid_t" >&5
|
||||
|
@ -15529,7 +15529,7 @@ if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
|
|||
else
|
||||
unistd_defines_pthreads=no
|
||||
fi
|
||||
rm -f -r conftest*
|
||||
rm -f conftest*
|
||||
|
||||
{ echo "$as_me:$LINENO: result: $unistd_defines_pthreads" >&5
|
||||
echo "${ECHO_T}$unistd_defines_pthreads" >&6; }
|
||||
|
@ -16827,7 +16827,7 @@ if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
|
|||
$EGREP "yes" >/dev/null 2>&1; then
|
||||
ipv6type=$i
|
||||
fi
|
||||
rm -f -r conftest*
|
||||
rm -f conftest*
|
||||
|
||||
;;
|
||||
kame)
|
||||
|
@ -16850,7 +16850,7 @@ if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
|
|||
ipv6libdir=/usr/local/v6/lib
|
||||
ipv6trylibc=yes
|
||||
fi
|
||||
rm -f -r conftest*
|
||||
rm -f conftest*
|
||||
|
||||
;;
|
||||
linux-glibc)
|
||||
|
@ -16871,7 +16871,7 @@ if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
|
|||
ipv6type=$i;
|
||||
ipv6trylibc=yes
|
||||
fi
|
||||
rm -f -r conftest*
|
||||
rm -f conftest*
|
||||
|
||||
;;
|
||||
linux-inet6)
|
||||
|
@ -16909,7 +16909,7 @@ if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
|
|||
ipv6lib=inet6;
|
||||
ipv6libdir=/usr/local/v6/lib
|
||||
fi
|
||||
rm -f -r conftest*
|
||||
rm -f conftest*
|
||||
|
||||
;;
|
||||
v6d)
|
||||
|
@ -16932,7 +16932,7 @@ if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
|
|||
ipv6libdir=/usr/local/v6/lib;
|
||||
BASECFLAGS="-I/usr/local/v6/include $BASECFLAGS"
|
||||
fi
|
||||
rm -f -r conftest*
|
||||
rm -f conftest*
|
||||
|
||||
;;
|
||||
zeta)
|
||||
|
@ -16954,7 +16954,7 @@ if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
|
|||
ipv6lib=inet6;
|
||||
ipv6libdir=/usr/local/v6/lib
|
||||
fi
|
||||
rm -f -r conftest*
|
||||
rm -f conftest*
|
||||
|
||||
;;
|
||||
esac
|
||||
|
@ -17370,6 +17370,10 @@ echo "${ECHO_T}MACHDEP_OBJS" >&6; }
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -17378,14 +17382,14 @@ echo "${ECHO_T}MACHDEP_OBJS" >&6; }
|
|||
for ac_func in alarm setitimer getitimer bind_textdomain_codeset chown \
|
||||
clock confstr ctermid execv fchmod fchown fork fpathconf ftime ftruncate \
|
||||
gai_strerror getgroups getlogin getloadavg getpeername getpgid getpid \
|
||||
getpriority getpwent getspnam getspent getsid getwd \
|
||||
getpriority getresuid getresgid getpwent getspnam getspent getsid getwd \
|
||||
kill killpg lchmod lchown lstat mbrtowc mkfifo mknod mktime \
|
||||
mremap nice pathconf pause plock poll pthread_init \
|
||||
putenv readlink realpath \
|
||||
select sem_open sem_timedwait sem_getvalue sem_unlink setegid seteuid \
|
||||
setgid \
|
||||
setlocale setregid setreuid setsid setpgid setpgrp setuid setvbuf snprintf \
|
||||
sigaction siginterrupt sigrelse strftime strlcpy \
|
||||
setlocale setregid setreuid setresuid setresgid setsid setpgid setpgrp setuid setvbuf \
|
||||
sigaction siginterrupt sigrelse snprintf strftime strlcpy \
|
||||
sysconf tcgetpgrp tcsetpgrp tempnam timegm times tmpfile tmpnam tmpnam_r \
|
||||
truncate uname unsetenv utimes waitpid wait3 wait4 \
|
||||
wcscoll wcsftime wcsxfrm _getpty
|
||||
|
@ -25044,7 +25048,7 @@ cat >>confdefs.h <<\_ACEOF
|
|||
_ACEOF
|
||||
|
||||
fi
|
||||
rm -f -r conftest*
|
||||
rm -f conftest*
|
||||
|
||||
cat >conftest.$ac_ext <<_ACEOF
|
||||
/* confdefs.h. */
|
||||
|
@ -25063,7 +25067,7 @@ cat >>confdefs.h <<\_ACEOF
|
|||
_ACEOF
|
||||
|
||||
fi
|
||||
rm -f -r conftest*
|
||||
rm -f conftest*
|
||||
|
||||
fi
|
||||
|
||||
|
@ -25333,7 +25337,7 @@ cat >>confdefs.h <<\_ACEOF
|
|||
_ACEOF
|
||||
|
||||
fi
|
||||
rm -f -r conftest*
|
||||
rm -f conftest*
|
||||
|
||||
fi
|
||||
|
||||
|
|
|
@ -2417,14 +2417,14 @@ AC_MSG_RESULT(MACHDEP_OBJS)
|
|||
AC_CHECK_FUNCS(alarm setitimer getitimer bind_textdomain_codeset chown \
|
||||
clock confstr ctermid execv fchmod fchown fork fpathconf ftime ftruncate \
|
||||
gai_strerror getgroups getlogin getloadavg getpeername getpgid getpid \
|
||||
getpriority getpwent getspnam getspent getsid getwd \
|
||||
getpriority getresuid getresgid getpwent getspnam getspent getsid getwd \
|
||||
kill killpg lchmod lchown lstat mbrtowc mkfifo mknod mktime \
|
||||
mremap nice pathconf pause plock poll pthread_init \
|
||||
putenv readlink realpath \
|
||||
select sem_open sem_timedwait sem_getvalue sem_unlink setegid seteuid \
|
||||
setgid \
|
||||
setlocale setregid setreuid setsid setpgid setpgrp setuid setvbuf snprintf \
|
||||
sigaction siginterrupt sigrelse strftime strlcpy \
|
||||
setlocale setregid setreuid setresuid setresgid setsid setpgid setpgrp setuid setvbuf \
|
||||
sigaction siginterrupt sigrelse snprintf strftime strlcpy \
|
||||
sysconf tcgetpgrp tcsetpgrp tempnam timegm times tmpfile tmpnam tmpnam_r \
|
||||
truncate uname unsetenv utimes waitpid wait3 wait4 \
|
||||
wcscoll wcsftime wcsxfrm _getpty)
|
||||
|
|
|
@ -314,6 +314,12 @@
|
|||
/* Define to 1 if you have the `getpwent' function. */
|
||||
#undef HAVE_GETPWENT
|
||||
|
||||
/* Define to 1 if you have the `getresgid' function. */
|
||||
#undef HAVE_GETRESGID
|
||||
|
||||
/* Define to 1 if you have the `getresuid' function. */
|
||||
#undef HAVE_GETRESUID
|
||||
|
||||
/* Define to 1 if you have the `getsid' function. */
|
||||
#undef HAVE_GETSID
|
||||
|
||||
|
@ -578,6 +584,12 @@
|
|||
/* Define to 1 if you have the `setregid' function. */
|
||||
#undef HAVE_SETREGID
|
||||
|
||||
/* Define to 1 if you have the `setresgid' function. */
|
||||
#undef HAVE_SETRESGID
|
||||
|
||||
/* Define to 1 if you have the `setresuid' function. */
|
||||
#undef HAVE_SETRESUID
|
||||
|
||||
/* Define to 1 if you have the `setreuid' function. */
|
||||
#undef HAVE_SETREUID
|
||||
|
||||
|
|
Loading…
Reference in New Issue