diff options
author | Johannes Löthberg <johannes@kyriasis.com> | 2015-06-23 14:18:12 +0200 |
---|---|---|
committer | Lukas Fleischer <lfleischer@archlinux.org> | 2015-06-27 13:04:03 +0200 |
commit | e9485531be24b090162ec317bd3a3de3ec9a3d82 (patch) | |
tree | 4f97fbd36f78dc3239a4b1e876992ffbe390d36e /git-interface/git-auth.py | |
parent | ae2907a57ec50bba2c74d4ce1d137fe822fddf3b (diff) | |
download | aur-e9485531be24b090162ec317bd3a3de3ec9a3d82.tar.gz aur-e9485531be24b090162ec317bd3a3de3ec9a3d82.tar.xz |
git: Use AUR_USER env var instead of ForceCommand argument
Also add an utility function for formatting the ForceCommand, using
shlex.quote to quote the value.
Signed-off-by: Johannes Löthberg <johannes@kyriasis.com>
Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
Diffstat (limited to 'git-interface/git-auth.py')
-rwxr-xr-x | git-interface/git-auth.py | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/git-interface/git-auth.py b/git-interface/git-auth.py index c9e1f015..be7d4f14 100755 --- a/git-interface/git-auth.py +++ b/git-interface/git-auth.py @@ -2,10 +2,27 @@ import configparser import mysql.connector +import shlex import os import re import sys + +def format_command(env_vars, command, ssh_opts, ssh_key): + environment = '' + for key, var in env_vars.items(): + environment += '{}={} '.format(key, shlex.quote(var)) + + command = shlex.quote(command) + command = '{}{}'.format(environment, command) + + # The command is being substituted into an authorized_keys line below, + # so we need to escape the double quotes. + command = command.replace('"', '\\"') + msg = 'command="{}",{} {}'.format(command, ssh_opts, ssh_key) + return msg + + config = configparser.RawConfigParser() config.read(os.path.dirname(os.path.realpath(__file__)) + "/../conf/config") @@ -40,5 +57,9 @@ user = cur.fetchone()[0] if not re.match(username_regex, user): exit(1) -print('command="%s %s",%s %s' % (git_serve_cmd, user, ssh_opts, - keytype + " " + keytext)) +env_vars = { + 'AUR_USER': user, +} +key = keytype + ' ' + keytext + +print(format_command(env_vars, git_serve_cmd, ssh_opts, key)) |