kdbus.h: add KDBUS_HELLO_ACCEPT_MEMFD (ABI break)
authorDaniel Mack <daniel@zonque.org>
Tue, 14 Oct 2014 17:53:23 +0000 (19:53 +0200)
committerDaniel Mack <daniel@zonque.org>
Tue, 14 Oct 2014 18:03:45 +0000 (20:03 +0200)
Add another flags to the connection's flags to denote whether it
want to receive memfds. Reject messages with -ECOMM if it contains
a memfd if the receiver can't cope with it.

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

index ac26a03cb84c8b0390ffeb8b393475cb926ad801..daa3340352c7659006eb0d927a087ac17fdb1077 100644 (file)
@@ -506,7 +506,8 @@ static int kdbus_conn_entry_insert(struct kdbus_conn *conn,
                goto exit_unlock;
        }
 
-       if (kmsg->fds && !(conn->flags & KDBUS_HELLO_ACCEPT_FD)) {
+       if ((kmsg->fds && !(conn->flags & KDBUS_HELLO_ACCEPT_FD)) ||
+           (kmsg->memfds_count && !(conn->flags & KDBUS_HELLO_ACCEPT_FD))) {
                ret = -ECOMM;
                goto exit_unlock;
        }
@@ -1414,9 +1415,10 @@ int kdbus_conn_new(struct kdbus_ep *ep,
        BUG_ON(*c);
 
        /* Reject unknown flags */
-       if (hello->conn_flags & ~(KDBUS_HELLO_ACCEPT_FD |
-                                 KDBUS_HELLO_ACTIVATOR |
-                                 KDBUS_HELLO_POLICY_HOLDER |
+       if (hello->conn_flags & ~(KDBUS_HELLO_ACCEPT_FD         |
+                                 KDBUS_HELLO_ACCEPT_MEMFD      |
+                                 KDBUS_HELLO_ACTIVATOR         |
+                                 KDBUS_HELLO_POLICY_HOLDER     |
                                  KDBUS_HELLO_MONITOR))
                return -EOPNOTSUPP;
 
diff --git a/kdbus.h b/kdbus.h
index 79a17f3449a55cd9ce36019f1a90e0e99c85a4eb..1ea4329ea2642bbd572c5937624f389028ed169b 100644 (file)
--- a/kdbus.h
+++ b/kdbus.h
@@ -500,6 +500,8 @@ enum kdbus_policy_type {
  * enum kdbus_hello_flags - flags for struct kdbus_cmd_hello
  * @KDBUS_HELLO_ACCEPT_FD:     The connection allows the reception of
  *                             any passed file descriptors
+ * @KDBUS_HELLO_ACCEPT_MEMFD:  The connection allows the reception of
+ *                             any passed memfd file descriptors
  * @KDBUS_HELLO_ACTIVATOR:     Special-purpose connection which registers
  *                             a well-know name for a process to be started
  *                             when traffic arrives
@@ -514,9 +516,10 @@ enum kdbus_policy_type {
  */
 enum kdbus_hello_flags {
        KDBUS_HELLO_ACCEPT_FD           =  1ULL <<  0,
-       KDBUS_HELLO_ACTIVATOR           =  1ULL <<  1,
-       KDBUS_HELLO_POLICY_HOLDER       =  1ULL <<  2,
-       KDBUS_HELLO_MONITOR             =  1ULL <<  3,
+       KDBUS_HELLO_ACCEPT_MEMFD        =  1ULL <<  1,
+       KDBUS_HELLO_ACTIVATOR           =  1ULL <<  2,
+       KDBUS_HELLO_POLICY_HOLDER       =  1ULL <<  3,
+       KDBUS_HELLO_MONITOR             =  1ULL <<  4,
 };
 
 /**
index a34fc98b38979ff7ea6d11d029e9bcb2bee798df..2993b56cc434d590eb602a45f93d5f1cd39c2b05 100644 (file)
@@ -137,7 +137,8 @@ kdbus_hello(const char *path, uint64_t flags,
                return NULL;
        }
 
-       h.hello.conn_flags = flags | KDBUS_HELLO_ACCEPT_FD;
+       h.hello.conn_flags = flags | KDBUS_HELLO_ACCEPT_FD |
+                            KDBUS_HELLO_ACCEPT_MEMFD;
        h.hello.attach_flags = _KDBUS_ATTACH_ALL;
        h.conn_name.type = KDBUS_ITEM_CONN_NAME;
        strcpy(h.conn_name.str, "this-is-my-name");
index bc397d9b6df3be526b8c165341df8261f578507e..7d51b4d025f56d975145de40878665c9785080b7 100644 (file)
@@ -104,7 +104,7 @@ int kdbus_test_hello(struct kdbus_test_env *env)
        if (fd < 0)
                return TEST_ERR;
 
-       hello.conn_flags = KDBUS_HELLO_ACCEPT_FD;
+       hello.conn_flags = KDBUS_HELLO_ACCEPT_FD | KDBUS_HELLO_ACCEPT_MEMFD;
        hello.attach_flags = _KDBUS_ATTACH_ALL;
        hello.size = sizeof(struct kdbus_cmd_hello);
        hello.pool_size = POOL_SIZE;
@@ -125,8 +125,6 @@ int kdbus_test_hello(struct kdbus_test_env *env)
        ret = ioctl(fd, KDBUS_CMD_HELLO, &hello);
        ASSERT_RETURN(ret == -1 && errno == EOPNOTSUPP);
 
-       hello.conn_flags = KDBUS_HELLO_ACCEPT_FD;
-
        /* check for faulty pool sizes */
        hello.pool_size = 0;
        ret = ioctl(fd, KDBUS_CMD_HELLO, &hello);
@@ -136,9 +134,9 @@ int kdbus_test_hello(struct kdbus_test_env *env)
        ret = ioctl(fd, KDBUS_CMD_HELLO, &hello);
        ASSERT_RETURN(ret == -1 && errno == EFAULT);
 
-       hello.pool_size = POOL_SIZE;
-
        /* success test */
+       hello.pool_size = POOL_SIZE;
+       hello.conn_flags = KDBUS_HELLO_ACCEPT_FD | KDBUS_HELLO_ACCEPT_MEMFD;
        ret = ioctl(fd, KDBUS_CMD_HELLO, &hello);
        ASSERT_RETURN(ret == 0);
 
@@ -304,7 +302,7 @@ int kdbus_test_writable_pool(struct kdbus_test_env *env)
        ASSERT_RETURN(fd >= 0);
 
        memset(&hello, 0, sizeof(hello));
-       hello.conn_flags = KDBUS_HELLO_ACCEPT_FD;
+       hello.conn_flags = KDBUS_HELLO_ACCEPT_FD | KDBUS_HELLO_ACCEPT_MEMFD;
        hello.attach_flags = _KDBUS_ATTACH_ALL;
        hello.size = sizeof(struct kdbus_cmd_hello);
        hello.pool_size = POOL_SIZE;
index 4bb61b70f869c99bf67c367eb9a4a037c0e02482..ef7381e76ab3de82803fd9421f861b1a91e9531b 100644 (file)
@@ -81,7 +81,8 @@ static struct conn *kdbus_hello(const char *path, uint64_t flags)
                return NULL;
        }
 
-       h.hello.conn_flags = flags | KDBUS_HELLO_ACCEPT_FD;
+       h.hello.conn_flags = flags | KDBUS_HELLO_ACCEPT_FD |
+                            KDBUS_HELLO_ACCEPT_MEMFD;
        h.hello.attach_flags = _KDBUS_ATTACH_ALL;
        h.type = KDBUS_ITEM_CONN_NAME;
        strncpy(h.comm, "monitor", sizeof(h.comm) - 1);