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