chiark / gitweb /
bus: parse audit metadata from kdbus messages
authorLennart Poettering <lennart@poettering.net>
Tue, 23 Apr 2013 02:38:38 +0000 (23:38 -0300)
committerLennart Poettering <lennart@poettering.net>
Tue, 23 Apr 2013 02:38:38 +0000 (23:38 -0300)
src/libsystemd-bus/bus-kernel.c
src/libsystemd-bus/bus-message.c
src/libsystemd-bus/bus-message.h
src/systemd/sd-bus.h

index 115297d..42b1696 100644 (file)
@@ -473,6 +473,8 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k, sd_bus_mess
                         m->cmdline_length = l;
                 } else if (d->type == KDBUS_MSG_SRC_CGROUP)
                         m->cgroup = d->str;
+                else if (d->type == KDBUS_MSG_SRC_AUDIT)
+                        m->audit = &d->audit;
                 else
                         log_debug("Got unknown field from kernel %llu", d->type);
         }
index f0de7a3..6b4a0f3 100644 (file)
@@ -904,6 +904,30 @@ int sd_bus_message_get_cmdline(sd_bus_message *m, char ***cmdline) {
         return 0;
 }
 
+int sd_bus_message_get_audit_sessionid(sd_bus_message *m, uint32_t *sessionid) {
+        if (!m)
+                return -EINVAL;
+        if (!sessionid)
+                return -EINVAL;
+        if (!m->audit)
+                return -ESRCH;
+
+        *sessionid = m->audit->sessionid;
+        return 0;
+}
+
+int sd_bus_message_get_audit_loginuid(sd_bus_message *m, uid_t *uid) {
+        if (!m)
+                return -EINVAL;
+        if (!uid)
+                return -EINVAL;
+        if (!m->audit)
+                return -ESRCH;
+
+        *uid = m->audit->loginuid;
+        return 0;
+}
+
 int sd_bus_message_is_signal(sd_bus_message *m, const char *interface, const char *member) {
         if (!m)
                 return -EINVAL;
@@ -3084,7 +3108,8 @@ int bus_message_dump(sd_bus_message *m) {
         char **cmdline = NULL;
         unsigned level = 1;
         int r;
-        uid_t owner;
+        uid_t owner, audit_loginuid;
+        uint32_t audit_sessionid;
 
         assert(m);
 
@@ -3163,6 +3188,10 @@ int bus_message_dump(sd_bus_message *m) {
                 printf("\tsession=[%s]\n", s);
         if (sd_bus_message_get_owner_uid(m, &owner) >= 0)
                 printf("\towner_uid=%lu\n", (unsigned long) owner);
+        if (sd_bus_message_get_audit_loginuid(m, &audit_loginuid) >= 0)
+                printf("\taudit_loginuid=%lu\n", (unsigned long) audit_loginuid);
+        if (sd_bus_message_get_audit_sessionid(m, &audit_sessionid) >= 0)
+                printf("\taudit_sessionid=%lu\n", (unsigned long) audit_sessionid);
 
         if (sd_bus_message_get_cmdline(m, &cmdline) >= 0) {
                 char **c;
index 9440bbe..66b4348 100644 (file)
@@ -119,6 +119,8 @@ struct sd_bus_message {
         char *session;
         char *unit;
         char *user_unit;
+
+        struct kdbus_audit *audit;
 };
 
 #define BUS_MESSAGE_NEED_BSWAP(m) ((m)->header->endian != SD_BUS_NATIVE_ENDIAN)
index 92ae31b..67923e7 100644 (file)
@@ -140,6 +140,8 @@ int sd_bus_message_get_unit(sd_bus_message *m, const char **unit);
 int sd_bus_message_get_user_unit(sd_bus_message *m, const char **unit);
 int sd_bus_message_get_session(sd_bus_message *m, const char **session);
 int sd_bus_message_get_owner_uid(sd_bus_message *m, uid_t *uid);
+int sd_bus_message_get_audit_sessionid(sd_bus_message *m, uint32_t *sessionid);
+int sd_bus_message_get_audit_loginuid(sd_bus_message *m, uid_t *loginuid);
 
 int sd_bus_message_is_signal(sd_bus_message *m, const char *interface, const char *member);
 int sd_bus_message_is_method_call(sd_bus_message *m, const char *interface, const char *member);