Merge pull request #938 from Neraud/git_commit_behind_fixed_shell

Git commit behind fixed shell
This commit is contained in:
Lars Kruse 2018-09-10 19:15:44 +02:00 committed by GitHub
commit 81833d05e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 2 deletions

View File

@ -114,6 +114,7 @@ GPLv2
import logging
import os
from pathlib import Path
import pwd
from random import randint
import re
from shlex import quote
@ -128,6 +129,8 @@ if int(os.getenv('MUNIN_DEBUG', 0)) > 0:
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s %(levelname)-7s %(message)s')
current_user = pwd.getpwuid(os.geteuid())[0]
conf = {
'git_path': os.getenv('git_path', '/usr/bin/git'),
'state_file': os.getenv('MUNIN_STATEFILE'),
@ -170,14 +173,14 @@ def print_config():
def generate_git_command(repo_conf, git_command):
if not repo_conf['user'] or repo_conf['user'] == os.environ['USER']:
if not repo_conf['user'] or repo_conf['user'] == current_user:
cmd = [quote(conf['git_path'])] + git_command
else:
shell_cmd = 'cd %s ; %s %s' % (
quote(repo_conf['path']),
quote(conf['git_path']),
' '.join(git_command))
cmd = ['su', '-', repo_conf['user'], '-c', shell_cmd]
cmd = ['su', '-', repo_conf['user'], '-s', '/bin/sh', '-c', shell_cmd]
return cmd