]> xenbits.xensource.com Git - libvirt.git/commitdiff
run.in: Detect binaries in builddir properly
authorMichal Privoznik <mprivozn@redhat.com>
Wed, 22 May 2024 15:21:04 +0000 (17:21 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 4 Jun 2024 12:39:00 +0000 (14:39 +0200)
When attempting to run:

  libvirt.git/_build # ./run --selinux ./src/libvirtd

the following error is thrown:

  Refusing to change selinux context of file './src/libvirtd' outside build directory

which is obviously wrong. The problem is 'being inside of build
directory' is detected by simple progpath.startswith(builddir).
While builddir is an absolute path, progpath isn't necessarily.

And while looking into the code, I've noticed chcon() function
accessing variable outside its scope when printing out the path
it's working on.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
run.in

diff --git a/run.in b/run.in
index 5b89b3dcd5b6b2591258be98100c4edf8984cb0c..2821b7123036eeb917112eb674b2daba655ba0d4 100644 (file)
--- a/run.in
+++ b/run.in
@@ -138,7 +138,7 @@ def change_unit(name, action):
 
 
 def chcon(path, user, role, type):
-    print("Setting file context of {} to u={}, r={}, t={}...".format(progpath,
+    print("Setting file context of {} to u={}, r={}, t={}...".format(path,
                                                                      user,
                                                                      role,
                                                                      type))
@@ -187,6 +187,10 @@ else:
     try:
         dorestorecon = False
         progpath = shutil.which(prog)
+        if not progpath:
+            raise Exception("Can't find executable {}"
+                            .format(prog))
+        progpath = os.path.abspath(progpath)
         if len(try_stop_units):
             print("Temporarily stopping systemd units...")
 
@@ -207,10 +211,6 @@ else:
                                 "executing a daemon directly without wrapper "
                                 "commands".format(prog))
 
-            if not progpath:
-                raise Exception("Can't find executable {} for selinux labeling"
-                                .format(prog))
-
             if not progpath.startswith(os.path.abspath(here)):
                 raise Exception("Refusing to change selinux context of file "
                                 "'{}' outside build directory"