LIBUCW_MOD_PATHS=$(addprefix $(o)/ucw/,$(LIBUCW_MODS))
-export LIBUCW_LIBS=-lm -lcap
+export LIBUCW_LIBS=-lm
ifdef CONFIG_UCW_THREADS
LIBUCW_LIBS+=-lpthread
endif
ifdef CONFIG_UCW_MONOTONIC_CLOCK
LIBUCW_LIBS+=-lrt
endif
+ifdef CONFIG_UCW_CAPABILITIES
+LIBUCW_LIBS+=-lcap
+endif
$(o)/ucw/libucw$(LV).a: $(addsuffix .o,$(LIBUCW_MOD_PATHS))
$(o)/ucw/libucw$(LV).so: $(addsuffix .oo,$(LIBUCW_MOD_PATHS))
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/file.h>
+#ifdef CONFIG_UCW_CAPABILITIES
#include <sys/prctl.h>
+#endif
void
daemon_resolve_ugid(struct daemon_params *dp)
void daemon_switch_ugid(struct daemon_params *dp)
{
+#ifdef CONFIG_UCW_CAPABILITIES
// If we want to preserve some caps across UID switch, keep all first, to avoid having to set them twice.
if (dp->keep_caps && prctl(PR_SET_KEEPCAPS, 1L) < 0)
die("Can not keep caps: %m");
+#endif
if (dp->want_setgid && setresgid(dp->run_as_gid, dp->run_as_gid, dp->run_as_gid) < 0)
die("Cannot set GID to %d: %m", (int) dp->run_as_gid);
if (dp->want_setgid > 1 && initgroups(dp->run_as_user, dp->run_as_gid) < 0)
die("Cannot initialize groups: %m");
if (dp->want_setuid && setresuid(dp->run_as_uid, dp->run_as_uid, dp->run_as_uid) < 0)
die("Cannot set UID to %d: %m", (int) dp->run_as_uid);
+#ifdef CONFIG_UCW_CAPABILITIES
if (dp->keep_caps)
{
cap_t caps = cap_init();
die("Couldn't give up keeping caps: %m");
cap_free(caps);
}
+#endif
}
void
#define _UCW_DAEMON_H
#include <sys/types.h>
+#ifdef CONFIG_UCW_CAPABILITIES
#include <sys/capability.h>
+#endif
#ifdef CONFIG_UCW_CLEAN_ABI
#define daemon_control ucw_daemon_control
const char *pid_file; // A path to PID file (optional)
const char *run_as_user; // User name or "#uid" (optional)
const char *run_as_group; // Group name or "#gid" (optional)
+#ifdef CONFIG_UCW_CAPABILITIES
const cap_value_t *keep_caps; // Keep these capabilities across UID switch (optional)
int keep_cap_count;
+#endif
// Internal
uid_t run_as_uid;
# Use monotonic clock (default: yes on Linux, no elsewhere)
# Set("CONFIG_UCW_MONOTONIC_CLOCK");
+# Have support for capabilities (default: yes on Linux, no elsewhere)
+# Set("CONFIG_UCW_CAPABILITIES");
+
# Which regular expression library should be used? If none is selected, we use BSD regex from libc.
UnSet("CONFIG_UCW_POSIX_REGEX");
UnSet("CONFIG_UCW_PCRE");
return Get("CONFIG_LINUX");
});
+# Check if we have capabilities (available on linux)
+TestBool("CONFIG_UCW_CAPABILITIES", "Checking for capabilities support", sub {
+ return Get("CONFIG_LINUX");
+});
+
if (IsSet("CONFIG_DARWIN")) {
# Darwin does not support BSD regexes, fix up
if (!IsSet("CONFIG_UCW_POSIX_REGEX") && !IsSet("CONFIG_UCW_PCRE")) {