aboutsummaryrefslogtreecommitdiff
path: root/t/lib-sudo.sh
diff options
context:
space:
mode:
authorJohannes Schindelin <johannes.schindelin@gmx.de>2022-06-23 12:36:12 +0200
committerJohannes Schindelin <johannes.schindelin@gmx.de>2022-06-23 12:36:12 +0200
commit8f8eea8c3aba154ce1f9eaab4fa06c73b60550dc (patch)
tree9eb673bb05503f8b8a2c2c868cc773b20407e8cf /t/lib-sudo.sh
parentdc8c8deaa6b5847733bd7df011a4c7b7d1a64e0a (diff)
parent359da658ae32d9a7e5e93ac173fc221352b62917 (diff)
downloadgit-8f8eea8c3aba154ce1f9eaab4fa06c73b60550dc.tar.xz
Sync with 2.35.4
* maint-2.35: Git 2.35.4 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
+}