[systemd-devel] [PATCH 04/12] test: add conn_update() to test KDBUS_CMD_CONN_UPDATE
Djalal Harouni
tixxdz at opendz.org
Fri Jun 20 09:49:58 PDT 2014
Add conn_update() to perform KDBUS_CMD_CONN_UPDATE ioctl() calls.
Signed-off-by: Djalal Harouni <tixxdz at opendz.org>
---
test/kdbus-util.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
test/kdbus-util.h | 4 +++
2 files changed, 78 insertions(+)
diff --git a/test/kdbus-util.c b/test/kdbus-util.c
index 965c95d..6bb3bbf 100644
--- a/test/kdbus-util.c
+++ b/test/kdbus-util.c
@@ -1,6 +1,7 @@
/*
* Copyright (C) 2013 Daniel Mack
* Copyright (C) 2013 Kay Sievers
+ * Copyright (C) 2014 Djalal Harouni
*
* kdbus is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the
@@ -606,6 +607,79 @@ int name_list(struct conn *conn, uint64_t flags)
return 0;
}
+int conn_update(struct conn *conn, const char *name,
+ const struct kdbus_policy_access *access,
+ size_t num_access, uint64_t flags)
+{
+ struct kdbus_cmd_update *update;
+ struct kdbus_item *item;
+ size_t i, size;
+ int ret;
+
+ size = sizeof(struct kdbus_cmd_update);
+ size += KDBUS_ITEM_SIZE(sizeof(uint64_t));
+ size += KDBUS_ITEM_SIZE(strlen(name) + 1);
+ size += num_access * KDBUS_ITEM_SIZE(sizeof(struct kdbus_policy_access));
+
+ update = malloc(size);
+ if (!update) {
+ ret = -errno;
+ fprintf(stderr, "error malloc: %d (%m)\n", ret);
+ return ret;
+ }
+
+ memset(update, 0, size);
+ update->size = size;
+
+ item = update->items;
+
+ /*
+ * normally having flags == 0 is valid, but just keep
+ * HELLO flags of __kdbus_hello(), don't check them.
+ */
+ item->type = KDBUS_ITEM_ATTACH_FLAGS;
+ item->size = KDBUS_ITEM_HEADER_SIZE + sizeof(uint64_t);
+ item->data64[0] = flags ? flags : KDBUS_ATTACH_TIMESTAMP |
+ KDBUS_ATTACH_CREDS |
+ KDBUS_ATTACH_NAMES |
+ KDBUS_ATTACH_COMM |
+ KDBUS_ATTACH_EXE |
+ KDBUS_ATTACH_CMDLINE |
+ KDBUS_ATTACH_CAPS |
+ KDBUS_ATTACH_CGROUP |
+ KDBUS_ATTACH_SECLABEL |
+ KDBUS_ATTACH_AUDIT |
+ KDBUS_ATTACH_CONN_NAME;
+ item = KDBUS_ITEM_NEXT(item);
+
+ item->type = KDBUS_ITEM_NAME;
+ item->size = KDBUS_ITEM_HEADER_SIZE + strlen(name) + 1;
+ strcpy(item->str, name);
+ item = KDBUS_ITEM_NEXT(item);
+
+ for (i = 0; i < num_access; i++) {
+ item->size = KDBUS_ITEM_HEADER_SIZE +
+ sizeof(struct kdbus_policy_access);
+ item->type = KDBUS_ITEM_POLICY_ACCESS;
+
+ item->policy_access.type = access[i].type;
+ item->policy_access.access = access[i].access;
+ item->policy_access.id = access[i].id;
+
+ item = KDBUS_ITEM_NEXT(item);
+ }
+
+ ret = ioctl(conn->fd, KDBUS_CMD_CONN_UPDATE, update);
+ if (ret < 0) {
+ ret = -errno;
+ fprintf(stderr, "error conn update: %d (%m)\n", ret);
+ }
+
+ free(update);
+
+ return ret;
+}
+
void add_match_empty(int fd)
{
struct {
diff --git a/test/kdbus-util.h b/test/kdbus-util.h
index dd7d7b6..0fcfb72 100644
--- a/test/kdbus-util.h
+++ b/test/kdbus-util.h
@@ -53,6 +53,10 @@ struct conn *kdbus_hello_activator(const char *path, const char *name,
size_t num_access);
struct kdbus_item *make_policy_name(const char *name);
struct kdbus_item *make_policy_access(__u64 type, __u64 bits, __u64 id);
+int conn_update(struct conn *conn, const char *name,
+ const struct kdbus_policy_access *access,
+ size_t num_access, uint64_t flags);
+
void add_match_empty(int fd);
int drop_privileges(uid_t uid, gid_t gid);
--
1.9.0
More information about the systemd-devel
mailing list