Files

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

51 lines
1.5 KiB
Python
Raw Permalink Normal View History

2011-10-21 14:01:48 -07:00
#!/usr/bin/env python
import os
2017-06-13 22:04:03 +02:00
import subprocess
import sys
2017-05-23 10:55:58 +02:00
# you may configure the paths below which modifications are allowed.
# should contain the full paths to job_working_directory and new_file_path.
# if set to None every file can be modified by the script.
# this can increase security in particular if write access to this
# script is removed by the admin.
2017-06-12 17:35:34 +02:00
#
2017-05-23 15:01:31 +02:00
# ALLOWED_PATHS = [ "job_working_directory", "new_file_path" ]
2017-06-12 17:35:34 +02:00
ALLOWED_PATHS = None
2011-10-21 14:01:48 -07:00
2017-06-13 22:04:03 +02:00
def validate_parameters():
2015-07-13 20:13:28 +01:00
if len(sys.argv) < 4:
2024-04-27 16:03:22 +01:00
sys.stderr.write(f"usage: {sys.argv[0]} path user_name gid\n")
2011-10-21 14:01:48 -07:00
exit(1)
2017-08-17 00:33:02 +01:00
path = os.path.abspath(sys.argv[1])
2017-06-12 17:35:34 +02:00
if ALLOWED_PATHS is None:
2017-05-23 10:55:58 +02:00
allowed = True
else:
allowed = False
for p in ALLOWED_PATHS:
2017-08-17 00:33:02 +01:00
if path.startswith(p):
2017-05-23 10:55:58 +02:00
allowed = True
break
if not allowed:
2024-04-27 16:03:22 +01:00
sys.stderr.write(f"owner and group modifications in {path} are not allowed\n")
2017-08-17 00:33:02 +01:00
sys.exit(1)
2017-05-23 10:55:58 +02:00
2015-07-13 20:13:28 +01:00
galaxy_user_name = sys.argv[2]
gid = sys.argv[3]
return path, galaxy_user_name, gid
2011-10-21 14:01:48 -07:00
def main():
2017-06-13 22:04:03 +02:00
path, galaxy_user_name, gid = validate_parameters()
2017-08-17 00:33:02 +01:00
for cmd in [["chown", "-Rh", galaxy_user_name, path], ["chgrp", "-Rh", gid, path]]:
2017-06-13 22:04:03 +02:00
p = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
2026-01-19 22:33:34 +00:00
stdoutdata, stderrdata = p.communicate()
exitcode = p.returncode
if exitcode != 0:
2024-04-27 16:03:22 +01:00
sys.exit("external_chown_script: could not chown\ncmd was {}\n".format(" ".join(cmd)))
2016-11-14 21:12:14 +00:00
2017-06-13 16:49:35 +02:00
2011-10-21 14:01:48 -07:00
if __name__ == "__main__":
main()