Compare commits

..

1 commit

Author SHA1 Message Date
Sven Velt 89e0b9fa53 Fix for awk/os-release with different OS 2020-02-22 13:34:10 +01:00

View file

@ -1,34 +1,10 @@
#!/bin/sh
'''':
for pyint in /usr/libexec/platform-python python3 python python2; do
command -v $pyint >/dev/null 2>&1 && exec $pyint "$0" "$@"
done
echo "$0: No python could be found" >&2
exit 1
# '''
#!/usr/bin/env python
import argparse
import os
import re
import shlex
import subprocess
import sys
import syslog
parser = argparse.ArgumentParser()
parser.add_argument('--verbose', '-v', action='count', default=0)
parser.add_argument('--silent', action='store_true', default=False)
args = parser.parse_args()
if args.silent:
args.verbose = -1
if args.verbose >= 0:
syslog.openlog(
ident=sys.argv[0],
logoption=syslog.LOG_PID,
facility=syslog.LOG_LOCAL3 | syslog.LOG_ERR
)
allowed = [
##### System informations
@ -57,37 +33,22 @@ allowed = [
cmdline = os.getenv('SSH_ORIGINAL_COMMAND')
if not cmdline:
print('This is just a wrapper, no command specified!')
if args.verbose >= 0:
syslog.syslog('Called without SSH_ORIGINAL_COMMAND')
print 'This is just a wrapper, no command specified!'
sys.exit(3)
for maybe in allowed:
if re.match(maybe, cmdline):
if args.verbose >= 2:
syslog.syslog(syslog.LOG_INFO, 'Found command line >%s< with regexp >%s<' % ( cmdline, maybe ) )
cmdlinelist = shlex.split(cmdline)
cmdline = shlex.split(cmdline)
try:
cmd = subprocess.Popen(cmdlinelist, stdout=subprocess.PIPE)
except Exception as exc:
print('Could not execute plugin: %s' % exc)
if args.verbose >= 0:
syslog.syslog('Could not execute plugin >%s<' % cmdline)
cmd = subprocess.Popen(cmdline, stdout=subprocess.PIPE)
except Exception, exc:
print 'Could not execute plugin ("%s"): %s' % (' '.join(cmdline), exc)
sys.exit(3)
else:
(out, outerr) = cmd.communicate()
out = out.rstrip().decode('utf-8')
outerr = (outerr or b'').rstrip().decode('utf-8')
print(out)
if args.verbose >= 1:
syslog.syslog('Executed command line >%s<' % cmdline)
if args.verbose >= 3:
syslog.syslog('Output >%s<, Error >%s<' % (out, outerr))
print cmd.communicate()[0].rstrip()
sys.exit(cmd.returncode)
print('%s: No allowed command found!' % sys.argv[0])
if args.verbose >= 0:
syslog.syslog('No allowed command found for >%s<' % cmdline)
print '%s: No allowed command found!' % sys.argv[0]
sys.exit(3)