1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 This file is part of systemd.
5 Copyright 2010 Lennart Poettering
9 #include <linux/netlink.h>
11 #include <sys/socket.h>
13 #include "alloc-util.h"
14 #include "audit-util.h"
18 #include "parse-util.h"
19 #include "process-util.h"
20 #include "user-util.h"
22 int audit_session_from_pid(pid_t pid, uint32_t *id) {
23 _cleanup_free_ char *s = NULL;
30 /* We don't convert ENOENT to ESRCH here, since we can't
31 * really distuingish between "audit is not available in the
32 * kernel" and "the process does not exist", both which will
33 * result in ENOENT. */
35 p = procfs_file_alloca(pid, "sessionid");
37 r = read_one_line_file(p, &s);
41 r = safe_atou32(s, &u);
45 if (!audit_session_is_valid(u))
52 int audit_loginuid_from_pid(pid_t pid, uid_t *uid) {
53 _cleanup_free_ char *s = NULL;
60 p = procfs_file_alloca(pid, "loginuid");
62 r = read_one_line_file(p, &s);
67 if (r == -ENXIO) /* the UID was -1 */
76 #if 0 /// UNNEEDED by elogind
77 bool use_audit(void) {
78 static int cached_use = -1;
83 fd = socket(AF_NETLINK, SOCK_RAW|SOCK_CLOEXEC|SOCK_NONBLOCK, NETLINK_AUDIT);
85 cached_use = !IN_SET(errno, EAFNOSUPPORT, EPROTONOSUPPORT, EPERM);
87 log_debug_errno(errno, "Won't talk to audit: %m");