summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/shared/acl-util.c48
-rw-r--r--src/shared/acl-util.h4
2 files changed, 31 insertions, 21 deletions
diff --git a/src/shared/acl-util.c b/src/shared/acl-util.c
index c6c673984d..b734ee1e0c 100644
--- a/src/shared/acl-util.c
+++ b/src/shared/acl-util.c
@@ -90,6 +90,7 @@ int add_base_acls_if_needed(acl_t *acl_p, const char *path) {
_cleanup_(acl_freep) acl_t basic = NULL;
assert(acl_p);
+ assert(path);
for (r = acl_get_entry(*acl_p, ACL_FIRST_ENTRY, &i);
r > 0;
@@ -208,12 +209,16 @@ int acl_search_groups(const char *path, char ***ret_groups) {
return ret;
}
-int parse_acl(const char *text, acl_t *acl_access, acl_t *acl_default, bool want_mask) {
+int parse_acl(const char *text, acl_t *ret_acl_access, acl_t *ret_acl_default, bool want_mask) {
_cleanup_free_ char **a = NULL, **d = NULL; /* strings are not freed */
_cleanup_strv_free_ char **split = NULL;
int r = -EINVAL;
_cleanup_(acl_freep) acl_t a_acl = NULL, d_acl = NULL;
+ assert(text);
+ assert(ret_acl_access);
+ assert(ret_acl_default);
+
split = strv_split(text, ",");
if (!split)
return -ENOMEM;
@@ -266,8 +271,8 @@ int parse_acl(const char *text, acl_t *acl_access, acl_t *acl_default, bool want
}
}
- *acl_access = TAKE_PTR(a_acl);
- *acl_default = TAKE_PTR(d_acl);
+ *ret_acl_access = TAKE_PTR(a_acl);
+ *ret_acl_default = TAKE_PTR(d_acl);
return 0;
}
@@ -322,7 +327,7 @@ static int acl_entry_equal(acl_entry_t a, acl_entry_t b) {
}
}
-static int find_acl_entry(acl_t acl, acl_entry_t entry, acl_entry_t *out) {
+static int find_acl_entry(acl_t acl, acl_entry_t entry, acl_entry_t *ret) {
acl_entry_t i;
int r;
@@ -334,36 +339,40 @@ static int find_acl_entry(acl_t acl, acl_entry_t entry, acl_entry_t *out) {
if (r < 0)
return r;
if (r > 0) {
- *out = i;
- return 1;
+ if (ret)
+ *ret = i;
+ return 0;
}
}
if (r < 0)
return -errno;
- return 0;
+
+ return -ENOENT;
}
-int acls_for_file(const char *path, acl_type_t type, acl_t new, acl_t *acl) {
- _cleanup_(acl_freep) acl_t old;
+int acls_for_file(const char *path, acl_type_t type, acl_t acl, acl_t *ret) {
+ _cleanup_(acl_freep) acl_t applied = NULL;
acl_entry_t i;
int r;
- old = acl_get_file(path, type);
- if (!old)
+ assert(path);
+
+ applied = acl_get_file(path, type);
+ if (!applied)
return -errno;
- for (r = acl_get_entry(new, ACL_FIRST_ENTRY, &i);
+ for (r = acl_get_entry(acl, ACL_FIRST_ENTRY, &i);
r > 0;
- r = acl_get_entry(new, ACL_NEXT_ENTRY, &i)) {
+ r = acl_get_entry(acl, ACL_NEXT_ENTRY, &i)) {
acl_entry_t j;
- r = find_acl_entry(old, i, &j);
- if (r < 0)
- return r;
- if (r == 0)
- if (acl_create_entry(&old, &j) < 0)
+ r = find_acl_entry(applied, i, &j);
+ if (r == -ENOENT) {
+ if (acl_create_entry(&applied, &j) < 0)
return -errno;
+ } else if (r < 0)
+ return r;
if (acl_copy_entry(j, i) < 0)
return -errno;
@@ -371,7 +380,8 @@ int acls_for_file(const char *path, acl_type_t type, acl_t new, acl_t *acl) {
if (r < 0)
return -errno;
- *acl = TAKE_PTR(old);
+ if (ret)
+ *ret = TAKE_PTR(applied);
return 0;
}
diff --git a/src/shared/acl-util.h b/src/shared/acl-util.h
index 03595c6651..d3a341fbe6 100644
--- a/src/shared/acl-util.h
+++ b/src/shared/acl-util.h
@@ -15,8 +15,8 @@ int acl_find_uid(acl_t acl, uid_t uid, acl_entry_t *entry);
int calc_acl_mask_if_needed(acl_t *acl_p);
int add_base_acls_if_needed(acl_t *acl_p, const char *path);
int acl_search_groups(const char* path, char ***ret_groups);
-int parse_acl(const char *text, acl_t *acl_access, acl_t *acl_default, bool want_mask);
-int acls_for_file(const char *path, acl_type_t type, acl_t new, acl_t *acl);
+int parse_acl(const char *text, acl_t *ret_acl_access, acl_t *ret_acl_default, bool want_mask);
+int acls_for_file(const char *path, acl_type_t type, acl_t new, acl_t *ret);
int fd_add_uid_acl_permission(int fd, uid_t uid, unsigned mask);
/* acl_free takes multiple argument types.