chgrp 559 B

123456789101112131415161718192021222324252627282930
  1. #!/usr/bin/env python3
  2. #
  3. # Wrapper around 'chgrp' that redirects to root in all cases
  4. import os
  5. import shutil
  6. import sys
  7. # calculate path to the real 'chgrp'
  8. path = os.environ['PATH']
  9. path = path.replace(os.path.dirname(sys.argv[0]), '')
  10. real_chgrp = shutil.which('chgrp', path=path)
  11. args = list()
  12. found = False
  13. args.append(real_chgrp)
  14. for i in sys.argv[1:]:
  15. if i.startswith("-"):
  16. args.append(i)
  17. continue
  18. if not found:
  19. args.append("root")
  20. found = True
  21. else:
  22. args.append(i)
  23. os.execv(real_chgrp, args)