From 017db6bb2dfa84f44c7b465de5486e4ba18c6bff Mon Sep 17 00:00:00 2001 From: evgeny Date: Wed, 4 Nov 2026 00:32:08 +0100 Subject: [PATCH] Read only published membership for attachment roles and invitations --- src/chat/chat_attachment.c | 3 ++- src/chat/chat_msg.c | 3 ++- src/chat/invite_build.c | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/chat/chat_attachment.c b/src/chat/chat_attachment.c index 48c92692d..83d778ef3 100644 --- a/src/chat/chat_attachment.c +++ b/src/chat/chat_attachment.c @@ -1110,7 +1110,8 @@ int chat_attachment_downloaded(struct UTUN_INSTANCE* inst, const char* channel, int rc = sqlite3_exec(db, "BEGIN IMMEDIATE /* attachment downloaded */", NULL, NULL, NULL); if (rc != SQLITE_OK) goto fail; char sql[768]; snprintf(sql, sizeof(sql), "SELECT downloaded,wanted,error,NOT EXISTS(SELECT 1 FROM peers_%s" - " WHERE node_id=? AND source=0 AND deleted=0 AND admitted=1 AND length(adm_tags_sig)=64 AND json_extract(adm_tags,'$.storage')='yes')" + " WHERE node_id=? AND record_state=0 AND source=0 AND deleted=0 AND admitted=1" + " AND length(adm_tags_sig)=64 AND json_extract(adm_tags,'$.storage')='yes')" " AND NOT EXISTS(SELECT 1 FROM attachment_key_requests r WHERE r.channel=a.channel AND r.message_id=a.message_id" " AND r.incoming=0 AND r.state=5) FROM attachment_keys a WHERE channel=? AND message_id=?", channel); stage = "prepare download state"; rc = sqlite3_prepare_v2(db, sql, -1, &st, NULL); diff --git a/src/chat/chat_msg.c b/src/chat/chat_msg.c index 64bb28382..5854c4f58 100644 --- a/src/chat/chat_msg.c +++ b/src/chat/chat_msg.c @@ -665,7 +665,8 @@ static int msg_list_ids(struct UTUN_INSTANCE* inst, const char* channel, uint8_t uint8_t* temporary = u_malloc(capacity); if (!temporary) { DEBUG_ERROR(DEBUG_CATEGORY_CHAT, "ID list: allocation bytes=%zu failed", capacity); return -1; } char sql[160]; - if (channel) snprintf(sql, sizeof(sql), "SELECT node_id FROM peers_%s WHERE deleted=0 AND admitted=1 ORDER BY node_id<0,node_id", channel); + if (channel) snprintf(sql, sizeof(sql), "SELECT node_id FROM peers_%s" + " WHERE record_state=0 AND deleted=0 AND admitted=1 ORDER BY node_id<0,node_id", channel); else strcpy(sql, "SELECT channel_id FROM channels ORDER BY created_at,channel_id"); sqlite3_stmt* st = NULL; size_t used = 2; uint16_t count = 0; int full = 0; int rc = sqlite3_prepare_v2(cc->db, sql, -1, &st, NULL); diff --git a/src/chat/invite_build.c b/src/chat/invite_build.c index 473aa2621..53e354252 100644 --- a/src/chat/invite_build.c +++ b/src/chat/invite_build.c @@ -81,7 +81,8 @@ static int select_nodes(struct UTUN_INSTANCE* inst, uint64_t channel, struct inv DEBUG_ERROR(DEBUG_CATEGORY_CHAT_SYNC, "invite_build: inactive context/invalid channel=%llu", (unsigned long long)channel); return -1; } char sql[256]; - snprintf(sql, sizeof(sql), "SELECT node_id,node_type FROM peers_%llu WHERE source=0 AND deleted=0 AND admitted=1 ORDER BY node_id<0,node_id", + snprintf(sql, sizeof(sql), "SELECT node_id,node_type FROM peers_%llu" + " WHERE record_state=0 AND source=0 AND deleted=0 AND admitted=1 ORDER BY node_id<0,node_id", (unsigned long long)channel); sqlite3_stmt* st = NULL; result->priority = 4; int rc = sqlite3_prepare_v2(cc->db, sql, -1, &st, NULL);