From f7d201859a589620a22bf71f98fcf8d9b25263d2 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Wed, 16 Aug 2023 22:43:08 +0000 Subject: [PATCH] Use the sqlite authorizer for async requests, too. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4401 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- src/ssb.db.c | 4 ++-- src/ssb.db.h | 2 ++ src/ssb.js.c | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/ssb.db.c b/src/ssb.db.c index 41f9c011c..9c06566a3 100644 --- a/src/ssb.db.c +++ b/src/ssb.db.c @@ -927,7 +927,7 @@ static JSValue _tf_ssb_sqlite_row_to_json(JSContext* context, sqlite3_stmt* row) return result; } -static int _tf_ssb_sqlite_authorizer(void* user_data, int action_code, const char* arg0, const char* arg1, const char* arg2, const char* arg3) +int tf_ssb_sqlite_authorizer(void* user_data, int action_code, const char* arg0, const char* arg1, const char* arg2, const char* arg3) { int result = SQLITE_DENY; switch (action_code) @@ -973,7 +973,7 @@ JSValue tf_ssb_db_visit_query(tf_ssb_t* ssb, const char* query, const JSValue bi sqlite3* db = tf_ssb_acquire_db_reader(ssb); JSContext* context = tf_ssb_get_context(ssb); sqlite3_stmt* statement; - sqlite3_set_authorizer(db, _tf_ssb_sqlite_authorizer, ssb); + sqlite3_set_authorizer(db, tf_ssb_sqlite_authorizer, ssb); if (sqlite3_prepare(db, query, -1, &statement, NULL) == SQLITE_OK) { JSValue bind_result = _tf_ssb_sqlite_bind_json(context, db, statement, binds); diff --git a/src/ssb.db.h b/src/ssb.db.h index e7b26c723..c58f819ea 100644 --- a/src/ssb.db.h +++ b/src/ssb.db.h @@ -58,3 +58,5 @@ typedef struct _tf_ssb_db_stored_connection_t tf_ssb_db_stored_connection_t* tf_ssb_db_get_stored_connections(tf_ssb_t* ssb, int* out_count); void tf_ssb_db_forget_stored_connection(tf_ssb_t* ssb, const char* address, int port, const char* pubkey); + +int tf_ssb_sqlite_authorizer(void* user_data, int action_code, const char* arg0, const char* arg1, const char* arg2, const char* arg3); diff --git a/src/ssb.js.c b/src/ssb.js.c index 9aaf57753..e2efd90e2 100644 --- a/src/ssb.js.c +++ b/src/ssb.js.c @@ -411,6 +411,7 @@ static void _tf_ssb_sqlAsync_work(uv_work_t* work) sql_work->start_time = uv_hrtime(); sql_work->thread_id = uv_thread_self(); sqlite3* db = tf_ssb_acquire_db_reader(sql_work->ssb); + sqlite3_set_authorizer(db, tf_ssb_sqlite_authorizer, sql_work->ssb); sqlite3_stmt* statement = NULL; sql_work->result = sqlite3_prepare(db, sql_work->query, -1, &statement, NULL); if (sql_work->result == SQLITE_OK) @@ -504,6 +505,7 @@ static void _tf_ssb_sqlAsync_work(uv_work_t* work) { sql_work->error = tf_strdup(sqlite3_errmsg(db)); } + sqlite3_set_authorizer(db, NULL, NULL); tf_ssb_release_db_reader(sql_work->ssb, db); sql_work->end_time = uv_hrtime(); tf_trace_end(trace);