From f05ac0a5891c2888f00262494f4a0292dd4db346 Mon Sep 17 00:00:00 2001 From: Iustin Pop Date: Sat, 28 Jun 2008 08:19:37 +0200 Subject: [PATCH] Imple the acl_equiv_mode function This is another Linux-specific function, but very easy to implement. --- acl.c | 22 ++++++++++++++++++++++ test/test_acls.py | 12 ++++++++++++ 2 files changed, 34 insertions(+) diff --git a/acl.c b/acl.c index bdc196d..b27ab2b 100644 --- a/acl.c +++ b/acl.c @@ -289,6 +289,25 @@ static PyObject* ACL_richcompare(PyObject* o1, PyObject* o2, int op) { Py_INCREF(ret); return ret; } + +static char __equiv_mode_doc__[] = + "Return the octal mode the ACL is equivalent to.\n" + "\n" + "This is a non-portable, Linux specific extension that checks\n" + "if the ACL is a basic ACL and returns the corresponding mode.\n" + "\n" + "An IOerror exception will be raised if the ACL is an extended ACL\n" + ; + +/* The acl_equiv_mode method */ +static PyObject* ACL_equiv_mode(PyObject* obj, PyObject* args) { + ACL_Object *self = (ACL_Object*) obj; + mode_t mode; + + if(acl_equiv_mode(self->acl, &mode) == -1) + return PyErr_SetFromErrno(PyExc_IOError); + return PyInt_FromLong(mode); +} #endif /* Implementation of the compare for ACLs */ @@ -1070,6 +1089,7 @@ static PyMethodDef ACL_methods[] = { {"to_any_text", (PyCFunction)ACL_to_any_text, METH_VARARGS | METH_KEYWORDS, __to_any_text_doc__}, {"check", ACL_check, METH_NOARGS, __check_doc__}, + {"equiv_mode", ACL_equiv_mode, METH_NOARGS, __equiv_mode_doc__}, #endif #ifdef HAVE_ACL_COPYEXT {"__getstate__", ACL_get_state, METH_NOARGS, @@ -1548,9 +1568,11 @@ void initposix1e(void) { PyModule_AddIntConstant(m, "HAS_ACL_FROM_MODE", 1); PyModule_AddIntConstant(m, "HAS_ACL_CHECK", 1); PyModule_AddIntConstant(m, "HAS_EXTENDED_CHECK", 1); + PyModule_AddIntConstant(m, "HAS_EQUIV_MODE", 1); #else PyModule_AddIntConstant(m, "HAS_ACL_FROM_MODE", 0); PyModule_AddIntConstant(m, "HAS_ACL_CHECK", 0); PyModule_AddIntConstant(m, "HAS_EXTENDED_CHECK", 0); + PyModule_AddIntConstant(m, "HAS_EQUIV_MODE", 0); #endif } diff --git a/test/test_acls.py b/test/test_acls.py index d1a45ae..eacd769 100644 --- a/test/test_acls.py +++ b/test/test_acls.py @@ -133,6 +133,18 @@ class AclExtensions(aclTest, unittest.TestCase): self.failUnless(has_extended(item), "An extended ACL should be reported as such") + @has_ext(HAS_EQUIV_MODE) + def testEquivMode(self): + """Test the equiv_mode function""" + if HAS_ACL_FROM_MODE: + for mode in 0644, 0755: + acl = posix1e.ACL(mode=mode) + self.failUnlessEqual(acl.equiv_mode(), mode) + acl = posix1e.ACL(text="u::rw,g::r,o::r") + self.failUnlessEqual(acl.equiv_mode(), 0644) + acl = posix1e.ACL(text="u::rx,g::-,o::-") + self.failUnlessEqual(acl.equiv_mode(), 0500) + class WriteTests(aclTest, unittest.TestCase): """Write tests""" -- 2.39.5