Since ordinary connections are only interested in the attach-flags and
policy holders in policies, split conn_update() into:
1) conn_update_attach_flags()
2) conn_update_policy()

This way we use the conn_update_policy() function in test-kdbus-policy
with a policy-holding connection and we pass all the tests. This
prevents messing up with the attach-flags.

Signed-off-by: Djalal Harouni <tix...@opendz.org>
---
 test/kdbus-util.c        | 62 +++++++++++++++++++++++++++++++-----------------
 test/kdbus-util.h        |  7 +++---
 test/test-kdbus-policy.c |  2 +-
 3 files changed, 45 insertions(+), 26 deletions(-)

diff --git a/test/kdbus-util.c b/test/kdbus-util.c
index e04aab1..c93390e 100644
--- a/test/kdbus-util.c
+++ b/test/kdbus-util.c
@@ -602,19 +602,15 @@ 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)
+int conn_update_attach_flags(struct conn *conn, uint64_t flags)
 {
+       int ret;
+       size_t size;
        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) {
@@ -628,25 +624,47 @@ int conn_update(struct conn *conn, const char *name,
 
        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->data64[0] = flags;
        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;
+}
+
+int conn_update_policy(struct conn *conn, const char *name,
+                      const struct kdbus_policy_access *access,
+                      size_t num_access)
+{
+       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(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;
+
        item->type = KDBUS_ITEM_NAME;
        item->size = KDBUS_ITEM_HEADER_SIZE + strlen(name) + 1;
        strcpy(item->str, name);
diff --git a/test/kdbus-util.h b/test/kdbus-util.h
index 615f318..ba94d7b 100644
--- a/test/kdbus-util.h
+++ b/test/kdbus-util.h
@@ -55,9 +55,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);
+int conn_update_attach_flags(struct conn *conn, uint64_t flags);
+int conn_update_policy(struct conn *conn, const char *name,
+                      const struct kdbus_policy_access *access,
+                      size_t num_access);
 
 void add_match_empty(int fd);
 
diff --git a/test/test-kdbus-policy.c b/test/test-kdbus-policy.c
index e0bd619..4f8e763 100644
--- a/test/test-kdbus-policy.c
+++ b/test/test-kdbus-policy.c
@@ -64,7 +64,7 @@ static int kdbus_set_policy_talk(struct conn *conn,
                .access = KDBUS_POLICY_TALK,
        };
 
-       return conn_update(conn, name, &access, 1, 0);
+       return conn_update_policy(conn, name, &access, 1);
 }
 
 /* The policy access will be stored in a policy holder connection */
-- 
1.9.3

_______________________________________________
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel

Reply via email to