From ace88012251ad607c262dc3263ed7928dbeecc20 Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Sun, 28 May 2023 17:18:57 -0400 Subject: endofossil will find *.fossil files in various paths --- src/endofossil | 46 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/endofossil b/src/endofossil index c4ae60d..f645e9c 100644 --- a/src/endofossil +++ b/src/endofossil @@ -5,7 +5,8 @@ IFS=/ read n pid uid <<< "$1" [ "$pid" ] [ "$uid" -gt 0 ] -IFS=: read username realname _ _ gecos homedir shell < <(getent passwd "$uid") +IFS=: read username realname uid_ gid gecos homedir shell < <(getent passwd "$uid") +[ "$uid" = "$uid_" ] authtype= while read -d '' @@ -29,26 +30,49 @@ do done < <(ssh-keygen -f <(printf '%s\n' "$keytype $keyvalue") -r .) [ "$keyhash" ] +declare -a shared_paths +shared_paths=("$homedir"/./src /srv/./src /usr/./src /usr/local/./src) +require_extension=.fossil + case "$SSH_ORIGINAL_COMMAND" in *\"* ) exit 1 ;; - fossil\ test-http\ * ) ;; - *) exit 1 ;; + fossil\ test-http\ * ) + set -- $SSH_ORIGINAL_COMMAND + [ $# = 3 ] + f=/${f%$require_extension}$require_extension + for d in "${shared_paths[@]}" + do + relativePart=${d#*/./} + absolutePart=${d%$relativePart} + tryPath=$absolutePart$relativePart${f#/$relativePart} + if [ -f "$tryPath" ] + then + upstreamDatabase=$(realpath -e -s "$tryPath") + break + fi + done + [ "$upstreamDatabase" ] + ;; + * ) exit 1 ;; esac -# This is no way to do it. -# Let's just share /home/*/src and /srv/src and /usr/src. -fossil_dir=$homedir/src/fossil -upstreamDatabase=$fossil_dir/db -readWriteDbName=db.fossil # Must end in .fossil for 'fossil test-http' to find it. -readWriteDir=$fossil_dir/remotes/$keyhash +fossil_dir=$(dirname "${upstreamDatabase}") +readWriteDir=$fossil_dir/.fossil-remotes/$keyhash +readWriteDbName=$(basename "$upstreamDatabase") # Must end in .fossil for 'fossil test-http' to find it. as_user() { - setpriv --reuid="$username" --init-groups --inh-caps=-all "$@" + setpriv --reuid="$uid" --regid="$gid" --clear-groups --inh-caps=-all "$@" } if ! [ -d "$readWriteDir" ] then - as_user mkdir "$readWriteDir" + make_parents= + if [[ $readWriteDir == $home/* ]] + then + [ -d "$fossil_dir" ] + make_parents=-p + fi + as_user mkdir $make_parents "$readWriteDir" fi as_user cp -n --reflink -- "$upstreamDatabase" "$readWriteDir"/"$readWriteDbName" -- cgit v1.2.3