-static int bus_get_selinux_security_context(
- DBusConnection *connection,
- const char *name,
- char **scon,
- DBusError *error) {
-
- _cleanup_dbus_message_unref_ DBusMessage *m = NULL, *reply = NULL;
- DBusMessageIter iter, sub;
- const char *bytes;
- char *b;
- int nbytes;
-
- m = dbus_message_new_method_call(
- DBUS_SERVICE_DBUS,
- DBUS_PATH_DBUS,
- DBUS_INTERFACE_DBUS,
- "GetConnectionSELinuxSecurityContext");
- if (!m) {
- dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, NULL);
- return -ENOMEM;
- }
-
- if (!dbus_message_append_args(
- m,
- DBUS_TYPE_STRING, &name,
- DBUS_TYPE_INVALID)) {
- dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, NULL);
- return -ENOMEM;
- }
-
- reply = dbus_connection_send_with_reply_and_block(connection, m, -1, error);
- if (!reply)
- return -EIO;
-
- if (dbus_set_error_from_message(error, reply))
- return -EIO;
-
- if (!dbus_message_iter_init(reply, &iter))
- return -EIO;
-
- if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY)
- return -EIO;
-
- dbus_message_iter_recurse(&iter, &sub);
- dbus_message_iter_get_fixed_array(&sub, &bytes, &nbytes);
-
- b = strndup(bytes, nbytes);
- if (!b)
- return -ENOMEM;
-
- *scon = b;
-
- log_debug("GetConnectionSELinuxSecurityContext %s (pid %ld)", *scon, (long) bus_get_unix_process_id(connection, name, error));
-
- return 0;
-}
-
-static int bus_get_audit_data(
- DBusConnection *connection,
- const char *name,
- struct auditstruct *audit,
- DBusError *error) {
-
- pid_t pid;
- int r;
-
- pid = bus_get_unix_process_id(connection, name, error);
- if (pid <= 0)
- return -EIO;
-
- r = audit_loginuid_from_pid(pid, &audit->loginuid);
- if (r < 0)
- return r;
-
- r = get_process_uid(pid, &audit->uid);
- if (r < 0)
- return r;
-
- r = get_process_gid(pid, &audit->gid);
- if (r < 0)
- return r;
-
- r = get_process_cmdline(pid, 0, true, &audit->cmdline);
- if (r < 0)
- return r;
-
- return 0;
-}
-