From f93db50e4c5ef8d58a5489fd5222d4cc3f6b7f46 Mon Sep 17 00:00:00 2001 From: Iustin Pop Date: Sat, 28 Jun 2008 00:55:02 +0200 Subject: [PATCH] Implement the acl_extended_* functions This patch adds support for the Linux-specific acl_extended_fd and acl_extended_file function, both exposed at module level through the has_extended function name. --- acl.c | 43 +++++++++++++++++++++++++++++++++++++++++++ test/test_acls.py | 17 +++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/acl.c b/acl.c index 7f09712..bdc196d 100644 --- a/acl.c +++ b/acl.c @@ -1379,10 +1379,51 @@ static PyObject* aclmodule_delete_default(PyObject* obj, PyObject* args) { return Py_None; } +#ifdef HAVE_LINUX +static char __has_extended_doc__[] = + "Check if a file or filehandle has an extended ACL.\n" + "\n" + "Parameter:\n" + " - either a filename or a file-like object or an integer; this\n" + " represents the filesystem object on which to act\n" + ; + +/* Check for extended ACL a file or fd */ +static PyObject* aclmodule_has_extended(PyObject* obj, PyObject* args) { + PyObject *myarg; + int nret; + int fd; + + if (!PyArg_ParseTuple(args, "O", &myarg)) + return NULL; + + if(PyString_Check(myarg)) { + const char *filename = PyString_AS_STRING(myarg); + nret = acl_extended_file(filename); + } else if((fd = PyObject_AsFileDescriptor(myarg)) != -1) { + nret = acl_extended_fd(fd); + } else { + PyErr_SetString(PyExc_TypeError, "argument 1 must be string, int," + " or file-like object"); + return 0; + } + if(nret == -1) { + return PyErr_SetFromErrno(PyExc_IOError); + } + + /* Return the result */ + return PyBool_FromLong(nret); +} +#endif + /* The module methods */ static PyMethodDef aclmodule_methods[] = { {"delete_default", aclmodule_delete_default, METH_VARARGS, __deletedef_doc__}, +#ifdef HAVE_LINUX + {"has_extended", aclmodule_has_extended, METH_VARARGS, + __has_extended_doc__}, +#endif {NULL, NULL, 0, NULL} }; @@ -1506,8 +1547,10 @@ void initposix1e(void) { /* declare the Linux extensions */ PyModule_AddIntConstant(m, "HAS_ACL_FROM_MODE", 1); PyModule_AddIntConstant(m, "HAS_ACL_CHECK", 1); + PyModule_AddIntConstant(m, "HAS_EXTENDED_CHECK", 1); #else PyModule_AddIntConstant(m, "HAS_ACL_FROM_MODE", 0); PyModule_AddIntConstant(m, "HAS_ACL_CHECK", 0); + PyModule_AddIntConstant(m, "HAS_EXTENDED_CHECK", 0); #endif } diff --git a/test/test_acls.py b/test/test_acls.py index ad5ab53..d1a45ae 100644 --- a/test/test_acls.py +++ b/test/test_acls.py @@ -116,6 +116,23 @@ class AclExtensions(aclTest, unittest.TestCase): acl2 = posix1e.ACL() self.failUnless(acl2.check(), "Empty ACL should not be valid") + @has_ext(HAS_EXTENDED_CHECK) + def testExtended(self): + """Test the acl_extended function""" + fd, fname = self._getfile() + basic_acl = posix1e.ACL(text=BASIC_ACL_TEXT) + basic_acl.applyto(fd) + for item in fd, fname: + self.failIf(has_extended(item), + "A simple ACL should not be reported as extended") + enhanced_acl = posix1e.ACL(text="u::rw,g::-,o::-,u:root:rw,mask::r") + self.failUnless(enhanced_acl.valid(), + "Failure to build an extended ACL") + enhanced_acl.applyto(fd) + for item in fd, fname: + self.failUnless(has_extended(item), + "An extended ACL should be reported as such") + class WriteTests(aclTest, unittest.TestCase): """Write tests""" -- 2.39.5