Publish co-owner invite role and validate policy command arguments

This commit is contained in:
evgeny committed 2026-11-03 16:25:30 +01:00
1 parent e40e9f6eb1
commit 48761ff473
2 files changed
+16 -2

No files matched your search

+6
View File
@@ -106,6 +106,12 @@ static void admin_key_recv_cb(struct ETCP_CONN* conn, struct ll_entry* entry) {
DEBUG_INFO(DEBUG_CATEGORY_CHAT_SYNC, "%s: received admin key ch=%s from 0x%016llx — imported, now co-owner",
CA_ID, ch_id, (unsigned long long)from_node);
/* Другие узлы проверяют право приглашать по подписанной роли, а не по наличию нашего приватного ключа. */
struct chat_member_tags* tags = chat_member_tags_load(inst, ch_id, inst->node_id);
if (!tags || chat_member_tags_set(tags, "admin", "yes") || chat_member_tags_commit(inst, tags))
DEBUG_ERROR(DEBUG_CATEGORY_CHAT_SYNC, "%s: co-owner key imported, publishing admin role failed ch=%s", CA_ID, ch_id);
chat_member_tags_free(tags);
uint8_t evt[72];
uint8_t cl = (uint8_t)strlen(ch_id);
evt[0] = cl; memcpy(evt + 1, ch_id, cl);
+10 -2
View File
@@ -1098,8 +1098,16 @@ static void hc_handle_command(struct headless_client* cli, const char* json) {
if (!strcmp(cmd, "group_policy")) {
char channel[21], token[65], keep[RECV_BUF_SIZE]; char* result = NULL;
if (json_get_str(cli, "ch", channel, sizeof(channel))) { send_response(cli, id, NULL, "missing channel"); goto done; }
json_get_str(cli, "token", token, sizeof(token));
if (json_get_str(cli, "keep", keep, sizeof(keep))) strcpy(keep, "[]");
token[0] = 0; strcpy(keep, "[]");
for (unsigned i = 0; i < request.count; i++) {
const char* key = request.fields[i].key;
if ((!strcmp(key, "token") && (json_get_str(cli, key, token, sizeof(token)) || strlen(token) != 64)) ||
(!strcmp(key, "keep") && json_get_str(cli, key, keep, sizeof(keep))) ||
(!strcmp(key, "all_members") && request.fields[i].kind != 2)) {
DEBUG_WARN(DEBUG_CATEGORY_HEADLESS, "headless: invalid group policy parameter key=%s", key);
send_response(cli, id, NULL, "invalid group policy parameter"); goto done;
}
}
group_policy_command(cli->hc->inst, channel, json_get_int(cli, "all_members", 0), token[0] ? token : NULL, keep, &result);
send_response(cli, id, result, result ? NULL : "group policy unavailable"); u_free(result); goto done;
}