const gid_t group,
const char* const label,
const char** const destination,
+ uint16_t destination_size,
const char* const path,
const char* const interface,
const char* const member,
int type)
{
- int i = 0;
MatchItemSend matcher(interface, member, path, static_cast<MessageType>(type));
if (destination)
- while (destination[i]) {
- matcher.addName(destination[i++]);
+ for (size_t i = 0; i < destination_size; i++) {
+ matcher.addName(destination[i]);
}
return static_cast<int>(policy_checker(bus_type).check(user, group, label, matcher));
}
const gid_t group,
const char* const label,
const char** const sender,
+ uint16_t sender_size,
const char* const path,
const char* const interface,
const char* const member,
int type)
{
- int i = 0;
MatchItemReceive matcher(interface, member, path, static_cast<MessageType>(type));
if (sender)
- while (sender[i]) {
- matcher.addName(sender[i++]);
+ for (size_t i = 0; i < sender_size; i++) {
+ matcher.addName(sender[i]);
}
return static_cast<int>(policy_checker(bus_type).check(user, group, label, matcher));
}
struct kdbus_cmd_param {
char const *label;
- const char* k_names[KDBUS_CONN_MAX_NAMES+1];
+ const char* k_names[KDBUS_CONN_MAX_NAMES];
__u64 free_offset;
uid_t uid_n;
gid_t gid_n;
- bool empty_names;
+ uint16_t names_num;
};
int kdbus_get_conn_info(struct kconn *kconn, const char *destination, struct kdbus_cmd_param *info, __u64 flags)
{
char const *label = NULL;
- const char** k_names = info->k_names;
- int k_i = 0;
int r;
uid_t uid_n = UID_INVALID;
gid_t gid_n = GID_INVALID;
- bool empty_names = true;
union kdbus_cmd_union cmd;
struct kdbus_info *conn_info;
_Static_assert((unsigned)KDBUS_ITEM_SECLABEL == KDBUS_ITEM_SECLABEL, "KDBUS_ITEM_SECLABEL not preserved when cast to unsigned");
_Static_assert((unsigned)KDBUS_ITEM_OWNED_NAME == KDBUS_ITEM_OWNED_NAME, "KDBUS_ITEM_OWNED_NAME not preserved when cast to unsigned");
+ info->names_num = 0;
for (item = conn_info->items; (uintptr_t)item < items_end; item = (typeof(item))ALIGN8((uintptr_t)item + (unsigned)item->size)) {
switch ((unsigned)item->type) {
case KDBUS_ITEM_CREDS:
label = item->str;
break;
case KDBUS_ITEM_OWNED_NAME:
- empty_names = false;
- k_names[k_i++] = item->name.name;
+ info->k_names[info->names_num++] = item->name.name;
break;
}
}
- if (!empty_names)
- k_names[k_i++] = NULL;
end:
info->label = label;
info->uid_n = uid_n;
info->gid_n = gid_n;
- info->empty_names = empty_names;
return r;
}
struct kconn *kconn = configuration;
int r;
- struct kdbus_cmd_param info = {
- .empty_names = true
- };
+ struct kdbus_cmd_param info;
char *dest_label = NULL;
bool free_conn_info = false;
free_conn_info = true;
}
- if (info.empty_names)
+ if (0 == info.names_num)
r = __internal_can_send(kconn->bus_type, g_udesc.uid, g_udesc.gid, g_udesc.label, destination, path, interface, member, message_type);
else
- r = __internal_can_send_multi_dest(kconn->bus_type, g_udesc.uid, g_udesc.gid, g_udesc.label, info.k_names, path, interface, member, message_type);
+ r = __internal_can_send_multi_dest(kconn->bus_type, g_udesc.uid, g_udesc.gid, g_udesc.label, info.k_names, info.names_num, path, interface, member, message_type);
if (r <= 0)
goto end;
kdbus_free_by_offset(kconn->fd, info.free_offset);
free_conn_info = false;
}
-
- info.empty_names = true;
}
/* check can recv */
}
free_conn_info = true;
- if (info.empty_names)
+ if (0 == info.names_num)
r = __internal_can_recv(kconn->bus_type, dest_uid_n, dest_gid_n, dest_label, sender, path, interface, member, message_type);
else
- r = __internal_can_recv_multi(kconn->bus_type, dest_uid_n, dest_gid_n, dest_label, info.k_names, path, interface, member, message_type);
+ r = __internal_can_recv_multi(kconn->bus_type, dest_uid_n, dest_gid_n, dest_label, info.k_names, info.names_num, path, interface, member, message_type);
end:
if (free_conn_info)
struct kconn *kconn = configuration;
int r;
- struct kdbus_cmd_param info = {
- .empty_names = true
- };
+ struct kdbus_cmd_param info;
__internal_enter();
goto end;
}
- if (info.empty_names)
+ if (0 == info.names_num)
r = __internal_can_send(kconn->bus_type, sender_uid, sender_gid, sender_label, destination, path, interface, member, message_type);
else
- r = __internal_can_send_multi_dest(kconn->bus_type, sender_uid, sender_gid, sender_label, info.k_names, path, interface, member, message_type);
+ r = __internal_can_send_multi_dest(kconn->bus_type, sender_uid, sender_gid, sender_label, info.k_names, info.names_num, path, interface, member, message_type);
if (r <= 0)
goto end;