summaryrefslogtreecommitdiff
path: root/src/systemctl/systemctl.c
diff options
context:
space:
mode:
authorChristian Göttsche <cgzones@googlemail.com>2020-09-01 17:45:11 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2020-09-02 09:07:59 +0200
commit346543d6f939ab0c9941b71c0a5e3ead07b447d1 (patch)
tree6ce8406918117493bfad81237ca89ae911ae9832 /src/systemctl/systemctl.c
parente4ec78206c67d6a88f004d10fe3b566d1373878f (diff)
downloadsystemd-346543d6f939ab0c9941b71c0a5e3ead07b447d1.tar.gz
selinux/systemctl: create unit file with default context on edit
Diffstat (limited to 'src/systemctl/systemctl.c')
-rw-r--r--src/systemctl/systemctl.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 592c27c27f..e22efb92ac 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -7313,19 +7313,30 @@ static int create_edit_temp_file(const char *new_path, const char *original_path
if (r < 0)
return log_error_errno(r, "Failed to determine temporary filename for \"%s\": %m", new_path);
- r = mkdir_parents(new_path, 0755);
+ r = mkdir_parents_label(new_path, 0755);
if (r < 0)
return log_error_errno(r, "Failed to create directories for \"%s\": %m", new_path);
+ r = mac_selinux_create_file_prepare(original_path, S_IFREG);
+ if (r < 0)
+ return r;
+
r = copy_file(original_path, t, 0, 0644, 0, 0, COPY_REFLINK);
if (r == -ENOENT) {
r = touch(t);
+
+ mac_selinux_create_file_clear();
+
if (r < 0)
return log_error_errno(r, "Failed to create temporary file \"%s\": %m", t);
- } else if (r < 0)
- return log_error_errno(r, "Failed to create temporary file for \"%s\": %m", new_path);
+ } else {
+ mac_selinux_create_file_clear();
+
+ if (r < 0)
+ return log_error_errno(r, "Failed to create temporary file for \"%s\": %m", new_path);
+ }
*ret_tmp_fn = TAKE_PTR(t);
@@ -7604,6 +7615,10 @@ static int edit(int argc, char *argv[], void *userdata) {
if (r < 0)
return log_error_errno(r, "Failed to determine unit paths: %m");
+ r = mac_selinux_init();
+ if (r < 0)
+ return r;
+
r = acquire_bus(BUS_MANAGER, &bus);
if (r < 0)
return r;