Skip to content

Commit 36b5cc6

Browse files
notrojrpluem
authored andcommitted
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 (cherry picked from commit 9b17700)
1 parent 289ca22 commit 36b5cc6

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed
Lines changed: 2 additions & 0 deletions
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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ APACHE_MODULE(systemd, Systemd support, , , no, [
2323
AC_MSG_WARN([Your system does not support systemd.])
2424
enable_systemd="no"
2525
else
26+
AC_CHECK_LIB(selinux, is_selinux_enabled, [
27+
AC_DEFINE(HAVE_SELINUX, 1, [Defined if SELinux is supported])
28+
APR_ADDTO(MOD_SYSTEMD_LDADD, [-lselinux])
29+
])
30+
2631
APR_ADDTO(MOD_SYSTEMD_LDADD, [$SYSTEMD_LIBS])
2732
fi
2833
])

modules/arch/unix/mod_systemd.c

Lines changed: 26 additions & 1 deletion
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)