aboutsummaryrefslogtreecommitdiff
path: root/t/lib-sudo.sh
diff options
context:
space:
mode:
authorJohannes Schindelin <johannes.schindelin@gmx.de>2022-06-23 12:36:03 +0200
committerJohannes Schindelin <johannes.schindelin@gmx.de>2022-06-23 12:36:03 +0200
commitaef3d5948c5b00a0409e117da7e720f574040505 (patch)
tree0faf03246ee43768f4eee7ef66e7a838e471958f /t/lib-sudo.sh
parentd516b2db0af2221bd6b13e7347abdcb5830b2829 (diff)
parentf2eed22852b0a21556f0c9f56732913eba553e62 (diff)
downloadgit-aef3d5948c5b00a0409e117da7e720f574040505.tar.xz
Sync with 2.34.4
* maint-2.34: Git 2.34.4 Git 2.33.4 Git 2.32.3 Git 2.31.4 Git 2.30.5 setup: tighten ownership checks post CVE-2022-24765 git-compat-util: allow root to access both SUDO_UID and root owned t0034: add negative tests and allow git init to mostly work under sudo git-compat-util: avoid failing dir ownership checks if running privileged t: regression git needs safe.directory when using sudo
Diffstat (limited to 't/lib-sudo.sh')
-rw-r--r--t/lib-sudo.sh15
1 files changed, 15 insertions, 0 deletions
diff --git a/t/lib-sudo.sh b/t/lib-sudo.sh
new file mode 100644
index 0000000000..b4d7788f4e
--- /dev/null
+++ b/t/lib-sudo.sh
@@ -0,0 +1,15 @@
+# Helpers for running git commands under sudo.
+
+# Runs a scriplet passed through stdin under sudo.
+run_with_sudo () {
+ local ret
+ local RUN="$TEST_DIRECTORY/$$.sh"
+ write_script "$RUN" "$TEST_SHELL_PATH"
+ # avoid calling "$RUN" directly so sudo doesn't get a chance to
+ # override the shell, add aditional restrictions or even reject
+ # running the script because its security policy deem it unsafe
+ sudo "$TEST_SHELL_PATH" -c "\"$RUN\""
+ ret=$?
+ rm -f "$RUN"
+ return $ret
+}