#include <sys/types.h>
#include <sys/acl.h>
+
bool has_default_acl(const char* path) {
/* Return true if the given path has a default ACL, false
otherwise. */
int tag_result = acl_get_tag_type(entry, &tag);
if (tag_result == -1) {
- perror("has_default_tag_acl");
+ perror("has_default_tag_acl - acl_get_tag_type");
return false;
}
else {
int get_default_tag_permset(const char* path,
acl_tag_t tag_type,
acl_permset_t* output_perms) {
- /* Return true if the given path has a default ACL for the supplied
- tag, false otherwise. */
+ /* Returns 0 if successful or -1 on error in accordance with
+ acl_get_permset. */
acl_t defacl = acl_get_file(path, ACL_TYPE_DEFAULT);
if (defacl == (acl_t)NULL) {
/* Follow the acl_foo convention of -1 == error. */
+ errno = EINVAL;
return -1;
}
result = acl_get_entry(defacl, ACL_NEXT_ENTRY, &entry);
}
-
- return false;
+
+ errno = EINVAL;
+ return -1;
}
int get_default_user_obj_permset(const char* path,
}
+
+bool has_default_tag_perm(const char* path, acl_perm_t, perm) {
+ acl_permset_t permset;
+ int ps_result = get_default_tag_permset(path, tag, &permset);
+
+ if (ps_result == -1) {
+ perror("has_default_tag_perm - get_default_tag_permset");
+ return false;
+ }
+
+ int p_result = acl_get_perm(permset, perm);
+ if (p_result == 1) {
+ return true;
+ }
+ else if (p_result == 0) {
+ return false;
+ }
+ else {
+ /* p_result == -1 */
+ perror("has_default_tag_perm - get_default_tag_permset");
+ return false;
+ }
+}
+
+bool has_default_user_obj_read(const char* path) {
+ return has_default_tag_perm(ACL_USER_OBJ, ACL_READ);
+}
+
+bool has_default_user_obj_write(const char* path) {
+ return has_default_tag_perm(ACL_USER_OBJ, ACL_WRITE);
+}
+
+bool has_default_user_obj_execute(const char* path) {
+ return has_default_tag_perm(ACL_USER_OBJ, ACL_EXECUTE);
+}
+
int main(int argc, char* argv[]) {
const char* target = argv[1];
printf("Target: %s\n", target);