aboutsummaryrefslogtreecommitdiff
path: root/usr/local/bin
diff options
context:
space:
mode:
authorAlex Pooley (@zuedev) <zuedev@gmail.com>2026-05-07 22:58:39 +0100
committerAlex Pooley (@zuedev) <zuedev@gmail.com>2026-05-07 22:58:39 +0100
commite85f068022e6dda23ec0d1c602be653a2d56aa1c (patch)
tree5d0e3c75bf7699c1fac9cadff27c92d0692aebd4 /usr/local/bin
parent73cf5091807b75810e007458544ee40d5427675d (diff)
downloadgit.zue.dev-e85f068022e6dda23ec0d1c602be653a2d56aa1c.tar
git.zue.dev-e85f068022e6dda23ec0d1c602be653a2d56aa1c.tar.gz
git.zue.dev-e85f068022e6dda23ec0d1c602be653a2d56aa1c.tar.bz2
git.zue.dev-e85f068022e6dda23ec0d1c602be653a2d56aa1c.tar.xz
git.zue.dev-e85f068022e6dda23ec0d1c602be653a2d56aa1c.zip
Handle git init to create new bare repositories
Diffstat (limited to 'usr/local/bin')
-rw-r--r--usr/local/bin/git-wrapper23
1 files changed, 22 insertions, 1 deletions
diff --git a/usr/local/bin/git-wrapper b/usr/local/bin/git-wrapper
index 12c6d21..e46b135 100644
--- a/usr/local/bin/git-wrapper
+++ b/usr/local/bin/git-wrapper
@@ -7,6 +7,27 @@ if [ -z "$SSH_ORIGINAL_COMMAND" ]; then
exit 1
fi
+# Handle git init to create new bare repositories
+if [[ "$SSH_ORIGINAL_COMMAND" == git\ init* ]]; then
+ repo=$(echo "$SSH_ORIGINAL_COMMAND" | awk '{print $NF}')
+
+ # Block path traversal attempts and absolute paths
+ if [[ "$repo" == *..* ]] || [[ "$repo" == /* ]]; then
+ echo "Invalid path" >&2
+ exit 1
+ fi
+
+ path="/repositories/$repo"
+
+ # Check if the repository already exists
+ if [ -d "$path" ]; then
+ echo "Repository already exists: $repo" >&2
+ exit 1
+ fi
+
+ exec git init --bare "$path"
+fi
+
# Normalize the SSH_ORIGINAL_COMMAND as modern Git clients can send either form depending on version and protocol negotiation
SSH_ORIGINAL_COMMAND=$(echo "$SSH_ORIGINAL_COMMAND" | sed \
's/^git upload-pack/git-upload-pack/;
@@ -42,4 +63,4 @@ case "$cmd" in
echo "Command not allowed: $cmd" >&2
exit 1
;;
-esac \ No newline at end of file
+esac