From 021fdf69c8a649bfa98234bb1cf5b5dad0a1df0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristoffer=20Nordstr=C3=B6m?= Date: Thu, 12 Feb 2015 20:34:17 +0100 Subject: [PATCH 1/4] First cygwin version, no ACL support though. --- attic/platform.py | 7 +++++++ attic/xattr.py | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) mode change 100644 => 100755 attic/platform.py mode change 100644 => 100755 attic/xattr.py diff --git a/attic/platform.py b/attic/platform.py old mode 100644 new mode 100755 index 5e0ec917..c4661f7e --- a/attic/platform.py +++ b/attic/platform.py @@ -8,6 +8,13 @@ from attic.platform_freebsd import acl_get, acl_set, API_VERSION elif platform == 'Darwin': from attic.platform_darwin import acl_get, acl_set, API_VERSION +elif platform.startswith('CYGWIN'): + API_VERSION = 2 + + def acl_get(path, item, numeric_owner=False): + pass + def acl_set(path, item, numeric_owner=False): + pass else: API_VERSION = 1 diff --git a/attic/xattr.py b/attic/xattr.py old mode 100644 new mode 100755 index e0061015..04ce588e --- a/attic/xattr.py +++ b/attic/xattr.py @@ -36,7 +36,7 @@ def _check(rv, path=None): raise OSError(get_errno(), path) return rv -if sys.platform.startswith('linux'): +if sys.platform.startswith('linux') or sys.platform.startswith('cygwin'): libc.llistxattr.argtypes = (c_char_p, c_char_p, c_size_t) libc.llistxattr.restype = c_ssize_t libc.flistxattr.argtypes = (c_int, c_char_p, c_size_t) From f7552c83fa5b679fc8cb94e5ee2d450a077f04d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristoffer=20Nordstr=C3=B6m?= Date: Fri, 13 Feb 2015 01:31:33 +0100 Subject: [PATCH 2/4] Supporting ACL through (set|get)facl.exe system calls. --- attic/archive.py | 3 ++- attic/platform.py | 31 ++++++++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 4 deletions(-) mode change 100644 => 100755 attic/archive.py diff --git a/attic/archive.py b/attic/archive.py old mode 100644 new mode 100755 index d78ce4b8..7099f5a6 --- a/attic/archive.py +++ b/attic/archive.py @@ -353,7 +353,8 @@ def stat_attrs(self, st, path): b'mode': st.st_mode, b'uid': st.st_uid, b'user': uid2user(st.st_uid), b'gid': st.st_gid, b'group': gid2group(st.st_gid), - b'mtime': int_to_bigint(st_mtime_ns(st)) + b'mtime': int_to_bigint(st_mtime_ns(st)), + b'acl_access' : None } if self.numeric_owner: item[b'user'] = item[b'group'] = None diff --git a/attic/platform.py b/attic/platform.py index c4661f7e..64309b2d 100755 --- a/attic/platform.py +++ b/attic/platform.py @@ -1,4 +1,6 @@ import os +import subprocess +import io platform = os.uname()[0] @@ -11,10 +13,33 @@ elif platform.startswith('CYGWIN'): API_VERSION = 2 - def acl_get(path, item, numeric_owner=False): - pass + def acl_get(path, item, st, numeric_owner=False): + try: + # Using non-numeric names, i.e., group names, has caused problems. + # Hence the -n option + ACL_text = subprocess.check_output(['getfacl.exe', '-n', path]) + item[b'acl_access'] = ACL_text + except: + pass + def acl_set(path, item, numeric_owner=False): - pass + print ("acl_set()") + try: + ACL_Access = item[b'acl_access'] + except: + return + + buf = io.StringIO(ACL_Access.decode('utf-8')) + + for line in buf: + if len(line.strip()) > 0 and (not line.strip().startswith('#')): + param = ['setfacl.exe', '-m', line.rstrip(), path] + #print(' '.join(param)) + retVal = subprocess.call(param) + if retVal != 0: + print(retVal) + raise Exception('set ACL not successful') + else: API_VERSION = 1 From c667b1171589fd704e9745c6e9c6b830a0e3711f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristoffer=20Nordstr=C3=B6m?= Date: Sat, 21 Feb 2015 21:50:40 +0100 Subject: [PATCH 3/4] Removing unnecessary print statements. --- attic/platform.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/attic/platform.py b/attic/platform.py index 64309b2d..034606d7 100755 --- a/attic/platform.py +++ b/attic/platform.py @@ -23,7 +23,6 @@ def acl_get(path, item, st, numeric_owner=False): pass def acl_set(path, item, numeric_owner=False): - print ("acl_set()") try: ACL_Access = item[b'acl_access'] except: @@ -34,11 +33,9 @@ def acl_set(path, item, numeric_owner=False): for line in buf: if len(line.strip()) > 0 and (not line.strip().startswith('#')): param = ['setfacl.exe', '-m', line.rstrip(), path] - #print(' '.join(param)) retVal = subprocess.call(param) if retVal != 0: - print(retVal) - raise Exception('set ACL not successful') + raise Exception('ACLs not set successfully') else: API_VERSION = 1 From 2a72d44fd9ba434a1efeb4cda6a8aeb99602afb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristoffer=20Nordstr=C3=B6m?= Date: Sun, 31 May 2015 05:42:41 +0200 Subject: [PATCH 4/4] Fixing bare excepts and other pylint issues. For a proper win32 solution see http://timgolden.me.uk/python/win32_how_do_i/add-security-to-a-file.html --- attic/platform.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/attic/platform.py b/attic/platform.py index 034606d7..af02a54b 100755 --- a/attic/platform.py +++ b/attic/platform.py @@ -1,6 +1,7 @@ import os import subprocess import io +import logging platform = os.uname()[0] @@ -17,18 +18,18 @@ def acl_get(path, item, st, numeric_owner=False): try: # Using non-numeric names, i.e., group names, has caused problems. # Hence the -n option - ACL_text = subprocess.check_output(['getfacl.exe', '-n', path]) - item[b'acl_access'] = ACL_text - except: - pass + acl_text = subprocess.check_output(['getfacl.exe', '-n', path]) + item[b'acl_access'] = acl_text + except CalledProcessError as e: + logging.warning('getfacl.exe failed with error code: ' + e.returncode) def acl_set(path, item, numeric_owner=False): try: - ACL_Access = item[b'acl_access'] - except: - return - - buf = io.StringIO(ACL_Access.decode('utf-8')) + acl_access = item[b'acl_access'] + except KeyError: + return + + buf = io.StringIO(acl_access.decode('utf-8')) for line in buf: if len(line.strip()) > 0 and (not line.strip().startswith('#')): @@ -36,7 +37,7 @@ def acl_set(path, item, numeric_owner=False): retVal = subprocess.call(param) if retVal != 0: raise Exception('ACLs not set successfully') - + else: API_VERSION = 1