teknoraver / rpms / systemd

Forked from rpms/systemd 3 months ago
Clone

Blame SOURCES/0268-install-make-sure-that-root-mode-doesn-t-make-us-con.patch

84b277
From 8d32393e5a3fbc12371edf69830d0258a097211f Mon Sep 17 00:00:00 2001
84b277
From: Lennart Poettering <lennart@poettering.net>
84b277
Date: Tue, 17 Jun 2014 00:53:49 +0200
84b277
Subject: [PATCH] install: make sure that --root= mode doesn't make us consider
84b277
 all units outside of search path
84b277
84b277
(cherry picked from commit 8f294b45cbb627d31342f6a79444be59ce7e2274)
84b277
84b277
Related: #1111199
84b277
---
84b277
 src/shared/install.c | 41 +++++++++++++++++++++++++++++++++++++----
84b277
 src/shared/util.c    | 16 ----------------
84b277
 src/shared/util.h    |  1 -
84b277
 3 files changed, 37 insertions(+), 21 deletions(-)
84b277
84b277
diff --git a/src/shared/install.c b/src/shared/install.c
84b277
index 871de78..7dad66d 100644
84b277
--- a/src/shared/install.c
84b277
+++ b/src/shared/install.c
84b277
@@ -47,6 +47,37 @@ typedef struct {
84b277
 #define _cleanup_lookup_paths_free_ _cleanup_(lookup_paths_free)
84b277
 #define _cleanup_install_context_done_ _cleanup_(install_context_done)
84b277
 
84b277
+static int in_search_path(const char *path, char **search, const char *root_dir) {
84b277
+        _cleanup_free_ char *parent = NULL;
84b277
+        char **i;
84b277
+        int r;
84b277
+
84b277
+        assert(path);
84b277
+
84b277
+        r = path_get_parent(path, &parent);
84b277
+        if (r < 0)
84b277
+                return r;
84b277
+
84b277
+        STRV_FOREACH(i, search) {
84b277
+                _cleanup_free_ char *buf = NULL;
84b277
+                const char *p;
84b277
+
84b277
+                if (root_dir) {
84b277
+                        buf = strjoin(root_dir, "/", *i, NULL);
84b277
+                        if (!buf)
84b277
+                                return -ENOMEM;
84b277
+
84b277
+                        p = buf;
84b277
+                } else
84b277
+                        p = *i;
84b277
+
84b277
+                if (path_equal(parent, p))
84b277
+                        return 1;
84b277
+        }
84b277
+
84b277
+        return 0;
84b277
+}
84b277
+
84b277
 static int lookup_paths_init_from_scope(LookupPaths *paths,
84b277
                                         UnitFileScope scope,
84b277
                                         const char *root_dir) {
84b277
@@ -741,7 +772,7 @@ int unit_file_link(
84b277
                         continue;
84b277
                 }
84b277
 
84b277
-                q = in_search_path(*i, paths.unit_path);
84b277
+                q = in_search_path(*i, paths.unit_path, root_dir);
84b277
                 if (q < 0)
84b277
                         return q;
84b277
 
84b277
@@ -1296,6 +1327,7 @@ static int install_info_symlink_link(
84b277
                 InstallInfo *i,
84b277
                 LookupPaths *paths,
84b277
                 const char *config_path,
84b277
+                const char *root_dir,
84b277
                 bool force,
84b277
                 UnitFileChange **changes,
84b277
                 unsigned *n_changes) {
84b277
@@ -1308,7 +1340,7 @@ static int install_info_symlink_link(
84b277
         assert(config_path);
84b277
         assert(i->path);
84b277
 
84b277
-        r = in_search_path(i->path, paths->unit_path);
84b277
+        r = in_search_path(i->path, paths->unit_path, root_dir);
84b277
         if (r != 0)
84b277
                 return r;
84b277
 
84b277
@@ -1323,6 +1355,7 @@ static int install_info_apply(
84b277
                 InstallInfo *i,
84b277
                 LookupPaths *paths,
84b277
                 const char *config_path,
84b277
+                const char *root_dir,
84b277
                 bool force,
84b277
                 UnitFileChange **changes,
84b277
                 unsigned *n_changes) {
84b277
@@ -1343,7 +1376,7 @@ static int install_info_apply(
84b277
         if (r == 0)
84b277
                 r = q;
84b277
 
84b277
-        q = install_info_symlink_link(i, paths, config_path, force, changes, n_changes);
84b277
+        q = install_info_symlink_link(i, paths, config_path, root_dir, force, changes, n_changes);
84b277
         if (r == 0)
84b277
                 r = q;
84b277
 
84b277
@@ -1383,7 +1416,7 @@ static int install_context_apply(
84b277
                 } else if (r >= 0)
84b277
                         r += q;
84b277
 
84b277
-                q = install_info_apply(i, paths, config_path, force, changes, n_changes);
84b277
+                q = install_info_apply(i, paths, config_path, root_dir, force, changes, n_changes);
84b277
                 if (r >= 0 && q < 0)
84b277
                         r = q;
84b277
         }
84b277
diff --git a/src/shared/util.c b/src/shared/util.c
84b277
index e313ea9..fc1f765 100644
84b277
--- a/src/shared/util.c
84b277
+++ b/src/shared/util.c
84b277
@@ -4490,22 +4490,6 @@ int dirent_ensure_type(DIR *d, struct dirent *de) {
84b277
         return 0;
84b277
 }
84b277
 
84b277
-int in_search_path(const char *path, char **search) {
84b277
-        char **i;
84b277
-        _cleanup_free_ char *parent = NULL;
84b277
-        int r;
84b277
-
84b277
-        r = path_get_parent(path, &parent);
84b277
-        if (r < 0)
84b277
-                return r;
84b277
-
84b277
-        STRV_FOREACH(i, search)
84b277
-                if (path_equal(parent, *i))
84b277
-                        return 1;
84b277
-
84b277
-        return 0;
84b277
-}
84b277
-
84b277
 int get_files_in_directory(const char *path, char ***list) {
84b277
         _cleanup_closedir_ DIR *d = NULL;
84b277
         size_t bufsize = 0, n = 0;
84b277
diff --git a/src/shared/util.h b/src/shared/util.h
84b277
index 3f30917..ec18d2c 100644
84b277
--- a/src/shared/util.h
84b277
+++ b/src/shared/util.h
84b277
@@ -475,7 +475,6 @@ int glob_extend(char ***strv, const char *path);
84b277
 
84b277
 int dirent_ensure_type(DIR *d, struct dirent *de);
84b277
 
84b277
-int in_search_path(const char *path, char **search);
84b277
 int get_files_in_directory(const char *path, char ***list);
84b277
 
84b277
 char *strjoin(const char *x, ...) _sentinel_;