git-srv-admin.sh: Only allow manipulating own repos

Disallow attempts to manipulate other user's repositories.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2016-11-26 12:18:37 +00:00
commit d504aa21cd

View file

@ -53,6 +53,11 @@ md()
} }
} }
check_user_is_self()
{
[ "$id" != "$user" ] && fatal "User $id is not allowed to do this to user $user's repositories."
}
# ----------------- commands # ----------------- commands
md_p() md_p()
{ {
@ -90,8 +95,9 @@ create_personal_project()
list_personal_projects() list_personal_projects()
{ {
cd $pdir cd $pdir || return 1
ls */HEAD | sed 's%/HEAD%%' 2>/dev/null ls */HEAD | sed 's%/HEAD%%' 2>/dev/null
return $?
} }
# ----------------- here we go # ----------------- here we go
@ -123,10 +129,11 @@ shift $(($OPTIND - 1))
if [ "$user" ]; then if [ "$user" ]; then
id=$user id=$user
else else
[ "$SUDO_UID" ] && { if [ "$SUDO_UID" ]; then
id=`/opt/ytools/bin/getpwuid $SUDO_UID | sed '/^name *=/ !d; s/^name *= *//'` id=`/opt/ytools/bin/getpwuid $SUDO_UID | sed '/^name *=/ !d; s/^name *= *//'`
[ "$id" ] || fatal "failed to find uid $SUDO_UID in user database" [ "$id" ] || fatal "failed to find uid $SUDO_UID in user database"
} fi
user=$id
fi fi
git_home=/srv/git/$id git_home=/srv/git/$id
@ -141,6 +148,7 @@ dir=$pdir/$p
case $cmd in case $cmd in
create-personal-project) create-personal-project)
check_user_is_self
create_personal_project "$@" create_personal_project "$@"
;; ;;
list-personal-projects) list-personal-projects)
@ -148,6 +156,7 @@ list-personal-projects)
;; ;;
create-project-dir) create-project-dir)
dir=$1 # this is all a horrible variable and usage mess dir=$1 # this is all a horrible variable and usage mess
check_user_is_self
create_project_dir "$@" create_project_dir "$@"
;; ;;
*) *)