Commit 120f919e authored by Lennart Poettering's avatar Lennart Poettering

bus: parse audit metadata from kdbus messages

parent bc7f3beb
......@@ -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);
}
......
......@@ -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;
......
......@@ -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)
......
......@@ -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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment