Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ Cargo.lock
tests/pg_regress/results
tests/pg_regress/regression.diffs
tests/pg_regress/regression.out
out/
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down
48 changes: 48 additions & 0 deletions buildkit/pg_block_copy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
apiVersion: v1
name: block_copy_command
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.1.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"
buildDependencies:
- curl
- build-essential
- clang
- libclang-dev
- pkg-config
- libssl-dev
build:
pre:
- name: Install Rust toolchain
run: |
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
main:
- name: Build and package extension
run: |
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}
49 changes: 49 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Loading