kdbus.h: attach items[] to kdbus_cmd_conn_info, not name[] (ABI break!)
authorDaniel Mack <daniel@zonque.org>
Thu, 2 Oct 2014 10:57:53 +0000 (12:57 +0200)
committerDaniel Mack <daniel@zonque.org>
Thu, 2 Oct 2014 11:00:34 +0000 (13:00 +0200)
Instead of directly attaching the string to kdbus_cmd_conn_info, use
items as we do in all other commands. That allows for more flexibility
later.

Signed-off-by: Daniel Mack <daniel@zonque.org>
connection.c
kdbus.h
kdbus.txt
test/kdbus-util.c
test/test-connection.c

index 514dea04bc3ec968e6701159396ee59b4490ab0e..9e6bec81a2b6621428a34fe9d67afde1027142c2 100644 (file)
@@ -1169,13 +1169,15 @@ int kdbus_cmd_conn_info(struct kdbus_conn *conn,
        u64 flags;
 
        if (cmd_info->id == 0) {
-               size_t len = cmd_info->size -
-                            offsetof(struct kdbus_cmd_conn_info, name);
+               const char *name;
 
-               if (strnlen(cmd_info->name, len) + 1 != len)
+               ret = kdbus_items_get_str(cmd_info->items,
+                                         KDBUS_ITEMS_SIZE(cmd_info, items),
+                                         KDBUS_ITEM_NAME, &name);
+               if (ret < 0)
                        return -EINVAL;
 
-               if (!kdbus_name_is_valid(cmd_info->name, false))
+               if (!kdbus_name_is_valid(name, false))
                        return -EINVAL;
 
                /* check if 'conn' is allowed to see 'name' */
@@ -1183,7 +1185,7 @@ int kdbus_cmd_conn_info(struct kdbus_conn *conn,
                mutex_lock(&conn->lock);
 
                ret = kdbus_ep_policy_check_see_access_unlocked(conn->ep, conn,
-                                                               cmd_info->name);
+                                                               name);
 
                mutex_unlock(&conn->lock);
                up_read(&conn->ep->policy_db.entries_rwlock);
@@ -1191,8 +1193,7 @@ int kdbus_cmd_conn_info(struct kdbus_conn *conn,
                if (ret < 0)
                        return ret;
 
-               entry = kdbus_name_lock(conn->bus->name_registry,
-                                       cmd_info->name);
+               entry = kdbus_name_lock(conn->bus->name_registry, name);
                if (!entry)
                        return -ESRCH;
                else if (entry->conn)
diff --git a/kdbus.h b/kdbus.h
index 7fb11713fc3cd620f8ebad16390bb119329c4ce5..c97994974b7882246c9d04fe689870f3d1fc8175 100644 (file)
--- a/kdbus.h
+++ b/kdbus.h
@@ -681,7 +681,7 @@ struct kdbus_cmd_conn_info {
        __u64 flags;
        __u64 id;
        __u64 offset;
-       char name[0];
+       struct kdbus_item items[0];
 } __attribute__((aligned(8)));
 
 /**
index 9090700d66255fbd7542f033908475b708300991..4c9a59d29d96f412b52eabbec4146e0ffdf968be 100644 (file)
--- a/kdbus.txt
+++ b/kdbus.txt
@@ -537,9 +537,10 @@ struct kdbus_cmd_conn_info {
     When the ioctl returns, this value will yield the offset of the connection
     information inside the caller's pool.
 
-  char name[0];
-    The name of the connection to retrieve information for. Only looked at if
-    the 'id' field is set to 0.
+  struct kdbus_item items[0];
+    The name of the connection to retrieve information for, stored in an item
+    of type KDBUS_ITEM_NAME. Only required at if the 'id' field is set to 0.
+    All other items are currently ignored.
 };
 
 After the ioctl returns, the following struct  will be stored in the caller's
index efb03e92fc7778dfe469d7f5782c354a1d91b642..2d5cfb395cf24f58bdc19cde72f617d71d7d79a0 100644 (file)
@@ -229,16 +229,19 @@ int kdbus_conn_info(struct kdbus_conn *conn, uint64_t id,
        int ret;
 
        if (name)
-               size += strlen(name) + 1;
+               size += KDBUS_ITEM_HEADER_SIZE + strlen(name) + 1;
 
        cmd = alloca(size);
        memset(cmd, 0, size);
        cmd->size = size;
 
-       if (name)
-               strcpy(cmd->name, name);
-       else
+       if (name) {
+               cmd->items[0].size = KDBUS_ITEM_HEADER_SIZE + strlen(name) + 1;
+               cmd->items[0].type = KDBUS_ITEM_NAME;
+               strcpy(cmd->items[0].str, name);
+       } else {
                cmd->id = id;
+       }
 
        ret = ioctl(conn->fd, KDBUS_CMD_CONN_INFO, cmd);
        if (ret < 0)
index cc4e6b7c8a72510af903f3b6313b16e0c9421754..bc397d9b6df3be526b8c165341df8261f578507e 100644 (file)
@@ -207,7 +207,12 @@ int kdbus_test_conn_info(struct kdbus_test_env *env)
        int ret;
        struct {
                struct kdbus_cmd_conn_info cmd_info;
-               char name[64];
+
+               struct {
+                       uint64_t size;
+                       uint64_t type;
+                       char str[64];
+               } name;
        } buf;
 
        buf.cmd_info.size = sizeof(struct kdbus_cmd_conn_info);
@@ -218,9 +223,12 @@ int kdbus_test_conn_info(struct kdbus_test_env *env)
        ASSERT_RETURN(ret == 0);
 
        /* try to pass a name that is longer than the buffer's size */
-       strcpy(buf.cmd_info.name, "foo.bar.bla");
+       buf.name.size = KDBUS_ITEM_HEADER_SIZE + 1;
+       buf.name.type = KDBUS_ITEM_NAME;
+       strcpy(buf.name.str, "foo.bar.bla");
+
        buf.cmd_info.id = 0;
-       buf.cmd_info.size = sizeof(struct kdbus_cmd_conn_info) + 10;
+       buf.cmd_info.size = sizeof(buf.cmd_info) + buf.name.size;
        ret = ioctl(env->conn->fd, KDBUS_CMD_CONN_INFO, &buf);
        ASSERT_RETURN(ret == -1 && errno == EINVAL);