label: tweak LabelOps post() hook to take "created" boolean
We have two distinct implementations of the post hook. 1. For SELinux we just reset the selinux label we told the kernel earlier to use for new inodes. 2. For SMACK we might apply an xattr to the specified file. The two calls are quite different: the first call we want to call in all cases (failure or success), the latter only if we actually managed to create an inode, in which case it is called on the inode.
This commit is contained in:
+2
-2
@@ -1184,7 +1184,7 @@ int xopenat_full(int dir_fd, const char *path, int open_flags, XOpenFlags xopen_
|
||||
made_dir = true;
|
||||
|
||||
if (FLAGS_SET(xopen_flags, XO_LABEL)) {
|
||||
r = label_ops_post(dir_fd, path);
|
||||
r = label_ops_post(dir_fd, path, made_dir);
|
||||
if (r < 0)
|
||||
goto error;
|
||||
}
|
||||
@@ -1211,7 +1211,7 @@ int xopenat_full(int dir_fd, const char *path, int open_flags, XOpenFlags xopen_
|
||||
}
|
||||
|
||||
if (FLAGS_SET(open_flags, O_CREAT) && FLAGS_SET(xopen_flags, XO_LABEL)) {
|
||||
r = label_ops_post(dir_fd, path);
|
||||
r = label_ops_post(dir_fd, path, made_file || made_dir);
|
||||
if (r < 0)
|
||||
goto error;
|
||||
}
|
||||
|
||||
+2
-2
@@ -22,11 +22,11 @@ int label_ops_pre(int dir_fd, const char *path, mode_t mode) {
|
||||
return label_ops->pre(dir_fd, path, mode);
|
||||
}
|
||||
|
||||
int label_ops_post(int dir_fd, const char *path) {
|
||||
int label_ops_post(int dir_fd, const char *path, bool created) {
|
||||
if (!label_ops || !label_ops->post)
|
||||
return 0;
|
||||
|
||||
return label_ops->post(dir_fd, path);
|
||||
return label_ops->post(dir_fd, path, created);
|
||||
}
|
||||
|
||||
void label_ops_reset(void) {
|
||||
|
||||
+4
-2
@@ -1,15 +1,17 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#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);
|
||||
int (*post)(int dir_fd, const char *path, bool created);
|
||||
} 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);
|
||||
int label_ops_post(int dir_fd, const char *path, bool created);
|
||||
|
||||
void label_ops_reset(void);
|
||||
|
||||
Reference in New Issue
Block a user