Advertisement
Omnifarious

Steam contained

Oct 11th, 2019
2,908
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.29 KB | None | 0 0
  1. # mount -t overlay overlay -o lowerdir=/home/me,upperdir=/giant_disk/steam/overlay,workdir=/giant_disk/steam/working /giant_disk/steam/main
  2.  
  3. #!/usr/bin/python3
  4.  
  5. import ctypes
  6. import ctypes.util
  7. import os
  8. import unshare
  9.  
  10.  
  11. libc = ctypes.CDLL(ctypes.util.find_library('c'), use_errno=True)
  12. libc.mount.argtypes = (ctypes.c_char_p, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_ulong, ctypes.c_char_p)
  13.  
  14.  
  15. def mount(source: bytes, target: bytes, fs: bytes=b'', flags: int=0, options: bytes=b''):
  16.     ret = libc.mount(source, target, fs, flags, options)
  17.     if ret < 0:
  18.         errno = ctypes.get_errno()
  19.         errstr = os.strerror(errno)
  20.         raise OSError(errno, f"Error mounting {source} ({fs}) on {target} with options '{options}' and flags {flags}: {errstr}")
  21.  
  22.  
  23. uid = os.getuid()
  24. gid = os.getgid()
  25. wd = os.getcwd()
  26. os.chdir('/')
  27. unshare.unshare(unshare.CLONE_NEWNS|unshare.CLONE_NEWUSER)
  28. mount(b'/giant_disk/steam/main', b'/home/me', b'', 4096)
  29. with open('/proc/self/setgroups', 'wb') as f:
  30.     f.write(b'deny')
  31. with open('/proc/self/uid_map', 'wb') as f:
  32.     f.write(f'{uid} {uid} 1\n'.encode('ascii'))
  33. with open('/proc/self/gid_map', 'wb') as f:
  34.     f.write(f'{gid} {gid} 1\n'.encode('ascii'))
  35. os.chdir(wd)
  36. os.execv('/bin/bash', ['/bin/bash'])  # You run steam from this bash shell
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement