From abd5b40c9b094e721e91a5d75132639149d7952f Mon Sep 17 00:00:00 2001
From: Paul Eggleton <paul.eggleton@linux.intel.com>
Date: Tue, 17 Jul 2012 11:27:39 +0100
Subject: [PATCH] Log the SELinux context at startup.

Log the SELinux context at startup.

Upstream-Status: Inappropriate [other]

Note: unlikely to be any interest in this upstream
---
 configure.in  |  5 +++++
 server/core.c | 26 ++++++++++++++++++++++++++
 2 files changed, 31 insertions(+)

diff --git a/configure.in b/configure.in
index 352711a..f58620f 100644
--- a/configure.in
+++ b/configure.in
@@ -514,6 +514,11 @@ gettid
 dnl confirm that a void pointer is large enough to store a long integer
 APACHE_CHECK_VOID_PTR_LEN
 
+AC_CHECK_LIB(selinux, is_selinux_enabled, [
+   AC_DEFINE(HAVE_SELINUX, 1, [Defined if SELinux is supported])
+   APR_ADDTO(AP_LIBS, [-lselinux])
+])
+
 if test $ac_cv_func_gettid = no; then
   # On Linux before glibc 2.30, gettid() is only usable via syscall()
   AC_CACHE_CHECK([for gettid() via syscall], ap_cv_gettid,
diff --git a/server/core.c b/server/core.c
index 30b317e..81f145f 100644
--- a/server/core.c
+++ b/server/core.c
@@ -65,6 +65,10 @@
 #include <unistd.h>
 #endif
 
+#ifdef HAVE_SELINUX
+#include <selinux/selinux.h>
+#endif
+
 /* LimitRequestBody handling */
 #define AP_LIMIT_REQ_BODY_UNSET         ((apr_off_t) -1)
 #define AP_DEFAULT_LIMIT_REQ_BODY       ((apr_off_t) 1<<30) /* 1GB */
@@ -5139,6 +5143,28 @@ static int core_post_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *pte
     }
 #endif
 
+#ifdef HAVE_SELINUX
+    {
+        static int already_warned = 0;
+        int is_enabled = is_selinux_enabled() > 0;
+
+        if (is_enabled && !already_warned) {
+            security_context_t con;
+
+            if (getcon(&con) == 0) {
+
+                ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, NULL,
+                             "SELinux policy enabled; "
+                             "httpd running as context %s", con);
+
+                already_warned = 1;
+
+                freecon(con);
+            }
+        }
+    }
+#endif
+
     return OK;
 }
 
-- 
2.40.0

