Browse Source

Version 3

Sven Velt 7 years atrás
parent
commit
eef01a1064
1 changed files with 12 additions and 4 deletions
  1. 12 4
      ssh-wrapper.py

+ 12 - 4
ssh-wrapper.py

@@ -16,15 +16,23 @@ allowed = [
 	]
 
 cmdline = os.getenv('SSH_ORIGINAL_COMMAND')
+if not cmdline:
+	print 'This is just a wrapper, no command specified!'
+	sys.exit(3)
 
 for maybe in allowed:
 	if re.match(maybe, cmdline):
 		cmdline = shlex.split(cmdline)
 
-		cmd = subprocess.Popen(cmdline, stdout=subprocess.PIPE)
-		print cmd.communicate()[0].rstrip()
-		sys.exit(cmd.returncode)
+		try:
+			cmd = subprocess.Popen(cmdline, stdout=subprocess.PIPE)
+		except Exception, exc:
+			print 'Could not execute plugin ("%s"): %s' % (' '.join(cmdline), exc)
+			sys.exit(3)
+		else:
+			print cmd.communicate()[0].rstrip()
+			sys.exit(cmd.returncode)
 
-print '%s: No command found!' % sys.argv[0]
+print '%s: No allowed command found!' % sys.argv[0]
 sys.exit(3)