acl_sys/
lib.rs

1//  Copyright (C) 2015 Steven Allen
2//
3//  This library is free software; you can redistribute it and/or
4//  modify it under the terms of the GNU Lesser General Public
5//  License as published by the Free Software Foundation; either
6//  version 2.1 of the License, or (at your option) any later version.
7//
8//  This library is distributed in the hope that it will be useful,
9//  but WITHOUT ANY WARRANTY; without even the implied warranty of
10//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11//  Lesser General Public License for more details.
12//
13//  You should have received a copy of the GNU Lesser General Public
14//  License along with this library; if not, write to the Free Software
15//  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
16//
17//  This file is heavily based on the C header sys/acl.h
18//  (C) 1999 Andreas Gruenbacher, <a.gruenbacher@computer.org>
19#![allow(non_camel_case_types)]
20
21extern crate libc;
22
23use libc::{c_void, c_uint, c_int, c_char, ssize_t};
24
25pub type acl_t = *mut c_void;
26pub type acl_permset_t = *mut c_void;
27pub type acl_entry_t = *mut c_void;
28
29pub type acl_type_t = c_uint;
30pub type acl_tag_t = c_int;
31pub type acl_perm_t = c_uint;
32
33pub const ACL_TYPE_ACCESS: acl_type_t = 0x8000;
34pub const ACL_TYPE_DEFAULT: acl_type_t = 0x4000;
35
36pub const ACL_READ: acl_perm_t = 0x04;
37pub const ACL_WRITE: acl_perm_t = 0x02;
38pub const ACL_EXECUTE: acl_perm_t = 0x01;
39
40pub const ACL_UNDEFINED_TAG: acl_tag_t = 0x00;
41pub const ACL_USER_OBJ: acl_tag_t = 0x01;
42pub const ACL_USER: acl_tag_t = 0x02;
43pub const ACL_GROUP_OBJ: acl_tag_t = 0x04;
44pub const ACL_GROUP: acl_tag_t = 0x08;
45pub const ACL_MASK: acl_tag_t = 0x10;
46pub const ACL_OTHER: acl_tag_t = 0x20;
47
48pub const ACL_FIRST_ENTRY: c_int = 0;
49pub const ACL_NEXT_ENTRY: c_int = 1;
50
51// On Linux link to libacl, other OSes have this in libc and need no annotation
52#[cfg_attr(target_os = "linux", link(name = "acl"))]
53extern "C" {
54    /*=== ACL manipulation ===*/
55
56    pub fn acl_init(count: c_int) -> acl_t;
57    pub fn acl_dup(acl: acl_t) -> acl_t;
58    pub fn acl_free(data: *mut c_void) -> c_int;
59    pub fn acl_valid(acl: acl_t) -> c_int;
60
61    /*=== Entry manipulation ===*/
62
63    pub fn acl_copy_entry(dest: acl_entry_t, src: acl_entry_t) -> c_int;
64    pub fn acl_create_entry(acl: *mut acl_t, entry: *mut acl_entry_t) -> c_int;
65    pub fn acl_delete_entry(acl: acl_t, entry: acl_entry_t) -> c_int;
66    pub fn acl_get_entry(acl: acl_t, entry_id: c_int, entry: *mut acl_entry_t) -> c_int;
67
68    /* Manipulate ACL entry permissions */
69
70    pub fn acl_add_perm(permset: acl_permset_t, perm: acl_perm_t) -> c_int;
71    pub fn acl_calc_mask(acl: *mut acl_t) -> c_int;
72    pub fn acl_clear_perms(permset: acl_permset_t) -> c_int;
73    pub fn acl_delete_perms(permset: acl_permset_t, perm: acl_perm_t) -> c_int;
74    pub fn acl_get_permset(entry: acl_entry_t, permset: *mut acl_permset_t) -> c_int;
75    pub fn acl_set_permset(entry: acl_entry_t, permset: acl_permset_t) -> c_int;
76
77    /* Manipulate ACL entry tag type and qualifier */
78
79    pub fn acl_get_qualifier(entry: acl_entry_t) -> *mut c_void;
80    pub fn acl_get_tag_type(entry: acl_entry_t, tag_type: *const acl_tag_t) -> c_int;
81    pub fn acl_set_qualifier(entry: acl_entry_t, tag_qualifier: *const c_void) -> c_int;
82    pub fn acl_set_tag_type(entry: acl_entry_t, tag_type: acl_tag_t) -> c_int;
83
84    /*=== Format translation ===*/
85
86    pub fn acl_copy_ext(buf: *mut c_void, acl: acl_t, size: ssize_t) -> ssize_t;
87    pub fn acl_copy_int(buf: *const c_void) -> acl_t;
88    pub fn acl_from_text(buf: *const c_char) -> acl_t;
89    pub fn acl_size(acl: acl_t) -> ssize_t;
90    pub fn acl_to_text(acl: acl_t, len: *mut ssize_t) -> *mut c_char;
91
92    /*=== Object manipulation ===*/
93
94    pub fn acl_delete_def_file(path: *const c_char) -> c_int;
95    pub fn acl_get_fd(fd: c_int) -> acl_t;
96    pub fn acl_get_file(path: *const c_char, typ: acl_type_t) -> acl_t;
97    pub fn acl_set_fd(fd: c_int, acl: acl_t) -> c_int;
98    pub fn acl_set_file(path: *const c_char, typ: acl_type_t, acl: acl_t) -> c_int;
99}