.flags = TEST_CREATE_BUS | TEST_CREATE_CONN,
.timeout = 10,
},
+ {
+ .name = "seclabel",
+ .desc = "dynamic seclabel change for messages and CONN_INFO",
+ .func = kdbus_test_dynamic_seclabel,
+ .flags = TEST_CREATE_BUS | TEST_CREATE_CONN,
+ .timeout = 10,
+ },
{
.name = "message-free",
.desc = "freeing of memory",
wur int kdbus_test_sync_byebye(struct kdbus_test_env *env);
wur int kdbus_test_sync_reply(struct kdbus_test_env *env);
wur int kdbus_test_big_metadata(struct kdbus_test_env *env);
+wur int kdbus_test_dynamic_seclabel(struct kdbus_test_env *env);
wur int kdbus_test_timeout(struct kdbus_test_env *env);
wur int kdbus_test_writable_pool(struct kdbus_test_env *env);
return TEST_OK;
}
+
+static wur int assert_label(char const *label, struct kdbus_item const *item)
+{
+ while (KDBUS_ITEM_SECLABEL != item->type)
+ item = KDBUS_ITEM_NEXT(item);
+ ASSERT_ZERO(strcmp(item->str, label));
+ return TEST_OK;
+}
+
+wur int kdbus_test_dynamic_seclabel(struct kdbus_test_env *env)
+{
+ char const *labels[] = {"System::Privileged", "UserTest"};
+ unsigned i;
+ for (i=TABSIZE(labels); --i;) {
+ char const *label = labels[i];
+ int fd = open("/proc/self/attr/current", O_RDWR);
+ ASSERT_RETURN(fd,>=,0);
+ int l = strlen(label);
+ ASSERT_NONZERO(l);
+ ASSERT_RETURN(l,==,write(fd, label, l));
+ ASSERT_ZERO(close(fd));
+
+ {
+ struct kdbus_msg *msg;
+ ASSERT_ZERO(kdbus_msg_send(env->conn, NULL, 1, 0, 0, 0, env->conn->id));
+ ASSERT_ZERO(kdbus_msg_recv(env->conn, &msg, NULL));
+ ASSERT_ZERO(assert_label(label, msg->items));
+ kdbus_msg_free(msg);
+ }
+
+ {
+ uint64_t offset = 0;
+ ASSERT_ZERO(kdbus_conn_info(env->conn, env->conn->id, NULL, KDBUS_ATTACH_SECLABEL, &offset));
+ struct kdbus_info *info = (struct kdbus_info *)(env->conn->buf + offset);
+ ASSERT_RETURN(info->id,==,env->conn->id);
+ ASSERT_ZERO(assert_label(label, info->items));
+ ASSERT_ZERO(kdbus_free(env->conn, offset));
+ }
+ }
+
+ return TEST_OK;
+}