altarch-user / rpms / httpd

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