From 4fa925fa597b199ff2a3a32e261b021e11c408d2 Mon Sep 17 00:00:00 2001 From: Iustin Pop Date: Mon, 23 Dec 2002 21:05:40 +0000 Subject: [PATCH] Addedd __setstate__ and some docs --- IMPLEMENTATION | 38 ++++++++++++++++++++++++++++++++++++++ PLATFORMS | 24 ++++++++++++++++++++++++ README | 7 +++---- acl.c | 33 +++++++++++++++++++++++++++++++-- setup.py | 14 +++++++++----- 5 files changed, 105 insertions(+), 11 deletions(-) create mode 100644 IMPLEMENTATION create mode 100644 PLATFORMS diff --git a/IMPLEMENTATION b/IMPLEMENTATION new file mode 100644 index 0000000..c6207df --- /dev/null +++ b/IMPLEMENTATION @@ -0,0 +1,38 @@ +The IEEE 1003.1e draft 17 ("POSIX.1e") describes a set of 17 +functions. These are grouped into three groups, based on their +portability: + - first group, the most portable one. All systems which claim to + support POSIX.1e should implement these: + acl_delete_def_file(3), acl_dup(3), acl_free(3), acl_from_text(3), + acl_get_fd(3), acl_get_file(3), acl_init(3), acl_set_fd(3), + acl_set_file(3), acl_to_text(3), acl_valid(3) + + - second group, containing the rest of the POSIX ACL functions. Systems + which claim to fully implement POSIX.1e should implement these: + acl_add_perm(3), acl_calc_mask(3), acl_clear_perms(3), acl_copy_entry(3), + acl_copy_ext(3), acl_copy_int(3), acl_create_entry(3), + acl_delete_entry(3), acl_delete_perm(3), acl_get_entry(3), + acl_get_permset(3), acl_get_qualifier(3), acl_get_tag_type(3), + acl_set_permset(3), acl_set_qualifier(3), acl_set_tag_type(3), + acl_size(3) + + - third group, containing extra functions implemented by each OS. These + are non-portable version. Both Linux and FreeBSD implement some extra + function. + +Thus we have the level of compliance. Depending on whether the system +library support the second group, you get some extra methods for the +ACL object. + + +Internal structure + + The POSIX draft has the following stuff (correct me if I'm wrong): + - an ACL is denoted by acl_t + - an ACL contains many acl_entry_t, these are the individual entries + in the list + - each entry_t has a qualifier (think uid_t or gid_t), whose type is + denoted by the acl_tag_t type, and an acl_permset_t + - the acl_permset_t can contain acl_perm_t value (ACL_READ, ACL_WRITE, + ACL_EXECUTE, ACL_ADD, ACL_DELETE, ...) + - function to manipulate all these, and functions to manipulate files diff --git a/PLATFORMS b/PLATFORMS new file mode 100644 index 0000000..647f993 --- /dev/null +++ b/PLATFORMS @@ -0,0 +1,24 @@ +The current supported platforms: + +Linux + + It needs kernel 2.4 or higher and the libacl library installed (with + development headers, if installing from rpm). The url is + http://acl.bestbits.at if using for ext2/ext3 and JFS, and + http://oss.sgi.com/projects/xfs/ if using for XFS. + + The level of compliance is level 2 (see IMPLEMENTATION). + + +FreeBSD + + The current teste version is 4.6. I hope to be able to test 5.0 after + it's released. + + The level of compliance is level 1. I hope that in FreeBSD 5 they will + improve. + + +For any other platform, volunteers are welcome. To add support, look +into setup.py at first and then into acl.c + diff --git a/README b/README index 762997e..e17837d 100644 --- a/README +++ b/README @@ -1,7 +1,6 @@ -This is an extesion for Python which implements POSIX ACLs (POSIX.1e). +This is an extension for Python which implements POSIX ACLs (POSIX.1e). -Right now, the module is known to build on Linux (the acl library must -be installed) and on FreeBSD. To add support, send a patch or contact -the author. +To see the supported platforms, look at PLATFORMS. +To see internal details, look at IMPLEMENTATION. Iustin Pop, diff --git a/acl.c b/acl.c index dd2c3ca..eab65f2 100644 --- a/acl.c +++ b/acl.c @@ -8,6 +8,7 @@ static PyObject* ACL_applyto(PyObject* obj, PyObject* args); static PyObject* ACL_valid(PyObject* obj, PyObject* args); #ifdef HAVE_LEVEL2 static PyObject* ACL_get_state(PyObject *obj, PyObject* args); +static PyObject* ACL_set_state(PyObject *obj, PyObject* args); #endif typedef struct { @@ -21,6 +22,7 @@ static PyMethodDef ACL_methods[] = { {"valid", ACL_valid, METH_NOARGS, "Test the ACL for validity."}, #ifdef HAVE_LEVEL2 {"__getstate__", ACL_get_state, METH_NOARGS, "Dumps the ACL to an external format."}, + {"__setstate__", ACL_set_state, METH_VARARGS, "Loads the ACL from an external format."}, #endif {NULL, NULL, 0, NULL} }; @@ -174,6 +176,33 @@ static PyObject* ACL_get_state(PyObject *obj, PyObject* args) { return ret; } +static PyObject* ACL_set_state(PyObject *obj, PyObject* args) { + ACLObject *self = (ACLObject*) obj; + const void *buf; + int bufsize; + acl_t ptr; + + /* Parse the argument */ + if (!PyArg_ParseTuple(args, "s#", &buf, &bufsize)) + return NULL; + + /* Try to import the external representation */ + if((ptr = acl_copy_int(buf)) == NULL) + return PyErr_SetFromErrno(PyExc_IOError); + + /* Free the old acl. Should we ignore errors here? */ + if(self->ob_acl != NULL) { + if(acl_free(self->ob_acl) == -1) + return PyErr_SetFromErrno(PyExc_IOError); + } + + self->ob_acl = ptr; + + /* Return the result */ + Py_INCREF(Py_None); + return Py_None; +} + #endif /* The definition of the ACL Type */ @@ -236,10 +265,10 @@ static PyMethodDef aclmodule_methods[] = { {NULL, NULL, 0, NULL} }; -DL_EXPORT(void) initacl(void) { +DL_EXPORT(void) initposixacl(void) { ACLType.ob_type = &PyType_Type; if(PyType_Ready(&ACLType) < 0) return; - Py_InitModule("acl", aclmodule_methods); + Py_InitModule("posixacl", aclmodule_methods); } diff --git a/setup.py b/setup.py index bd8ff56..782b2b9 100644 --- a/setup.py +++ b/setup.py @@ -17,16 +17,20 @@ elif u_sysname == "FreeBSD": else: raise ValueError("I don't know your system. Please contact the author") -setup(name="pyacl", - version="0.1", - description="POSIX ACLs for python", +version = "0.1" +setup(name="pylibacl", + version=version, + description="POSIX.1e ACLs for python", long_description="""This is a C extension module for Python which implements POSIX ACLs manipulation. It is a wrapper on top - of the acl C library - see acl(5).""", + of the systems's acl C library - see acl(5).""", author="Iustin Pop", author_email="iusty@k1024.org", - ext_modules=[Extension("acl", ["acl.c"], + url="http://pylibacl.sourceforge.net", + license="GPL", + ext_modules=[Extension("posixacl", ["acl.c"], libraries=libs, define_macros=macros, )], + data_files=[("/usr/share/doc/pylibacl-%s" % version, ["README",])], ) -- 2.39.5