prescript.py 603 B

12345678910111213141516171819202122232425262728
  1. import ctypes
  2. import os
  3. import sys
  4. import traceback
  5. # setup sys.excepthook
  6. def excepthook(type, value, tb):
  7. sys.stderr.write("".join(traceback.format_exception(type, value, tb)))
  8. sys.stderr.flush()
  9. sys.exit(-1)
  10. sys.excepthook = excepthook
  11. lib = ctypes.CDLL("./var/sandbox/sandbox-python/python.so")
  12. lib.DifySeccomp.argtypes = [ctypes.c_uint32, ctypes.c_uint32, ctypes.c_bool]
  13. lib.DifySeccomp.restype = None
  14. # get running path
  15. running_path = sys.argv[1]
  16. if not running_path:
  17. exit(-1)
  18. os.chdir(running_path)
  19. {{preload}}
  20. lib.DifySeccomp({{uid}}, {{gid}}, {{enable_network}})
  21. {{code}}