2 posix1e - a python module exposing the posix acl functions
4 Copyright (C) 2002-2009 Iustin Pop <iusty@k1024.org>
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 #include <sys/types.h>
29 #include <acl/libacl.h>
30 #define get_perm acl_get_perm
32 #define get_perm acl_get_perm_np
35 #if PY_MAJOR_VERSION >= 3
37 #define PyInt_Check(op) PyLong_Check(op)
38 #define PyInt_FromString PyLong_FromString
39 #define PyInt_FromUnicode PyLong_FromUnicode
40 #define PyInt_FromLong PyLong_FromLong
41 #define PyInt_FromSize_t PyLong_FromSize_t
42 #define PyInt_FromSsize_t PyLong_FromSsize_t
43 #define PyInt_AsLong PyLong_AsLong
44 #define PyInt_AsSsize_t PyLong_AsSsize_t
45 #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask
46 #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
47 #define PyInt_AS_LONG PyLong_AS_LONG
49 #define PyBytes_Check PyString_Check
50 #define PyBytes_AS_STRING PyString_AS_STRING
51 #define PyBytes_FromStringAndSize PyString_FromStringAndSize
52 #define PyBytes_FromString PyString_FromString
53 #define PyBytes_FromFormat PyString_FromFormat
54 #define PyBytes_ConcatAndDel PyString_ConcatAndDel
56 /* Python 2.6 already defines Py_TYPE */
58 #define Py_TYPE(o) (((PyObject*)(o))->ob_type)
62 static PyTypeObject ACL_Type;
63 static PyObject* ACL_applyto(PyObject* obj, PyObject* args);
64 static PyObject* ACL_valid(PyObject* obj, PyObject* args);
66 #ifdef HAVE_ACL_COPY_EXT
67 static PyObject* ACL_get_state(PyObject *obj, PyObject* args);
68 static PyObject* ACL_set_state(PyObject *obj, PyObject* args);
72 static PyTypeObject Entry_Type;
73 static PyTypeObject Permset_Type;
74 static PyObject* Permset_new(PyTypeObject* type, PyObject* args,
78 static acl_perm_t holder_ACL_EXECUTE = ACL_EXECUTE;
79 static acl_perm_t holder_ACL_READ = ACL_READ;
80 static acl_perm_t holder_ACL_WRITE = ACL_WRITE;
94 PyObject *parent_acl; /* The parent acl, so it won't run out on us */
100 PyObject *parent_entry; /* The parent entry, so it won't run out on us */
101 acl_permset_t permset;
106 /* Creation of a new ACL instance */
107 static PyObject* ACL_new(PyTypeObject* type, PyObject* args,
111 newacl = type->tp_alloc(type, 0);
114 ((ACL_Object*)newacl)->acl = NULL;
116 ((ACL_Object*)newacl)->entry_id = ACL_FIRST_ENTRY;
123 /* Initialization of a new ACL instance */
124 static int ACL_init(PyObject* obj, PyObject* args, PyObject *keywds) {
125 ACL_Object* self = (ACL_Object*) obj;
127 static char *kwlist[] = { "file", "fd", "text", "acl", "filedef",
129 char *format = "|etisO!sH";
132 static char *kwlist[] = { "file", "fd", "text", "acl", "filedef", NULL };
133 char *format = "|etisO!s";
136 char *filedef = NULL;
139 ACL_Object* thesrc = NULL;
141 if(!PyTuple_Check(args) || PyTuple_Size(args) != 0 ||
142 (keywds != NULL && PyDict_Check(keywds) && PyDict_Size(keywds) > 1)) {
143 PyErr_SetString(PyExc_ValueError, "a max of one keyword argument"
147 if(!PyArg_ParseTupleAndKeywords(args, keywds, format, kwlist,
148 NULL, &file, &fd, &text, &ACL_Type,
156 /* Free the old acl_t without checking for error, we don't
158 if(self->acl != NULL)
162 self->acl = acl_get_file(file, ACL_TYPE_ACCESS);
163 else if(text != NULL)
164 self->acl = acl_from_text(text);
166 self->acl = acl_get_fd(fd);
167 else if(thesrc != NULL)
168 self->acl = acl_dup(thesrc->acl);
169 else if(filedef != NULL)
170 self->acl = acl_get_file(filedef, ACL_TYPE_DEFAULT);
172 else if(PyMapping_HasKeyString(keywds, kwlist[5]))
173 self->acl = acl_from_mode(mode);
176 self->acl = acl_init(0);
178 if(self->acl == NULL) {
179 PyErr_SetFromErrno(PyExc_IOError);
186 /* Standard type functions */
187 static void ACL_dealloc(PyObject* obj) {
188 ACL_Object *self = (ACL_Object*) obj;
189 PyObject *err_type, *err_value, *err_traceback;
190 int have_error = PyErr_Occurred() ? 1 : 0;
193 PyErr_Fetch(&err_type, &err_value, &err_traceback);
194 if(self->acl != NULL && acl_free(self->acl) != 0)
195 PyErr_WriteUnraisable(obj);
197 PyErr_Restore(err_type, err_value, err_traceback);
201 /* Converts the acl to a text format */
202 static PyObject* ACL_str(PyObject *obj) {
204 ACL_Object *self = (ACL_Object*) obj;
207 text = acl_to_text(self->acl, NULL);
209 return PyErr_SetFromErrno(PyExc_IOError);
211 ret = PyBytes_FromString(text);
212 if(acl_free(text) != 0) {
214 return PyErr_SetFromErrno(PyExc_IOError);
220 static char __to_any_text_doc__[] =
221 "Convert the ACL to a custom text format.\n"
223 "This method encapsulates the acl_to_any_text function. It allows a \n"
224 "customized text format to be generated for the ACL. See\n"
225 "acl_to_any_text(3) for more details.\n"
228 " - prefix: if given, this string will be prepended to all lines\n"
229 " - separator: a single character (defaults to '\\n'); this will be\n"
230 " user to separate the entries in the ACL\n"
231 " - options: a bitwise combination of:\n"
232 " - TEXT_ABBREVIATE: use 'u' instead of 'user', 'g' instead of \n"
234 " - TEXT_NUMERIC_IDS: User and group IDs are included as decimal\n"
235 " numbers instead of names\n"
236 " - TEXT_SOME_EFFECTIVE: Include comments denoting the effective\n"
237 " permissions when some are masked\n"
238 " - TEXT_ALL_EFFECTIVE: Include comments after all ACL entries\n"
239 " affected by an ACL_MASK entry\n"
240 " - TEXT_SMART_INDENT: Used in combination with the _EFFECTIVE\n"
241 " options, this will ensure that comments \n"
242 " are alligned to the fourth tab position\n"
243 " (assuming one tab equals eight spaces)\n"
246 /* Converts the acl to a custom text format */
247 static PyObject* ACL_to_any_text(PyObject *obj, PyObject *args,
250 ACL_Object *self = (ACL_Object*) obj;
252 char *arg_prefix = NULL;
253 char arg_separator = '\n';
255 static char *kwlist[] = {"prefix", "separator", "options", NULL};
257 if (!PyArg_ParseTupleAndKeywords(args, kwds, "|sci", kwlist, &arg_prefix,
258 &arg_separator, &arg_options))
261 text = acl_to_any_text(self->acl, arg_prefix, arg_separator, arg_options);
263 return PyErr_SetFromErrno(PyExc_IOError);
265 ret = PyBytes_FromString(text);
266 if(acl_free(text) != 0) {
268 return PyErr_SetFromErrno(PyExc_IOError);
273 static char __check_doc__[] =
274 "Check the ACL validity.\n"
276 "This is a non-portable, Linux specific extension that allow more\n"
277 "information to be retrieved in case an ACL is not valid than the\n"
278 "validate() method.\n"
280 "This method will return either False (the ACL is valid), or a tuple\n"
281 "with two elements. The first element is one of the following\n"
283 " - ACL_MULTI_ERROR: The ACL contains multiple entries that have a\n"
284 " tag type that may occur at most once\n"
285 " - ACL_DUPLICATE_ERROR: The ACL contains multiple ACL_USER or \n"
286 " ACL_GROUP entries with the same ID\n"
287 " - ACL_MISS_ERROR: A required entry is missing\n"
288 " - ACL_ENTRY_ERROR: The ACL contains an invalid entry tag type\n"
290 "The second element of the tuple is the index of the entry that is\n"
291 "invalid (in the same order as by iterating over the ACL entry)\n"
294 /* The acl_check method */
295 static PyObject* ACL_check(PyObject* obj, PyObject* args) {
296 ACL_Object *self = (ACL_Object*) obj;
300 if((result = acl_check(self->acl, &eindex)) == -1)
301 return PyErr_SetFromErrno(PyExc_IOError);
306 return PyTuple_Pack(2, PyInt_FromLong(result), PyInt_FromLong(eindex));
309 /* Implementation of the rich compare for ACLs */
310 static PyObject* ACL_richcompare(PyObject* o1, PyObject* o2, int op) {
311 ACL_Object *acl1, *acl2;
315 if(!PyObject_IsInstance(o2, (PyObject*)&ACL_Type)) {
320 PyErr_SetString(PyExc_TypeError, "can only compare to an ACL");
324 acl1 = (ACL_Object*)o1;
325 acl2 = (ACL_Object*)o2;
326 if((n=acl_cmp(acl1->acl, acl2->acl))==-1)
327 return PyErr_SetFromErrno(PyExc_IOError);
330 ret = n == 0 ? Py_True : Py_False;
333 ret = n == 1 ? Py_True : Py_False;
336 ret = Py_NotImplemented;
342 static char __equiv_mode_doc__[] =
343 "Return the octal mode the ACL is equivalent to.\n"
345 "This is a non-portable, Linux specific extension that checks\n"
346 "if the ACL is a basic ACL and returns the corresponding mode.\n"
348 "An IOerror exception will be raised if the ACL is an extended ACL\n"
351 /* The acl_equiv_mode method */
352 static PyObject* ACL_equiv_mode(PyObject* obj, PyObject* args) {
353 ACL_Object *self = (ACL_Object*) obj;
356 if(acl_equiv_mode(self->acl, &mode) == -1)
357 return PyErr_SetFromErrno(PyExc_IOError);
358 return PyInt_FromLong(mode);
362 /* Implementation of the compare for ACLs */
363 static int ACL_nocmp(PyObject* o1, PyObject* o2) {
365 PyErr_SetString(PyExc_TypeError, "cannot compare ACLs using cmp()");
370 static char __applyto_doc__[] =
371 "Apply the ACL to a file or filehandle.\n"
374 " - either a filename or a file-like object or an integer; this\n"
375 " represents the filesystem object on which to act\n"
376 " - optional flag representing the type of ACL to set, either\n"
377 " ACL_TYPE_ACCESS (default) or ACL_TYPE_DEFAULT\n"
380 /* Applyes the ACL to a file */
381 static PyObject* ACL_applyto(PyObject* obj, PyObject* args) {
382 ACL_Object *self = (ACL_Object*) obj;
384 acl_type_t type = ACL_TYPE_ACCESS;
388 if (!PyArg_ParseTuple(args, "O|i", &myarg, &type))
391 if(PyBytes_Check(myarg)) {
392 char *filename = PyBytes_AS_STRING(myarg);
393 nret = acl_set_file(filename, type, self->acl);
394 } else if (PyUnicode_Check(myarg)) {
396 PyUnicode_AsEncodedString(myarg,
397 Py_FileSystemDefaultEncoding, "strict");
400 const char *filename = PyBytes_AS_STRING(o);
401 nret = acl_set_file(filename, type, self->acl);
403 } else if((fd = PyObject_AsFileDescriptor(myarg)) != -1) {
404 nret = acl_set_fd(fd, self->acl);
406 PyErr_SetString(PyExc_TypeError, "argument 1 must be string, int,"
407 " or file-like object");
411 return PyErr_SetFromErrno(PyExc_IOError);
414 /* Return the result */
419 static char __valid_doc__[] =
420 "Test the ACL for validity.\n"
422 "This method tests the ACL to see if it is a valid ACL\n"
423 "in terms of the filesystem. More precisely, it checks that:\n"
425 "The ACL contains exactly one entry with each of the\n"
426 "ACL_USER_OBJ, ACL_GROUP_OBJ, and ACL_OTHER tag types. Entries\n"
427 "with ACL_USER and ACL_GROUP tag types may appear zero or more\n"
428 "times in an ACL. An ACL that contains entries of ACL_USER or\n"
429 "ACL_GROUP tag types must contain exactly one entry of the \n"
430 "ACL_MASK tag type. If an ACL contains no entries of\n"
431 "ACL_USER or ACL_GROUP tag types, the ACL_MASK entry is optional.\n"
433 "All user ID qualifiers must be unique among all entries of\n"
434 "the ACL_USER tag type, and all group IDs must be unique among all\n"
435 "entries of ACL_GROUP tag type.\n"
437 "The method will return 1 for a valid ACL and 0 for an invalid one.\n"
438 "This has been chosen because the specification for acl_valid in\n"
439 "the POSIX.1e standard documents only one possible value for errno\n"
440 "in case of an invalid ACL, so we can't differentiate between\n"
441 "classes of errors. Other suggestions are welcome.\n"
444 /* Checks the ACL for validity */
445 static PyObject* ACL_valid(PyObject* obj, PyObject* args) {
446 ACL_Object *self = (ACL_Object*) obj;
448 if(acl_valid(self->acl) == -1) {
457 #ifdef HAVE_ACL_COPY_EXT
458 static PyObject* ACL_get_state(PyObject *obj, PyObject* args) {
459 ACL_Object *self = (ACL_Object*) obj;
464 size = acl_size(self->acl);
466 return PyErr_SetFromErrno(PyExc_IOError);
468 if((ret = PyBytes_FromStringAndSize(NULL, size)) == NULL)
470 buf = PyBytes_AsString(ret);
472 if((nsize = acl_copy_ext(buf, self->acl, size)) == -1) {
474 return PyErr_SetFromErrno(PyExc_IOError);
480 static PyObject* ACL_set_state(PyObject *obj, PyObject* args) {
481 ACL_Object *self = (ACL_Object*) obj;
486 /* Parse the argument */
487 if (!PyArg_ParseTuple(args, "s#", &buf, &bufsize))
490 /* Try to import the external representation */
491 if((ptr = acl_copy_int(buf)) == NULL)
492 return PyErr_SetFromErrno(PyExc_IOError);
494 /* Free the old acl. Should we ignore errors here? */
495 if(self->acl != NULL) {
496 if(acl_free(self->acl) == -1)
497 return PyErr_SetFromErrno(PyExc_IOError);
502 /* Return the result */
510 /* tp_iter for the ACL type; since it can be iterated only
511 * destructively, the type is its iterator
513 static PyObject* ACL_iter(PyObject *obj) {
514 ACL_Object *self = (ACL_Object*)obj;
515 self->entry_id = ACL_FIRST_ENTRY;
520 /* the tp_iternext function for the ACL type */
521 static PyObject* ACL_iternext(PyObject *obj) {
522 ACL_Object *self = (ACL_Object*)obj;
523 acl_entry_t the_entry_t;
524 Entry_Object *the_entry_obj;
527 nerr = acl_get_entry(self->acl, self->entry_id, &the_entry_t);
528 self->entry_id = ACL_NEXT_ENTRY;
530 return PyErr_SetFromErrno(PyExc_IOError);
532 /* Docs says this is not needed */
533 /*PyErr_SetObject(PyExc_StopIteration, Py_None);*/
537 the_entry_obj = (Entry_Object*) PyType_GenericNew(&Entry_Type, NULL, NULL);
538 if(the_entry_obj == NULL)
541 the_entry_obj->entry = the_entry_t;
543 the_entry_obj->parent_acl = obj;
544 Py_INCREF(obj); /* For the reference we have in entry->parent */
546 return (PyObject*)the_entry_obj;
549 static char __ACL_delete_entry_doc__[] =
550 "Deletes an entry from the ACL.\n"
552 "Note: Only with level 2\n"
554 " - the Entry object which should be deleted; note that after\n"
555 " this function is called, that object is unusable any longer\n"
556 " and should be deleted\n"
559 /* Deletes an entry from the ACL */
560 static PyObject* ACL_delete_entry(PyObject *obj, PyObject *args) {
561 ACL_Object *self = (ACL_Object*)obj;
564 if (!PyArg_ParseTuple(args, "O!", &Entry_Type, &e))
567 if(acl_delete_entry(self->acl, e->entry) == -1)
568 return PyErr_SetFromErrno(PyExc_IOError);
570 /* Return the result */
575 static char __ACL_calc_mask_doc__[] =
576 "Compute the file group class mask.\n"
578 "The calc_mask() method calculates and sets the permissions \n"
579 "associated with the ACL_MASK Entry of the ACL.\n"
580 "The value of the new permissions is the union of the permissions \n"
581 "granted by all entries of tag type ACL_GROUP, ACL_GROUP_OBJ, or \n"
582 "ACL_USER. If the ACL already contains an ACL_MASK entry, its \n"
583 "permissions are overwritten; if it does not contain an ACL_MASK \n"
584 "Entry, one is added.\n"
586 "The order of existing entries in the ACL is undefined after this \n"
590 /* Updates the mask entry in the ACL */
591 static PyObject* ACL_calc_mask(PyObject *obj, PyObject *args) {
592 ACL_Object *self = (ACL_Object*)obj;
594 if(acl_calc_mask(&self->acl) == -1)
595 return PyErr_SetFromErrno(PyExc_IOError);
597 /* Return the result */
602 static char __ACL_append_doc__[] =
603 "Append a new Entry to the ACL and return it.\n"
605 "This is a convenience function to create a new Entry \n"
606 "and append it to the ACL.\n"
607 "If a parameter of type Entry instance is given, the \n"
608 "entry will be a copy of that one (as if copied with \n"
609 "Entry.copy()), otherwise, the new entry will be empty.\n"
612 /* Convenience method to create a new Entry */
613 static PyObject* ACL_append(PyObject *obj, PyObject *args) {
614 ACL_Object* self = (ACL_Object*) obj;
615 Entry_Object* newentry;
616 Entry_Object* oldentry = NULL;
619 newentry = (Entry_Object*)PyType_GenericNew(&Entry_Type, NULL, NULL);
620 if(newentry == NULL) {
624 if (!PyArg_ParseTuple(args, "|O!", &Entry_Type, &oldentry))
627 nret = acl_create_entry(&self->acl, &newentry->entry);
630 return PyErr_SetFromErrno(PyExc_IOError);
633 if(oldentry != NULL) {
634 nret = acl_copy_entry(newentry->entry, oldentry->entry);
637 return PyErr_SetFromErrno(PyExc_IOError);
641 newentry->parent_acl = obj;
644 return (PyObject*)newentry;
647 /***** Entry type *****/
649 /* Creation of a new Entry instance */
650 static PyObject* Entry_new(PyTypeObject* type, PyObject* args,
654 newentry = PyType_GenericNew(type, args, keywds);
656 if(newentry != NULL) {
657 ((Entry_Object*)newentry)->entry = NULL;
658 ((Entry_Object*)newentry)->parent_acl = NULL;
664 /* Initialization of a new Entry instance */
665 static int Entry_init(PyObject* obj, PyObject* args, PyObject *keywds) {
666 Entry_Object* self = (Entry_Object*) obj;
667 ACL_Object* parent = NULL;
669 if (!PyArg_ParseTuple(args, "O!", &ACL_Type, &parent))
672 if(acl_create_entry(&parent->acl, &self->entry) == -1) {
673 PyErr_SetFromErrno(PyExc_IOError);
677 self->parent_acl = (PyObject*)parent;
683 /* Free the Entry instance */
684 static void Entry_dealloc(PyObject* obj) {
685 Entry_Object *self = (Entry_Object*) obj;
686 PyObject *err_type, *err_value, *err_traceback;
687 int have_error = PyErr_Occurred() ? 1 : 0;
690 PyErr_Fetch(&err_type, &err_value, &err_traceback);
691 if(self->parent_acl != NULL) {
692 Py_DECREF(self->parent_acl);
693 self->parent_acl = NULL;
696 PyErr_Restore(err_type, err_value, err_traceback);
700 /* Converts the entry to a text format */
701 static PyObject* Entry_str(PyObject *obj) {
705 PyObject *format, *kind;
706 Entry_Object *self = (Entry_Object*) obj;
708 if(acl_get_tag_type(self->entry, &tag) == -1) {
709 PyErr_SetFromErrno(PyExc_IOError);
712 if(tag == ACL_USER || tag == ACL_GROUP) {
713 if((p = acl_get_qualifier(self->entry)) == NULL) {
714 PyErr_SetFromErrno(PyExc_IOError);
717 qualifier = *(uid_t*)p;
723 format = PyBytes_FromString("ACL entry for ");
726 if(tag == ACL_UNDEFINED_TAG) {
727 kind = PyBytes_FromString("undefined type");
728 } else if(tag == ACL_USER_OBJ) {
729 kind = PyBytes_FromString("the owner");
730 } else if(tag == ACL_GROUP_OBJ) {
731 kind = PyBytes_FromString("the group");
732 } else if(tag == ACL_OTHER) {
733 kind = PyBytes_FromString("the others");
734 } else if(tag == ACL_USER) {
735 kind = PyBytes_FromFormat("user with uid %d", qualifier);
736 } else if(tag == ACL_GROUP) {
737 kind = PyBytes_FromFormat("group with gid %d", qualifier);
738 } else if(tag == ACL_MASK) {
739 kind = PyBytes_FromString("the mask");
741 kind = PyBytes_FromString("UNKNOWN_TAG_TYPE!");
745 PyBytes_ConcatAndDel(&format, kind);
750 /* Sets the tag type of the entry */
751 static int Entry_set_tag_type(PyObject* obj, PyObject* value, void* arg) {
752 Entry_Object *self = (Entry_Object*) obj;
755 PyErr_SetString(PyExc_TypeError,
756 "tag type deletion is not supported");
760 if(!PyInt_Check(value)) {
761 PyErr_SetString(PyExc_TypeError,
762 "tag type must be integer");
765 if(acl_set_tag_type(self->entry, (acl_tag_t)PyInt_AsLong(value)) == -1) {
766 PyErr_SetFromErrno(PyExc_IOError);
773 /* Returns the tag type of the entry */
774 static PyObject* Entry_get_tag_type(PyObject *obj, void* arg) {
775 Entry_Object *self = (Entry_Object*) obj;
778 if (self->entry == NULL) {
779 PyErr_SetString(PyExc_AttributeError, "entry attribute");
782 if(acl_get_tag_type(self->entry, &value) == -1) {
783 PyErr_SetFromErrno(PyExc_IOError);
787 return PyInt_FromLong(value);
790 /* Sets the qualifier (either uid_t or gid_t) for the entry,
791 * usable only if the tag type if ACL_USER or ACL_GROUP
793 static int Entry_set_qualifier(PyObject* obj, PyObject* value, void* arg) {
794 Entry_Object *self = (Entry_Object*) obj;
798 PyErr_SetString(PyExc_TypeError,
799 "qualifier deletion is not supported");
803 if(!PyInt_Check(value)) {
804 PyErr_SetString(PyExc_TypeError,
805 "tag type must be integer");
808 uidgid = PyInt_AsLong(value);
809 if(acl_set_qualifier(self->entry, (void*)&uidgid) == -1) {
810 PyErr_SetFromErrno(PyExc_IOError);
817 /* Returns the qualifier of the entry */
818 static PyObject* Entry_get_qualifier(PyObject *obj, void* arg) {
819 Entry_Object *self = (Entry_Object*) obj;
823 if (self->entry == NULL) {
824 PyErr_SetString(PyExc_AttributeError, "entry attribute");
827 if((p = acl_get_qualifier(self->entry)) == NULL) {
828 PyErr_SetFromErrno(PyExc_IOError);
834 return PyInt_FromLong(value);
837 /* Returns the parent ACL of the entry */
838 static PyObject* Entry_get_parent(PyObject *obj, void* arg) {
839 Entry_Object *self = (Entry_Object*) obj;
841 Py_INCREF(self->parent_acl);
842 return self->parent_acl;
845 /* Returns the a new Permset representing the permset of the entry
846 * FIXME: Should return a new reference to the same object, which
847 * should be created at init time!
849 static PyObject* Entry_get_permset(PyObject *obj, void* arg) {
850 Entry_Object *self = (Entry_Object*)obj;
854 p = Permset_new(&Permset_Type, NULL, NULL);
857 ps = (Permset_Object*)p;
858 if(acl_get_permset(self->entry, &ps->permset) == -1) {
859 PyErr_SetFromErrno(PyExc_IOError);
862 ps->parent_entry = obj;
868 /* Sets the permset of the entry to the passed Permset */
869 static int Entry_set_permset(PyObject* obj, PyObject* value, void* arg) {
870 Entry_Object *self = (Entry_Object*)obj;
873 if(!PyObject_IsInstance(value, (PyObject*)&Permset_Type)) {
874 PyErr_SetString(PyExc_TypeError, "argument 1 must be posix1e.Permset");
877 p = (Permset_Object*)value;
878 if(acl_set_permset(self->entry, p->permset) == -1) {
879 PyErr_SetFromErrno(PyExc_IOError);
885 static char __Entry_copy_doc__[] =
886 "Copy an ACL entry.\n"
888 "This method sets all the parameters to those of another\n"
889 "entry, even one of another's ACL\n"
891 " - src, instance of type Entry\n"
894 /* Sets all the entry parameters to another's entry */
895 static PyObject* Entry_copy(PyObject *obj, PyObject *args) {
896 Entry_Object *self = (Entry_Object*)obj;
899 if(!PyArg_ParseTuple(args, "O!", &Entry_Type, &other))
902 if(acl_copy_entry(self->entry, other->entry) == -1)
903 return PyErr_SetFromErrno(PyExc_IOError);
909 /**** Permset type *****/
911 /* Creation of a new Permset instance */
912 static PyObject* Permset_new(PyTypeObject* type, PyObject* args,
914 PyObject* newpermset;
916 newpermset = PyType_GenericNew(type, args, keywds);
918 if(newpermset != NULL) {
919 ((Permset_Object*)newpermset)->permset = NULL;
920 ((Permset_Object*)newpermset)->parent_entry = NULL;
926 /* Initialization of a new Permset instance */
927 static int Permset_init(PyObject* obj, PyObject* args, PyObject *keywds) {
928 Permset_Object* self = (Permset_Object*) obj;
929 Entry_Object* parent = NULL;
931 if (!PyArg_ParseTuple(args, "O!", &Entry_Type, &parent))
934 if(acl_get_permset(parent->entry, &self->permset) == -1) {
935 PyErr_SetFromErrno(PyExc_IOError);
939 self->parent_entry = (PyObject*)parent;
945 /* Free the Permset instance */
946 static void Permset_dealloc(PyObject* obj) {
947 Permset_Object *self = (Permset_Object*) obj;
948 PyObject *err_type, *err_value, *err_traceback;
949 int have_error = PyErr_Occurred() ? 1 : 0;
952 PyErr_Fetch(&err_type, &err_value, &err_traceback);
953 if(self->parent_entry != NULL) {
954 Py_DECREF(self->parent_entry);
955 self->parent_entry = NULL;
958 PyErr_Restore(err_type, err_value, err_traceback);
962 /* Permset string representation */
963 static PyObject* Permset_str(PyObject *obj) {
964 Permset_Object *self = (Permset_Object*) obj;
967 pstr[0] = get_perm(self->permset, ACL_READ) ? 'r' : '-';
968 pstr[1] = get_perm(self->permset, ACL_WRITE) ? 'w' : '-';
969 pstr[2] = get_perm(self->permset, ACL_EXECUTE) ? 'x' : '-';
970 return PyBytes_FromStringAndSize(pstr, 3);
973 static char __Permset_clear_doc__[] =
974 "Clear all permissions from the permission set.\n"
977 /* Clears all permissions from the permset */
978 static PyObject* Permset_clear(PyObject* obj, PyObject* args) {
979 Permset_Object *self = (Permset_Object*) obj;
981 if(acl_clear_perms(self->permset) == -1)
982 return PyErr_SetFromErrno(PyExc_IOError);
984 /* Return the result */
989 static PyObject* Permset_get_right(PyObject *obj, void* arg) {
990 Permset_Object *self = (Permset_Object*) obj;
992 if(get_perm(self->permset, *(acl_perm_t*)arg)) {
1001 static int Permset_set_right(PyObject* obj, PyObject* value, void* arg) {
1002 Permset_Object *self = (Permset_Object*) obj;
1006 if(!PyInt_Check(value)) {
1007 PyErr_SetString(PyExc_ValueError, "a maximum of one argument must"
1011 on = PyInt_AsLong(value);
1013 nerr = acl_add_perm(self->permset, *(acl_perm_t*)arg);
1015 nerr = acl_delete_perm(self->permset, *(acl_perm_t*)arg);
1017 PyErr_SetFromErrno(PyExc_IOError);
1023 static char __Permset_add_doc__[] =
1024 "Add a permission to the permission set.\n"
1026 "The add() function adds the permission contained in \n"
1027 "the argument perm to the permission set. An attempt \n"
1028 "to add a permission that is already contained in the \n"
1029 "permission set is not considered an error.\n"
1032 " - perm: a permission (ACL_WRITE, ACL_READ, ACL_EXECUTE, ...)\n"
1034 "Return value: None\n"
1036 "Can raise: IOError\n"
1039 static PyObject* Permset_add(PyObject* obj, PyObject* args) {
1040 Permset_Object *self = (Permset_Object*) obj;
1043 if (!PyArg_ParseTuple(args, "i", &right))
1046 if(acl_add_perm(self->permset, (acl_perm_t) right) == -1)
1047 return PyErr_SetFromErrno(PyExc_IOError);
1049 /* Return the result */
1054 static char __Permset_delete_doc__[] =
1055 "Delete a permission from the permission set.\n"
1057 "The delete() function deletes the permission contained in \n"
1058 "the argument perm from the permission set. An attempt \n"
1059 "to delete a permission that is not contained in the \n"
1060 "permission set is not considered an error.\n"
1062 " - perm a permission (ACL_WRITE, ACL_READ, ACL_EXECUTE, ...)\n"
1063 "Return value: None\n"
1065 "Can raise: IOError\n"
1068 static PyObject* Permset_delete(PyObject* obj, PyObject* args) {
1069 Permset_Object *self = (Permset_Object*) obj;
1072 if (!PyArg_ParseTuple(args, "i", &right))
1075 if(acl_delete_perm(self->permset, (acl_perm_t) right) == -1)
1076 return PyErr_SetFromErrno(PyExc_IOError);
1078 /* Return the result */
1083 static char __Permset_test_doc__[] =
1084 "Test if a permission exists in the permission set.\n"
1086 "The test() function tests if the permission contained in \n"
1087 "the argument perm exits the permission set.\n"
1089 " - perm a permission (ACL_WRITE, ACL_READ, ACL_EXECUTE, ...)\n"
1090 "Return value: Boolean\n"
1092 "Can raise: IOError\n"
1095 static PyObject* Permset_test(PyObject* obj, PyObject* args) {
1096 Permset_Object *self = (Permset_Object*) obj;
1100 if (!PyArg_ParseTuple(args, "i", &right))
1103 ret = get_perm(self->permset, (acl_perm_t) right);
1105 return PyErr_SetFromErrno(PyExc_IOError);
1111 Py_INCREF(Py_False);
1118 static char __ACL_Type_doc__[] =
1119 "Type which represents a POSIX ACL\n"
1121 "Parameters (only one keword parameter should be provided):\n"
1122 " - file=\"...\", meaning create ACL representing\n"
1123 " the access ACL of that file\n"
1124 " - filedef=\"...\", meaning create ACL representing\n"
1125 " the default ACL of that directory\n"
1126 " - fd=<int>, meaning create ACL representing\n"
1127 " the access ACL of that file descriptor\n"
1128 " - text=\"...\", meaning create ACL from a \n"
1129 " textual description\n"
1130 " - acl=<ACL instance>, meaning create a copy\n"
1131 " of an existing ACL instance\n"
1132 " - mode=<int>, meaning create an ACL from a numeric mode\n"
1133 " (e.g. mode=0644) (this is valid only when the C library\n"
1134 " provides the acl_from_mode call)\n"
1136 "If no parameters are passed, create an empty ACL; this\n"
1137 "makes sense only when your OS supports ACL modification\n"
1138 "(i.e. it implements full POSIX.1e support)\n"
1141 /* ACL type methods */
1142 static PyMethodDef ACL_methods[] = {
1143 {"applyto", ACL_applyto, METH_VARARGS, __applyto_doc__},
1144 {"valid", ACL_valid, METH_NOARGS, __valid_doc__},
1146 {"to_any_text", (PyCFunction)ACL_to_any_text, METH_VARARGS | METH_KEYWORDS,
1147 __to_any_text_doc__},
1148 {"check", ACL_check, METH_NOARGS, __check_doc__},
1149 {"equiv_mode", ACL_equiv_mode, METH_NOARGS, __equiv_mode_doc__},
1151 #ifdef HAVE_ACL_COPYEXT
1152 {"__getstate__", ACL_get_state, METH_NOARGS,
1153 "Dumps the ACL to an external format."},
1154 {"__setstate__", ACL_set_state, METH_VARARGS,
1155 "Loads the ACL from an external format."},
1158 {"delete_entry", ACL_delete_entry, METH_VARARGS, __ACL_delete_entry_doc__},
1159 {"calc_mask", ACL_calc_mask, METH_NOARGS, __ACL_calc_mask_doc__},
1160 {"append", ACL_append, METH_VARARGS, __ACL_append_doc__},
1162 {NULL, NULL, 0, NULL}
1166 /* The definition of the ACL Type */
1167 static PyTypeObject ACL_Type = {
1169 PyVarObject_HEAD_INIT(NULL, 0)
1171 PyObject_HEAD_INIT(NULL)
1177 ACL_dealloc, /* tp_dealloc */
1181 ACL_nocmp, /* tp_compare */
1183 0, /* tp_as_number */
1184 0, /* tp_as_sequence */
1185 0, /* tp_as_mapping */
1188 ACL_str, /* tp_str */
1189 0, /* tp_getattro */
1190 0, /* tp_setattro */
1191 0, /* tp_as_buffer */
1192 Py_TPFLAGS_DEFAULT, /* tp_flags */
1193 __ACL_Type_doc__, /* tp_doc */
1194 0, /* tp_traverse */
1197 ACL_richcompare, /* tp_richcompare */
1199 0, /* tp_richcompare */
1201 0, /* tp_weaklistoffset */
1207 0, /* tp_iternext */
1209 ACL_methods, /* tp_methods */
1214 0, /* tp_descr_get */
1215 0, /* tp_descr_set */
1216 0, /* tp_dictoffset */
1217 ACL_init, /* tp_init */
1219 ACL_new, /* tp_new */
1224 /* Entry type methods */
1225 static PyMethodDef Entry_methods[] = {
1226 {"copy", Entry_copy, METH_VARARGS, __Entry_copy_doc__},
1227 {NULL, NULL, 0, NULL}
1230 static char __Entry_tagtype_doc__[] =
1231 "The tag type of the current entry\n"
1234 " - ACL_UNDEFINED_TAG\n"
1237 " - ACL_GROUP_OBJ\n"
1243 static char __Entry_qualifier_doc__[] =
1244 "The qualifier of the current entry\n"
1246 "If the tag type is ACL_USER, this should be a user id.\n"
1247 "If the tag type if ACL_GROUP, this should be a group id.\n"
1248 "Else, it doesn't matter.\n"
1251 static char __Entry_parent_doc__[] =
1252 "The parent ACL of this entry\n"
1255 static char __Entry_permset_doc__[] =
1256 "The permission set of this ACL entry\n"
1260 static PyGetSetDef Entry_getsets[] = {
1261 {"tag_type", Entry_get_tag_type, Entry_set_tag_type,
1262 __Entry_tagtype_doc__},
1263 {"qualifier", Entry_get_qualifier, Entry_set_qualifier,
1264 __Entry_qualifier_doc__},
1265 {"parent", Entry_get_parent, NULL, __Entry_parent_doc__},
1266 {"permset", Entry_get_permset, Entry_set_permset, __Entry_permset_doc__},
1270 static char __Entry_Type_doc__[] =
1271 "Type which represents an entry in an ACL.\n"
1273 "The type exists only if the OS has full support for POSIX.1e\n"
1274 "Can be created either by:\n"
1276 " >>> e = posix1e.Entry(myACL) # this creates a new entry in the ACL\n"
1277 " >>> e = myACL.append() # another way for doing the same thing\n"
1280 " >>> for entry in myACL:\n"
1281 " ... print entry\n"
1283 "Note that the Entry keeps a reference to its ACL, so even if \n"
1284 "you delete the ACL, it won't be cleaned up and will continue to \n"
1285 "exist until its Entry(ies) will be deleted.\n"
1287 /* The definition of the Entry Type */
1288 static PyTypeObject Entry_Type = {
1290 PyVarObject_HEAD_INIT(NULL, 0)
1292 PyObject_HEAD_INIT(NULL)
1296 sizeof(Entry_Object),
1298 Entry_dealloc, /* tp_dealloc */
1304 0, /* tp_as_number */
1305 0, /* tp_as_sequence */
1306 0, /* tp_as_mapping */
1309 Entry_str, /* tp_str */
1310 0, /* tp_getattro */
1311 0, /* tp_setattro */
1312 0, /* tp_as_buffer */
1313 Py_TPFLAGS_DEFAULT, /* tp_flags */
1314 __Entry_Type_doc__, /* tp_doc */
1315 0, /* tp_traverse */
1317 0, /* tp_richcompare */
1318 0, /* tp_weaklistoffset */
1320 0, /* tp_iternext */
1321 Entry_methods, /* tp_methods */
1323 Entry_getsets, /* tp_getset */
1326 0, /* tp_descr_get */
1327 0, /* tp_descr_set */
1328 0, /* tp_dictoffset */
1329 Entry_init, /* tp_init */
1331 Entry_new, /* tp_new */
1334 /* Permset type methods */
1335 static PyMethodDef Permset_methods[] = {
1336 {"clear", Permset_clear, METH_NOARGS, __Permset_clear_doc__, },
1337 {"add", Permset_add, METH_VARARGS, __Permset_add_doc__, },
1338 {"delete", Permset_delete, METH_VARARGS, __Permset_delete_doc__, },
1339 {"test", Permset_test, METH_VARARGS, __Permset_test_doc__, },
1340 {NULL, NULL, 0, NULL}
1343 static char __Permset_execute_doc__[] =
1344 "Execute permsission\n"
1346 "This is a convenience method of access; the \n"
1347 "same effect can be achieved using the functions\n"
1348 "add(), test(), delete(), and those can take any \n"
1349 "permission defined by your platform.\n"
1352 static char __Permset_read_doc__[] =
1353 "Read permsission\n"
1355 "This is a convenience method of access; the \n"
1356 "same effect can be achieved using the functions\n"
1357 "add(), test(), delete(), and those can take any \n"
1358 "permission defined by your platform.\n"
1361 static char __Permset_write_doc__[] =
1362 "Write permsission\n"
1364 "This is a convenience method of access; the \n"
1365 "same effect can be achieved using the functions\n"
1366 "add(), test(), delete(), and those can take any \n"
1367 "permission defined by your platform.\n"
1370 /* Permset getset */
1371 static PyGetSetDef Permset_getsets[] = {
1372 {"execute", Permset_get_right, Permset_set_right,
1373 __Permset_execute_doc__, &holder_ACL_EXECUTE},
1374 {"read", Permset_get_right, Permset_set_right,
1375 __Permset_read_doc__, &holder_ACL_READ},
1376 {"write", Permset_get_right, Permset_set_right,
1377 __Permset_write_doc__, &holder_ACL_WRITE},
1381 static char __Permset_Type_doc__[] =
1382 "Type which represents the permission set in an ACL entry\n"
1384 "The type exists only if the OS has full support for POSIX.1e\n"
1385 "Can be retrieved either by:\n\n"
1386 ">>> perms = myEntry.permset\n"
1389 ">>> perms = posix1e.Permset(myEntry)\n"
1391 "Note that the Permset keeps a reference to its Entry, so even if \n"
1392 "you delete the entry, it won't be cleaned up and will continue to \n"
1393 "exist until its Permset will be deleted.\n"
1396 /* The definition of the Permset Type */
1397 static PyTypeObject Permset_Type = {
1399 PyVarObject_HEAD_INIT(NULL, 0)
1401 PyObject_HEAD_INIT(NULL)
1405 sizeof(Permset_Object),
1407 Permset_dealloc, /* tp_dealloc */
1413 0, /* tp_as_number */
1414 0, /* tp_as_sequence */
1415 0, /* tp_as_mapping */
1418 Permset_str, /* tp_str */
1419 0, /* tp_getattro */
1420 0, /* tp_setattro */
1421 0, /* tp_as_buffer */
1422 Py_TPFLAGS_DEFAULT, /* tp_flags */
1423 __Permset_Type_doc__,/* tp_doc */
1424 0, /* tp_traverse */
1426 0, /* tp_richcompare */
1427 0, /* tp_weaklistoffset */
1429 0, /* tp_iternext */
1430 Permset_methods, /* tp_methods */
1432 Permset_getsets, /* tp_getset */
1435 0, /* tp_descr_get */
1436 0, /* tp_descr_set */
1437 0, /* tp_dictoffset */
1438 Permset_init, /* tp_init */
1440 Permset_new, /* tp_new */
1445 /* Module methods */
1447 static char __deletedef_doc__[] =
1448 "Delete the default ACL from a directory.\n"
1450 "This function deletes the default ACL associated with \n"
1451 "a directory (the ACL which will be ANDed with the mode\n"
1452 "parameter to the open, creat functions).\n"
1454 " - a string representing the directory whose default ACL\n"
1455 " should be deleted\n"
1458 /* Deletes the default ACL from a directory */
1459 static PyObject* aclmodule_delete_default(PyObject* obj, PyObject* args) {
1462 /* Parse the arguments */
1463 if (!PyArg_ParseTuple(args, "et", NULL, &filename))
1466 if(acl_delete_def_file(filename) == -1) {
1467 return PyErr_SetFromErrno(PyExc_IOError);
1470 /* Return the result */
1476 static char __has_extended_doc__[] =
1477 "Check if a file or filehandle has an extended ACL.\n"
1480 " - either a filename or a file-like object or an integer; this\n"
1481 " represents the filesystem object on which to act\n"
1484 /* Check for extended ACL a file or fd */
1485 static PyObject* aclmodule_has_extended(PyObject* obj, PyObject* args) {
1490 if (!PyArg_ParseTuple(args, "O", &myarg))
1493 if(PyBytes_Check(myarg)) {
1494 const char *filename = PyBytes_AS_STRING(myarg);
1495 nret = acl_extended_file(filename);
1496 } else if (PyUnicode_Check(myarg)) {
1498 PyUnicode_AsEncodedString(myarg,
1499 Py_FileSystemDefaultEncoding, "strict");
1502 const char *filename = PyBytes_AS_STRING(o);
1503 nret = acl_extended_file(filename);
1505 } else if((fd = PyObject_AsFileDescriptor(myarg)) != -1) {
1506 nret = acl_extended_fd(fd);
1508 PyErr_SetString(PyExc_TypeError, "argument 1 must be string, int,"
1509 " or file-like object");
1513 return PyErr_SetFromErrno(PyExc_IOError);
1516 /* Return the result */
1517 return PyBool_FromLong(nret);
1521 /* The module methods */
1522 static PyMethodDef aclmodule_methods[] = {
1523 {"delete_default", aclmodule_delete_default, METH_VARARGS,
1526 {"has_extended", aclmodule_has_extended, METH_VARARGS,
1527 __has_extended_doc__},
1529 {NULL, NULL, 0, NULL}
1532 static char __posix1e_doc__[] =
1533 "POSIX.1e ACLs manipulation\n"
1535 "This module provides support for manipulating POSIX.1e ACLS\n"
1537 "Depending on the operating system support for POSIX.1e, \n"
1538 "the ACL type will have more or less capabilities:\n"
1539 " - level 1, only basic support, you can create\n"
1540 " ACLs from files and text descriptions;\n"
1541 " once created, the type is immutable\n"
1542 " - level 2, complete support, you can alter\n"
1543 " the ACL once it is created\n"
1545 "Also, in level 2, more types are available, corresponding\n"
1546 "to acl_entry_t (the Entry type), acl_permset_t (the Permset type).\n"
1548 "The existence of level 2 support and other extensions can be\n"
1549 "checked by the constants:\n"
1550 " - HAS_ACL_ENTRY for level 2 and the Entry/Permset classes\n"
1551 " - HAS_ACL_FROM_MODE for ACL(mode=...) usage\n"
1552 " - HAS_ACL_CHECK for the ACL().check function\n"
1553 " - HAS_EXTENDED_CHECK for the module-level has_extended function\n"
1554 " - HAS_EQUIV_MODE for the ACL().equiv_mode method\n"
1558 ">>> import posix1e\n"
1559 ">>> acl1 = posix1e.ACL(file=\"file.txt\") \n"
1565 ">>> b = posix1e.ACL(text=\"u::rx,g::-,o::-\")\n"
1571 ">>> b.applyto(\"file.txt\")\n"
1572 ">>> print posix1e.ACL(file=\"file.txt\")\n"
1582 static struct PyModuleDef posix1emodule = {
1583 PyModuleDef_HEAD_INIT,
1590 #define INITERROR return NULL
1593 PyInit_posix1e(void)
1596 #define INITERROR return
1598 void initposix1e(void)
1603 Py_TYPE(&ACL_Type) = &PyType_Type;
1604 if(PyType_Ready(&ACL_Type) < 0)
1608 Py_TYPE(&Entry_Type) = &PyType_Type;
1609 if(PyType_Ready(&Entry_Type) < 0)
1612 Py_TYPE(&Permset_Type) = &PyType_Type;
1613 if(PyType_Ready(&Permset_Type) < 0)
1618 m = PyModule_Create(&posix1emodule);
1620 m = Py_InitModule3("posix1e", aclmodule_methods, __posix1e_doc__);
1625 d = PyModule_GetDict(m);
1629 Py_INCREF(&ACL_Type);
1630 if (PyDict_SetItemString(d, "ACL",
1631 (PyObject *) &ACL_Type) < 0)
1634 /* 23.3.6 acl_type_t values */
1635 PyModule_AddIntConstant(m, "ACL_TYPE_ACCESS", ACL_TYPE_ACCESS);
1636 PyModule_AddIntConstant(m, "ACL_TYPE_DEFAULT", ACL_TYPE_DEFAULT);
1640 Py_INCREF(&Entry_Type);
1641 if (PyDict_SetItemString(d, "Entry",
1642 (PyObject *) &Entry_Type) < 0)
1645 Py_INCREF(&Permset_Type);
1646 if (PyDict_SetItemString(d, "Permset",
1647 (PyObject *) &Permset_Type) < 0)
1650 /* 23.2.2 acl_perm_t values */
1651 PyModule_AddIntConstant(m, "ACL_READ", ACL_READ);
1652 PyModule_AddIntConstant(m, "ACL_WRITE", ACL_WRITE);
1653 PyModule_AddIntConstant(m, "ACL_EXECUTE", ACL_EXECUTE);
1655 /* 23.2.5 acl_tag_t values */
1656 PyModule_AddIntConstant(m, "ACL_UNDEFINED_TAG", ACL_UNDEFINED_TAG);
1657 PyModule_AddIntConstant(m, "ACL_USER_OBJ", ACL_USER_OBJ);
1658 PyModule_AddIntConstant(m, "ACL_USER", ACL_USER);
1659 PyModule_AddIntConstant(m, "ACL_GROUP_OBJ", ACL_GROUP_OBJ);
1660 PyModule_AddIntConstant(m, "ACL_GROUP", ACL_GROUP);
1661 PyModule_AddIntConstant(m, "ACL_MASK", ACL_MASK);
1662 PyModule_AddIntConstant(m, "ACL_OTHER", ACL_OTHER);
1664 /* Document extended functionality via easy-to-use constants */
1665 PyModule_AddIntConstant(m, "HAS_ACL_ENTRY", 1);
1667 PyModule_AddIntConstant(m, "HAS_ACL_ENTRY", 0);
1671 /* Linux libacl specific acl_to_any_text constants */
1672 PyModule_AddIntConstant(m, "TEXT_ABBREVIATE", TEXT_ABBREVIATE);
1673 PyModule_AddIntConstant(m, "TEXT_NUMERIC_IDS", TEXT_NUMERIC_IDS);
1674 PyModule_AddIntConstant(m, "TEXT_SOME_EFFECTIVE", TEXT_SOME_EFFECTIVE);
1675 PyModule_AddIntConstant(m, "TEXT_ALL_EFFECTIVE", TEXT_ALL_EFFECTIVE);
1676 PyModule_AddIntConstant(m, "TEXT_SMART_INDENT", TEXT_SMART_INDENT);
1678 /* Linux libacl specific acl_check constants */
1679 PyModule_AddIntConstant(m, "ACL_MULTI_ERROR", ACL_MULTI_ERROR);
1680 PyModule_AddIntConstant(m, "ACL_DUPLICATE_ERROR", ACL_DUPLICATE_ERROR);
1681 PyModule_AddIntConstant(m, "ACL_MISS_ERROR", ACL_MISS_ERROR);
1682 PyModule_AddIntConstant(m, "ACL_ENTRY_ERROR", ACL_ENTRY_ERROR);
1684 /* declare the Linux extensions */
1685 PyModule_AddIntConstant(m, "HAS_ACL_FROM_MODE", 1);
1686 PyModule_AddIntConstant(m, "HAS_ACL_CHECK", 1);
1687 PyModule_AddIntConstant(m, "HAS_EXTENDED_CHECK", 1);
1688 PyModule_AddIntConstant(m, "HAS_EQUIV_MODE", 1);
1690 PyModule_AddIntConstant(m, "HAS_ACL_FROM_MODE", 0);
1691 PyModule_AddIntConstant(m, "HAS_ACL_CHECK", 0);
1692 PyModule_AddIntConstant(m, "HAS_EXTENDED_CHECK", 0);
1693 PyModule_AddIntConstant(m, "HAS_EQUIV_MODE", 0);