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:
@@ -3,6 +3,7 @@
|
||||
|
||||
use crate::{Error, QueryRunner, Reader, Result, SCHEMA_VERSION, Writer};
|
||||
use bakashrot_config::Synchronous;
|
||||
use rusqlite::hooks::{AuthAction, AuthContext, Authorization};
|
||||
use rusqlite::{Connection, OptionalExtension, TransactionBehavior};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::time::Duration;
|
||||
@@ -126,10 +127,18 @@ impl Database {
|
||||
Ok(Reader::new(self.connect()?))
|
||||
}
|
||||
|
||||
/// A connection for clients' queries: read-only (`query_only`).
|
||||
/// A connection for clients' queries: read-only (`query_only`), and
|
||||
/// every PRAGMA refused from then on (SQLite's authorizer). Some take
|
||||
/// effect when they're prepared, before a statement can be refused
|
||||
/// for what it is: `PRAGMA query_only = 0` turned `query_only` off
|
||||
/// for the connection's next queries.
|
||||
pub fn query_runner(&self) -> Result<QueryRunner> {
|
||||
let connection = self.connect()?;
|
||||
let mut connection = self.connect()?;
|
||||
connection.pragma_update(None, "query_only", true)?;
|
||||
connection.authorizer(Some(|context: AuthContext<'_>| match context.action {
|
||||
AuthAction::Pragma { .. } => Authorization::Deny,
|
||||
_ => Authorization::Allow,
|
||||
}))?;
|
||||
Ok(QueryRunner::new(connection))
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,10 @@
|
||||
//! Read-only three ways: the connection has `query_only` on (SQLite
|
||||
//! refuses any write), the statement must be one SQLite says only reads
|
||||
//! (`sqlite3_stmt_readonly`), and only one statement runs (more is an
|
||||
//! error, not ignored). The result is JSON, every value a string or null
|
||||
//! error, not ignored). PRAGMAs are refused as they're prepared
|
||||
//! (`Database::query_runner`'s authorizer): some would change the
|
||||
//! connection, `query_only` included, before the statement is looked
|
||||
//! at. The result is JSON, every value a string or null
|
||||
//! (as in protocol 6): `{"columns":[...],"rows":[[...],...]}`.
|
||||
|
||||
use crate::{Error, Result};
|
||||
|
||||
Reference in New Issue
Block a user