2 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
4 shell = None # set to "/bin/bash" or similar to allow shell access
7 if len(run) != 3: return False
8 if run[0] != "scp": return False
9 if run[1] not in ("-f", "-t"): return False
10 if run[2].startswith('-'): return False
14 if len(run) < 3: return False
15 if run[0] != "rsync": return False
16 if run[1] != "--server": return False
20 if len(run) != 1: return False
21 return run[0] == "/usr/lib/openssh/sftp-server"
23 allowCommands = [allowSCP, allowRSync, allowSFTP]
24 commandPaths = ["/usr/bin", "/bin"]
26 # END of Configuration
27 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
28 # DO NOT TOUCH ANYTHING BELOW THIS LINE
30 import logging, logging.handlers
31 import os, sys, shlex, pwd
33 logger = logging.getLogger("schsh")
34 logger.setLevel(logging.INFO)
35 logger.addHandler(logging.handlers.SysLogHandler(address = '/dev/log',
36 facility = logging.handlers.SysLogHandler.LOG_AUTH))
39 return pwd.getpwuid(os.getuid()).pw_name
41 def log(msg, lvl = logging.INFO):
42 logger.log(lvl, "%s[%d]: <%s> %s" % ("schsh", os.getpid(), get_username(), msg))
45 log(msg, logging.ERROR)
48 def commandAllowed(run):
49 for allowed in allowCommands:
55 if prog.startswith("/"):
57 # look for it in the paths
58 for path in commandPaths:
59 fullprog = os.path.join(path, prog)
60 if os.path.exists(fullprog):
66 if len(sys.argv) == 1:
68 print "No shell for you!"
69 logquit("Shell access not allowed")
72 elif len(sys.argv) == 3 and sys.argv[1] == "-c":
73 # check if the command is allowed, and add path
74 run = shlex.split(sys.argv[2])
75 if commandAllowed(run):
76 run[0] = addPath(run[0])
77 log("Running '"+str(run)+"'")
79 print "You are not allowed to run this command."
80 logquit("Attempt to run invalid command '"+sys.argv[2]+"'")
82 logquit("Invalid arguments for schsh: "+str(sys.argv))
85 os.execl("/usr/bin/schroot", "/usr/bin/schroot", "-c", "schsh-"+get_username(), "-d", "/data", "--", *run)