Blame SOURCES/httpd-2.4.25-selinux.patch

af9b8b
af9b8b
Log the SELinux context at startup.
af9b8b
af9b8b
Upstream-Status: unlikely to be any interest in this upstream
af9b8b
af9b8b
--- httpd-2.4.1/configure.in.selinux
af9b8b
+++ httpd-2.4.1/configure.in
af9b8b
@@ -458,6 +458,11 @@ fopen64
af9b8b
 dnl confirm that a void pointer is large enough to store a long integer
af9b8b
 APACHE_CHECK_VOID_PTR_LEN
af9b8b
 
af9b8b
+AC_CHECK_LIB(selinux, is_selinux_enabled, [
af9b8b
+   AC_DEFINE(HAVE_SELINUX, 1, [Defined if SELinux is supported])
3fd4d8
+   APR_ADDTO(HTTPD_LIBS, [-lselinux])
af9b8b
+])
af9b8b
+
af9b8b
 AC_CACHE_CHECK([for gettid()], ac_cv_gettid,
af9b8b
 [AC_TRY_RUN(#define _GNU_SOURCE
af9b8b
 #include <unistd.h>
af9b8b
--- httpd-2.4.1/server/core.c.selinux
af9b8b
+++ httpd-2.4.1/server/core.c
af9b8b
@@ -58,6 +58,10 @@
af9b8b
 #include <unistd.h>
af9b8b
 #endif
af9b8b
 
af9b8b
+#ifdef HAVE_SELINUX
af9b8b
+#include <selinux/selinux.h>
af9b8b
+#endif
af9b8b
+
af9b8b
 /* LimitRequestBody handling */
af9b8b
 #define AP_LIMIT_REQ_BODY_UNSET         ((apr_off_t) -1)
af9b8b
 #define AP_DEFAULT_LIMIT_REQ_BODY       ((apr_off_t) 0)
af9b8b
@@ -4452,6 +4456,28 @@ static int core_post_config(apr_pool_t *
af9b8b
     }
af9b8b
 #endif
af9b8b
 
af9b8b
+#ifdef HAVE_SELINUX
af9b8b
+    {
af9b8b
+        static int already_warned = 0;
af9b8b
+        int is_enabled = is_selinux_enabled() > 0;
af9b8b
+        
af9b8b
+        if (is_enabled && !already_warned) {
af9b8b
+            security_context_t con;
af9b8b
+            
af9b8b
+            if (getcon(&con) == 0) {
af9b8b
+                
af9b8b
+                ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, NULL,
af9b8b
+                             "SELinux policy enabled; "
af9b8b
+                             "httpd running as context %s", con);
af9b8b
+                
af9b8b
+                already_warned = 1;
af9b8b
+                
af9b8b
+                freecon(con);
af9b8b
+            }
af9b8b
+        }
af9b8b
+    }
af9b8b
+#endif
af9b8b
+
af9b8b
     return OK;
af9b8b
 }
af9b8b