chiark / gitweb /
journald: DO recalculate the ACL mask, but only if it doesn't exist
authorJan Alexander Steffens (heftig) <jan.steffens@gmail.com>
Tue, 28 May 2013 18:45:34 +0000 (20:45 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 30 May 2013 04:43:39 +0000 (00:43 -0400)
Since 11ec7ce, journald isn't setting the ACLs properly anymore if
the files had no ACLs to begin with: acl_set_fd fails with EINVAL.

An ACL with ACL_USER or ACL_GROUP entries but no ACL_MASK entry is
invalid, so make sure a mask exists before trying to set the ACL.

src/journal/journald-server.c
src/shared/acl-util.c
src/shared/acl-util.h

index b717b92ffb51a1d4c61372af95bd0c15b2f76217..da5b7258635070126acc2e2e2c44276b65f4d920 100644 (file)
@@ -227,9 +227,11 @@ void server_fix_perms(Server *s, JournalFile *f, uid_t uid) {
                 }
         }
 
                 }
         }
 
-        /* We do not recalculate the mask here, so that the fchmod() mask above stays intact. */
+        /* We do not recalculate the mask unconditionally here,
+         * so that the fchmod() mask above stays intact. */
         if (acl_get_permset(entry, &permset) < 0 ||
         if (acl_get_permset(entry, &permset) < 0 ||
-            acl_add_perm(permset, ACL_READ) < 0) {
+            acl_add_perm(permset, ACL_READ) < 0 ||
+            calc_acl_mask_if_needed(&acl) < 0) {
                 log_warning("Failed to patch ACL on %s, ignoring: %m", f->path);
                 goto finish;
         }
                 log_warning("Failed to patch ACL on %s, ignoring: %m", f->path);
                 goto finish;
         }
index 48bb12f46b7e73d156f136f2045ae835a871bf3a..fb04e49dc4367e74454bb9996b23823c42b4f926 100644 (file)
@@ -69,6 +69,34 @@ int acl_find_uid(acl_t acl, uid_t uid, acl_entry_t *entry) {
         return 0;
 }
 
         return 0;
 }
 
+int calc_acl_mask_if_needed(acl_t *acl_p) {
+        acl_entry_t i;
+        int found;
+
+        assert(acl_p);
+
+        for (found = acl_get_entry(*acl_p, ACL_FIRST_ENTRY, &i);
+             found > 0;
+             found = acl_get_entry(*acl_p, ACL_NEXT_ENTRY, &i)) {
+
+                acl_tag_t tag;
+
+                if (acl_get_tag_type(i, &tag) < 0)
+                        return -errno;
+
+                if (tag == ACL_MASK)
+                        return 0;
+        }
+
+        if (found < 0)
+                return -errno;
+
+        if (acl_calc_mask(acl_p) < 0)
+                return -errno;
+
+        return 0;
+}
+
 int search_acl_groups(char*** dst, const char* path, bool* belong) {
         acl_t acl;
 
 int search_acl_groups(char*** dst, const char* path, bool* belong) {
         acl_t acl;
 
index 23090d99843a6d55b9c1b04763e6bbd508773239..36ef490d7eb92fe567d2fcb44f1ef10c434ea1b7 100644 (file)
@@ -24,4 +24,5 @@
 #include <stdbool.h>
 
 int acl_find_uid(acl_t acl, uid_t uid, acl_entry_t *entry);
 #include <stdbool.h>
 
 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 search_acl_groups(char*** dst, const char* path, bool* belong);
 int search_acl_groups(char*** dst, const char* path, bool* belong);