Skip to content

Commit 9b17700

Browse files
committed
mod_systemd: if SELinux is available and enabled, log the SELinux
context at startup, since this may vary when httpd is started via systemd vs being started directly. * modules/arch/unix/mod_systemd.c (systemd_post_config): Do nothing for the pre-config iteration. Log the SELinux context if available. * modules/arch/unix/config5.m4: Detect libselinux. Have at least one CI job build mod_systemd. Github: closes #422 git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1916344 13f79535-47bb-0310-9956-ffa450edef68
1 parent dc7d167 commit 9b17700

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

.github/workflows/linux.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,8 @@ jobs:
246246
TEST_INSTALL=1
247247
TEST_MOD_TLS=1
248248
- name: Configured w/reduced exports
249-
config: --enable-reduced-exports --enable-maintainer-mode
249+
config: --enable-reduced-exports --enable-maintainer-mode --enable-systemd
250+
pkgs: libsystemd-dev
250251
env: |
251252
SKIP_TESTING=1
252253
TEST_INSTALL=1

changes-entries/systemd-selinux.patch

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*) mod_systemd: Log the SELinux context at startup if available and
2+
enabled. [Joe Orton]

modules/arch/unix/config5.m4

+5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ APACHE_MODULE(systemd, Systemd support, , , no, [
2525
AC_MSG_WARN([Your system does not support systemd.])
2626
enable_systemd="no"
2727
else
28+
AC_CHECK_LIB(selinux, is_selinux_enabled, [
29+
AC_DEFINE(HAVE_SELINUX, 1, [Defined if SELinux is supported])
30+
APR_ADDTO(MOD_SYSTEMD_LDADD, [-lselinux])
31+
])
32+
2833
APR_ADDTO(MOD_SYSTEMD_LDADD, [$SYSTEMD_LIBS])
2934
fi
3035
])

modules/arch/unix/mod_systemd.c

+26-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
#include "scoreboard.h"
3030
#include "mpm_common.h"
3131

32+
#ifdef HAVE_SELINUX
33+
#include <selinux/selinux.h>
34+
#endif
35+
3236
#include "systemd/sd-daemon.h"
3337

3438
#if APR_HAVE_UNISTD_H
@@ -45,16 +49,37 @@ static int systemd_pre_config(apr_pool_t *pconf, apr_pool_t *plog,
4549
return OK;
4650
}
4751

52+
#ifdef HAVE_SELINUX
53+
static void log_selinux_context(void)
54+
{
55+
char *con;
56+
57+
if (is_selinux_enabled() && getcon(&con) == 0) {
58+
ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, NULL,
59+
APLOGNO(10497) "SELinux is enabled; "
60+
"httpd running as context %s", con);
61+
freecon(con);
62+
}
63+
}
64+
#endif
65+
4866
/* Report the service is ready in post_config, which could be during
4967
* startup or after a reload. The server could still hit a fatal
5068
* startup error after this point during ap_run_mpm(), so this is
5169
* perhaps too early, but by post_config listen() has been called on
5270
* the TCP ports so new connections will not be rejected. There will
5371
* always be a possible async failure event simultaneous to the
5472
* service reporting "ready", so this should be good enough. */
55-
static int systemd_post_config(apr_pool_t *p, apr_pool_t *plog,
73+
static int systemd_post_config(apr_pool_t *pconf, apr_pool_t *plog,
5674
apr_pool_t *ptemp, server_rec *main_server)
5775
{
76+
if (ap_state_query(AP_SQ_MAIN_STATE) == AP_SQ_MS_CREATE_PRE_CONFIG)
77+
return OK;
78+
79+
#ifdef HAVE_SELINUX
80+
log_selinux_context();
81+
#endif
82+
5883
sd_notify(0, "READY=1\n"
5984
"STATUS=Configuration loaded.\n");
6085
return OK;

0 commit comments

Comments
 (0)