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