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