#define KDBUS_SYSNAME_MAX_LEN 63
-static int install_name_add_match(struct kdbus_conn *conn, const char *name)
+static wur int install_name_add_match(struct kdbus_conn *conn, const char *name)
{
struct {
struct kdbus_cmd_match cmd;
return 0;
}
-static int create_endpoint(const char *buspath, uid_t uid, const char *name,
+static wur int create_endpoint(const char *buspath, uid_t uid, const char *name,
uint64_t flags)
{
struct {
return fd;
}
-static int unpriv_test_custom_ep(const char *buspath)
+static wur int unpriv_test_custom_ep(const char *buspath)
{
int ret, ep_fd1, ep_fd2;
char *ep1, *ep2, *tmp1, *tmp2;
- tmp1 = strdup(buspath);
- tmp2 = strdup(buspath);
- ASSERT_RETURN(tmp1 && tmp2);
+ ASSERT_NONZERO(tmp1 = strdup(buspath));
+ ASSERT_NONZERO(tmp2 = strdup(buspath));
ret = asprintf(&ep1, "%s/%u-%s", dirname(tmp1), getuid(), "apps1");
- ASSERT_RETURN(ret >= 0);
+ ASSERT_RETURN(ret,>,0);
ret = asprintf(&ep2, "%s/%u-%s", dirname(tmp2), getuid(), "apps2");
- ASSERT_RETURN(ret >= 0);
+ ASSERT_RETURN(ret,>,0);
free(tmp1);
free(tmp2);
/* endpoint only accessible to current uid */
ep_fd1 = create_endpoint(buspath, getuid(), "apps1", 0);
- ASSERT_RETURN(ep_fd1 >= 0);
+ ASSERT_RETURN(ep_fd1,>=,0);
/* endpoint world accessible */
ep_fd2 = create_endpoint(buspath, getuid(), "apps2",
KDBUS_MAKE_ACCESS_WORLD);
- ASSERT_RETURN(ep_fd2 >= 0);
+ ASSERT_RETURN(ep_fd2,>=,0);
- ret = RUN_UNPRIVILEGED(UNPRIV_UID, UNPRIV_UID, ({
+ RUN_UNPRIVILEGED(UNPRIV_UID, UNPRIV_UID, ({
int ep_fd;
struct kdbus_conn *ep_conn;
*/
ep_fd = create_endpoint(buspath, getuid(),
"unpriv_costum_ep", 0);
- ASSERT_EXIT(ep_fd == -EPERM);
+ ASSERT_EXIT(ep_fd,==,-EPERM);
/*
* Endpoint "apps1" only accessible to same users,
* that own the endpoint. Access denied by VFS
*/
ep_conn = kdbus_hello(ep1, 0, NULL, 0);
- ASSERT_EXIT(!ep_conn && errno == EACCES);
+ ASSERT_EXIT(errno,==,EACCES);
+ ASSERT_EXIT_ZERO(ep_conn);
/* Endpoint "apps2" world accessible */
- ep_conn = kdbus_hello(ep2, 0, NULL, 0);
- ASSERT_EXIT(ep_conn);
+ ASSERT_EXIT_NONZERO(ep_conn = kdbus_hello(ep2, 0, NULL, 0));
kdbus_conn_free(ep_conn);
- _exit(EXIT_SUCCESS);
+ exit(EXIT_SUCCESS);
}),
- ({ 0; }));
- ASSERT_RETURN(ret == 0);
+ ({}));
- close(ep_fd1);
- close(ep_fd2);
+ CLOSE(ep_fd1);
+ CLOSE(ep_fd2);
free(ep1);
free(ep2);
return 0;
}
-static int update_endpoint(int fd, const char *name)
+static wur int update_endpoint(int fd, const char *name)
{
int len = strlen(name) + 1;
struct {
return 0;
}
-int kdbus_test_custom_endpoint(struct kdbus_test_env *env)
+wur int kdbus_test_custom_endpoint(struct kdbus_test_env *env)
{
char *ep, *tmp;
int ret, ep_fd;
memset(fake_ep, 'X', sizeof(fake_ep) - 1);
/* Try to create a custom endpoint with a long name */
- ret = create_endpoint(env->buspath, getuid(), fake_ep, 0);
- ASSERT_RETURN(ret == -ENAMETOOLONG);
+ ASSERT_RETURN(-ENAMETOOLONG,==,create_endpoint(env->buspath, getuid(), fake_ep, 0));
/* Try to create a custom endpoint with a different uid */
- ret = create_endpoint(env->buspath, getuid() + 1, "foobar", 0);
- ASSERT_RETURN(ret == -EINVAL);
+ ASSERT_RETURN(-EINVAL,==,create_endpoint(env->buspath, getuid() + 1, "foobar", 0));
/* create a custom endpoint, and open a connection on it */
- ep_fd = create_endpoint(env->buspath, getuid(), "foo", 0);
- ASSERT_RETURN(ep_fd >= 0);
+ ASSERT_RETURN(0,<=,ep_fd = create_endpoint(env->buspath, getuid(), "foo", 0));
- tmp = strdup(env->buspath);
- ASSERT_RETURN(tmp);
-
- ret = asprintf(&ep, "%s/%u-%s", dirname(tmp), getuid(), epname);
+ ASSERT_NONZERO(tmp = strdup(env->buspath));
+ ASSERT_RETURN(0,<=,asprintf(&ep, "%s/%u-%s", dirname(tmp), getuid(), epname));
free(tmp);
- ASSERT_RETURN(ret >= 0);
/* Register a connection that listen to broadcasts */
- reader = kdbus_hello(ep, 0, NULL, 0);
- ASSERT_RETURN(reader);
+ ASSERT_NONZERO(reader = kdbus_hello(ep, 0, NULL, 0));
/* Register to kernel signals */
- ret = kdbus_add_match_id(reader, 0x1, KDBUS_ITEM_ID_ADD,
- KDBUS_MATCH_ID_ANY);
- ASSERT_RETURN(ret == 0);
-
- ret = kdbus_add_match_id(reader, 0x2, KDBUS_ITEM_ID_REMOVE,
- KDBUS_MATCH_ID_ANY);
- ASSERT_RETURN(ret == 0);
-
- ret = install_name_add_match(reader, name);
- ASSERT_RETURN(ret == 0);
+ ASSERT_ZERO(kdbus_add_match_id(reader, 0x1, KDBUS_ITEM_ID_ADD, KDBUS_MATCH_ID_ANY));
+ ASSERT_ZERO(kdbus_add_match_id(reader, 0x2, KDBUS_ITEM_ID_REMOVE, KDBUS_MATCH_ID_ANY));
+ ASSERT_ZERO(install_name_add_match(reader, name));
/* Monitor connections are not supported on custom endpoints */
ep_conn = kdbus_hello(ep, KDBUS_HELLO_MONITOR, NULL, 0);
- ASSERT_RETURN(!ep_conn && errno == EOPNOTSUPP);
+ ASSERT_RETURN(errno,==,EOPNOTSUPP);
+ ASSERT_ZERO(ep_conn);
- ep_conn = kdbus_hello(ep, 0, NULL, 0);
- ASSERT_RETURN(ep_conn);
+ ASSERT_NONZERO(ep_conn = kdbus_hello(ep, 0, NULL, 0));
+
+ /* Check that the reader got the IdAdd notification */
+ ASSERT_ZERO(kdbus_msg_recv(reader, &msg, NULL));
+ ASSERT_RETURN(msg->items[0].type,==,(typeof(msg->items[0].type))KDBUS_ITEM_ID_ADD);
+ ASSERT_RETURN(msg->items[0].id_change.id,==,ep_conn->id);
+ kdbus_msg_free(msg);
/*
* Add a name add match on the endpoint connection, acquire name from
* endpoint connection may not be able to call conn_info, neither on
* the name nor on the ID.
*/
- ret = install_name_add_match(ep_conn, name);
- ASSERT_RETURN(ret == 0);
-
- ret = kdbus_name_acquire(env->conn, name, NULL);
- ASSERT_RETURN(ret == 0);
+ ASSERT_ZERO(install_name_add_match(ep_conn, name));
- ret = kdbus_msg_recv(ep_conn, NULL, NULL);
- ASSERT_RETURN(ret == -EAGAIN);
+ ASSERT_ZERO(kdbus_name_acquire(env->conn, name, NULL));
- ret = kdbus_conn_info(ep_conn, 0, name, 0, NULL);
- ASSERT_RETURN(ret == -ESRCH);
+ ASSERT_RETURN(ONTIZEN(0,-EAGAIN),==,kdbus_msg_recv(ep_conn, NULL, NULL));
+ ASSERT_RETURN(ONTIZEN(0,-ESRCH),==,kdbus_conn_info(ep_conn, 0, name, 0, NULL));
+ ASSERT_RETURN(-ESRCH,==,kdbus_conn_info(ep_conn, 0, "random.crappy.name", 0, NULL));
+ ASSERT_RETURN(ONTIZEN(0,-ENXIO),==,kdbus_conn_info(ep_conn, env->conn->id, NULL, 0, NULL));
+ ASSERT_RETURN(-ENXIO,==,kdbus_conn_info(ep_conn, 0x0fffffffffffffffULL, NULL, 0, NULL));
- ret = kdbus_conn_info(ep_conn, 0, "random.crappy.name", 0, NULL);
- ASSERT_RETURN(ret == -ESRCH);
-
- ret = kdbus_conn_info(ep_conn, env->conn->id, NULL, 0, NULL);
- ASSERT_RETURN(ret == -ENXIO);
-
- ret = kdbus_conn_info(ep_conn, 0x0fffffffffffffffULL, NULL, 0, NULL);
- ASSERT_RETURN(ret == -ENXIO);
-
- /* Check that the reader did not receive anything */
- ret = kdbus_msg_recv(reader, NULL, NULL);
- ASSERT_RETURN(ret == -EAGAIN);
+ /* Check that the reader did not receive the name notification */
+ ASSERT_RETURN(ONTIZEN(0,-EAGAIN),==,kdbus_msg_recv(reader, NULL, NULL));
/*
* Release the name again, update the custom endpoint policy,
* and try again. This time, the connection on the custom endpoint
* should have gotten it.
*/
- ret = kdbus_name_release(env->conn, name);
- ASSERT_RETURN(ret == 0);
+ ASSERT_ZERO(kdbus_name_release(env->conn, name));
- ret = update_endpoint(ep_fd, name);
- ASSERT_RETURN(ret == 0);
+ /* Check that the reader did not receive the name notification */
+ ASSERT_RETURN(-EAGAIN,==,kdbus_msg_recv(reader, NULL, NULL));
- ret = kdbus_name_acquire(env->conn, name, NULL);
- ASSERT_RETURN(ret == 0);
+ ASSERT_ZERO(update_endpoint(ep_fd, name));
- ret = kdbus_msg_recv(ep_conn, &msg, NULL);
- ASSERT_RETURN(ret == 0);
- ASSERT_RETURN(msg->items[0].type == KDBUS_ITEM_NAME_ADD);
- ASSERT_RETURN(msg->items[0].name_change.old_id.id == 0);
- ASSERT_RETURN(msg->items[0].name_change.new_id.id == env->conn->id);
- ASSERT_RETURN(strcmp(msg->items[0].name_change.name, name) == 0);
+ ASSERT_ZERO(kdbus_name_acquire(env->conn, name, NULL));
+
+ ASSERT_ZERO(kdbus_msg_recv(ep_conn, &msg, NULL));
+ ASSERT_RETURN(msg->items[0].type,==,(typeof(msg->items[0].type))KDBUS_ITEM_NAME_ADD);
+ ASSERT_ZERO(msg->items[0].name_change.old_id.id);
+ ASSERT_RETURN(msg->items[0].name_change.new_id.id,==,env->conn->id);
+ ASSERT_ZERO(strcmp(msg->items[0].name_change.name, name));
kdbus_msg_free(msg);
- ret = kdbus_msg_recv(reader, &msg, NULL);
- ASSERT_RETURN(ret == 0);
- ASSERT_RETURN(strcmp(msg->items[0].name_change.name, name) == 0);
+ ASSERT_ZERO(kdbus_msg_recv(reader, &msg, NULL));
+ ASSERT_ZERO(strcmp(msg->items[0].name_change.name, name));
kdbus_msg_free(msg);
- ret = kdbus_conn_info(ep_conn, 0, name, 0, NULL);
- ASSERT_RETURN(ret == 0);
+ ASSERT_ZERO(kdbus_conn_info(ep_conn, 0, name, 0, NULL));
- ret = kdbus_conn_info(ep_conn, env->conn->id, NULL, 0, NULL);
- ASSERT_RETURN(ret == 0);
+ ASSERT_ZERO(kdbus_conn_info(ep_conn, env->conn->id, NULL, 0, NULL));
/* If we have privileges test custom endpoints */
ret = test_is_capable(CAP_SETUID, CAP_SETGID, -1);
- ASSERT_RETURN(ret >= 0);
+ ASSERT_RETURN(ret,>=,0);
/*
* All uids/gids are mapped and we have the necessary caps
*/
- if (ret && all_uids_gids_are_mapped()) {
- ret = unpriv_test_custom_ep(env->buspath);
- ASSERT_RETURN(ret == 0);
- }
+ if (ret && all_uids_gids_are_mapped())
+ ASSERT_ZERO(unpriv_test_custom_ep(env->buspath));
kdbus_conn_free(reader);
kdbus_conn_free(ep_conn);
- close(ep_fd);
+ CLOSE(ep_fd);
return TEST_OK;
}