]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/shared/fileio-label.c
util-lib: split out all temporary file related calls into tmpfiles-util.c
[thirdparty/systemd.git] / src / shared / fileio-label.c
index 0711826e85915fc067e96550667a68ac70fdda09..22df9c937905fa4e8315e238108a3e50bc5e3cf6 100644 (file)
@@ -1,41 +1,21 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+/* SPDX-License-Identifier: LGPL-2.1+ */
 
-/***
-  This file is part of systemd.
-
-  Copyright 2010 Lennart Poettering
-  Copyright 2010 Harald Hoyer
-
-  systemd is free software; you can redistribute it and/or modify it
-  under the terms of the GNU Lesser General Public License as published by
-  the Free Software Foundation; either version 2.1 of the License, or
-  (at your option) any later version.
-
-  systemd is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-  Lesser General Public License for more details.
-
-  You should have received a copy of the GNU Lesser General Public License
-  along with systemd; If not, see <http://www.gnu.org/licenses/>.
-***/
-#include <sys/types.h>
 #include <sys/stat.h>
-#include <unistd.h>
 
 #include "fileio-label.h"
-#include "label.h"
+#include "fileio.h"
+#include "selinux-util.h"
 
-int write_string_file_atomic_label(const char *fn, const char *line) {
+int write_string_file_atomic_label_ts(const char *fn, const char *line, struct timespec *ts) {
         int r;
 
-        r = label_context_set(fn, S_IFREG);
-        if (r  < 0)
+        r = mac_selinux_create_file_prepare(fn, S_IFREG);
+        if (r < 0)
                 return r;
 
-        write_string_file_atomic(fn, line);
+        r = write_string_file_ts(fn, line, WRITE_STRING_FILE_CREATE|WRITE_STRING_FILE_ATOMIC, ts);
 
-        label_context_clear();
+        mac_selinux_create_file_clear();
 
         return r;
 }
@@ -43,13 +23,29 @@ int write_string_file_atomic_label(const char *fn, const char *line) {
 int write_env_file_label(const char *fname, char **l) {
         int r;
 
-        r = label_context_set(fname, S_IFREG);
-        if (r  < 0)
+        r = mac_selinux_create_file_prepare(fname, S_IFREG);
+        if (r < 0)
                 return r;
 
-        write_env_file(fname, l);
+        r = write_env_file(fname, l);
 
-        label_context_clear();
+        mac_selinux_create_file_clear();
 
         return r;
 }
+
+int create_shutdown_run_nologin_or_warn(void) {
+        int r;
+
+        /* This is used twice: once in systemd-user-sessions.service, in order to block logins when we actually go
+         * down, and once in systemd-logind.service when shutdowns are scheduled, and logins are to be turned off a bit
+         * in advance. We use the same wording of the message in both cases. */
+
+        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).");
+        if (r < 0)
+                return log_error_errno(r, "Failed to create /run/nologin: %m");
+
+        return 0;
+}