#include <freeradius-devel/util/misc.h>
#include <freeradius-devel/util/syserror.h>
+#ifdef HAVE_CAPABILITY_H
+#include <freeradius-devel/util/cap.h
+#endif
+
#include <ctype.h>
#include <fcntl.h>
#include <signal.h>
}
#endif
+#ifdef HAVE_CAPABILITIES_H
+#define DUMP_CAPABILITIES(_phase) \
+{ \
+ char *cap_str; \
+ if (fr_cap_set_to_str(autofree, &cap_str) < 0) { \
+ PWARN("Failed retrieving %s capabilities", _phase); \
+ } else { \
+ INFO("%s capabilities: %s", cap_str, _phase); \
+ talloc_free(cap_str); \
+ } \
+}
+#else
+#define DUMP_CAPABILITIES(_phase)
+#endif
+
/** Entry point for the daemon
*
* @hidecallgraph
pid_t pid;
int devnull;
+ DUMP_CAPABILITIES("pre-fork");
+
/*
* Really weird things happen if we leave stdin open and call things like
* system() later.
#ifdef HAVE_SETSID
setsid();
#endif
+
+ DUMP_CAPABILITIES("post-fork");
+ } else {
+ DUMP_CAPABILITIES("pre-suid-down");
}
/*
*/
rad_suid_down_permanent();
+ DUMP_CAPABILITIES("post-suid-down");
+
/*
* Dropping down may change the RLIMIT_CORE value, so
* reset it back to what to should be here.
return ret;
}
+
+/** Snapshot the processes' current capability set, printing it to a string
+ *
+ * @param[in] ctx Where to allocate the string.
+ * @param[out] out The string containing the capabilities.
+ */
+ssize_t fr_cap_set_to_str(TALLOC_CTX *ctx, char **out)
+{
+ cap_t caps = NULL;
+ char const *tmp;
+ size_t len;
+
+ caps = cap_get_proc();
+ if (unlikely(!caps)) {
+ fr_strerror_printf("Failed retrieving process capabilities: %s", fr_syserror(errno));
+ return -1;
+ }
+ tmp = cap_to_text(out, &len)
+ cap_free(caps);
+ if (unlikely(!tmp)) {
+ fr_strerror_printf("Failed converting capabilities to string: %s", fr_syserror(errno));
+ return -1;
+ }
+
+ *out = talloc_bstrndup(ctx, tmp, len);
+ free(tmp);
+
+ return ret;
+}
#endif /* HAVE_CAPABILITY_H */
int fr_cap_enable(cap_value_t cap, cap_flag_t set);
int fr_cap_disable(cap_value_t cap, cap_flag_t set);
+
+ssize_t fr_cap_set_to_str(TALLOC_CTX *ctx, char **out);
#endif
#ifdef __cplusplus