summaryrefslogtreecommitdiff
path: root/src/run
blob: 5b18bc8a3118213645723868af69d2439797fb48 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env fish

# load environment
source (dirname (status --current-filename))/env

# check given git command
set -l currentUser (whoami)
set -l matcher (string match -r -g $_GIT_VALIDATION_REGEX -- "$argv")
if test (count $matcher) -ne 2
	# there should be two groups otherwise something is wrong
	echo "$(date -Is): DENY bad_format user=$currentUser ip=$SSH_CONNECTION argv=$argv" &>$LOG
	exit 1
end

# extract variables from git command
set -l gitCommand $matcher[1]
set -l repo $matcher[2]

# adjust repo path to /srv/repos
set -l repoDir /(string join -n '/' srv repos (string split '/' $repo))

# check repo jail in /srv/repos
if not string match -r -q -- "/srv/repos/.*" "(realpath $repoDir)"
	# something is for sure wrong here
	echo "$(date -Is): DENY jail_escape user=$currentUser ip=$SSH_CONNECTION argv=$argv" &>$LOG
	exit 2
end

# check for permissions
if not cat $_REPO_PERMISSIONS_FILE | grep -q -E "^$repoDir:$currentUser\$"
	# something is for sure wrong here
	echo "$(date -Is): DENY no_permissions user=$currentUser ip=$SSH_CONNECTION argv=$argv" &>$LOG
	exit 1
end

# execute parsed git command
/usr/bin/sudo -u git /usr/bin/git-shell -c "$gitCommand '$repoDir'"