]> source.dussan.org Git - tigervnc.git/commitdiff
SELinux: restore SELinux context in case of different policies 1372/head
authorJan Grulich <jgrulich@redhat.com>
Thu, 11 Nov 2021 12:52:41 +0000 (13:52 +0100)
committerJan Grulich <jgrulich@redhat.com>
Thu, 13 Jan 2022 08:00:30 +0000 (09:00 +0100)
CMakeLists.txt
unix/vncserver/CMakeLists.txt
unix/vncserver/vncsession.c

index 50247c7dac234065b5844167558eb768348059b9..1708eb3d8ea6f3980e47e4fb7b5c5702ad6f4f99 100644 (file)
@@ -268,6 +268,19 @@ if(UNIX AND NOT APPLE)
   endif()
 endif()
 
+# Check for SELinux library
+if(UNIX AND NOT APPLE)
+  check_include_files(selinux/selinux.h HAVE_SELINUX_H)
+  if(HAVE_SELINUX_H)
+    set(CMAKE_REQUIRED_LIBRARIES -lselinux)
+    set(CMAKE_REQUIRED_LIBRARIES)
+    set(SELINUX_LIBS selinux)
+    add_definitions("-DHAVE_SELINUX")
+  else()
+    message(WARNING "Could not find SELinux development files")
+  endif()
+endif()
+
 # Generate config.h and make sure the source finds it
 configure_file(config.h.in config.h)
 add_definitions(-DHAVE_CONFIG_H)
index f65ccc7db98cbf359a79087d5ad1d9f4a4a3cfdd..ae69dc09832ba99e82126188169d6048780eaabd 100644 (file)
@@ -1,5 +1,5 @@
 add_executable(vncsession vncsession.c)
-target_link_libraries(vncsession ${PAM_LIBS})
+target_link_libraries(vncsession ${PAM_LIBS} ${SELINUX_LIBS})
 
 configure_file(vncserver@.service.in vncserver@.service @ONLY)
 configure_file(vncsession-start.in vncsession-start @ONLY)
index 3573e5e9b2dd191900c9306f168eb0951c27d284..f6d2fd59e57cf9803d2a6bb2763fc85eec0633b1 100644 (file)
 #include <sys/types.h>
 #include <sys/wait.h>
 
+#ifdef HAVE_SELINUX
+#include <selinux/selinux.h>
+#include <selinux/restorecon.h>
+#endif
+
 extern char **environ;
 
 // PAM service name
@@ -360,6 +365,17 @@ redir_stdio(const char *homedir, const char *display)
             syslog(LOG_CRIT, "Failure creating \"%s\": %s", logfile, strerror(errno));
             _exit(EX_OSERR);
         }
+
+#ifdef HAVE_SELINUX
+        int result;
+        if (selinux_file_context_verify(logfile, 0) == 0) {
+            result = selinux_restorecon(logfile, SELINUX_RESTORECON_RECURSE);
+
+            if (result < 0) {
+                syslog(LOG_WARNING, "Failure restoring SELinux context for \"%s\": %s", logfile, strerror(errno));
+            }
+        }
+#endif
     }
 
     hostlen = sysconf(_SC_HOST_NAME_MAX);