chiark / gitweb /
acl-util: only set the mask if not present
[elogind.git] / src / shared / acl-util.c
index ad0e481b9fcd82c7f3a1f510e880b0586383195d..27225e3fe775247cc139676a7e36483b2e079e84 100644 (file)
 #include <stdbool.h>
 
 #include "acl-util.h"
-#include "util.h"
+#include "alloc-util.h"
+#include "string-util.h"
 #include "strv.h"
+#include "user-util.h"
+#include "util.h"
 
 int acl_find_uid(acl_t acl, uid_t uid, acl_entry_t *entry) {
         acl_entry_t i;
@@ -65,9 +68,11 @@ int acl_find_uid(acl_t acl, uid_t uid, acl_entry_t *entry) {
         return 0;
 }
 
+#if 0 /// UNNEEDED by elogind
 int calc_acl_mask_if_needed(acl_t *acl_p) {
         acl_entry_t i;
         int r;
+        bool need = false;
 
         assert(acl_p);
 
@@ -82,21 +87,18 @@ int calc_acl_mask_if_needed(acl_t *acl_p) {
                 if (tag == ACL_MASK)
                         return 0;
 
-                if (IN_SET(tag, ACL_USER, ACL_GROUP)) {
-                        if (acl_calc_mask(acl_p) < 0)
-                                return -errno;
-
-                        return 1;
-                }
+                if (IN_SET(tag, ACL_USER, ACL_GROUP))
+                        need = true;
         }
         if (r < 0)
                 return -errno;
 
-        return 0;
+        if (need && acl_calc_mask(acl_p) < 0)
+                return -errno;
+
+        return need;
 }
 
-/// UNNEEDED by elogind
-#if 0
 int add_base_acls_if_needed(acl_t *acl_p, const char *path) {
         acl_entry_t i;
         int r;