From 913b8351fe4a7bc29699bfb5b40adb6bbaae670d Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Mon, 5 Oct 2020 23:45:53 -0700 Subject: [PATCH] git-daemon-verify: prepare for enhanced peek_packet Handle the case when peek_packet produces more than one output line. A forthcoming version of peek_packet will provide the parsed information from a host parameter using extra output lines. If the extra information is provided by peek_packet, pick it up and include it in the information sent to the log. Signed-off-by: Kyle J. McKay --- bin/git-daemon-verify | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/bin/git-daemon-verify b/bin/git-daemon-verify index 522b205..bae5ac7 100755 --- a/bin/git-daemon-verify +++ b/bin/git-daemon-verify @@ -73,11 +73,39 @@ esac PATH="$(dirname "$cfg_git_daemon_bin"):$PATH" export PATH -if ! request="$("$cfg_basedir/bin/peek_packet")"; then +if ! request="$("$cfg_basedir/bin/peek_packet")" || [ -z "$request" ]; then invalbaderr exit 1 fi +_IFS="$IFS" +IFS=' +' +set -- $request +IFS="$_IFS" +[ $# -ge 1 ] || { invalidbaderr; exit 1; } +request="$1" +shift + +# Extract host and port now +[ "${hnam+set}" != "set" ] || unset hnam +[ "${pnum+set}" != "set" ] || unset pnum +[ "${hostport+set}" != "set" ] || unset hostport +for extra in "$@"; do + case "$extra" in + "host="*) hnam="${extra#host=}";; + "port="*) pnum="${extra#port=}";; + esac +done +# Make nice hostport variable for later use +if [ "${hnam+set}" = "set" ]; then + case "$hnam" in + *":"*) hostport="[$hnam]";; + *) hostport="$hnam";; + esac + [ "${pnum+set}" != "set" ] || hostport="$hostport:$pnum" +fi + # The request should look like one of the following # # git-upload-pack /dir @@ -102,12 +130,12 @@ case "$request" in exit 1 esac if [ "$type" = 'receive-pack' ]; then - logmsg "denied $type $dir" + logmsg "denied $type $dir${hostport+ host=$hostport}" invalerr exit 1 fi case "$dir" in /*) :;; *) - logmsg "denied $type $dir" + logmsg "denied $type $dir${hostport+ host=$hostport}" invalerr exit 1 esac @@ -124,7 +152,7 @@ esac # Reject any project names that start with _ or contain .. case "$proj" in _*|*..*) - logmsg "denied $type $dir" + logmsg "denied $type $dir${hostport+ host=$hostport}" denied exit 1 esac @@ -143,13 +171,13 @@ dir="$reporoot/$proj" testpath="${dir#$reporoot/}" testpath="${testpath%.git}" case "$testpath/" in *.[Gg][Ii][Tt]/*|_*) - logmsg "denied $type $odir" + logmsg "denied $type $odir${hostport+ host=$hostport}" denied exit 1 esac if ! [ -d "$dir" ] || ! [ -f "$dir/HEAD" ] || ! [ -d "$dir/objects" ]; then - logmsg "denied $type $odir" + logmsg "denied $type $odir${hostport+ host=$hostport}" denied exit 1 fi @@ -162,7 +190,7 @@ if [ "${cfg_fetch_stash_refs:-0}" = "0" ]; then git_add_config "uploadpack.hiderefs=refs/tgstash" fi -logmsg "accepted $type $odir" +logmsg "accepted $type $odir${hostport+ host=$hostport}" exec "$cfg_git_daemon_bin" --inetd --verbose --export-all --enable=upload-archive --base-path="$cfg_reporoot" internalerr "exec failed: $cfg_git_daemon_bin" exit 1 -- 2.11.4.GIT