From 19815f519d331e770bdea3938825c65ff5c8df6a Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Sun, 24 Oct 2021 20:57:36 -0400 Subject: cleanup in AnonymousAccessCommand --- EndoForge/src/AnonymousAccessCommand | 49 +++++++++++++++++------------------- 1 file changed, 23 insertions(+), 26 deletions(-) (limited to 'EndoForge/src/AnonymousAccessCommand') diff --git a/EndoForge/src/AnonymousAccessCommand b/EndoForge/src/AnonymousAccessCommand index 5146da4..526f53d 100755 --- a/EndoForge/src/AnonymousAccessCommand +++ b/EndoForge/src/AnonymousAccessCommand @@ -52,18 +52,12 @@ ssh_client_fingerprint_base16() echo $6 } -check_if_self_forge() +is_self_forge() { - # TODO: don't use description, but something else. - local dir="$1" - [ -d "$dir" ] || exit - [ -r "$dir"/description ] || exit - read description < "$dir"/description - if [ "$description" != self-forge ] && [ "$(GIT_DIR=$dir git config core.self-forge)" != true ] - then - echo 'Error: access denied. The specified directory is not a self-forge.' >&2 - exit - fi + local dir="$1" confval + [ -d "$dir" ] || return + confval=$(GIT_DIR=$dir git config core.self-forge) || return + [ "$confval" = true ] } with_soul_bare() @@ -85,14 +79,8 @@ read authtype authline < "$SSH_USER_AUTH" || exit cmd=${SSH_ORIGINAL_COMMAND%% *} case "$cmd" in - git-send-pack | git-upload-pack) - GIT_NAMESPACE= - ;; - git-receive-pack) - export GIT_NAMESPACE="$(ssh_client_fingerprint_base16)" - [ "$GIT_NAMESPACE" ] || exit - ;; - *) + git-send-pack | git-upload-pack | git-receive-pack ) ;; + * ) default_msg exit ;; @@ -102,18 +90,27 @@ arg=${SSH_ORIGINAL_COMMAND#* } arg=${arg%\'} arg=${arg#\'} case "$arg" in - *\'*) exit ;; + *\'*) exit ;; # we should support these wtf *.git) ;; *) arg=$arg/.git ;; esac dir=$(readlink -e "$arg") || exit -check_if_self_forge "$dir" - -if [ "$GIT_NAMESPACE" ] +if ! is_self_forge "$dir" then - GIT_DIR=$dir with_soul_bare "$cmd" "$dir" -else - "$cmd" "$dir" + echo 'Error: access denied. The specified directory is not a self-forge.' >&2 + exit fi + +case "$cmd" in + git-send-pack | git-upload-pack ) + GIT_NAMESPACE= + "$cmd" "$dir" + ;; + git-receive-pack ) + export GIT_NAMESPACE="$(ssh_client_fingerprint_base16)" + [ "$GIT_NAMESPACE" ] + GIT_DIR=$dir with_soul_bare "$cmd" "$dir" + ;; +esac -- cgit v1.2.3