-static int get_audit_data(
- DBusConnection *connection,
- DBusMessage *message,
- struct auditstruct *audit,
- DBusError *error) {
-
- const char *sender;
- int r, fd;
- struct ucred ucred;
- socklen_t len;
-
- sender = dbus_message_get_sender(message);
- if (sender)
- return bus_get_audit_data(connection, sender, audit, error);
-
- if (!dbus_connection_get_unix_fd(connection, &fd))
- return -EINVAL;
-
- r = getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &ucred, &len);
- if (r < 0) {
- log_error("Failed to determine peer credentials: %m");
- return -errno;
- }
-
- audit->uid = ucred.uid;
- audit->gid = ucred.gid;
-
- r = audit_loginuid_from_pid(ucred.pid, &audit->loginuid);
- if (r < 0)
- return r;
-
- r = get_process_cmdline(ucred.pid, LINE_MAX, true, &audit->cmdline);
- if (r < 0)
- return r;
-
- return 0;
-}
-
-/*
- This function returns the security context of the remote end of the dbus
- connections. Whether it is on the bus or a local connection.
-*/
-static int get_calling_context(
- DBusConnection *connection,
- DBusMessage *message,
- security_context_t *scon,
- DBusError *error) {
-
- const char *sender;
- int r;
- int fd;
-
- /*
- If sender exists then
- if sender is NULL this indicates a local connection. Grab the fd
- from dbus and do an getpeercon to peers process context
- */
- sender = dbus_message_get_sender(message);
- if (sender) {
- r = bus_get_selinux_security_context(connection, sender, scon, error);
- if (r >= 0)
- return r;
-
- log_debug("bus_get_selinux_security_context failed %m");
- }
-
- if (!dbus_connection_get_unix_fd(connection, &fd)) {
- log_error("bus_connection_get_unix_fd failed %m");
- return -EINVAL;
- }
-
- r = getpeercon(fd, scon);
- if (r < 0) {
- log_error("getpeercon failed %m");
- return -errno;
- }
-
- return 0;
-}
-