fileio: port write_string_file() to LabelOps, and thus add WRITE_STRING_FILE_LABEL flag
Given that we have the LabelOps abstraction these days, we can teach write_string_file() to use it, which means we can get rid of fileio-label.[ch] as a separate concept. (The only reason that fileio-label.[ch] exists independently of fileio.[ch] was that the former linekd to libselinux potentially, and thus had to be in src/shared/ while the other always was in src/basic/. But the LabelOps vtable provides us with a nice work-around)
This commit is contained in:
+2
-2
@@ -12,7 +12,7 @@
|
||||
#include "dropin.h"
|
||||
#include "escape.h"
|
||||
#include "fd-util.h"
|
||||
#include "fileio-label.h"
|
||||
#include "fileio.h"
|
||||
#include "hashmap.h"
|
||||
#include "log.h"
|
||||
#include "macro.h"
|
||||
@@ -87,7 +87,7 @@ int write_drop_in(
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return write_string_file_at_label(AT_FDCWD, p, data, WRITE_STRING_FILE_CREATE|WRITE_STRING_FILE_ATOMIC|WRITE_STRING_FILE_MKDIR_0755);
|
||||
return write_string_file(p, data, WRITE_STRING_FILE_CREATE|WRITE_STRING_FILE_ATOMIC|WRITE_STRING_FILE_MKDIR_0755|WRITE_STRING_FILE_LABEL);
|
||||
}
|
||||
|
||||
int write_drop_in_format(
|
||||
|
||||
@@ -6,20 +6,6 @@
|
||||
#include "fileio.h"
|
||||
#include "selinux-util.h"
|
||||
|
||||
int write_string_file_full_label(int atfd, const char *fn, const char *line, WriteStringFileFlags flags, struct timespec *ts) {
|
||||
int r;
|
||||
|
||||
r = mac_selinux_create_file_prepare_at(atfd, fn, S_IFREG);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = write_string_file_full(atfd, fn, line, flags, ts);
|
||||
|
||||
mac_selinux_create_file_clear();
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
int create_shutdown_run_nologin_or_warn(void) {
|
||||
int r;
|
||||
|
||||
@@ -33,9 +19,10 @@ int create_shutdown_run_nologin_or_warn(void) {
|
||||
* 13 years later we stopped managing /etc/nologin, leaving it for the administrator to manage.
|
||||
*/
|
||||
|
||||
r = write_string_file_atomic_label("/run/nologin",
|
||||
"System is going down. Unprivileged users are not permitted to log in anymore. "
|
||||
"For technical details, see pam_nologin(8).");
|
||||
r = write_string_file("/run/nologin",
|
||||
"System is going down. Unprivileged users are not permitted to log in anymore. "
|
||||
"For technical details, see pam_nologin(8).",
|
||||
WRITE_STRING_FILE_CREATE|WRITE_STRING_FILE_ATOMIC|WRITE_STRING_FILE_LABEL);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to create /run/nologin: %m");
|
||||
|
||||
|
||||
@@ -9,12 +9,4 @@
|
||||
|
||||
#include "fileio.h"
|
||||
|
||||
int write_string_file_full_label(int atfd, const char *fn, const char *line, WriteStringFileFlags flags, struct timespec *ts);
|
||||
static inline int write_string_file_at_label(int atfd, const char *fn, const char *line, WriteStringFileFlags flags) {
|
||||
return write_string_file_full_label(atfd, fn, line, flags, /* ts= */ NULL);
|
||||
}
|
||||
static inline int write_string_file_atomic_label(const char *fn, const char *line) {
|
||||
return write_string_file_at_label(AT_FDCWD, fn, line, WRITE_STRING_FILE_CREATE|WRITE_STRING_FILE_ATOMIC);
|
||||
}
|
||||
|
||||
int create_shutdown_run_nologin_or_warn(void);
|
||||
|
||||
Reference in New Issue
Block a user