X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fshared%2Faudit.c;h=54148fcf1836a40c0062a649f6ea676d77a9a2b8;hp=f101050825384ff43e5b8e1f711dfc6c93f21e09;hb=6ec9b87c4ecf5144b5ea845a53a352dd9f2d173a;hpb=f841a154efbb3162d2a732936f031ac7a6b0d4cf
diff --git a/src/shared/audit.c b/src/shared/audit.c
index f10105082..54148fcf1 100644
--- a/src/shared/audit.c
+++ b/src/shared/audit.c
@@ -19,20 +19,14 @@
along with systemd; If not, see .
***/
-#include
-#include
-#include
#include
-#include
#include
-#include
#include "macro.h"
#include "audit.h"
#include "util.h"
-#include "log.h"
+#include "process-util.h"
#include "fileio.h"
-#include "virt.h"
int audit_session_from_pid(pid_t pid, uint32_t *id) {
_cleanup_free_ char *s = NULL;
@@ -52,7 +46,7 @@ int audit_session_from_pid(pid_t pid, uint32_t *id) {
if (r < 0)
return r;
- if (u == (uint32_t) -1 || u <= 0)
+ if (u == AUDIT_SESSION_INVALID || u <= 0)
return -ENXIO;
*id = u;
@@ -80,3 +74,21 @@ int audit_loginuid_from_pid(pid_t pid, uid_t *uid) {
*uid = (uid_t) u;
return 0;
}
+
+bool use_audit(void) {
+ static int cached_use = -1;
+
+ if (cached_use < 0) {
+ int fd;
+
+ fd = socket(AF_NETLINK, SOCK_RAW|SOCK_CLOEXEC|SOCK_NONBLOCK, NETLINK_AUDIT);
+ if (fd < 0)
+ cached_use = errno != EAFNOSUPPORT && errno != EPROTONOSUPPORT;
+ else {
+ cached_use = true;
+ safe_close(fd);
+ }
+ }
+
+ return cached_use;
+}