diff options
Diffstat (limited to 'acl')
| -rw-r--r-- | acl/acl-update.c | 108 | ||||
| -rw-r--r-- | acl/acl-update.h | 3 |
2 files changed, 57 insertions, 54 deletions
diff --git a/acl/acl-update.c b/acl/acl-update.c index 1d83c15d..be796b55 100644 --- a/acl/acl-update.c +++ b/acl/acl-update.c @@ -1,69 +1,71 @@ #include "acl-update.h" -#include <stdlib.h> +#include <acl/libacl.h> #include <stdbool.h> +#include <stdlib.h> #include <sys/acl.h> -#include <acl/libacl.h> -int f_acl_update_file_by_uid(const char *path_p, uid_t uid, acl_perm_t *perms, size_t plen) { - int ret = -1; - bool v; - int i; - acl_t acl; - acl_entry_t entry; - acl_tag_t tag_type; - void *qualifier_p; - acl_permset_t permset; +int f_acl_update_file_by_uid(const char *path_p, uid_t uid, acl_perm_t *perms, + size_t plen) { + int ret = -1; + bool v; + int i; + acl_t acl; + acl_entry_t entry; + acl_tag_t tag_type; + void *qualifier_p; + acl_permset_t permset; - acl = acl_get_file(path_p, ACL_TYPE_ACCESS); - if (acl == NULL) - goto out; + acl = acl_get_file(path_p, ACL_TYPE_ACCESS); + if (acl == NULL) + goto out; - // prune entries by uid - for (i = acl_get_entry(acl, ACL_FIRST_ENTRY, &entry); i == 1; i = acl_get_entry(acl, ACL_NEXT_ENTRY, &entry)) { - if (acl_get_tag_type(entry, &tag_type) != 0) - return -1; - if (tag_type != ACL_USER) - continue; + // prune entries by uid + for (i = acl_get_entry(acl, ACL_FIRST_ENTRY, &entry); i == 1; + i = acl_get_entry(acl, ACL_NEXT_ENTRY, &entry)) { + if (acl_get_tag_type(entry, &tag_type) != 0) + return -1; + if (tag_type != ACL_USER) + continue; - qualifier_p = acl_get_qualifier(entry); - if (qualifier_p == NULL) - return -1; - v = *(uid_t *)qualifier_p == uid; - acl_free(qualifier_p); + qualifier_p = acl_get_qualifier(entry); + if (qualifier_p == NULL) + return -1; + v = *(uid_t *)qualifier_p == uid; + acl_free(qualifier_p); - if (!v) - continue; + if (!v) + continue; - acl_delete_entry(acl, entry); - } + acl_delete_entry(acl, entry); + } - if (plen == 0) - goto set; + if (plen == 0) + goto set; - if (acl_create_entry(&acl, &entry) != 0) - goto out; - if (acl_get_permset(entry, &permset) != 0) - goto out; - for (i = 0; i < plen; i++) { - if (acl_add_perm(permset, perms[i]) != 0) - goto out; - } - if (acl_set_tag_type(entry, ACL_USER) != 0) - goto out; - if (acl_set_qualifier(entry, (void *)&uid) != 0) - goto out; + if (acl_create_entry(&acl, &entry) != 0) + goto out; + if (acl_get_permset(entry, &permset) != 0) + goto out; + for (i = 0; i < plen; i++) { + if (acl_add_perm(permset, perms[i]) != 0) + goto out; + } + if (acl_set_tag_type(entry, ACL_USER) != 0) + goto out; + if (acl_set_qualifier(entry, (void *)&uid) != 0) + goto out; set: - if (acl_calc_mask(&acl) != 0) - goto out; - if (acl_valid(acl) != 0) - goto out; - if (acl_set_file(path_p, ACL_TYPE_ACCESS, acl) == 0) - ret = 0; + if (acl_calc_mask(&acl) != 0) + goto out; + if (acl_valid(acl) != 0) + goto out; + if (acl_set_file(path_p, ACL_TYPE_ACCESS, acl) == 0) + ret = 0; out: - free((void *)path_p); - if (acl != NULL) - acl_free((void *)acl); - return ret; + free((void *)path_p); + if (acl != NULL) + acl_free((void *)acl); + return ret; } diff --git a/acl/acl-update.h b/acl/acl-update.h index e758788e..fa1541fd 100644 --- a/acl/acl-update.h +++ b/acl/acl-update.h @@ -1,3 +1,4 @@ #include <sys/acl.h> -int f_acl_update_file_by_uid(const char *path_p, uid_t uid, acl_perm_t *perms, size_t plen); +int f_acl_update_file_by_uid(const char *path_p, uid_t uid, acl_perm_t *perms, + size_t plen); |
