From d16348285127f638ae94aa91fdc94d6509d45af1 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Wed, 8 Apr 2020 22:30:21 +0200 Subject: vyos.util: introduce chmod_750() for files/directories --- python/vyos/util.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'python') diff --git a/python/vyos/util.py b/python/vyos/util.py index f1fb5ce27..385dc73df 100644 --- a/python/vyos/util.py +++ b/python/vyos/util.py @@ -103,6 +103,14 @@ def chown(path, user, group): gid = getgrnam(group).gr_gid os.chown(path, uid, gid) +def chmod_750(path): + """ make file/directory only executable to user and group """ + from stat import S_IRUSR, S_IWUSR, S_IXUSR, S_IRGRP, S_IXGRP + + if os.path.exists(path): + bitmask = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP + os.chmod(path, bitmask) + def chmod_x(path): """ make file executable """ -- cgit v1.2.3