From ae1ffa7c7a6823423b6c9b961e7d1c28a86af9ef Mon Sep 17 00:00:00 2001 From: VG Date: Tue, 27 Sep 2016 20:39:55 +0200 Subject: first commit --- gitcmd | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100755 gitcmd (limited to 'gitcmd') diff --git a/gitcmd b/gitcmd new file mode 100755 index 0000000..53cd3d8 --- /dev/null +++ b/gitcmd @@ -0,0 +1,47 @@ +#!/usr/bin/python3 + +import sys +import os + +def printerr(*l, **d): return print(*l, **d, file=sys.stderr) +def fail(*l, **d): printerr(*l, **d); raise SystemExit(1) + +try: + user = sys.argv[1] +except IndexError: + fail('Bad adminsys, he forgot to set user associated with this key.') + +try: + with open(user + '.listro', 'r', encoding='utf8') as f: + repositories_ro = f.read().splitlines() +except FileNotFoundError: + repositories_ro = [] + +try: + with open(user + '.listrw', 'r', encoding='utf8') as f: + repositories_rw = f.read().splitlines() +except FileNotFoundError: + repositories_rw = [] + +try: + ssh_original_command = os.environ['SSH_ORIGINAL_COMMAND'].split() + command = ssh_original_command[0] + repository = ssh_original_command[1].split('.git')[0].strip("'") +except IndexError: + if command == 'ls': + print('\n'.join(repositories_ro + repositories_rw or ['Empty list'])) + raise SystemExit(0) + fail('Invalid repository name or git usage') +except KeyError: + fail('Bad boy, git only access authorized.') + +repositories_ro = repositories_ro + repositories_rw +if command == 'git-upload-pack' and repository in repositories_ro: + os.execv('/usr/bin/git-upload-pack', + ['/usr/bin/git-upload-pack', '--strict', '--timeout=600', + repository]) +elif command == 'git-receive-pack' and repository in repositories_rw: + os.execv('/usr/bin/git-receive-pack', + ['/usr/bin/git-receive-pack', repository]) +else: + fail('Bad git command or inexistant repository or access denied') -- cgit v1.2.3