[systemd-devel] [PATCH 5/7] libsystemd-bus: add sd_bus_get_selinux_ctx() and sd_bus_get_audit_session_data()
Daniel Mack
zonque at gmail.com
Fri Nov 15 10:32:21 PST 2013
Implementations for both org.freedesktop.DBus and kdbus are available
---
src/libsystemd-bus/bus-control.c | 116 ++++++++++++++++++++++++++++++++++
src/libsystemd-bus/libsystemd-bus.sym | 2 +
src/systemd/sd-bus.h | 2 +
3 files changed, 120 insertions(+)
diff --git a/src/libsystemd-bus/bus-control.c b/src/libsystemd-bus/bus-control.c
index 28adebd..55912c8 100644
--- a/src/libsystemd-bus/bus-control.c
+++ b/src/libsystemd-bus/bus-control.c
@@ -434,6 +434,122 @@ _public_ int sd_bus_get_owner_pid(sd_bus *bus, const char *name, pid_t *pid) {
return 0;
}
+_public_ int sd_bus_get_selinux_ctx(sd_bus *bus, const char *name, const void **ctx, size_t *sz) {
+ _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
+ _cleanup_free_ struct kdbus_cmd_name_info *info = NULL;
+ int r;
+
+ if (!bus)
+ return -EINVAL;
+ if (!name)
+ return -EINVAL;
+ if (!ctx)
+ return -EINVAL;
+ if (!sz)
+ return -EINVAL;
+ if (!BUS_IS_OPEN(bus->state))
+ return -ENOTCONN;
+ if (bus_pid_changed(bus))
+ return -ECHILD;
+
+ if (bus->kernel) {
+ struct kdbus_item *item;
+
+ r = kdbus_name_info(bus, name, &info);
+ if (r < 0)
+ return r;
+
+ KDBUS_PART_FOREACH(item, info, items) {
+ if (item->type != KDBUS_NAME_INFO_ITEM_SECLABEL)
+ continue;
+
+ *sz = item->size - KDBUS_PART_HEADER_SIZE;
+ *ctx = memdup(item->data, *sz);
+ if (!*ctx)
+ return log_oom();
+
+ break;
+ }
+ } else {
+ r = sd_bus_call_method(
+ bus,
+ "org.freedesktop.DBus",
+ "/",
+ "org.freedesktop.DBus",
+ "GetConnectionSELinuxSecurityContext",
+ NULL,
+ &reply,
+ "s",
+ name);
+ if (r < 0)
+ return r;
+
+ r = sd_bus_message_read_array(reply, 'y', ctx, sz);
+ if (r < 0)
+ return r;
+ }
+
+ return 0;
+}
+
+_public_ int sd_bus_get_audit_session_data(sd_bus *bus, const char *name, const void **data, size_t *sz) {
+ _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
+ _cleanup_free_ struct kdbus_cmd_name_info *info = NULL;
+ int r;
+
+ if (!bus)
+ return -EINVAL;
+ if (!name)
+ return -EINVAL;
+ if (!data)
+ return -EINVAL;
+ if (!sz)
+ return -EINVAL;
+ if (!BUS_IS_OPEN(bus->state))
+ return -ENOTCONN;
+ if (bus_pid_changed(bus))
+ return -ECHILD;
+
+ if (bus->kernel) {
+ struct kdbus_item *item;
+
+ r = kdbus_name_info(bus, name, &info);
+ if (r < 0)
+ return r;
+
+ KDBUS_PART_FOREACH(item, info, items) {
+ if (item->type != KDBUS_NAME_INFO_ITEM_AUDIT)
+ continue;
+
+ *sz = item->size - KDBUS_PART_HEADER_SIZE;
+ *data = memdup(item->data, *sz);
+ if (!*data)
+ return log_oom();
+
+ break;
+ }
+ } else {
+ r = sd_bus_call_method(
+ bus,
+ "org.freedesktop.DBus",
+ "/",
+ "org.freedesktop.DBus",
+ "GetAdtAuditSessionData",
+ NULL,
+ &reply,
+ "s",
+ name);
+ if (r < 0)
+ return r;
+
+ r = sd_bus_message_read_array(reply, 'y', data, sz);
+ if (r < 0)
+ return r;
+ }
+
+ return 0;
+}
+
int bus_add_match_internal(
sd_bus *bus,
const char *match,
diff --git a/src/libsystemd-bus/libsystemd-bus.sym b/src/libsystemd-bus/libsystemd-bus.sym
index f1abf01..7952dc5 100644
--- a/src/libsystemd-bus/libsystemd-bus.sym
+++ b/src/libsystemd-bus/libsystemd-bus.sym
@@ -173,6 +173,8 @@ global:
sd_bus_get_owner;
sd_bus_get_owner_uid;
sd_bus_get_owner_pid;
+ sd_bus_get_selinux_ctx;
+ sd_bus_get_audit_session_data;
sd_bus_get_owner_machine_id;
/* Error structures */
diff --git a/src/systemd/sd-bus.h b/src/systemd/sd-bus.h
index 61f232c..901c678 100644
--- a/src/systemd/sd-bus.h
+++ b/src/systemd/sd-bus.h
@@ -248,6 +248,8 @@ int sd_bus_list_names(sd_bus *bus, char ***l);
int sd_bus_get_owner(sd_bus *bus, const char *name, char **owner); /* free the result! */
int sd_bus_get_owner_uid(sd_bus *bus, const char *name, uid_t *uid);
int sd_bus_get_owner_pid(sd_bus *bus, const char *name, pid_t *pid);
+int sd_bus_get_selinux_ctx(sd_bus *bus, const char *name, const void **ctx, size_t *sz);
+int sd_bus_get_audit_session_data(sd_bus *bus, const char *name, const void **data, size_t *sz);
int sd_bus_get_owner_machine_id(sd_bus *bus, const char *name, sd_id128_t *machine);
/* Error structures */
--
1.8.4.2
More information about the systemd-devel
mailing list