From 5be1e5230de1938bdfba5c595a9ec9861f34893f Mon Sep 17 00:00:00 2001 From: Rust Wizard Date: Tue, 24 Mar 2026 08:54:30 +0300 Subject: [PATCH 1/5] add buildkit config --- buildkit.yaml | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 buildkit.yaml diff --git a/buildkit.yaml b/buildkit.yaml new file mode 100644 index 0000000..572c8c1 --- /dev/null +++ b/buildkit.yaml @@ -0,0 +1,42 @@ +apiVersion: v1 +name: block_copy_command +version: "0.1.0" +homepage: https://github.com/rustwizard/block_copy_command +repository: https://github.com/rustwizard/block_copy_command +source: https://github.com/rustwizard/block_copy_command/archive/refs/tags/v0.1.0.tar.gz +description: PostgreSQL extension that blocks COPY commands via a configurable ProcessUtility hook +license: BSD-3-Clause +keywords: + - security + - copy + - hook +arch: + - amd64 + - arm64 +maintainers: + - name: RustWizard + email: rustwizard.0@gmail.com +pgVersions: + - "13" + - "14" + - "15" + - "16" + - "17" +buildDependencies: + - curl + - build-essential + - clang + - libclang-dev +build: + pre: + - name: Install Rust toolchain + run: | + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path + export PATH="$HOME/.cargo/bin:$PATH" + cargo install --locked cargo-pgrx --version 0.17.0 + cargo pgrx init --pg${PG_VERSION} ${PG_CONFIG} + main: + - name: Build and package extension + run: | + export PATH="$HOME/.cargo/bin:$PATH" + cargo pgrx package --pg-config ${PG_CONFIG} --out-dir ${DESTDIR} From b1b6d35de09a9edfcbf950353a1be94d00f95f8f Mon Sep 17 00:00:00 2001 From: Rust Wizard Date: Tue, 24 Mar 2026 09:07:12 +0300 Subject: [PATCH 2/5] fix --- buildkit.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/buildkit.yaml b/buildkit.yaml index 572c8c1..c151111 100644 --- a/buildkit.yaml +++ b/buildkit.yaml @@ -21,7 +21,6 @@ pgVersions: - "14" - "15" - "16" - - "17" buildDependencies: - curl - build-essential From 8751c8ff00d184230ab5655800eb951f5ec4b244 Mon Sep 17 00:00:00 2001 From: Rust Wizard Date: Tue, 24 Mar 2026 10:16:07 +0300 Subject: [PATCH 3/5] rename pgxman config --- buildkit.yaml => buildkit/pg_block_copy.yaml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename buildkit.yaml => buildkit/pg_block_copy.yaml (100%) diff --git a/buildkit.yaml b/buildkit/pg_block_copy.yaml similarity index 100% rename from buildkit.yaml rename to buildkit/pg_block_copy.yaml From 62a2535dfd297fae8281d4a8929a689d9285f5fb Mon Sep 17 00:00:00 2001 From: Rust Wizard Date: Tue, 24 Mar 2026 15:07:14 +0300 Subject: [PATCH 4/5] fix pg13 ProcessUtility hook signature and update Rust toolchain for pgxman build --- Cargo.toml | 2 +- buildkit/pg_block_copy.yaml | 20 +++++++++------ src/lib.rs | 49 +++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7989006..50e88ee 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "block_copy_command" -version = "0.1.0" +version = "0.1.1" edition = "2021" description = "PostgreSQL extension that blocks COPY commands via a configurable ProcessUtility hook" authors = ["RustWizard"] diff --git a/buildkit/pg_block_copy.yaml b/buildkit/pg_block_copy.yaml index c151111..91859ea 100644 --- a/buildkit/pg_block_copy.yaml +++ b/buildkit/pg_block_copy.yaml @@ -1,9 +1,9 @@ apiVersion: v1 name: block_copy_command -version: "0.1.0" +version: "0.1.1" homepage: https://github.com/rustwizard/block_copy_command repository: https://github.com/rustwizard/block_copy_command -source: https://github.com/rustwizard/block_copy_command/archive/refs/tags/v0.1.0.tar.gz +source: https://github.com/rustwizard/block_copy_command/archive/refs/tags/v0.1.1.tar.gz description: PostgreSQL extension that blocks COPY commands via a configurable ProcessUtility hook license: BSD-3-Clause keywords: @@ -11,7 +11,7 @@ keywords: - copy - hook arch: - - amd64 + #- amd64 - arm64 maintainers: - name: RustWizard @@ -26,16 +26,22 @@ buildDependencies: - build-essential - clang - libclang-dev + - pkg-config + - libssl-dev build: pre: - name: Install Rust toolchain run: | - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path - export PATH="$HOME/.cargo/bin:$PATH" + export RUSTUP_HOME=/opt/rustup + export CARGO_HOME=/opt/cargo + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path --default-toolchain 1.89.0 + export PATH="/opt/cargo/bin:$PATH" cargo install --locked cargo-pgrx --version 0.17.0 - cargo pgrx init --pg${PG_VERSION} ${PG_CONFIG} main: - name: Build and package extension run: | - export PATH="$HOME/.cargo/bin:$PATH" + export RUSTUP_HOME=/opt/rustup + export CARGO_HOME=/opt/cargo + export PATH="/opt/cargo/bin:$PATH" + cargo pgrx init --pg${PG_VERSION} ${PG_CONFIG} cargo pgrx package --pg-config ${PG_CONFIG} --out-dir ${DESTDIR} diff --git a/src/lib.rs b/src/lib.rs index 70fe54c..18eab7e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,6 +25,7 @@ static mut PREV_PROCESS_UTILITY_HOOK: pg_sys::ProcessUtility_hook_type = None; struct ProcessUtilityArgs { pstmt: *mut pg_sys::PlannedStmt, query_string: *const std::os::raw::c_char, + #[cfg(not(feature = "pg13"))] read_only_tree: bool, context: pg_sys::ProcessUtilityContext::Type, params: pg_sys::ParamListInfo, @@ -80,6 +81,29 @@ unsafe fn block_copy_process_utility(args: ProcessUtilityArgs) { } } + #[cfg(feature = "pg13")] + match PREV_PROCESS_UTILITY_HOOK { + Some(prev) => prev( + args.pstmt, + args.query_string, + args.context, + args.params, + args.query_env, + args.dest, + args.qc, + ), + None => pg_sys::standard_ProcessUtility( + args.pstmt, + args.query_string, + args.context, + args.params, + args.query_env, + args.dest, + args.qc, + ), + } + + #[cfg(not(feature = "pg13"))] match PREV_PROCESS_UTILITY_HOOK { Some(prev) => prev( args.pstmt, @@ -105,6 +129,31 @@ unsafe fn block_copy_process_utility(args: ProcessUtilityArgs) { } #[pg_guard] +#[cfg(feature = "pg13")] +unsafe extern "C-unwind" fn hook_trampoline( + pstmt: *mut pg_sys::PlannedStmt, + query_string: *const std::os::raw::c_char, + context: pg_sys::ProcessUtilityContext::Type, + params: pg_sys::ParamListInfo, + query_env: *mut pg_sys::QueryEnvironment, + dest: *mut pg_sys::DestReceiver, + qc: *mut pg_sys::QueryCompletion, +) { + unsafe { + block_copy_process_utility(ProcessUtilityArgs { + pstmt, + query_string, + context, + params, + query_env, + dest, + qc, + }); + } +} + +#[pg_guard] +#[cfg(not(feature = "pg13"))] unsafe extern "C-unwind" fn hook_trampoline( pstmt: *mut pg_sys::PlannedStmt, query_string: *const std::os::raw::c_char, From 0ff0d2f1bae0ea94520f644de7acf799eda008f7 Mon Sep 17 00:00:00 2001 From: Rust Wizard Date: Tue, 24 Mar 2026 15:52:02 +0300 Subject: [PATCH 5/5] enable amd64 arch and add out/ to gitignore - enable amd64 target in pgxman buildkit config (was commented out) - set CARGO_INCREMENTAL=0 in main build step to reduce disk usage during compilation across multiple PostgreSQL versions - add out/ directory to .gitignore (pgxman build output) --- .gitignore | 1 + buildkit/pg_block_copy.yaml | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index abf56f2..74183ed 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ Cargo.lock tests/pg_regress/results tests/pg_regress/regression.diffs tests/pg_regress/regression.out +out/ \ No newline at end of file diff --git a/buildkit/pg_block_copy.yaml b/buildkit/pg_block_copy.yaml index 91859ea..b782a21 100644 --- a/buildkit/pg_block_copy.yaml +++ b/buildkit/pg_block_copy.yaml @@ -11,7 +11,7 @@ keywords: - copy - hook arch: - #- amd64 + - amd64 - arm64 maintainers: - name: RustWizard @@ -43,5 +43,6 @@ build: export RUSTUP_HOME=/opt/rustup export CARGO_HOME=/opt/cargo export PATH="/opt/cargo/bin:$PATH" + export CARGO_INCREMENTAL=0 cargo pgrx init --pg${PG_VERSION} ${PG_CONFIG} cargo pgrx package --pg-config ${PG_CONFIG} --out-dir ${DESTDIR}