fortify/acl/acl-update.c
Ophestra 4900cd6d41
All checks were successful
Test / Create distribution (push) Successful in 24s
Test / Run NixOS test (push) Successful in 3m17s
acl: implement removeEntry in C
Signed-off-by: Ophestra <cat@gensokyo.uk>
2025-02-17 20:37:10 +09:00

48 lines
1.2 KiB
C

#include "acl-update.h"
#include <stdlib.h>
#include <stdbool.h>
#include <sys/acl.h>
#include <acl/libacl.h>
acl_t f_acl_get_file(const char *path_p, acl_type_t type) {
acl_t acl = acl_get_file(path_p, type);
free((void *)path_p);
return acl;
}
int f_acl_set_file(const char *path_p, acl_type_t type, acl_t acl) {
if (acl_valid(acl) != 0) {
return -1;
}
int ret = acl_set_file(path_p, type, acl);
free((void *)path_p);
return ret;
}
void f_acl_delete_by_uid(acl_t acl, uid_t uid) {
acl_entry_t entry; // acl_get_entry does not store entry_p
acl_tag_t tag_type; // acl_get_tag_type does not store tag_type_p
void *qualifier_p;
bool res;
for (int r = acl_get_entry(acl, ACL_FIRST_ENTRY, &entry); r == 1; r = acl_get_entry(acl, ACL_NEXT_ENTRY, &entry)) {
if (acl_get_tag_type(entry, &tag_type) != 0)
return;
if (tag_type != ACL_USER)
continue;
qualifier_p = acl_get_qualifier(entry);
if (qualifier_p == NULL)
return;
res = *(uid_t *)qualifier_p == uid;
acl_free(qualifier_p);
if (!res)
continue;
acl_delete_entry(acl, entry);
break;
}
}