#include <sys/resource.h>
#include <unistd.h>
+#ifdef ENABLE_CAP_NG
+#include <cap-ng.h>
+#endif
+
#include <lua.h>
#include <uv.h>
#if SYSTEMD_VERSION > 0
return some_bad_ret;
}
+/* Drop POSIX 1003.1e capabilities. */
+static void drop_capabilities(void)
+{
+#ifdef ENABLE_CAP_NG
+ /* Drop all capabilities. */
+ if (capng_have_capability(CAPNG_EFFECTIVE, CAP_SETPCAP)) {
+ capng_clear(CAPNG_SELECT_BOTH);
+
+ /* Apply. */
+ if (capng_apply(CAPNG_SELECT_BOTH) < 0) {
+ kr_log_error("[system] failed to set process capabilities: %s\n",
+ strerror(errno));
+ }
+ } else {
+ kr_log_info("[system] process not allowed to set capabilities, skipping\n");
+ }
+#endif /* ENABLE_CAP_NG */
+}
+
int main(int argc, char **argv)
{
struct args args;
goto cleanup;
}
}
+ drop_capabilities();
if (engine_start(&engine) != 0) {
ret = EXIT_FAILURE;
goto cleanup;
# NOTE avoid using link_args for luajit due to a macOS issue
# https://github.com/Homebrew/homebrew-core/issues/37169
luajit_inc = luajit.partial_dependency(compile_args: true, includes: true)
-openssl = dependency('openssl', required: false)
message('------------------------------')
user = get_option('user')
group = get_option('group')
-## sendmmsg
+## Optional dependencies
+message('--- optional dependencies ---')
+capng = dependency('libcap-ng', required: false)
+openssl = dependency('openssl', required: false)
+
+### sendmmsg
has_sendmmsg = meson.get_compiler('c').has_function('sendmmsg',
prefix: '#define _GNU_SOURCE\n#include <sys/socket.h>')
if get_option('sendmmsg') == 'enabled' and not has_sendmmsg
sendmmsg = get_option('sendmmsg') == 'enabled'
endif
-## Systemd
-message('--- systemd socket activation ---')
+### Systemd
libsystemd = dependency('libsystemd', required: false)
systemd_files = get_option('systemd_files')
if systemd_files == 'enabled' and (
libsystemd.found() ? libsystemd.version().to_int() : -1)
conf_data.set('NOVERBOSELOG', not verbose_log)
conf_data.set('ENABLE_SENDMMSG', sendmmsg.to_int())
+conf_data.set('ENABLE_CAP_NG', capng.found())
kresconfig = configure_file(
output: 'kresconfig.h',