mirror of https://github.com/python/cpython.git
Issue #7333: The `posix` module gains an `initgroups()` function providing
access to the initgroups(3) C library call on Unix systems which implement it. Patch by Jean-Paul Calderone.
This commit is contained in:
parent
f2bf0d2a51
commit
30b3b35cba
|
@ -136,6 +136,15 @@ process and user.
|
||||||
Availability: Unix.
|
Availability: Unix.
|
||||||
|
|
||||||
|
|
||||||
|
.. function:: initgroups(username, gid)
|
||||||
|
|
||||||
|
Call the system initgroups() to initialize the group access list with all of
|
||||||
|
the groups of which the specified username is a member, plus the specified
|
||||||
|
group id. Availability: Unix.
|
||||||
|
|
||||||
|
.. versionadded:: 2.7
|
||||||
|
|
||||||
|
|
||||||
.. function:: getlogin()
|
.. function:: getlogin()
|
||||||
|
|
||||||
Return the name of the user logged in on the controlling terminal of the
|
Return the name of the user logged in on the controlling terminal of the
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
# Skip these tests if there is no posix module.
|
# Skip these tests if there is no posix module.
|
||||||
posix = test_support.import_module('posix')
|
posix = test_support.import_module('posix')
|
||||||
|
|
||||||
|
import errno
|
||||||
import time
|
import time
|
||||||
import os
|
import os
|
||||||
import pwd
|
import pwd
|
||||||
|
@ -83,6 +84,27 @@ def test_setresgid_exception(self):
|
||||||
new_group_ids = (current_group_ids[0]+1, -1, -1)
|
new_group_ids = (current_group_ids[0]+1, -1, -1)
|
||||||
self.assertRaises(OSError, posix.setresgid, *new_group_ids)
|
self.assertRaises(OSError, posix.setresgid, *new_group_ids)
|
||||||
|
|
||||||
|
@unittest.skipUnless(hasattr(posix, 'initgroups'),
|
||||||
|
"test needs os.initgroups()")
|
||||||
|
def test_initgroups(self):
|
||||||
|
# It takes a string and an integer; check that it raises a TypeError
|
||||||
|
# for other argument lists.
|
||||||
|
self.assertRaises(TypeError, posix.initgroups)
|
||||||
|
self.assertRaises(TypeError, posix.initgroups, None)
|
||||||
|
self.assertRaises(TypeError, posix.initgroups, 3, "foo")
|
||||||
|
self.assertRaises(TypeError, posix.initgroups, "foo", 3, object())
|
||||||
|
|
||||||
|
# If a non-privileged user invokes it, it should fail with OSError
|
||||||
|
# EPERM.
|
||||||
|
if os.getuid() != 0:
|
||||||
|
name = pwd.getpwuid(posix.getuid()).pw_name
|
||||||
|
try:
|
||||||
|
posix.initgroups(name, 13)
|
||||||
|
except OSError as e:
|
||||||
|
self.assertEquals(e.errno, errno.EPERM)
|
||||||
|
else:
|
||||||
|
self.fail("Expected OSError to be raised by initgroups")
|
||||||
|
|
||||||
def test_statvfs(self):
|
def test_statvfs(self):
|
||||||
if hasattr(posix, 'statvfs'):
|
if hasattr(posix, 'statvfs'):
|
||||||
self.assertTrue(posix.statvfs(os.curdir))
|
self.assertTrue(posix.statvfs(os.curdir))
|
||||||
|
|
|
@ -490,6 +490,10 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #7333: The `posix` module gains an `initgroups()` function providing
|
||||||
|
access to the initgroups(3) C library call on Unix systems which implement
|
||||||
|
it. Patch by Jean-Paul Calderone.
|
||||||
|
|
||||||
- Issue #7408: Fixed distutils.tests.sdist so it doesn't check for group
|
- Issue #7408: Fixed distutils.tests.sdist so it doesn't check for group
|
||||||
ownership when the group is not forced, because the group may be different
|
ownership when the group is not forced, because the group may be different
|
||||||
from the user's group and inherit from its container when the test is run.
|
from the user's group and inherit from its container when the test is run.
|
||||||
|
|
|
@ -3861,6 +3861,30 @@ posix_getgroups(PyObject *self, PyObject *noargs)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_INITGROUPS
|
||||||
|
PyDoc_STRVAR(posix_initgroups__doc__,
|
||||||
|
"initgroups(username, gid) -> None\n\n\
|
||||||
|
Call the system initgroups() to initialize the group access list with all of\n\
|
||||||
|
the groups of which the specified username is a member, plus the specified\n\
|
||||||
|
group id.");
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
posix_initgroups(PyObject *self, PyObject *args)
|
||||||
|
{
|
||||||
|
char *username;
|
||||||
|
long gid;
|
||||||
|
|
||||||
|
if (!PyArg_ParseTuple(args, "sl:initgroups", &username, &gid))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (initgroups(username, (gid_t) gid) == -1)
|
||||||
|
return PyErr_SetFromErrno(PyExc_OSError);
|
||||||
|
|
||||||
|
Py_INCREF(Py_None);
|
||||||
|
return Py_None;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_GETPGID
|
#ifdef HAVE_GETPGID
|
||||||
PyDoc_STRVAR(posix_getpgid__doc__,
|
PyDoc_STRVAR(posix_getpgid__doc__,
|
||||||
"getpgid(pid) -> pgid\n\n\
|
"getpgid(pid) -> pgid\n\n\
|
||||||
|
@ -8629,6 +8653,9 @@ static PyMethodDef posix_methods[] = {
|
||||||
#ifdef HAVE_SETGROUPS
|
#ifdef HAVE_SETGROUPS
|
||||||
{"setgroups", posix_setgroups, METH_O, posix_setgroups__doc__},
|
{"setgroups", posix_setgroups, METH_O, posix_setgroups__doc__},
|
||||||
#endif /* HAVE_SETGROUPS */
|
#endif /* HAVE_SETGROUPS */
|
||||||
|
#ifdef HAVE_INITGROUPS
|
||||||
|
{"initgroups", posix_initgroups, METH_VARARGS, posix_initgroups__doc__},
|
||||||
|
#endif /* HAVE_INITGROUPS */
|
||||||
#ifdef HAVE_GETPGID
|
#ifdef HAVE_GETPGID
|
||||||
{"getpgid", posix_getpgid, METH_VARARGS, posix_getpgid__doc__},
|
{"getpgid", posix_getpgid, METH_VARARGS, posix_getpgid__doc__},
|
||||||
#endif /* HAVE_GETPGID */
|
#endif /* HAVE_GETPGID */
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
# From configure.in Revision: 76558 .
|
# From configure.in Revision: 76568 .
|
||||||
# Guess values for system-dependent variables and create Makefiles.
|
# Guess values for system-dependent variables and create Makefiles.
|
||||||
# Generated by GNU Autoconf 2.61 for python 2.7.
|
# Generated by GNU Autoconf 2.61 for python 2.7.
|
||||||
#
|
#
|
||||||
|
@ -17893,13 +17893,14 @@ echo "${ECHO_T}MACHDEP_OBJS" >&6; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for ac_func in alarm setitimer getitimer bind_textdomain_codeset chown \
|
for ac_func in alarm setitimer getitimer bind_textdomain_codeset chown \
|
||||||
clock confstr ctermid execv fchmod fchown fork fpathconf ftime ftruncate \
|
clock confstr ctermid execv fchmod fchown fork fpathconf ftime ftruncate \
|
||||||
gai_strerror getgroups getlogin getloadavg getpeername getpgid getpid \
|
gai_strerror getgroups getlogin getloadavg getpeername getpgid getpid \
|
||||||
getpriority getresuid getresgid getpwent getspnam getspent getsid getwd \
|
getpriority getresuid getresgid getpwent getspnam getspent getsid getwd \
|
||||||
kill killpg lchmod lchown lstat mkfifo mknod mktime \
|
initgroups kill killpg lchmod lchown lstat mkfifo mknod mktime \
|
||||||
mremap nice pathconf pause plock poll pthread_init \
|
mremap nice pathconf pause plock poll pthread_init \
|
||||||
putenv readlink realpath \
|
putenv readlink realpath \
|
||||||
select sem_open sem_timedwait sem_getvalue sem_unlink setegid seteuid \
|
select sem_open sem_timedwait sem_getvalue sem_unlink setegid seteuid \
|
||||||
|
|
|
@ -2547,7 +2547,7 @@ AC_CHECK_FUNCS(alarm setitimer getitimer bind_textdomain_codeset chown \
|
||||||
clock confstr ctermid execv fchmod fchown fork fpathconf ftime ftruncate \
|
clock confstr ctermid execv fchmod fchown fork fpathconf ftime ftruncate \
|
||||||
gai_strerror getgroups getlogin getloadavg getpeername getpgid getpid \
|
gai_strerror getgroups getlogin getloadavg getpeername getpgid getpid \
|
||||||
getpriority getresuid getresgid getpwent getspnam getspent getsid getwd \
|
getpriority getresuid getresgid getpwent getspnam getspent getsid getwd \
|
||||||
kill killpg lchmod lchown lstat mkfifo mknod mktime \
|
initgroups kill killpg lchmod lchown lstat mkfifo mknod mktime \
|
||||||
mremap nice pathconf pause plock poll pthread_init \
|
mremap nice pathconf pause plock poll pthread_init \
|
||||||
putenv readlink realpath \
|
putenv readlink realpath \
|
||||||
select sem_open sem_timedwait sem_getvalue sem_unlink setegid seteuid \
|
select sem_open sem_timedwait sem_getvalue sem_unlink setegid seteuid \
|
||||||
|
|
|
@ -301,6 +301,9 @@
|
||||||
/* Define to 1 if you have the `getpeername' function. */
|
/* Define to 1 if you have the `getpeername' function. */
|
||||||
#undef HAVE_GETPEERNAME
|
#undef HAVE_GETPEERNAME
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `initgroups' function. */
|
||||||
|
#undef HAVE_INITGROUPS
|
||||||
|
|
||||||
/* Define to 1 if you have the `getpgid' function. */
|
/* Define to 1 if you have the `getpgid' function. */
|
||||||
#undef HAVE_GETPGID
|
#undef HAVE_GETPGID
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue