| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
#pragma once |
| 3 |
|
| 4 |
#include "sd-dlopen.h" |
| 5 |
|
| 6 |
#include "shared-forward.h" |
| 7 |
|
| 8 |
#if HAVE_ACL |
| 9 |
#include <acl/libacl.h> /* IWYU pragma: export */ |
| 10 |
#include <sys/acl.h> /* IWYU pragma: export */ |
| 11 |
|
| 12 |
#include "dlfcn-util.h" |
| 13 |
|
| 14 |
extern DLSYM_PROTOTYPE(acl_add_perm); |
| 15 |
extern DLSYM_PROTOTYPE(acl_calc_mask); |
| 16 |
extern DLSYM_PROTOTYPE(acl_copy_entry); |
| 17 |
extern DLSYM_PROTOTYPE(acl_create_entry); |
| 18 |
extern DLSYM_PROTOTYPE(acl_delete_entry); |
| 19 |
extern DLSYM_PROTOTYPE(acl_delete_perm); |
| 20 |
extern DLSYM_PROTOTYPE(acl_dup); |
| 21 |
extern DLSYM_PROTOTYPE(acl_entries); |
| 22 |
extern DLSYM_PROTOTYPE(acl_extended_file); |
| 23 |
extern DLSYM_PROTOTYPE(acl_free); |
| 24 |
extern DLSYM_PROTOTYPE(acl_from_mode); |
| 25 |
extern DLSYM_PROTOTYPE(acl_from_text); |
| 26 |
extern DLSYM_PROTOTYPE(acl_get_entry); |
| 27 |
extern DLSYM_PROTOTYPE(acl_get_fd); |
| 28 |
extern DLSYM_PROTOTYPE(acl_get_file); |
| 29 |
extern DLSYM_PROTOTYPE(acl_get_perm); |
| 30 |
extern DLSYM_PROTOTYPE(acl_get_permset); |
| 31 |
extern DLSYM_PROTOTYPE(acl_get_qualifier); |
| 32 |
extern DLSYM_PROTOTYPE(acl_get_tag_type); |
| 33 |
extern DLSYM_PROTOTYPE(acl_init); |
| 34 |
extern DLSYM_PROTOTYPE(acl_set_fd); |
| 35 |
extern DLSYM_PROTOTYPE(acl_set_file); |
| 36 |
extern DLSYM_PROTOTYPE(acl_set_permset); |
| 37 |
extern DLSYM_PROTOTYPE(acl_set_qualifier); |
| 38 |
extern DLSYM_PROTOTYPE(acl_set_tag_type); |
| 39 |
extern DLSYM_PROTOTYPE(acl_to_any_text); |
| 40 |
|
| 41 |
int devnode_acl(int fd, const Set *uids); |
| 42 |
|
| 43 |
int calc_acl_mask_if_needed(acl_t *acl_p); |
| 44 |
int add_base_acls_if_needed(acl_t *acl_p, const char *path); |
| 45 |
int acl_search_groups(const char* path, char ***ret_groups); |
| 46 |
int parse_acl( |
| 47 |
const char *text, |
| 48 |
acl_t *ret_acl_access, |
| 49 |
acl_t *ret_acl_access_exec, |
| 50 |
acl_t *ret_acl_default, |
| 51 |
bool want_mask); |
| 52 |
int acls_for_file(const char *path, acl_type_t type, acl_t acl, acl_t *ret); |
| 53 |
int fd_add_uid_acl_permission(int fd, uid_t uid, unsigned mask); |
| 54 |
|
| 55 |
/* acl_free() takes multiple argument types. Multiple cleanup functions are necessary. */ |
| 56 |
DEFINE_TRIVIAL_CLEANUP_FUNC_FULL_RENAME(acl_t, sym_acl_free, acl_freep, NULL); |
| 57 |
DEFINE_TRIVIAL_CLEANUP_FUNC_FULL_RENAME(char*, sym_acl_free, acl_free_charpp, NULL); |
| 58 |
DEFINE_TRIVIAL_CLEANUP_FUNC_FULL_RENAME(uid_t*, sym_acl_free, acl_free_uid_tpp, NULL); |
| 59 |
DEFINE_TRIVIAL_CLEANUP_FUNC_FULL_RENAME(gid_t*, sym_acl_free, acl_free_gid_tpp, NULL); |
| 60 |
|
| 61 |
static inline int acl_set_perm(acl_permset_t ps, acl_perm_t p, bool b) { |
| 62 |
return (b ? sym_acl_add_perm : sym_acl_delete_perm)(ps, p); |
| 63 |
} |
| 64 |
|
| 65 |
#define LIBACL_NOTE(priority) \ |
| 66 |
SD_ELF_NOTE_DLOPEN("acl", \ |
| 67 |
"Support for file Access Control Lists (ACLs)", \ |
| 68 |
priority, \ |
| 69 |
"libacl.so.1") |
| 70 |
|
| 71 |
#define DLOPEN_LIBACL(log_level, priority) \ |
| 72 |
({ \ |
| 73 |
LIBACL_NOTE(priority); \ |
| 74 |
dlopen_libacl(log_level); \ |
| 75 |
}) |
| 76 |
#else |
| 77 |
|
| 78 |
typedef void* acl_t; |
| 79 |
typedef int acl_tag_t; |
| 80 |
typedef unsigned acl_type_t; |
| 81 |
|
| 82 |
#define ACL_READ 0x04 |
| 83 |
#define ACL_WRITE 0x02 |
| 84 |
#define ACL_EXECUTE 0x01 |
| 85 |
|
| 86 |
/* acl_tag_t */ |
| 87 |
#define ACL_UNDEFINED_TAG (0x00) |
| 88 |
#define ACL_USER_OBJ (0x01) |
| 89 |
#define ACL_USER (0x02) |
| 90 |
#define ACL_GROUP_OBJ (0x04) |
| 91 |
#define ACL_GROUP (0x08) |
| 92 |
#define ACL_MASK (0x10) |
| 93 |
#define ACL_OTHER (0x20) |
| 94 |
|
| 95 |
/* acl_type_t */ |
| 96 |
#define ACL_TYPE_ACCESS (0x8000) |
| 97 |
#define ACL_TYPE_DEFAULT (0x4000) |
| 98 |
|
| 99 |
static inline int devnode_acl(int fd, const Set *uids) { |
| 100 |
return -EOPNOTSUPP; |
| 101 |
} |
| 102 |
|
| 103 |
static inline int fd_add_uid_acl_permission(int fd, uid_t uid, unsigned mask) { |
| 104 |
return -EOPNOTSUPP; |
| 105 |
} |
| 106 |
|
| 107 |
#define DLOPEN_LIBACL(log_level, priority) dlopen_libacl(log_level) |
| 108 |
#endif |
| 109 |
|
| 110 |
int dlopen_libacl(int log_level); |
| 111 |
|
| 112 |
int fd_acl_make_read_only(int fd); |
| 113 |
int fd_acl_make_writable(int fd); |
| 114 |
|
| 115 |
int inode_type_can_acl(mode_t mode); |