[systemd-devel] [PATCH 4/5] test: register multiple policies
Djalal Harouni
tixxdz at opendz.org
Wed Jul 23 09:34:35 PDT 2014
Update the policy test in order to register multiple policies
Signed-off-by: Djalal Harouni <tixxdz at opendz.org>
---
test/test-kdbus-policy.c | 57 +++++++++++++++++++++++++++++++++---------------
1 file changed, 40 insertions(+), 17 deletions(-)
diff --git a/test/test-kdbus-policy.c b/test/test-kdbus-policy.c
index de725e9..c12c3ad 100644
--- a/test/test-kdbus-policy.c
+++ b/test/test-kdbus-policy.c
@@ -27,8 +27,8 @@
#include "kdbus-enum.h"
#define MAX_CONN 64
-#define POLICY_NAME "foo.test.policy-test"
-
+#define POLICY_NAME "foo.test.policy-test"
+#define POLICY_NAME_DUMMY_A "foo.test.policy-dummy-a"
/**
* The purpose of these tests:
@@ -81,21 +81,15 @@ static int kdbus_register_activator(char *bus, const char *name,
return 0;
}
-static int kdbus_register_policy_holder(char *bus, const char *name,
- struct conn **conn)
+static int
+kdbus_register_policy_holder(char *bus,
+ const struct kdbus_policy_entry *entries,
+ size_t num_entries,
+ struct conn **conn)
{
struct conn *c;
- struct kdbus_policy_access access[2];
-
- access[0].type = KDBUS_POLICY_ACCESS_USER;
- access[0].access = KDBUS_POLICY_OWN;
- access[0].id = geteuid();
- access[1].type = KDBUS_POLICY_ACCESS_WORLD;
- access[1].access = KDBUS_POLICY_TALK;
- access[1].id = geteuid();
-
- c = kdbus_hello_registrar(bus, name, access, 2,
+ c = kdbus_hello_registrar(bus, entries, num_entries,
KDBUS_HELLO_POLICY_HOLDER);
if (!c)
return -errno;
@@ -268,7 +262,34 @@ static int kdbus_check_policy(char *bus)
{
int i;
int ret;
+ size_t num_entries;
struct conn *activator = NULL;
+ struct kdbus_policy_access policy_access[2] = {
+ {
+ .type = KDBUS_POLICY_ACCESS_USER,
+ .access = KDBUS_POLICY_OWN,
+ .id = geteuid(),
+ },
+ {
+ .type = KDBUS_POLICY_ACCESS_WORLD,
+ .access = KDBUS_POLICY_TALK,
+ .id = geteuid(),
+ },
+ };
+
+ struct kdbus_policy_entry policy_entries[] = {
+ {
+ .name = POLICY_NAME,
+ .num_access = 2,
+ .access = policy_access,
+ },
+ {
+ .name = POLICY_NAME_DUMMY_A,
+ .num_access = 0,
+ },
+ };
+
+ num_entries = sizeof(policy_entries)/sizeof(struct kdbus_policy_entry);
conn_db = calloc(MAX_CONN, sizeof(struct conn *));
if (!conn_db)
@@ -276,7 +297,8 @@ static int kdbus_check_policy(char *bus)
memset(conn_db, 0, MAX_CONN * sizeof(struct conn *));
- ret = kdbus_register_policy_holder(bus, POLICY_NAME, &conn_db[0]);
+ ret = kdbus_register_policy_holder(bus, policy_entries,
+ num_entries, &conn_db[0]);
printf("-- TEST 1) register '%s' as policy holder ",
POLICY_NAME);
if (ret < 0) {
@@ -287,9 +309,10 @@ static int kdbus_check_policy(char *bus)
printf("OK\n");
/* Try to register the same name with an activator */
- ret = kdbus_register_activator(bus, POLICY_NAME, &activator);
+ ret = kdbus_register_activator(bus, policy_entries[0].name,
+ &activator);
printf("-- TEST 2) register again '%s' as an activator ",
- POLICY_NAME);
+ policy_entries[0].name);
if (ret == 0) {
printf("succeeded: TEST FAILED\n");
fprintf(stderr, "--- error was able to register twice '%s'.\n",
--
1.9.3
More information about the systemd-devel
mailing list