1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 Copyright 2010 Lennart Poettering
7 #include <linux/netlink.h>
9 #include <sys/socket.h>
11 #include "alloc-util.h"
12 #include "audit-util.h"
16 #include "parse-util.h"
17 #include "process-util.h"
18 #include "user-util.h"
20 int audit_session_from_pid(pid_t pid, uint32_t *id) {
21 _cleanup_free_ char *s = NULL;
28 /* We don't convert ENOENT to ESRCH here, since we can't
29 * really distuingish between "audit is not available in the
30 * kernel" and "the process does not exist", both which will
31 * result in ENOENT. */
33 p = procfs_file_alloca(pid, "sessionid");
35 r = read_one_line_file(p, &s);
39 r = safe_atou32(s, &u);
43 if (!audit_session_is_valid(u))
50 int audit_loginuid_from_pid(pid_t pid, uid_t *uid) {
51 _cleanup_free_ char *s = NULL;
58 p = procfs_file_alloca(pid, "loginuid");
60 r = read_one_line_file(p, &s);
65 if (r == -ENXIO) /* the UID was -1 */
74 #if 0 /// UNNEEDED by elogind
75 bool use_audit(void) {
76 static int cached_use = -1;
81 fd = socket(AF_NETLINK, SOCK_RAW|SOCK_CLOEXEC|SOCK_NONBLOCK, NETLINK_AUDIT);
83 cached_use = !IN_SET(errno, EAFNOSUPPORT, EPROTONOSUPPORT, EPERM);
85 log_debug_errno(errno, "Won't talk to audit: %m");