test: split conn_update() into update attach-flags and update policy
authorDjalal Harouni <tixxdz@opendz.org>
Tue, 5 Aug 2014 01:46:08 +0000 (02:46 +0100)
committerKay Sievers <kay@vrfy.org>
Tue, 5 Aug 2014 07:24:29 +0000 (09:24 +0200)
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 <tixxdz@opendz.org>
test/kdbus-util.c
test/kdbus-util.h
test/test-kdbus-policy.c

index e04aab102060844232e99cb162161a922df19a24..c93390efd5e69d4b7d2bea37cc56b551606a8cc3 100644 (file)
@@ -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);
index 615f31889b68e5713cee756914bea2c2d4b70a6c..ba94d7bdd5912d8acc89135c997ecad529717ad7 100644 (file)
@@ -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);
 
index e0bd6198e85119d88e46af9f99907eaed96011e2..4f8e7636f8a8d045eacfc1dfeacf8b97980ba0ce 100644 (file)
@@ -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 */