@@ -5,26 +5,46 @@
#include "label.h"
-static const LabelOps *label_ops = NULL;
+#define POSSIBLE_LABEL_OPS 2 /* SELinux and Smack */
-int label_ops_set(const LabelOps *ops) {
- if (label_ops)
- return -EBUSY;
+static const LabelOps *label_ops[POSSIBLE_LABEL_OPS];
- label_ops = ops;
- return 0;
+int label_ops_set(const LabelOps *ops) {
+ int i;
+
+ for (i = 0; i < POSSIBLE_LABEL_OPS; i++) {
+ if (!label_ops[i]) {
+ label_ops[i] = ops;
+ return 0;
+ }
+ }
+ return -EBUSY;
}
int label_ops_pre(int dir_fd, const char *path, mode_t mode) {
- if (!label_ops || !label_ops->pre)
- return 0;
-
- return label_ops->pre(dir_fd, path, mode);
+ int i;
+ int r;
+
+ for (i = 0; i < POSSIBLE_LABEL_OPS; i++) {
+ if (label_ops[i] && label_ops[i]->pre) {
+ r = label_ops[i]->pre(dir_fd, path, mode);
+ if (r)
+ return r;
+ }
+ }
+ return 0;
}
int label_ops_post(int dir_fd, const char *path) {
- if (!label_ops || !label_ops->post)
- return 0;
-
- return label_ops->post(dir_fd, path);
+ int i;
+ int r;
+
+ for (i = 0; i < POSSIBLE_LABEL_OPS; i++) {
+ if (label_ops[i] && label_ops[i]->post) {
+ r = label_ops[i]->post(dir_fd, path);
+ if (r)
+ return r;
+ }
+ }
+ return 0;
}
@@ -319,7 +319,7 @@ int mac_smack_setup(bool *loaded_policy) {
}
#if HAVE_SMACK_RUN_LABEL
- r = write_string_file("/proc/self/attr/current", SMACK_RUN_LABEL, WRITE_STRING_FILE_DISABLE_BUFFER);
+ r = write_string_file("/proc/self/attr/smack/current", SMACK_RUN_LABEL, WRITE_STRING_FILE_DISABLE_BUFFER);
if (r < 0)
log_warning_errno(r, "Failed to set SMACK label \"" SMACK_RUN_LABEL "\" on self: %m");
r = write_string_file("/sys/fs/smackfs/ambient", SMACK_RUN_LABEL, WRITE_STRING_FILE_DISABLE_BUFFER);
@@ -120,8 +120,6 @@ int btrfs_subvol_make_label(const char *path) {
int mac_init(void) {
int r;
- assert(!(mac_selinux_use() && mac_smack_use()));
-
r = mac_selinux_init();
if (r < 0)
return r;
@@ -112,7 +112,7 @@ int mac_smack_apply_pid(pid_t pid, const char *label) {
if (!mac_smack_use())
return 0;
- p = procfs_file_alloca(pid, "attr/current");
+ p = procfs_file_alloca(pid, "attr/smack/current");
r = write_string_file(p, label, WRITE_STRING_FILE_DISABLE_BUFFER);
if (r < 0)
return r;