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
13 if len(run) < 3: return False
14 if run[0] != "rsync": return False
15 if run[1] != "--server": return False
19 if len(run) != 1: return False
20 return run[0] == "/usr/lib/openssh/sftp-server"
22 allowCommands = [allowSCP, allowRSync, allowSFTP]
23 commandPaths = ["/usr/bin", "/bin"]
25 # END of Configuration
26 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
27 # DO NOT TOUCH ANYTHING BELOW THIS LINE
29 import logging, logging.handlers
30 import os, sys, shlex, pwd
32 logger = logging.getLogger("schsh")
33 logger.setLevel(logging.INFO)
34 logger.addHandler(logging.handlers.SysLogHandler(address = '/dev/log',
35 facility = logging.handlers.SysLogHandler.LOG_AUTH))
38 return pwd.getpwuid(os.getuid()).pw_name
40 def log(msg, lvl = logging.INFO):
41 logger.log(lvl, "%s[%d]: <%s> %s" % ("schsh", os.getpid(), get_username(), msg))
44 log(msg, logging.ERROR)
47 def commandAllowed(run):
48 for allowed in allowCommands:
54 if prog.startswith("/"):
56 # look for it in the paths
57 for path in commandPaths:
58 fullprog = os.path.join(path, prog)
59 if os.path.exists(fullprog):
65 if len(sys.argv) == 1:
67 print "No shell for you!"
68 logquit("Shell access not allowed")
71 elif len(sys.argv) == 3 and sys.argv[1] == "-c":
72 # check if the command is allowed, and add path
73 run = shlex.split(sys.argv[2])
74 if commandAllowed(run):
75 run[0] = addPath(run[0])
76 log("Running '"+str(run)+"'")
78 print "You are not allowed to run this command."
79 logquit("Attempt to run invalid command '"+sys.argv[2]+"'")
81 logquit("Invalid arguments for schsh: "+str(sys.argv))
84 os.execl("/usr/bin/schroot", "/usr/bin/schroot", "-c", "schsh-"+get_username(), "-d", "/data", "--", *run)