diff options
author | Jonas Gunz <himself@jonasgunz.de> | 2020-07-20 03:42:34 +0200 |
---|---|---|
committer | Jonas Gunz <himself@jonasgunz.de> | 2020-07-20 03:42:34 +0200 |
commit | fe1aa6fd00d3da84276b2e0d1e9b0116c3bb23c6 (patch) | |
tree | 569b56bc0200141c7648b3b0e4d825d891ef4d87 /gitwrapper.sh | |
parent | 3b69a787e6b76cc4cbc762b8c02aae2ded5e3ab1 (diff) | |
download | reposync-fe1aa6fd00d3da84276b2e0d1e9b0116c3bb23c6.tar.gz |
gitwrapper: working access control
Diffstat (limited to 'gitwrapper.sh')
-rwxr-xr-x | gitwrapper.sh | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/gitwrapper.sh b/gitwrapper.sh index a7ef645..0ff0486 100755 --- a/gitwrapper.sh +++ b/gitwrapper.sh @@ -43,8 +43,6 @@ function has_access() { return 1 fi - basename $1 - readonly reponame_regex='^\w+\.git$' if [[ ! "$(basename "$1")" =~ $reponame_regex ]]; then perror "Invalid repository" @@ -55,7 +53,7 @@ function has_access() { [ "$(dirname "$1")" = "$dir" ] && return 0 done - perror Invalid repository + perror Invalid repository2 return 1 } @@ -91,14 +89,26 @@ if [ -z "$SSH_ORIGINAL_COMMAND" ]; then exit $? fi -repo_path=$(sed -n 's/^git upload-pack \(.*\)$/\1/p' <<< "$SSH_ORIGINAL_COMMAND") -if [ ! -z "$repo_path" ]; then +read direction repo_path < <( echo "$SSH_ORIGINAL_COMMAND" | sed -n 's/^git[ -]\(receive\|upload\)-pack \(.*\)$/\1 \2/p' | tr -d "'" ) +[ -z "$repo_path" ] && exit 1 + +perror "$repo_path" + +if [ "$direction" = "receive" ]; then if ! has_access "$repo_path" "w"; then perror "An error occured: No such file or directory." exit 1 fi - [ ! -e "$repo_path" ] && git init --bare "$repo_path" -fi + [ ! -e "$repo_path" ] && git init --bare "$repo_path" > /dev/null -eval $SSH_ORIGINAL_COMMAND + git-receive-pack "$repo_path" +elif [ "$direction" = "upload" ]; then + if ! has_access "$repo_path" "r"; then + perror "An error occured: No such file or directory." + exit 1 + fi + + [ -e "$repo_path" ] && git-upload-pack "$repo_path" || git-upload-pack empty.git +fi +exit $? |