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