label: Introduce LabelOps to do pre/post labelling operations

By default, label_ops is initialized with a NULL pointer which translates
to noop labelling operations. In mac_selinux_init() and the new mac_smack_init(),
we initialize label_ops with a MAC specific LabelOps pointer.

We also introduce mac_init() to initialize any configured MACs and replace all
usages of mac_selinux_init() with mac_init().
This commit is contained in:
Daan De Meyer
2023-05-31 13:15:53 +02:00
parent 0690160e2c
commit a452c807a4
25 changed files with 120 additions and 20 deletions
+30
View File
@@ -0,0 +1,30 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <errno.h>
#include <stddef.h>
#include "label.h"
static const LabelOps *label_ops = NULL;
int label_ops_set(const LabelOps *ops) {
if (label_ops)
return -EBUSY;
label_ops = ops;
return 0;
}
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 label_ops_post(int dir_fd, const char *path) {
if (!label_ops || !label_ops->post)
return 0;
return label_ops->post(dir_fd, path);
}
+14
View File
@@ -0,0 +1,14 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include <sys/types.h>
typedef struct LabelOps {
int (*pre)(int dir_fd, const char *path, mode_t mode);
int (*post)(int dir_fd, const char *path);
} LabelOps;
int label_ops_set(const LabelOps *label_ops);
int label_ops_pre(int dir_fd, const char *path, mode_t mode);
int label_ops_post(int dir_fd, const char *path);
+1
View File
@@ -44,6 +44,7 @@ basic_sources = files(
'inotify-util.c',
'io-util.c',
'ioprio-util.c',
'label.c',
'limits-util.c',
'locale-util.c',
'lock-util.c',