mirror of
https://github.com/aziascreations/BakaShrot.git
synced 2026-11-23 20:58:46 +01:00
Made the roles the only lists of topics, Refused PRAGMAs in queries
- Removed `[server] topics` and `[replication] replicated_topics`: a push is taken by its roles' `push_topics`, a replicated message by the peer's `accept_topics`; a topic exists from its first message. - Topics that only came from a peer are read and listed like any other; `ListNames` lists the topics with messages, filtered by the roles. - A push to a topic no role names is `NotAllowed`; `UnknownName` is only for nodes. - Clients' queries: every PRAGMA refused as it's prepared (SQLite's authorizer), `PRAGMA query_only = 0` used to take effect. - Noted the leads found by reading the code in `docs/known-issues.md`. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
@@ -219,12 +219,6 @@ async fn push(
|
||||
frames: &mut Frames,
|
||||
push: PushMessage,
|
||||
) -> Result<Packet, String> {
|
||||
if !shared.config.server.has_topic(&push.topic) {
|
||||
return Ok(refused(
|
||||
ErrorCode::UnknownName,
|
||||
format!("unknown topic '{}'", push.topic),
|
||||
));
|
||||
}
|
||||
if !peer.permissions.can_push(&push.topic) {
|
||||
return Ok(refused(
|
||||
ErrorCode::NotAllowed,
|
||||
@@ -378,12 +372,6 @@ async fn get_attachment(
|
||||
format!("{} may not read '{}'", peer.node, get.topic),
|
||||
)));
|
||||
}
|
||||
if !shared.config.server.has_topic(&get.topic) {
|
||||
return Ok(Some(refused(
|
||||
ErrorCode::UnknownName,
|
||||
format!("unknown topic '{}'", get.topic),
|
||||
)));
|
||||
}
|
||||
let message = format!("{}:{}#{}", get.topic, get.node, get.message_id);
|
||||
let GetAttachment {
|
||||
topic,
|
||||
@@ -462,12 +450,6 @@ async fn get_messages(shared: &Arc<Shared>, peer: &Peer, get: GetMessages) -> Pa
|
||||
format!("{} may not read '{}'", peer.node, get.topic),
|
||||
);
|
||||
}
|
||||
if !shared.config.server.has_topic(&get.topic) {
|
||||
return refused(
|
||||
ErrorCode::UnknownName,
|
||||
format!("unknown topic '{}'", get.topic),
|
||||
);
|
||||
}
|
||||
let GetMessages {
|
||||
topic,
|
||||
node,
|
||||
@@ -490,27 +472,21 @@ async fn get_messages(shared: &Arc<Shared>, peer: &Peer, get: GetMessages) -> Pa
|
||||
}
|
||||
}
|
||||
|
||||
/// Topics: the server's, those it may push to or read unless it may query
|
||||
/// (queries read everything). Nodes: every one with messages.
|
||||
/// Topics: those with messages (pushed here or replicated) that it may
|
||||
/// push to or read, every one if it may query (queries read everything).
|
||||
/// Nodes: every one with messages.
|
||||
async fn list_names(shared: &Arc<Shared>, peer: &Peer, list: ListNames) -> Packet {
|
||||
let mut names = match list.kind {
|
||||
NameKind::Topic => shared
|
||||
.config
|
||||
.server
|
||||
.topics
|
||||
.iter()
|
||||
.filter(|topic| {
|
||||
peer.permissions.can_query()
|
||||
|| peer.permissions.can_push(topic)
|
||||
|| peer.permissions.can_read(topic)
|
||||
})
|
||||
.cloned()
|
||||
.collect(),
|
||||
NameKind::Node => match shared.read(|reader| reader.nodes()).await {
|
||||
Ok(nodes) => nodes,
|
||||
Err(refused) => return refused.into(),
|
||||
},
|
||||
let found = match list.kind {
|
||||
NameKind::Topic => shared.read(|reader| reader.topics()).await,
|
||||
NameKind::Node => shared.read(|reader| reader.nodes()).await,
|
||||
};
|
||||
let mut names = match found {
|
||||
Ok(names) => names,
|
||||
Err(refused) => return refused.into(),
|
||||
};
|
||||
if list.kind == NameKind::Topic && !peer.permissions.can_query() {
|
||||
names.retain(|topic| peer.permissions.can_push(topic) || peer.permissions.can_read(topic));
|
||||
}
|
||||
let truncated = names.len() > MAX_NAMES_LIST_ENTRIES;
|
||||
names.truncate(MAX_NAMES_LIST_ENTRIES);
|
||||
NamesList {
|
||||
|
||||
Reference in New Issue
Block a user